Implementations Shijie Xu1 David Bremner1 Daniel Heidinga2 1IBM Centre for Advanced Studies (CAS Atlantic) University of New Brunswick, Canada 2IBM Ottawa, Canada July 18, 2016
executable reference to an underlying method, field, constructor, or similar low level operation, with optional transformations of arguments and return values1. MethodHandle g = lookup () . f i n d V i r t u a l ( S t r i n g .class, ” isEmpty ” , methodType ( boolean.class) ) ; MethodHandle gwt = MethodHandles . guardWithTest (g , t , f ) ; MethodType: argument types and return type. Executable reference. Method Type Transformation. e.g., GuardWithTest, CatchException, FilterReturn. 1 https://docs.oracle.com/javase/7/docs/api/java/lang/invoke/MethodHandle.html
S i t e bootstrapMethod ( . . . ) { C a l l S i t e cs = . . MethodHandle g = lookup () . f i n d V i r t u a l ( S t r i n g .class, ” isEmpty ” , methodType ( boolean.class) ) ; MethodHandle t = lookup () . f i n d S t a t i c (Some , ” addGoogle ” , methodType ( S t r i n g . class, S t r i n g .class) ) ; //Append google to the t a i l . MethodHandle f = lookup () . f i n d S t a t i c ( Other , ”addYahoo” , methodType ( S t r i n g . class, S t r i n g .class) ) ; //Append yahoo to the t a i l . MethodHandle gwt = MethodHandles . guardWithTest (g , t , f ) ; MethodHandle d0 = MethodHandles . f i l t e r R e t u r n ( gwt , f ) ; cs . setTarget ( d0 ) ; return cs ; }
MHG a’ MHG b’ MHG c’ native code native code native code 10 10 10 30 30 30 MHG b MHG c 10 MHG a X 10 native code 10 jit X No deduplication With Deduplication jit No Jit No Jit No Jit Case 1 Case 2 10 + +10=30
optional data} It represents a method handle about to be created. It has all parameters (i.e., method type, children, and other necessary data if present).
index key. Compare the index key to the existing MHs in the pool recursively. Create the method handle for the index key and add it to the pool if comparison false.
index key’s transformation. For each MHObject, compare its children to those of the index key. Fast comparison path: see if both a child MH of an index key and a child of the MH in the pool are the same instance.