Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8309390: [JVMCI] improve copying system properties into libgraal #14291

Closed
wants to merge 6 commits into from

Conversation

dougxc
Copy link
Member

@dougxc dougxc commented Jun 2, 2023

This PR reduces the amount of code executed during libgraal initialization. This not only improves VM startup overall but all fixes a number of JDK test failures that are caused by Java code executing "too early". For example, java/util/Locale/CompatWarning.java can fail if sun.util.locale.provider.LocaleProviderAdapter is initialized before the CheckWarning handler is registered.

Instead of serializing VM.savedProps via VMSupport.serializeSavedPropertiesToByteArray, the jdk.vm.ci.services.Services class now directly reads Arguments::system_properties() using Unsafe. Furthermore, the value of a system property is lazily converted to a String from a C string pointer.

Times

The basic benchmarking below shows that this change brings the time for a nop Java app with eager libgraal initialization (2) down to almost the same time as lazy libgraal initialization (1). The latter typically means no libgraal initialization happens as a top tier JIT compilation is never scheduled in such a short running app.

public class Nop {
    public static void main(String[] args) {}
}

(1) Baseline (no options):

> for i in (seq 10); java Nop; end
        0.05 real         0.04 user         0.01 sys
        0.04 real         0.03 user         0.01 sys
        0.04 real         0.03 user         0.01 sys
        0.04 real         0.03 user         0.01 sys
        0.03 real         0.03 user         0.00 sys
        0.04 real         0.03 user         0.01 sys
        0.04 real         0.03 user         0.00 sys
        0.03 real         0.03 user         0.00 sys
        0.04 real         0.03 user         0.01 sys
        0.03 real         0.03 user         0.00 sys

(2) Eagerly initialize libgraal (with PR):

> for i in (seq 10); /usr/bin/time java -XX:+EagerJVMCI Nop; end
        0.06 real         0.04 user         0.01 sys
        0.05 real         0.03 user         0.01 sys
        0.05 real         0.03 user         0.01 sys
        0.05 real         0.03 user         0.01 sys
        0.05 real         0.03 user         0.01 sys
        0.05 real         0.03 user         0.01 sys
        0.05 real         0.03 user         0.01 sys
        0.05 real         0.03 user         0.01 sys
        0.05 real         0.03 user         0.01 sys
        0.05 real         0.03 user         0.01 sys

(3) Eagerly initialize libgraal (without PR):

> for i in (seq 10); /usr/bin/time java -XX:+EagerJVMCI Nop; end
        0.11 real         0.08 user         0.02 sys
        0.08 real         0.06 user         0.01 sys
        0.08 real         0.07 user         0.01 sys
        0.10 real         0.07 user         0.01 sys
        0.08 real         0.06 user         0.01 sys
        0.10 real         0.07 user         0.01 sys
        0.08 real         0.07 user         0.01 sys
        0.08 real         0.07 user         0.01 sys
        0.08 real         0.06 user         0.01 sys
        0.08 real         0.06 user         0.01 sys

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-8309390: [JVMCI] improve copying system properties into libgraal (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14291

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 2, 2023

👋 Welcome back dnsimon! 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 Jun 2, 2023

@dougxc The following labels will be automatically applied to this pull request:

  • core-libs
  • graal
  • hotspot

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

@openjdk openjdk bot added graal graal-dev@openjdk.org hotspot hotspot-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Jun 2, 2023
@dougxc dougxc force-pushed the JDK-8309390 branch 2 times, most recently from cf1be09 to d636421 Compare June 3, 2023 11:25
@dougxc dougxc marked this pull request as ready for review June 3, 2023 11:35
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 3, 2023
@@ -59,7 +59,7 @@ public static boolean isBadIoTmpdir() {
* Note: Build-defined properties such as versions and vendor information
* are initialized by VersionProps.java-template.
*
* @return a Properties instance initialized with all of the properties
Copy link
Member Author

Choose a reason for hiding this comment

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

I took the liberty of correcting this javadoc to reflect the code.

@mlbridge
Copy link

mlbridge bot commented Jun 3, 2023

Webrevs

@tkrodriguez
Copy link
Contributor

I don't really love the hard code parsing of the HashMap. What properties are actually required for JVMCI? It seems to me that the contents of Arguments::system_properties() should contain all the properties we want to advertise to JVMCI. That would have avoid having to decode them after they've been converted into Java objects.

@dougxc
Copy link
Member Author

dougxc commented Jun 6, 2023

I don't really love the hard code parsing of the HashMap. What properties are actually required for JVMCI? It seems to me that the contents of Arguments::system_properties() should contain all the properties we want to advertise to JVMCI. That would have avoid having to decode them after they've been converted into Java objects.

I tired this but unfortunately, Graal relies on some properties that are only initialized in Java:

Caused by: java.lang.NullPointerException: Cannot invoke "String.compareTo(String)" because "this.javaSpecVersion" is null
	at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.JVMCIVersionCheck.run(JVMCIVersionCheck.java:181)
	at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.JVMCIVersionCheck.check(JVMCIVersionCheck.java:166)
	at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.HotSpotGraalCompilerFactory.initialize(HotSpotGraalCompilerFactory.java:117)
	at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.HotSpotGraalCompilerFactory.ensureInitialized(HotSpotGraalCompilerFactory.java:90)
	at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.HotSpotGraalCompilerFactory.createCompiler(HotSpotGraalCompilerFactory.java:180)
	at jdk.internal.vm.compiler/org.graalvm.compiler.hotspot.HotSpotGraalCompilerFactory.createCompiler(HotSpotGraalCompilerFactory.java:53)
	at jdk.internal.vm.ci/jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.getCompiler(HotSpotJVMCIRuntime.java:810)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.GraalAccess.<clinit>(GraalAccess.java:50)

That code is reading the "java.specification.version" property which is initialized in java.lang.VersionProps#init.

@tkrodriguez
Copy link
Contributor

HotSpot sets java.vm.specification.version which has the same value so we could change Graal to read that instead.

@openjdk
Copy link

openjdk bot commented Jun 7, 2023

@dougxc Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

@dougxc
Copy link
Member Author

dougxc commented Jun 7, 2023

Ok, I've pushed a change with your suggestion Tom and it seems to work. It assumes Arguments::system_properties() is fully initialized and effectively read-only by the time JVMCIEnv::init_saved_properties is called.

@@ -57,7 +57,7 @@
jvmci_method, \
jvmci_constructor) \
start_class(Services, jdk_vm_ci_services_Services) \
jvmci_method(CallStaticVoidMethod, GetStaticMethodID, call_static, void, Services, initializeSavedProperties, byte_array_void_signature, (JVMCIObject serializedProperties)) \
Copy link
Member Author

Choose a reason for hiding this comment

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

The final arg for the jvmci_method macro is never used so I removed it everywhere.

@dougxc dougxc closed this Jun 10, 2023
@openjdk
Copy link

openjdk bot commented Jun 11, 2023

@dougxc Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

for (long prop = systemProperties; prop != 0; prop = unsafe.getLong(prop + nextOffset)) {
String key = toJavaString(unsafe, unsafe.getLong(prop + keyOffset));
long valueAddress = unsafe.getLong(prop + valueOffset);
if (valueAddress != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the lazy value construction really necessary? It seems like it requires quite a bit of extra machinery.

Copy link
Member Author

Choose a reason for hiding this comment

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

In big apps, I image there can be quite some large system property values (e.g. java.class.path) so we don't want to pay memory overhead per libgraal isolate for such properties as they're ignored by libgraal.

I realized I can reduce the extra machinery based on the fact that SystemProperties is unmodifiable: 6c346d3
The only method that still eager converts the string is SystemProperties.values() but that's fine as it's not used by JVMCI or Graal.
I think the trade off is now acceptable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I like this trade off a bit better.

@openjdk
Copy link

openjdk bot commented Jun 12, 2023

@dougxc 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:

8309390: [JVMCI] improve copying system properties into libgraal

Reviewed-by: never, kvn

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 no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential 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 Jun 12, 2023
Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

VM changes seems fine. They are JVMCI specific.

@dougxc
Copy link
Member Author

dougxc commented Jun 13, 2023

Thanks for the reviews!

/integrate

@openjdk
Copy link

openjdk bot commented Jun 13, 2023

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

  • 63843b1: 8309907: Remove unused _print_gc_overhead_limit_would_be_exceeded
  • 6d05360: 8304403: Remove unused methods in RangeCheckElimination::Bound
  • 9b0baa1: 8306281: function isWsl() returns false on WSL2
  • c884862: 8309468: Remove jvmti Allocate locker test case
  • 05f896a: 8309862: Unsafe list operations in JfrStringPool
  • 4f23fc1: 8309671: Avoid using jvmci.Compiler property to determine if Graal is enabled
  • 1a9edb8: 8309838: Classfile API Util.toBinaryName and other cleanup
  • f7de726: 8295555: Primitive wrapper caches could be @Stable
  • 5d71612: 8309852: G1: Remove unnecessary assert_empty in G1ParScanThreadStateSet destructor
  • 23a54f3: 8309538: G1: Move total collection increment from Cleanup to Remark
  • ... and 5 more: https://git.openjdk.org/jdk/compare/3ce1240ca1b4139980444c171e317f4bfeff9314...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jun 13, 2023

@dougxc Pushed as commit c0aa6bf.

💡 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
core-libs core-libs-dev@openjdk.org graal graal-dev@openjdk.org hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants