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 5 of 5
invokevirtual instruction and resolves the symbolic reference to a direct reference to an instance method, that direct reference is likely
to be an offset into a method table. From that point forward, the same offset can be used. For an invokeinterface instruction, however, the virtual machine will have to search through the method table every single time the instruction
is encountered, because it can't assume the offset is the same as in previous invocations.The fastest instructions will most likely be invokespecial and invokestatic, because methods invoked by these instructions are statically bound. When the JVM resolves the symbolic reference for these
instructions and replaces it with a direct reference, that direct reference probably will include a pointer to the actual
bytecodes.
For example, the slowest kind of method to invoke traditionally has been the synchronized method, which takes about six times
as long as a non-synchronized method in Sun's 1.1 Java virtual machine. Sun has claimed that its next-generation virtual machine
will make synchronization "free." -- in other words, it will invoke a synchronized method as fast as a non-synchronized one.
Also, Sun's 1.1 virtual machine uses an "interface lookup table" to increase the execution speed of the invokeinterface instruction over that of its 1.0 virtual machine.
interface inYourFace {
void interfaceMethod ();
}
class itsABirdItsAPlaneItsSuperClass implements inYourFace {
itsABirdItsAPlaneItsSuperClass(int i) {
super(); // invokespecial (of an <init>)
}
static void classMethod() {
}
void instanceMethod() {
}
final void finalInstanceMethod() {
}
public void interfaceMethod() {
}
}
class subClass extends itsABirdItsAPlaneItsSuperClass {
subClass() {
this(0); // invokespecial (of an <init>)
}
subClass(int i) {
super(i); // invokespecial (of an <init>)
}
private void privateMethod() {
}
void instanceMethod() {
}
final void anotherFinalInstanceMethod() {
}
void exampleInstanceMethod() {
instanceMethod(); // invokevirtual
super.instanceMethod(); // invokespecial
privateMethod(); // invokespecial
finalInstanceMethod(); // invokevirtual
anotherFinalInstanceMethod(); // invokevirtual
interfaceMethod(); // invokevirtual
classMethod(); // invokestatic
}
}
class unrelatedClass {
public static void main(String args[]) {
subClass sc = new subClass(); // invokespecial (of an <init>)
subClass.classMethod(); // invokestatic
sc.classMethod(); // invokestatic
sc.instanceMethod(); // invokevirtual
sc.finalInstanceMethod(); // invokevirtual
sc.interfaceMethod(); // invokevirtual
inYourFace iyf = sc;
iyf.interfaceMethod(); // invokeinterface
}
| Opcode | Operand(s) | Description |
|---|
ireturn |
|
pop int, push onto stack of calling method and return |
lreturn |
|
pop long, push onto stack of calling method and return |
freturn |
|
pop float, push onto stack of calling method and return |
dreturn |
|
pop double, push onto stack of calling method and return |
areturn |
|
pop object reference, push onto stack of calling method and return |
return |
|
return void |
The ireturn instruction is used for methods that return int, char, byte, or short.
<init> methods, private methods, and methods invoked with the super keyword. In these three special cases, instance methods are statically bound.