What are CONSTANT_MethodHandle, CONSTANT_MethodType and CONSTANT_InvokeDynamic?

I studied how Java bytecode works, and I started working on Wikipedia. On the page dedicated to the file .class, it mentions 11 constant types that appear in the constant pool. However, the Java Virtual Machine Specification (JVMS) mentions 3 more:

  • CONSTANT_MethodHandle
  • CONSTANT_MethodType
  • CONSTANT_InvokeDynamic

The 11 mentioned on the Wikipedia page seem pretty clear, and I understand their purpose and use. However, I am confused by the 3 additional ones described in the JVMS. What are they and what are they used for?

+4
source share
2

Handle "" . . MethodType - , MethodHandle. , . Handle .

, java.lang.invoke.MethodHandle java.lang.invoke.MethodType. Java 7. - LDC MethodHandle_info MethodType_info , JVM MethodHandle MethodType .

invokedynamic bytecode MethodHandle. bootstrap , , Handle. invoke, . , . Java 8 -.

+3

. Java® 4. :

CONSTANT_MethodHandle_info :

CONSTANT_MethodHandle_info {
    u1 tag;
    u1 reference_kind;
    u2 reference_index;
}

CONSTANT_MethodType_info :

CONSTANT_MethodType_info {
    u1 tag;
    u2 descriptor_index;
}

CONSTANT_InvokeDynamic_info (§invokedynamic) , , , , , .

CONSTANT_InvokeDynamic_info {
    u1 tag;
    u2 bootstrap_method_attr_index;
    u2 name_and_type_index;
}

. invokedynamic MethodHandle

+3