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

8298099: [JVMCI] decouple libgraal from JVMCI module at runtime #11513

Closed
wants to merge 14 commits into from

Conversation

dougxc
Copy link
Member

@dougxc dougxc commented Dec 5, 2022

Libgraal is compiled ahead of time and should not need any JVMCI Java code to be dynamically loaded at runtime. Prior to this PR, this is not the case due to:

  • Code to copy system properties from the HotSpot heap into the libgraal heap. This is in jdk.vm.ci.services.Services.initializeSavedProperties(byte[]) and jdk.vm.ci.services.Services.serializeSavedProperties(). This code should be moved to java.base/jdk.internal.vm.VMSupport.
  • Code to translate exceptions from the HotSpot heap into the libgraal heap and vice versa. This code should be moved from jdk.internal.vm.ci//jdk.vm.ci.hotspot.TranslatedException to java.base/jdk.internal.vm.VMSupport.

This PR makes the above changes. As a result, it's possible to build a JDK image that includes (and uses) libgraal but does not include jdk.internal.vm.ci or jdk.internal.vm.compiler. This both reduces footprint and better isolates the JAVMCI and the Graal compiler as accessing these components from Java code is now impossible.


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-8298099: [JVMCI] decouple libgraal from JVMCI module at runtime

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11513

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 5, 2022

👋 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 openjdk bot added the rfr Pull request is ready for review label Dec 5, 2022
@openjdk
Copy link

openjdk bot commented Dec 5, 2022

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

  • core-libs
  • 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 hotspot hotspot-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Dec 5, 2022
@mlbridge
Copy link

mlbridge bot commented Dec 5, 2022

@@ -1415,6 +1415,23 @@ char* ClassLoader::lookup_vm_options() {
return options;
}

// Returns true if jdk.internal.vm.ci is present on the file system.
bool ClassLoader::has_jvmci_module() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be more useful to pass the module name so that the function tests if the module is is in the run-time image so that ClassLoader doesn't need to know the name "jdk.internal.vm.ci"?

Copy link
Member Author

@dougxc dougxc Dec 5, 2022

Choose a reason for hiding this comment

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

Yes, good idea: 3e89d40253b70251f9a2facce4b1d8d69701c045
I also fixed a bug due in the size computation of path. Ideally, I'd factor out and re-use the same code in ClassLoader::add_to_exploded_build_list. However, the latter uses a ResourceMark which is not available when calling is_module_resolvable early in VM startup before JavaThread is initialized.

static bool has_jvmci_module();

// Determines if the `module_name` module is resolvable.
static bool is_module_resolvable(const char* module_name);
Copy link
Member Author

Choose a reason for hiding this comment

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

Is "resolvable" the right concept here? Or should it be something like "findable" instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming --limit-modules isn't used, it is testing if the module is "observable".

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 assume this function should therefore be named is_module_observable?

Copy link
Member Author

Choose a reason for hiding this comment

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

How about this:

// Determines if the named module is present in the
// modules jimage file or in the exploded modules directory.
static bool is_module_observable(const char* module_name);

Copy link
Contributor

Choose a reason for hiding this comment

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

That looks okay to me. I don't have any other comments on this part.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Sorry Doug not a full review (not familiar enough with code) but a few drive-by nits.

Thanks.

ResourceMark rm;
tty->print("JVMCITrace-%d[%s]:%*c", level, thread->name(), level, ' ');
JavaThreadState state = ((JavaThread*) thread)->thread_state();
Copy link
Member

Choose a reason for hiding this comment

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

Please use JavaThread::cast(thread)

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've made this change. Out of interest, I grep'ed through src/hotspot and found a few other instances of (JavaThread*) style casts. While most of these are probably older code, I'm wondering what the guidelines are in this area. I assume JavaThread::cast should be preferred always given the assertion checking it does?

Copy link
Member

Choose a reason for hiding this comment

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

Yes JavaThread::cast(t) is preferred. We did a lot of cleanup work ensuring we use JavaThread when always dealing with a JavaThread, and so reduce the places we need to cast. I'm a little surprised we still have some raw casts left as I thought we had cleaned them all up. I will check and file another cleanup RFE. Thanks.

@@ -228,9 +229,17 @@ void JVMCI::vlog(int level, const char* format, va_list ap) {
void JVMCI::vtrace(int level, const char* format, va_list ap) {
if (JVMCITraceLevel >= level) {
Thread* thread = Thread::current_or_null_safe();
if (thread != nullptr) {
if (thread != nullptr && thread->is_Java_thread()) {
ResourceMark rm;
Copy link
Member

Choose a reason for hiding this comment

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

You can pass thread to the rm constructor to save an internal lookup.

// According to check_access_thread_state, it's unsafe to
// resolve the j.l.Thread object unless the thread is in
// one of the states above.
tty->print("JVMCITrace-%d[%s@" INTPTR_FORMAT "]:%*c", level, thread->type_name(), p2i(thread), level, ' ');
Copy link
Member

Choose a reason for hiding this comment

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

I think the current preferred style is to use PTR_FORMAT here.

@@ -1,10 +1,12 @@
/*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

If you just moved the file the original copyright year should remain - this is not new code.

if (!create_numbered_module_property("jdk.module.addmods", "jdk.internal.vm.ci", addmods_count++)) {
return false;
if (ClassLoader::is_module_observable("jdk.internal.vm.ci")) {
if(!create_numbered_module_property("jdk.module.addmods", "jdk.internal.vm.ci", addmods_count++)) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: space after if please

/**
* Support for translating exceptions between different runtime heaps.
* Support for translating exceptions between the HotSpot heap and libjvmci heap.
*/
@SuppressWarnings("serial")
final class TranslatedException extends Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to re-format this to avoid the wildly long (150+) lines? This seems to be moving jdk.vm.ci.hotspot.TranslatedException and hard to see what is going on.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there some tool support for formatting Java source code to meet OpenJDK coding guidelines? Rather unfortunate that one has to do this manually and reviewers have to spend time manually checking it.

Copy link
Contributor

Choose a reason for hiding this comment

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

There isn't globally agreed code conventions. The cleanup in the latest version looks okay.

*/
private static byte[] serializePropertiesToByteArray(Properties p) throws IOException {
private static byte[] serializePropertiesToByteArray(Properties p, boolean filter) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need more context as to why there are non-String system properties in use here.

Copy link
Member Author

Choose a reason for hiding this comment

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

This parameter exists to allow a caller to pass in a Properties object that is guaranteed to have only String keys and so does not need the extra filtering done in this method. I'll refactor the code to make it clearer.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hopefully this makes it clearer: 5c61079

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. I initially assumed it was done to support non-String key/values but it's actually an optimization because the save properties are always Strings.

props.put(e.getKey(), e.getValue());
}
if (props.get("oome") != null) {
throw new OutOfMemoryError("forced OOME");
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think code in java.base should be checking for a property named "oome". Is this for a test that sets this system property on the command line?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, that's debug code that I will remove.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, I couldn't see it set as a property anywhere so didn't know why it was there. I don't have any comments on this area.

@openjdk
Copy link

openjdk bot commented Dec 7, 2022

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

8298099: [JVMCI] decouple libgraal from JVMCI module at runtime

Reviewed-by: never

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 Dec 7, 2022
@@ -120,7 +127,8 @@ private static Throwable create(String className, String message, Throwable caus
try {
Class<?> cls = Class.forName(className);
Copy link
Contributor

Choose a reason for hiding this comment

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

A question about the Class.forName usage here. Class.forName uses the defining class loader of the current class so I'm wondering if the exceptions to be decoded are always of a type defined to the boot loader? jdk.internal.vm.ci is defined to the boot loader so this code hasn't really changed, it's just "new" to java.base in this PR.

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 exceptions can be of any type and defined by any loader. In the case that Class.forName fails, the name of the original exception type is shown as part of TranslationException.toString(). Combined with the stack trace, this has always been sufficient to understand the origin of an exception thrown on a HotSpot/libjvmci mixed stack.

@dougxc
Copy link
Member Author

dougxc commented Dec 7, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Dec 7, 2022

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

  • 8a9911e: 8295803: Console should be usable in jshell and other environments
  • 5d4c71c: 8281236: (D)TLS key exchange named groups

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Dec 7, 2022

@dougxc Pushed as commit 8b69a2e.

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

@dholmes-ora
Copy link
Member

@dougxc Two reviews are needed for all non-trivial hotspot changes, and this also warranted a review from core-libs! Your discussions with Alan still seemed to be in-progress.

@dougxc
Copy link
Member Author

dougxc commented Dec 8, 2022

Sorry I checked with Alan over Slack who said to go ahead with merging.

@AlanBateman
Copy link
Contributor

Sorry I checked with Alan over Slack who said to go ahead with merging.

Yeah, I was busy at the time and didn't get a chance to say that I didn't have any more comments/issues.

@dougxc dougxc deleted the JDK-8298099 branch May 23, 2023 07:51
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 hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
4 participants