Java bytecode, java Supplier and invokedynamic argument -
i have class, , compile it.
package org.test; import java.util.function.supplier; public class test { static string get() { return "!!"; } public static void main(string[] args) { supplier<string> sup = test::get; system.out.println(sup.get()); } }
then, trying it's bytecode, following beginning of public static void main
function:
public static void main(java.lang.string[]); descriptor: ([ljava/lang/string;)v flags: acc_public, acc_static code: stack=2, locals=2, args_size=1 0: invokedynamic #3, 0 // invokedynamic #0:get:()ljava/util/function/supplier; 5: astore_1 6: getstatic #4 // field java/lang/system.out:ljava/io/printstream;
here can see invokedynamic call, which, if understand correctly, creates anonymous instance of supplier interface. passed invokedynamic 2 arguments, 1 #3. second argument 0. so, first question is: 0 stand here for?
in constant pool #3 stands #3 = invokedynamic #0:#27 // #0:get:()ljava/util/function/supplier;
. there reference #27 in constant pool, no reference #0. second question is: #0 stand here?
the #0
(which can see in comment next invokedynamic) index in bootstrapmethods
table. first question, 0
refers #0
. , in turn index of bootstrapmethods table. provides link between invokedynamic
call origin , targeted method.
if decompile javap -c -v filename
you see whole constant pool. (which assuming have done?). here should find reference #x methodhandle #y:#z iddl.bootstrapdynamic
. point bootstrapmethods table links to. handle #0
links to, should resolve static bootstrapdynamic()
method.
Comments
Post a Comment