Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 2 of 5
Adding a new frame onto the Java stack when a method is invoked is called "pushing" a stack frame; removing a frame when a method returns is called "popping" a stack frame. The Java stack is made up solely of these frames.
In the case of an instance method, the virtual machine pops the objectref and args from the operand stack of the calling method's
stack frame. The JVM creates a new stack frame and places the objectref on the new stack frame as local variable 0, and all
the args as local variable 1, 2, and so on. The objectref is the implicit this pointer that is passed to any instance method.
For a class method, the virtual machine just pops the args from the operand stack of the calling method's frame and places them onto the new stack frame as local variable 0, 1, 2, and so on.
Once the objectref and args (or just the args, for a class method) have been placed into the local variables of the new frame, the virtual machine makes the new stack frame current and sets the program counter to point to the first instruction in the new method.
The JVM specification does not require a particular implementation for the Java stack. Frames could be allocated individually from a heap, or they could be taken from contiguous memory, or both. If two frames are contiguous, however, the virtual machine can just overlap them such that the top of the operand stack of one frame forms the bottom of the local variables of the next. In this scheme, the virtual machine need not copy objectref and args from one frame to another, because the two frames overlap. The operand stack word containing objectref in the calling method's frame would be the same memory location as local variable 0 of the new frame.
instance methods normally are invoked with invokevirtual, two other opcodes are used to invoke this kind of method in certain situations: invokespecial and invokeinterface.Invokespecial is used in three situations in which an instance method must be invoked based on the type of the reference, not on the class
of the object. The three situations are: