• Home
    • View
    • Login
    This page
    • Normal
    • Export PDF
    • Page Information

    Loading...
  1. Dashboard
  2. Undefined Space
  3. HotSpot
  4. Support pre-generated MethodHandle LambdaForms in CDS (JDK-8247536)

Support pre-generated MethodHandle LambdaForms in CDS (JDK-8247536)

  • Created by Ioi Lam, last modified on Jun 15, 2020

Goal

Improve start-up time by storing pre-generated LambdaForm handlers in an application-specific CDS archive.

Background

In JDK-8086045 Improve the java.lang.invoke first initialization costs, the JDK can reduce the number of dynamically generated LambdaForm  classes. Here's an example:

# Do this in your JDK build directory.
# The exploded JDK build:
$ jdk/bin/javac -J-verbose ~/tmp/HelloWorld.java | grep LambdaForm | grep __JVM_LookupDefineClass__ 
[0.142s][info][class,load] java.lang.invoke.LambdaForm$MH/0x0000000800066c40 source: __JVM_LookupDefineClass__
[0.143s][info][class,load] java.lang.invoke.LambdaForm$DMH/0x0000000800066040 source: __JVM_LookupDefineClass__
[0.143s][info][class,load] java.lang.invoke.LambdaForm$MH/0x0000000800066440 source: __JVM_LookupDefineClass__
[snip]

$ jdk/bin/javac -J-verbose ~/tmp/HelloWorld.java | grep LambdaForm | grep __JVM_LookupDefineClass__ | wc
    102     408   11400


# The final JDK image: 
$ images/jdk/bin/javac -J-verbose ~/tmp/HelloWorld.java | grep LambdaForm | grep __JVM_LookupDefineClass__ |  wc
     34     136    3800

Here's the difference between the exploded build and the final image:

$ jdk/bin/javap 'java.lang.invoke.DirectMethodHandle$Holder'
Compiled from "DirectMethodHandle.java"
final class java.lang.invoke.DirectMethodHandle$Holder {
  final java.lang.invoke.DirectMethodHandle this$0;
  java.lang.invoke.DirectMethodHandle$Holder(java.lang.invoke.DirectMethodHandle);
}


$ images/jdk/bin/javap 'java.lang.invoke.DirectMethodHandle$Holder'
Compiled from "DirectMethodHandle$Holder"
final class java.lang.invoke.DirectMethodHandle$Holder {
  static int invokeInterface(java.lang.Object, java.lang.Object, java.lang.Object);
  static java.lang.Object invokeSpecial(java.lang.Object, java.lang.Object, java.lang.Object, int);
  static java.lang.Object invokeSpecial(java.lang.Object, java.lang.Object, java.lang.Object, long);
  [~150 more lines ...]
}

The JDK image's version of the java.lang.invoke.DirectMethodHandle$Holder class is generated here in GenerateJLIClassesPlugin.java. This plugin is executed when we generate the file images/jdk/lib/modules.

private static final String DIRECT_HOLDER = "java/lang/invoke/DirectMethodHandle$Holder";
...
 byte[] bytes = JLIA.generateDirectMethodHandleHolderClassBytes(
                    DIRECT_HOLDER, directMethodTypes, dmhTypes);

The input of generateDirectMethodHandleHolderClassBytes comes from the default_jli_trace.txt file that is generated in GenerateLinkOptData.gmk:

	$(FIXPATH) $(INTERIM_IMAGE_DIR)/bin/java -XX:DumpLoadedClassList=$@.raw.2 \
	    -XX:SharedClassListFile=$@.interim -XX:SharedArchiveFile=$@.jsa \
	    -Djava.lang.invoke.MethodHandle.TRACE_RESOLVE=true \
	    -Duser.language=en -Duser.country=US \
	    --module-path $(SUPPORT_OUTPUTDIR)/classlist.jar \
	    -cp $(SUPPORT_OUTPUTDIR)/classlist.jar \
	    build.tools.classlist.HelloClasslist \
	    2> $(LINK_OPT_DIR)/stderr > $(JLI_TRACE_FILE)

Here's how roughly the contents of default_jli_trace.txt correspond to the generated methods in DirectMethodHandle$Holder

$ grep invokeSpecialIFC ./support/link_opt/default_jli_trace.txt
[LF_RESOLVE] java.lang.invoke.DirectMethodHandle$Holder invokeSpecialIFC L3I_I (fail)
[LF_RESOLVE] java.lang.invoke.DirectMethodHandle$Holder invokeSpecialIFC LLI_I (fail)

$ images/jdk/bin/javap  'java.lang.invoke.DirectMethodHandle$Holder' | grep invokeSpecialIFC
  static int invokeSpecialIFC(java.lang.Object, java.lang.Object, java.lang.Object, int);
  static int invokeSpecialIFC(java.lang.Object, java.lang.Object, int);

The methods in DirectMethodHandle$Holder are used in InvokerBytecodeGenerator.java when compiling for LambdaForms:

    private static MemberName lookupPregenerated(LambdaForm form, MethodType invokerType) {
        if (form.customized != null) {
            // No pre-generated version for customized LF
            return null;
        }
        String name = form.kind.methodName; 
        switch (form.kind) {
            [......]
            case DIRECT_INVOKE_INTERFACE:   // fall-through
            case DIRECT_INVOKE_SPECIAL:     // fall-through
            case DIRECT_INVOKE_SPECIAL_IFC: // fall-through
            case DIRECT_INVOKE_STATIC:      // fall-through
            case DIRECT_INVOKE_STATIC_INIT: // fall-through
            case DIRECT_INVOKE_VIRTUAL:     return resolveFrom(name, invokerType, DirectMethodHandle.Holder.class);
        }
        return null;




Overview
Content Tools
ThemeBuilder
  • No labels

Terms of Use
• License: GPLv2
• Privacy • Trademarks • Contact Us

Powered by a free Atlassian Confluence Open Source Project License granted to https://www.atlassian.com/software/views/opensource-community-additional-license-offer. Evaluate Confluence today.

  • Kolekti ThemeBuilder Powered by Atlassian Confluence 8.5.23
  • Kolekti ThemeBuilder printed.by.atlassian.confluence
  • Report a bug
  • Atlassian News
Atlassian
Kolekti ThemeBuilder EngineAtlassian Confluence
{"serverDuration": 143, "requestCorrelationId": "5eae1367055e6f88"}