Answer the question
In order to leave comments, you need to log in
What is the reason for the fact that the JVM is implemented as a stack VM?
Actually, subject. Why a stack implementation, and not, say, a register one? And what are the pros/cons?
Answer the question
In order to leave comments, you need to log in
The bytecode for the stack VM is more compact. And apparently it is easier to translate a stack code into a register code than a register code into another register code. Registered VMs are faster, but we must not forget that in Java, performance is provided by JIT translation, apparently the developers chose it because of the convenience of a registered VM. You yourself try to write a compiler - for a stack VM it's easier.
Among other things, it is worth remembering that cross-platform is extremely important for java. At the stage of compilation to bytecode, it is not clear which registers will be available at startup, so the stack is used. During JIT compilation, everything is known about the hardware, and it is easy to optimally scatter all the data over the available registers.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question