Question

Why is the JVM a stack based virtual machine? What exactly does that mean and what are the advantages over register based virtual machines? Are there any other major design / implementation choices for virtual machine builders?

Was it helpful?

Solution

A stack based virtual machine is very simple, both as a concept and to implement. Just about anyone with a CS background can implement a simple fully functional VM in a few hundred lines of code.

You can think of the stack as an arbitrary large number of registers if the need arises. Adding registers from the start would be pre-mature optimization.

A simple concept then makes it simpler to do real magic like Hotspot on top of the model. That's not simple, but you can choose the level of complexity based on your ability from a straight interpreter to a simple JIT to Hotspot.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top