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

8316746: Top of lock-stack does not match the unlocked object #16406

Closed

Conversation

TheRealMDoerr
Copy link
Contributor

@TheRealMDoerr TheRealMDoerr commented Oct 27, 2023

It took me quite a long journey to figure out that C2 OSR goes wrong only in the test "vmTestbase/nsk/jdi/StepEvent" because the interpreter fills the slots in a different order as expected by C2. (Interpreter and C1 don't care about it.)
I've reimplemented the search loop in monitorenter, improved comments and cleaned up the related code a bit. The test is passing with this change.


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-8316746: Top of lock-stack does not match the unlocked object (Bug - P2)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16406

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 27, 2023

👋 Welcome back mdoerr! 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 Oct 27, 2023
@openjdk
Copy link

openjdk bot commented Oct 27, 2023

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

  • hotspot-compiler

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-compiler hotspot-compiler-dev@openjdk.org label Oct 27, 2023
@mlbridge
Copy link

mlbridge bot commented Oct 27, 2023

Webrevs

@dean-long
Copy link
Member

Mystery solved!

@TheRealMDoerr
Copy link
Contributor Author

Mystery solved!

Yeah! Thanks again for your help! I hope I didn't steal too much of your time and that it was at least interesting for everybody.

@TobiHartmann
Copy link
Member

/label add hotspot-runtime

@openjdk openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Oct 31, 2023
@openjdk
Copy link

openjdk bot commented Oct 31, 2023

@TobiHartmann
The hotspot-runtime label was successfully added.

Copy link
Member

@reinrich reinrich left a comment

Choose a reason for hiding this comment

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

Hi Martin,

the order of BasicObjectLocks in the interpreter is specified if the locking operations are well-formed.

the comment on the PPC implementation of frame::interpreter_frame_monitor_end is wrong. It should be removed.

@TheRealMDoerr
Copy link
Contributor Author

You're right! Removed the comment from all platforms which still had it.

@reinrich
Copy link
Member

reinrich commented Nov 2, 2023

Thanks. I wasn't even aware that other implementations have it as well :)

Copy link
Member

@reinrich reinrich left a comment

Choose a reason for hiding this comment

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

The code in this PR is a lot easier to follow than the baseline version and it looks correct to me.
I tried to understand what's actually wrong with the baseline but gave up. Do you know where precisely the bug is?

Anyway, thanks for fixing this!
Richard.

ConditionRegister found_free_slot = CCR0,
found_same_obj = CCR1,
reached_limit = CCR6;
// Note: The order of the monitors is important for C2 OSR which derives the
Copy link
Member

Choose a reason for hiding this comment

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

You should refer to the decl. of the interpreter_frame_monitor_* where the expected order is specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks.

@openjdk
Copy link

openjdk bot commented Nov 2, 2023

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

8316746: Top of lock-stack does not match the unlocked object

Reviewed-by: rrich, lucy

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 136 new commits pushed to the master branch:

  • 7d25f1c: 8319423: Improve Year.isLeap by checking divisibility by 16
  • 59e9981: 8319376: ParallelGC: Forwarded objects found during heap inspection
  • 7c7f8ea: 8319456: jdk/jfr/event/gc/collection/TestGCCauseWith[Serial|Parallel].java : GC cause 'GCLocker Initiated GC' not in the valid causes
  • 7bc8e4c: 8294980: test/jdk/java/lang/invoke 15 test classes use experimental bytecode library
  • e841897: 8319374: JFR: Remove instrumentation for exception events
  • cd9719b: 8319306: Serial: Remove TenuredSpace::verify
  • 1e687b4: 8316719: C2 compilation still fails with "bad AD file"
  • 8555e0f: 8319318: bufferedStream fixed case can be removed
  • 73c5f60: 8319556: Harmonize interface formatting in the FFM API
  • cc4b0d9: 8319378: Spec for j.util.Timer::purge and j.util.Timer::cancel could be improved
  • ... and 126 more: https://git.openjdk.org/jdk/compare/2915d74a10c63cdca22d0055ebde67ef316a341b...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 Nov 2, 2023
@TheRealMDoerr
Copy link
Contributor Author

Thanks for the review! The old code simply reuses the first empty slot it finds (from top to bottom). That causes the order to be reversed if e.g. 2 slots are free and we lock 2 objects. The new code uses the free slot which is closer to the bottom first.

@TheRealMDoerr
Copy link
Contributor Author

@TobiHartmann: You were also interested in a test. I have included one which reproduces the issue on PPC64 without this fix.

Copy link
Contributor

@RealLucy RealLucy left a comment

Choose a reason for hiding this comment

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

Changes look good to me.
I added one minor optimization suggestion you may want to consider. It is not relevant for approval.

__ addi(Rcurrent_obj_addr, Rcurrent_obj_addr, - frame::interpreter_frame_monitor_size_in_bytes());
__ cmpdi(CCR0, Rfree_slot, 0);
__ beq(CCR0, Lallocate_new);
__ mr(Rcurrent_monitor, Rfree_slot);
__ b(Lfound);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be nice to use Rfree_slot from here on and save the move to Rcurrent_monitor and the unconditional branch?

  __ cmpdi(CCR0, Rfree_slot, 0);
  __ bne(CCR0, Lfound);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Changed.

__ addi(Rcurrent_obj_addr, Rcurrent_obj_addr, - frame::interpreter_frame_monitor_size_in_bytes());
__ cmpdi(CCR0, Rfree_slot, 0);
__ beq(CCR0, Lallocate_new);
__ mr(Rcurrent_monitor, Rfree_slot);
__ b(Lfound);

// We didn't find a free BasicObjLock => allocate one.
__ align(32, 12);
__ bind(Lallocate_new);
__ add_monitor_to_stack(false, Rscratch1, Rscratch2);
__ mr(Rcurrent_monitor, R26_monitor);
Copy link
Contributor

Choose a reason for hiding this comment

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

If you do the above optimization, this instruction would need to change to
__ mr(Rfree_slot, R26_monitor);

@@ -4241,7 +4232,7 @@ void TemplateTable::monitorenter() {
// The object has already been popped from the stack, so the expression stack looks correct.
__ addi(R14_bcp, R14_bcp, 1);

__ std(Robj_to_lock, 0, Rcurrent_obj_addr);
__ std(Robj_to_lock, in_bytes(BasicObjectLock::obj_offset()), Rcurrent_monitor);
__ lock_object(Rcurrent_monitor, Robj_to_lock);
Copy link
Contributor

Choose a reason for hiding this comment

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

Rcurrent_monitor would need to be replaced by Rfree_slot in the above two lines as well.

@TheRealMDoerr
Copy link
Contributor Author

Thanks for the review! I'm rerunning tests and will probably integrate tomorrow if everything is fine and there are no further comments.

@TheRealMDoerr
Copy link
Contributor Author

Tests are green.
/integrate

@openjdk
Copy link

openjdk bot commented Nov 9, 2023

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

  • dd9eab1: 8310886: C2 SuperWord: Two nodes should be isomorphic if they are loop invariant but pinned at different nodes outside the loop
  • 7e4cb2f: 8318962: Update ProcessTools javadoc with suggestions in 8315097
  • 0b58bde: 8319104: GtestWrapper crashes with SIGILL in AsyncLogTest::test_asynclog_raw on AIX opt
  • b0fc808: 8319725: G1: Subtracting virtual time from wall time after JDK-8319204
  • a26f7c0: 6928542: Chinese characters in RTF are not decoded
  • 4e8c036: 8319665: [macOS] Obsolete imports of <Carbon/Carbon.h> in java.desktop
  • f4ab952: 8319253: [BACKOUT] Change LockingMode default from LM_LEGACY to LM_LIGHTWEIGHT
  • c137b17: 8187655: jdk.lambda.vm.InterfaceAccessFlagsTest.testPrivateMethodCall needs update after nestmates support
  • fa331d7: 8319184: RISC-V: improve MD5 intrinsic
  • 4c0f6c6: 8311961: Update Manual Test Groups for ATR JDK22
  • ... and 137 more: https://git.openjdk.org/jdk/compare/2915d74a10c63cdca22d0055ebde67ef316a341b...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 9, 2023

@TheRealMDoerr Pushed as commit 7d8adfa.

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

@TheRealMDoerr TheRealMDoerr deleted the 8316746_lock_stack_V3 branch November 9, 2023 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants