Jvm word size and operand size

The JVM specification states that the jvm operand stack works in units of word size, which in many implementations is the size of the built-in pointer - 4 bytes for 32-bit systems and 8 bytes for 64-bit systems. My question is that if the operand that is inserted on the stack is char (2 bytes), and the operand stack pushes and pops the operands in units of word size (8 bytes in 64-bit systems), is this not a waste of space?

+4
source share
2 answers

Yes, this is a "lost space", but it greatly simplifies the execution time, and the size of the words corresponds to the processor on which they are built, therefore, while a waste of space, they are actually more efficient in terms of processing the processor.

And it is also simple for runtime parameters as well as actual stored data.

Finally, if you look at most Java programs, the bulk of what they pass in anyway points to objects, not scalars. So all this works very well in the wash.

+7
source

The Java Virtual Machine is an abstraction, a model that describes the execution of Java programs. Actual JVM implementations, such as the Oracle JDK JSM HotSpot, can allocate the Java stack stack anywhere or anywhere.

eg. in the JIT-compiled method, some operands can be stored in CPU registers or even processed as immediate constants, and not occupy the real stack space. Moreover, the built-in methods do not have their own stack frame; they share the parent frame.

So no, this is not a waste, because the specification does not impede the implementation of the optimized presentation JVM. Although JVMs are not usually taken care of: stack space is usually not a limiting factor - the stack contains mostly a small amount of temporary values, while the actual data is in the Java Heap.

+1
source

All Articles