Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jvm word size and operand stack

Tags:

java

jvm

The JVM specification says that the jvm operand stack works in units of word-size, which in many implementations is the size of the native pointer - 4 bytes for 32-bit systems and 8 bytes for 64-bit systems. My question is, if the operand that is being pushed onto the stack is char (2 bytes) and the operand stack pushes and pops off operands in units of word size (8 bytes in 64-bit systems), then is that not a waste of space?

like image 628
BestCoderEver Avatar asked Aug 01 '15 21:08

BestCoderEver


1 Answers

Yes it is "wasted space", but it simplifies the runtime immensely, plus the word sizes match the CPU they're built on, so while a waste of space, they're actually more efficient in terms of CPU processing.

And it's also just for runtime parameters, vs actual stored data.

Finally, if you look at most Java programs, the bulk of what they pass is pointers to objects, rather than scalars anyway. So it all pretty much works out in the wash.

like image 67
Will Hartung Avatar answered Sep 22 '22 02:09

Will Hartung