Java Reference
In-Depth Information
suppose a method
is invoked on an object of actual type t .Ifthat
method is resolved in class s ,then s must be a superclass of t (if s = t ,then s
is a nonproper superclass of t , so the definitionworks). If s . foo( ) invokes
amethod
foo
using super . bar( ), then the search for an appropriate bar
begins at the first proper superclass of s (i.e., the parent of s in the object
hierarchy).
bar
The invokespecialmethodcanalsobeusedtoinvokeaprivatemethod,
but this appears to be for e
ciency reasons only. A private method
cannot be overriden, so there is no reason to employ a virtual method
dispatch. Such methods should be invokable using invokevirtual as
well.
Stack Operations
The JVM provides some instructions specifically for manipulating items near
the TOS. Such instructionsmay seemsuperfluous, in that they can be simulated
using other instructions and registers. They are included to facilitate shorter
instruction sequences for common program fragments.
dup
The example depicts the duplication of the cell at TOS.
The instruction works for any 32-bit type (i.e., all types
except long and double). There is a dup2 instruction
that duplicates the top two cells to accommodate long
and double types.
Before
After
The dup instructionnicely accommodatesmultiple assignments (x=y=z=value).
It is also useful for constructing new objects. The new t instruction leaves a
reference on TOS to the newly allocated storage of type t , but that storage can-
not be accessed until a constructor has been invoked. Constructors consume
the reference to the allocated storage (along with their other parameters), but
they return nothing (they are void). Thus, to remember the reference, the TOS
is usually duped before the constructor invocation sequence is generated.
Other stack-manipulating instructions include pop and swap,whichare
self-explanatory. However, there are other instructions whose application
may not be obvious.
 
Search WWH ::




Custom Search