Skip to content

Conversation

@dougxc
Copy link
Member

@dougxc dougxc commented Oct 26, 2023

This PR reduces the context in which a libjvmci CompilerThread can make a Java call. By default, a CompileThread for a JVMCI compiler can make Java calls (as jarjvmci only works that way). When libjvmci calls into the VM via a CompilerToVM native method, it enters a scope where Java calls are disabled until either the call returns or a nested scope is entered that re-enables Java calls. The latter is required for the Truffle use case described in JDK-8318694 as well as for a few other VM entry points where libgraal currently still requires the ability to make Java calls (e.g. to load the Java classes used for boxing primitives). We may be able to eventually eliminate all need for libgraal to make Java calls but this PR is a first step in the right direction.


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-8318694: [JVMCI] disable can_call_java in most contexts for libjvmci compiler threads (Bug - P2)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16383

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

Using diff file

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

Webrev

Link to Webrev Comment

#define JNI_THROW(caller, name, msg) do { \
jint __throw_res = env->ThrowNew(JNIJVMCI::name::clazz(), msg); \
if (__throw_res != JNI_OK) { \
tty->print_cr("Throwing " #name " in " caller " returned %d", __throw_res); \
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 VM should prefer event logging over printing to the console.

if (strstr(val, "<trace>") != nullptr) {
tty->print_cr("CompilerToVM.lookupType: %s", str);
} else if (strstr(val, str) != nullptr) {
} else if (strstr(str, val) != nullptr) {
Copy link
Member Author

@dougxc dougxc Oct 26, 2023

Choose a reason for hiding this comment

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

This fixes an existing bug: the test is meant to be whether val is a substring of str, not the other way around.

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 26, 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 Oct 26, 2023

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

  • 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 labels Oct 26, 2023
@dougxc dougxc force-pushed the JDK-8318694_v2 branch 3 times, most recently from 4df5494 to 3e70e6e Compare October 26, 2023 21:40
C2V_END

C2V_VMENTRY_NULL(jobject, lookupType, (JNIEnv* env, jobject, jstring jname, ARGUMENT_PAIR(accessing_klass), jint accessing_klass_loader, jboolean resolve))
CompilerThreadCanCallJava canCallJava(thread, resolve); // Resolution requires Java calls
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 is currently required by libgraal - it may be fixable in future.

@dougxc dougxc force-pushed the JDK-8318694_v2 branch 2 times, most recently from 5457928 to 0c0b192 Compare October 27, 2023 08:19
@dougxc dougxc marked this pull request as ready for review October 27, 2023 11:15
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 27, 2023
@mlbridge
Copy link

mlbridge bot commented Oct 27, 2023

print_stack_element_to_stream(st, bte._mirror, bte._method_id, bte._version, bte._bci, bte._name);
}
{
if (THREAD->can_call_java()) {
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 allows java_lang_Throwable::print_stack_trace to be used in contexts where Java calls cannot be made.

@openjdk
Copy link

openjdk bot commented Oct 29, 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.

@openjdk
Copy link

openjdk bot commented Oct 29, 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.

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.

Can't comment on all the details of the changes, but I don't see anything untoward in general.

Thanks.

@openjdk
Copy link

openjdk bot commented Oct 30, 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:

8318694: [JVMCI] disable can_call_java in most contexts for libjvmci compiler threads

Reviewed-by: dholmes, 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 86 new commits pushed to the master branch:

  • ab19348: 8318647: Serial: Refactor BlockOffsetTable
  • b4f5379: 8304939: os::win32::exit_process_or_thread should be marked noreturn
  • 0461d9a: 8318016: Per-compilation memory ceiling
  • 2a76ad9: 8318683: compiler/c2/irTests/TestPhiDuplicatedConversion.java "Failed IR Rules (2) of Methods (2)"
  • b3fec6b: 8306980: Generated docs should contain correct Legal Documents
  • 1139482: 8316132: CDSProtectionDomain::get_shared_protection_domain should check for exception
  • 2182c93: 8313643: Update HarfBuzz to 8.2.2
  • 613a3cc: 8301846: Invalid TargetDataLine after screen lock when using JFileChooser or COM library
  • 613d32c: 8169475: WheelModifier.java fails by timeout
  • f1e8787: 8317609: Classfile API fails to verify /jdk.jcmd/sun/tools/jstat/Alignment.class
  • ... and 76 more: https://git.openjdk.org/jdk/compare/d2d1592dd94e897fae6fc4098e43b4fffb6d6750...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 30, 2023
Copy link
Contributor

@tkrodriguez tkrodriguez left a comment

Choose a reason for hiding this comment

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

This looks better than I'd imagined.

@tkrodriguez
Copy link
Contributor

Should we convert any assert only can_call_java checks into guarantees?

@dougxc
Copy link
Member Author

dougxc commented Oct 31, 2023

Should we convert any assert only can_call_java checks into guarantees?

Makes sense to me. There are only 3 such assertions and none of them are on performance critical paths:

What do you think @dholmes-ora @vnkozlov ?

JavaType fieldHolder = lookupType(holderIndex, opcode);

if (fieldHolder instanceof HotSpotResolvedObjectTypeImpl) {
if (fieldHolder instanceof HotSpotResolvedObjectTypeImpl) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (fieldHolder instanceof HotSpotResolvedObjectTypeImpl) {
if (fieldHolder instanceof HotSpotResolvedObjectTypeImpl) {

@dholmes-ora
Copy link
Member

What do you think @dholmes-ora @vnkozlov ?

Normally we use asserts for things that are absolutely expected to be uncovered during testing - things that are purely internal VM concerns and for which a failure is a VM coding error. So I don't think it is necessary to change these to guarantees provided we have sufficient test coverage. The guarantee may not hurt but the same could be said for many other assertions.

@dougxc
Copy link
Member Author

dougxc commented Nov 1, 2023

With GraalVM, we're doing a lot more testing with product builds than fastdebug builds as the majority of checks are done at the Java level and fastdebug just slows everything down. In that testing context, guarantees are much more useful. Given the importance of the "can_call_java" invariant, would you agree that converting these 3 specific assertions to guarantees is justified?

@dholmes-ora
Copy link
Member

The majority of hotspot testing is done on fastdebug and performance is not considered an issue there. But I don't have a hard objection to these three asserts becoming guarantees.

@dougxc
Copy link
Member Author

dougxc commented Nov 1, 2023

Thanks for all the reviews and useful input.

/integrate

@openjdk
Copy link

openjdk bot commented Nov 1, 2023

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

  • c86592d: 8319046: Execute tests in source/class-file order in JavadocTester
  • 3660a90: 8319139: Improve diagnosability of JavadocTester output
  • 7f47c51: 8316025: Use testUI() method of PassFailJFrame.Builder in FileChooserSymLinkTest.java
  • 36de19d: 8317048: VerifyError with unnamed pattern variable and more than one components
  • ab19348: 8318647: Serial: Refactor BlockOffsetTable
  • b4f5379: 8304939: os::win32::exit_process_or_thread should be marked noreturn
  • 0461d9a: 8318016: Per-compilation memory ceiling
  • 2a76ad9: 8318683: compiler/c2/irTests/TestPhiDuplicatedConversion.java "Failed IR Rules (2) of Methods (2)"
  • b3fec6b: 8306980: Generated docs should contain correct Legal Documents
  • 1139482: 8316132: CDSProtectionDomain::get_shared_protection_domain should check for exception
  • ... and 80 more: https://git.openjdk.org/jdk/compare/d2d1592dd94e897fae6fc4098e43b4fffb6d6750...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 1, 2023

@dougxc Pushed as commit d354141.

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

@dcubed-ojdk
Copy link
Member

With GraalVM, we're doing a lot more testing with product builds than fastdebug
builds as the majority of checks are done at the Java level and fastdebug just
slows everything down. In that testing context, guarantees are much more useful.
Given the importance of the "can_call_java" invariant, would you agree that
converting these 3 specific assertions to guarantees is justified?

Hmmm... I hope this doesn't mean that the GraalVM project has changed the
Tier[1-3] task definitions to focus on 'release' bits testing instead of 'fastdebug'
bits testing.

@dougxc
Copy link
Member Author

dougxc commented Nov 7, 2023

Hmmm... I hope this doesn't mean that the GraalVM project has changed the
Tier[1-3] task definitions to focus on 'release' bits testing instead of 'fastdebug'
bits testing.

No, we did not change this in the tier testing. I was referring to the Graal CI.

@dcubed-ojdk
Copy link
Member

No, we did not change this in the tier testing. I was referring to the Graal CI.

Thanks for the info. Does this mean that the Graal CI is running its own Tier[1-8]
definitions and not the same Tier[1-8] as the main JDK repo?

@dcubed-ojdk
Copy link
Member

I meant does that mean that Graal CI is running its own Graal-Tier[1-N] and it not
running the same Tier[1-8] definitions as the main JDK repo at all?

@dougxc
Copy link
Member Author

dougxc commented Nov 7, 2023

The Graal CI system is completely disjoint from mach5-based JDK testing.

@dougxc dougxc deleted the JDK-8318694_v2 branch August 20, 2024 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

5 participants