next up previous contents
Next: The Java Class Up: Internals of the Previous: Runtime Data Areas

Frames

 

The JVM stack is divided into frames. A new frame is created each time a method is invoked. A frame is destroyed when its method completes. Each frame contains space allocated for local variables and an operand stack.

The local variables are stored into an array of words. Each local variable is one word wide, except for variables of type long or double which need two words. Local variables are addressed as word offsets from the base of the array.

The operand stack of a frame is the place where JVM instructions take their values from and return their results to. It is also used to pass arguments to methods and receive method results. Each entry on the operand stack is one word wide. Values of type long or double are pushed onto the operand stack as two words. Values on the operand stack must be operated on according to their types. Most of the JVM instructions that operate on the operand stack are only allowed to operate on one type; it is incorrect to let them operate on any type other than the allowed type. If this is done, the JVM should give an error complaining about it. This also means for example that it is not allowed to push two values of type int onto the stack and treat them as a double.

At any point in a thread of control there is only one frame that is active, the current frame. This is because there can only be one active method at any point, the current method. When a method returns, it passes its method result, if any, back to the previous frame, the one of the calling method. The frame of the returning method is then destroyed.



next up previous contents
Next: The Java Class Up: Internals of the Previous: Runtime Data Areas



mark@bottom.xs4all.nl