Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 70 inside the jvm special attribute in the constant pool of the class that contains the dynamic invocation This attribute contains additional information to support the dynamic nature of the call called bootstrap methods BSMs These are a key part of invokedynamic and every invokedynamic call site has a constant pool entry for a corresponding BSM To allow the association of a BSM to a specific invokedynamic call site a new entry type also called InvokeDynamic has been added to the class file format as of Java 7 The call site of the invokedynamic instruction is said to be unlaced at class loading time The BSM is called to determine what method should actually be called and the resulting CallSite object will then be laced into the call site In the simplest case that of a One important difference between method handles and reflection is that lookup contexts return only methods that were accessible from the scope where the lookup object was created which means they are safe to use under all circumstances ConstantCallSite as soon as the lookup has been done once it will not need to be repeated Instead the target of the call site will be directly called on all future invocations without any further work This means that the call site is now stable and is therefore friendly to other JVM subsystems such as the just in time JIT compiler For this mechanism to work eficiently the JDK must contain suitable types to represent the call site the BSMs and other parts of the implementation Javas original core reflection types are capable of representing methods and types However the API dates from the very early days of the Java platform and has several aspects that make it a less than ideal choice For example reflection predates both collections and generics As a result method signatures are represented by Class in the Reflection API This can be cumbersome and errorprone and it is hampered by the verbose nature of Javas array syntax It is further complicated by the need to manually box and unbox primitive types and to work around the possibility of void methods
You must have JavaScript enabled to view digital editions.