and stored into the compiler’s Constant Pool data structure, the JVM bytecodes related to the
operation of the function are written to another temporary file dedicated for function declarations.
Then the identifier name of the function, along with the Constant Pool reference information, the
JVM bytecodes needed to to “prepare” for the execution of this function, the JVM bytecodes
needed to execute this function after all the arguments needed to pass into this function have been
pushed on to the frame (also known as the Java Operand Stack), and other Constant Pool entries
needed for the JVM to execute the function, are added in to the symbol table.
If a local variable declaration is parsed out within a function, the code generator only needs
to increment the total number of other local variables previously declared plus the number of
arguments of the function.
3
This number becomes the reference index to access this local variable
in the future. The code generator would then add the variable identifier name along with the
reference index into the symbol table.
Most of the JVM bytecode related to frame operations and instructions operate similarly to the
assembly language instructions of other machine platforms. The JVM allocates a frame (or Java
Operand Stack) for each function call. Most of the bytecodes of a particular function pops values
from the Operand Stack, operates on the values, and then returns a result to that same Operand
Stack. A majority of the bytecode instructions make some use of the Operand Stack, including
function invoking bytecode which pops the passing arguments (which passes by value) from the
Operand Stack.
One of the main differences between generating code for the JVM and other stack-based machine
platforms comes from the JVM’s method of memory management and the way its program counter
operates. Although similar to the other machine platforms in that the JVM is also stack and
heap based and allocates frames (Java Operand Stacks) upon function calls, the JVM is also quite
different since it performs all the memory managements automatically within the virtual machine
and does not allow others to directly access, make changes in, or allocate memory. Since the
allocation of memory for the stack, heap, and frames are all performed automatically by the JVM,
the code generator does not need (nor is it allowed) to generate code that explicitly move or store the
old stack or frame pointers upon invoking a function. The code generator only needs to generate
3
Assuming the local variable is of type int which is 4 bytes or one word wide. Future implementations of types
long and double would require incrementing the total count by tw o since they are t wo words wide.
10