Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 69 inside the jvm 5 astore_ 1 6 new 3 class java lang Thread 9 dup 10 aload_ 1 11 invokespecial 4 Method java lang Thread init Ljava lang Runnable V 14 astore_ 2 15 aload_ 2 16 invokevirtual 5 Method java lang Thread start V 19 aload_ 2 20 invokevirtual 6 Method java lang Thread join V 23 return The bytecode at ofset 0 indicates that some method is being called via invokedynamic and the return value of that call is placed upon the stack The rest of the bytecode in the method is a straightforward representation of the rest of the method How Invokedynamic Operates At this point I should discuss some of the details of the nature of invokedynamic and how the opcode operates When a class containing an invokedynamic instruction is loaded by the class loader the target of the method invocation is not known ahead of time This design difers from all other types of call sites in JVM bytecode For example in the case of invokestatic and invokespecial sites which I discussed in the previous article the exact implementation method referred to as the call target is known at compile time In the case of invokevirtual and invokeinterface the call target is determined at runtime However the target selection is subject to the constraints of the Java language inheritance rules and type system As a result at least some call target information is known at compile time In contrast invokedynamic is far more flexible about which method will actually be called when the opcode is dispatched To allow for this flexibility invokedynamic opcodes refer to a
You must have JavaScript enabled to view digital editions.