Skip to content

8377715: Thawing frame can undo deoptimization#30634

Open
pchilano wants to merge 1 commit intoopenjdk:masterfrom
pchilano:JDK-8377715
Open

8377715: Thawing frame can undo deoptimization#30634
pchilano wants to merge 1 commit intoopenjdk:masterfrom
pchilano:JDK-8377715

Conversation

@pchilano
Copy link
Copy Markdown
Contributor

@pchilano pchilano commented Apr 8, 2026

Please review the following fix. When thawing frames in the slow path, the call to patch() can undo the deoptimization of the caller frame here:

} else {
// caller might have been deoptimized during thaw but we've overwritten the return address when copying f from the heap.
// If the caller is not deoptimized, pc is unchanged.
ContinuationHelper::Frame::patch_pc(caller, caller.raw_pc());
}

The else branch is executed regardless of whether the frame was deoptimized during thaw, under the assumption, as the comment states, that if it was not, the pc written will be same as existing one. The problem with that assumption is that if the frame was already deoptimized before thaw, caller.raw_pc() will not return the deoptimized pc but the original one before deoptimization. This is because when creating the frame object, the actual frame is not yet laid out in the stack and so caller.is_deoptimized_frame() is always false (see comment here).

The proposed fix is to only execute the else branch for the case where the caller frame was indeed deoptimized in recurse_thaw_compiled_frame. I also added extra asserts to verify the return pc saved on the stack after thawing a frame is the correct one.

I added a new test that fails without this fix and passes with it. As I explained in the JBS comment, the bug is not that trivial to expose (without using WhiteBox) because of the post call nop mechanism which still forces deoptimization when returning to the nmethod. The test exercises the monitorenter case where this mechanism is not present. Still, we need to force deoptimization of the top compiled frame during the monitorenter call itself, as the frame needs to be already deoptimized when freezing. So the test relies on the MonitorContendedEnter event as a blocking point for deoptimizing it. I could have used WhiteBox instead to construct the test and call into the VM to inspect frame state, but I wanted to show that a real issue exists because of this bug.

I also run the patch through mach5 tiers 1-7.

Thanks,
Patricio


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-8377715: Thawing frame can undo deoptimization (Bug - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30634

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Apr 8, 2026

👋 Welcome back pchilanomate! 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
Copy Markdown

openjdk bot commented Apr 8, 2026

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added hotspot-runtime hotspot-runtime-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Apr 8, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 8, 2026

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

  • core-libs
  • hotspot-runtime

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.

@pchilano
Copy link
Copy Markdown
Contributor Author

pchilano commented Apr 8, 2026

/label remove core-libs, hotspot-runtime

@pchilano
Copy link
Copy Markdown
Contributor Author

pchilano commented Apr 8, 2026

/label add hotspot

@openjdk openjdk bot removed core-libs core-libs-dev@openjdk.org hotspot-runtime hotspot-runtime-dev@openjdk.org labels Apr 8, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 8, 2026

@pchilano
The core-libs label was successfully removed.

The hotspot-runtime label was successfully removed.

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Apr 8, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 8, 2026

@pchilano
The hotspot label was successfully added.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Apr 8, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 8, 2026

@pchilano core-libs has been added to this pull request based on files touched in new commit(s).

@pchilano
Copy link
Copy Markdown
Contributor Author

pchilano commented Apr 8, 2026

/label remove core-libs

@openjdk openjdk bot removed the core-libs core-libs-dev@openjdk.org label Apr 8, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 8, 2026

@pchilano
The core-libs label was successfully removed.

@pchilano pchilano marked this pull request as ready for review April 8, 2026 19:18
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 8, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge bot commented Apr 8, 2026

Webrevs

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

Labels

hotspot hotspot-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

1 participant