Java Magazine, September/October 2017
OPCODE NAME ARGUMENTS DESCRIPTION invokevirtual b0 b1 INVOKES THE METHOD FOUND AT CP C1 VIA VIRTUAL DISPATCH invokespecial b0 b1 INVOKES THE METHOD FOUND AT CP C1 VIA SPECIAL THAT IS EXACT DISPATCH invokeinterface b0 b1 x0 00 INVOKES THE INTERFACE METHOD FOUND AT CP C1 USING INTERFACE OFFSET LOOKUP invokestatic b0 b1 INVOKES THE STATIC METHOD FOUND AT CP C1 invokedynamic b0 b1 00 00 DYNAMICALLY LOOKS UP WHICH METHOD TO INVOKE AND CALLS IT Table 1 JVM bytecodes for invoke methods ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2017 47 java 9 invokeinterface even though the same method is being called Once again the return value from put is discarded via the pop at instruction 35 So far youve seen that invokestatic invokevirtual or invokeinterface can be produced by the Java compiler depending on the context of the call JVM Bytecodes for Invoking Methods Lets take a look at all the five JVM bytecodes that can be used to invoke methods see Table 1 In each case the bytes b0 and b1 are combined into the constant pool ofset represented by c1 It can be a useful exercise to write some Java code to see what circumstances produce each form of the bytecodes by disassembling the resulting Java class with javap The most common type of method invocation is invokevirtual which refers to virtual dispatch The term virtual dispatch means that the exact method to be invoked is determined at runtime To facilitate this you need to know that each class present in a running application has an area of memory inside the JVM that holds metadata corresponding to that type This area is called a klass in Java HotSpot VM at least and can be thought of as the JVMs representation of information about the type In Java 7 and earlier the klass metadata lived in an area of the Java heap called permgen Because objects within the Java heap must have an object header called an oop the klasses
You must have JavaScript enabled to view digital editions.