Java Reference
In-Depth Information
invokestatic
The Math.pow static method is called using the Jasmin
notation
3.0
invokestatic java/lang/Math/pow(DD)D
2.0
8.0
which specifies the full path to the method and also
contains the signature of the method.
In the example, two values (2
0) are popped
andsuppliedtotheMath.pow static method as its first
and second parameters, respectively. When Math.pow
completes, its result (8
.
0and3
.
.
0) is pushed on TOS.
Before
After
From the above example, it should be clear that a method's parameters are
pushed on the stack in left-to-right order. If a static method takes n parameters,
then its n
th parameter is on TOS just as the method is called.
For a method signature , the symbols between the parentheses indicate the
method's input parameter types, using the notation described in Figure 10.4.
In the above example, two double parameters ((DD)) are expected. Amethod's
return type is specified just after the parentheses. In the above example, the
return type is also double.
Although the Jasmin notation shows the method and its signature as part
of the invokestatic instruction, the method and signature descriptive infor-
mation is actually held in the constant pool. The invokestatic instruction
occupies 3 bytes, with the second two bytes forming an ordinal index into the
constant pool.
Instance-Specific Method Calls
An instance-specific method, such as PrintStream.print(),isinvokedina
manner similar to invokestatic with the following di
ff
erences:
Because the method is instance-specific, an instance must be pushed on
the stack before the method's parameters. The instance becomes this
inside the called method.
The invokevirtual operator is used instead of invokestatic.
Thus, an instance-specificmethod formally declaring that it takes n parameters
( p 1 , p 2 ,... p n ) actually takes n +
1 parameters where p 0 is e
ff
ectively the called
method's this .
 
Search WWH ::




Custom Search