Skip to content

Conversation

@iklam
Copy link
Member

@iklam iklam commented Oct 10, 2022

The @lambda-form-invoker lines in the default classlist ($JAVA_HOME/lib/classlist) control what lambda-form invoker methods are added to these classes that are generated during a CDS dump (see here):

  • java.lang.invoke.Invokers$Holder
  • java.lang.invoke.DirectMethodHandle$Holder
  • java.lang.invoke.DelegatingMethodHandle$Holder
  • java.lang.invoke.LambdaForm$Holder

The list of these invoker methods is generated as part of the JDK build process. They are used for invoking MethodHandles of commonly-used types, so that we can avoid generating custom LambdaForm classes.

When a CDS archive is created with a non-default classlist, (e.g., -XX:SharedClassListFile=foo.classlist), such a classlist may not contain all the @lambda-form-invoker lines as in the default classlist. As a result, at runtime, more custom LambdaForm classes may be generated than necessary.

The solution is to always load the @lambda-form-invoker lines from the default classlist, to make sure the CDS image has all the commonly-used invoker methods.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8295102: Always load @lambda-form-invoker lines from default classlist

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/10639/head:pull/10639
$ git checkout pull/10639

Update a local copy of the PR:
$ git checkout pull/10639
$ git pull https://git.openjdk.org/jdk pull/10639/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10639

View PR using the GUI difftool:
$ git pr show -t 10639

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/10639.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 10, 2022

👋 Welcome back iklam! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Oct 10, 2022

@iklam The following label will be automatically applied to this pull request:

  • hotspot-runtime

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Oct 10, 2022
@iklam iklam marked this pull request as ready for review October 11, 2022 02:15
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 11, 2022
@mlbridge
Copy link

mlbridge bot commented Oct 11, 2022

Webrevs

@dholmes-ora
Copy link
Member

Seems to me this is edging towards a scheme where the user-defined classlist is to be used to augment the default one, rather than being a complete replacement. Either the classlist should be the one-true-source for the classes to include in the archive, or else you need a way to express that you want to use it in union with the default list (to some extent), but not just (seemingly arbitrarily) decide that a special subset of classes should always be included even if missing from the classlist.

@iklam
Copy link
Member Author

iklam commented Oct 11, 2022

Seems to me this is edging towards a scheme where the user-defined classlist is to be used to augment the default one, rather than being a complete replacement. Either the classlist should be the one-true-source for the classes to include in the archive, or else you need a way to express that you want to use it in union with the default list (to some extent), but not just (seemingly arbitrarily) decide that a special subset of classes should always be included even if missing from the classlist.

This PR doesn't add extra classes into the archive. It just adds methods to the four Holder classes listed in the PR's description. In fact, these 4 classes (as stored in the JDK's module image) are generated at JDK build time to contain commonly used invoker methods. See GenerateLinkOptData.gmk.

The intention of the @lambda-form-invoker lines in the classlist is to add extra invoker methods into these holder classes (according to the app's profile) to avoid runtime generation of LambdaForm classes. Therefore, when dumping the archive, these 4 classes are regenerated and populated with methods specified by the @lambda-form-invoker lines.

However, the application's profile may use only a small number of invoker methods. As a result, if we just depend on the app's profile, the regenerated Holder classes, which are stored in the CDS archive, will be missing some invoker methods that are in JDK's module image.

These missing methods cause the following problems

  • Excessive LambdaForm classes may be generated at runtime if the app executes code outside of its profile
  • It will cause complication in future CDS optimizations (e.g., JDK-8293336)

The default classlist (also generated by GenerateLinkOptData.gmk) contains the @lambda-form-invoker lines to regenerate the exact same set of methods as in the JDK's module image (this is checked by the new test case). By always loading these lines, we can guarantee that when a Holder class is stored in the CDS archive, it will not be missing any of the methods that are in the modules image.

@iklam
Copy link
Member Author

iklam commented Oct 11, 2022

@dholmes-ora
Copy link
Member

Sorry this was an aspect of archive generation that I was not aware of - and I still don't really grok the full picture here.

Comment on lines 765 to 775
if (a.length > b.length) {
throw new RuntimeException("Output mismatch on line :" + max
+ ", a=" + a[max]
+ ", b=<none>");

}
if (a.length < b.length) {
throw new RuntimeException("Output mismatch on line :" + max
+ ", a=<none>"
+ ", b=" + b[max]);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these checks be done before the "for" loop at line 756? Otherwise, could one of the array be indexed out-out-bound?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding the bug. I have fixed it in version 2e6af77. I also tested locally with this code:

String[] a = {"1", "2"}, b = {"1"};
TestCommon.linesMustMatch(a, b);

which correctly produces this error:

java.lang.RuntimeException: Output mismatch on line 1: a=2, b=<none>

Copy link
Member

@cl4es cl4es left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch ensures that the methods in the LF holder classes at least contain the set of methods as generated by jlink at build, which seems to me to be reasonable to hold as an invariant to avoid surprises at runtime. (Does resolving a LF from a holder does trigger emitting a @lambda-form-invoker line when generating the classlist?)

@openjdk
Copy link

openjdk bot commented Oct 12, 2022

@iklam This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8295102: Always load @lambda-form-invoker lines from default classlist

Reviewed-by: redestad, ccheung

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 46 new commits pushed to the master branch:

  • 1961e81: 8289509: Improve test coverage for XPath Axes: descendant, descendant-or-self, following, following-sibling
  • 5699041: 8294772: Remove workaround in os::dll_address_to_library_name
  • d125265: 8277970: Test jdk/sun/security/ssl/SSLSessionImpl/NoInvalidateSocketException.java fails with "tag mismatch"
  • 0475c34: 8292386: jvmti/thread/SuspendThread/suspendthrd03 failed with "FAIL: Status is 2"
  • 760a260: 8295213: Run GHA manually with user-specified make and configure arguments
  • 8402260: 8295198: Update more openjdk.java.net => openjdk.org URLs
  • c357b59: 8295211: Fix autoconf 2.71 warning "AC_CHECK_HEADERS: you should use literals"
  • 8607842: 8295205: Add jcheck whitespace checking for markdown files
  • cb62f1c: 8295218: New KeepAliveTest.java has invalid copyright notice
  • 9cf6651: 8294238: ZGC: Move CLD claimed mark clearing
  • ... and 36 more: https://git.openjdk.org/jdk/compare/eb90c4fc0479379c8c1452afca8f37746c762e18...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 12, 2022
Copy link
Member

@calvinccheung calvinccheung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updates look good. Thanks.

@iklam
Copy link
Member Author

iklam commented Oct 12, 2022

This patch ensures that the methods in the LF holder classes at least contain the set of methods as generated by jlink at build, which seems to me to be reasonable to hold as an invariant to avoid surprises at runtime. (Does resolving a LF from a holder does trigger emitting a @lambda-form-invoker line when generating the classlist?)

The @lambda-form-invoker lines are generated in MethodHandleStatics.java::traceLambdaForm() when LambdaForms are being resolved:

static void traceLambdaForm(String name, MethodType type, Class<?> holder, MemberName resolvedMember) {
if (TRACE_RESOLVE) {
System.out.println("[LF_RESOLVE] " + holder.getName() + " " + name + " " +
shortenSignature(basicTypeSignature(type)) +
(resolvedMember != null ? " (success)" : " (fail)"));
}
if (CDS.isDumpingClassList()) {
CDS.traceLambdaFormInvoker("[LF_RESOLVE]", holder.getName(), name, shortenSignature(basicTypeSignature(type)));
}
}

This is the same place where GenerateLinkOptData.gmk gathers information for generating the Holder classes for the JDK's module image.

Copy link
Member

@calvinccheung calvinccheung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test changes look good.

@iklam
Copy link
Member Author

iklam commented Oct 12, 2022

Thanks to @calvinccheung and @cl4es for the review.
/integrate

@openjdk
Copy link

openjdk bot commented Oct 13, 2022

Going to push as commit 90fb9a0.
Since your change was applied there have been 47 commits pushed to the master branch:

  • ac19414: 8294994: Update Jarsigner and Keytool i18n tests to validate i18n compliance
  • 1961e81: 8289509: Improve test coverage for XPath Axes: descendant, descendant-or-self, following, following-sibling
  • 5699041: 8294772: Remove workaround in os::dll_address_to_library_name
  • d125265: 8277970: Test jdk/sun/security/ssl/SSLSessionImpl/NoInvalidateSocketException.java fails with "tag mismatch"
  • 0475c34: 8292386: jvmti/thread/SuspendThread/suspendthrd03 failed with "FAIL: Status is 2"
  • 760a260: 8295213: Run GHA manually with user-specified make and configure arguments
  • 8402260: 8295198: Update more openjdk.java.net => openjdk.org URLs
  • c357b59: 8295211: Fix autoconf 2.71 warning "AC_CHECK_HEADERS: you should use literals"
  • 8607842: 8295205: Add jcheck whitespace checking for markdown files
  • cb62f1c: 8295218: New KeepAliveTest.java has invalid copyright notice
  • ... and 37 more: https://git.openjdk.org/jdk/compare/eb90c4fc0479379c8c1452afca8f37746c762e18...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Oct 13, 2022
@openjdk openjdk bot closed this Oct 13, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Oct 13, 2022
@openjdk
Copy link

openjdk bot commented Oct 13, 2022

@iklam Pushed as commit 90fb9a0.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants