Skip to content

Conversation

tkrodriguez
Copy link
Contributor

@tkrodriguez tkrodriguez commented Jul 22, 2025

This a draft of adding support for JVMTI deferred locals on virtual threads. The JDK issue has a more full description but basically I'd like some feedback on whether the strategy seems ok and whether full JVMTI support for deferred locals would be a desired outcome. If it's not then I might be able to recast this in a way that is more JVMCI specific so it requires fewer changes to the core JVMTI deferred locals support which is probably the scariest looking part. Maybe @AlanBateman and @kevinjwalls could offer some opinions here?

For the deopt/loom interactions I tried to make the use of the chunk for heap frames fairly explicit as the absolutized heap frames make me nervous. But maybe I'm just making it too complicated?


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-8362968: [JVMCI] support modifying locals in StackIntrospection on virtual threads (Enhancement - P3)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26422

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 22, 2025

👋 Welcome back never! 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 Jul 22, 2025

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

@openjdk
Copy link

openjdk bot commented Jul 22, 2025

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

  • graal
  • hotspot
  • serviceability

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.

@sspitsyn
Copy link
Contributor

sspitsyn commented Jul 24, 2025

@tkrodriguez Thank you for working on this! I'll look at the JVMTI and related changes but it is going to take some time.

@AlanBateman
Copy link
Contributor

For the traditional usage, in the debugger, then it's not clear to me if it's worth having JVMTI deferred locals work with virtual threads. In the debugger it should be rare to want to change a local that is not in the top frame. So I think this is more about the Truffle usage.

@eregon
Copy link
Contributor

eregon commented Jul 28, 2025

In the debugger it should be rare to want to change a local that is not in the top frame.

I think it would be as likely as wanting to change a local that is not in the top frame for a platform thread.
Given that that is supported and is useful, I think it is worthwhile to support it for virtual threads too.

@tkrodriguez
Copy link
Contributor Author

That doesn't necessarily have to be addressed in this PR. If this change lands then in the future it would be possible to support it in JVMTI with some minor additional changes. If there was stronger interest in supporting JVMTI with this change then it would be additional motivation for the changes.

@tkrodriguez
Copy link
Contributor Author

@AlanBateman I don't know all the details of stackChunkOop management and one of my assumptions is that JavaThread::exit would have the chance to clean up any live frames that have jvmtiDeferredLocals. Otherwise we would leak this storage. Is that a reasonable assumption or is it possible for a virtual JavaThread to just be reclaimed by GC?

@AlanBateman
Copy link
Contributor

@AlanBateman I don't know all the details of stackChunkOop management and one of my assumptions is that JavaThread::exit would have the chance to clean up any live frames that have jvmtiDeferredLocals. Otherwise we would leak this storage. Is that a reasonable assumption or is it possible for a virtual JavaThread to just be reclaimed by GC?

As things stand, a virtual thread must run to completion and terminate before it can be GC'ed. This means no live frames in the heap when GC'ed.

That said, there is interest in exploring the topic of "ephemeral threads" that could be GC'ed before they terminate. This would mean a continuation and the stack chunks with frame information could get GC'ed. The JDK can't rush into allowing that of course as it would impact many parts of the system. Separately, there is interest in more exotic control flow, including generators, where there could be continuations that are GC'ed before they are "done". So not an issue right now, but something that might get explored further at some point.

@sspitsyn
Copy link
Contributor

sspitsyn commented Aug 6, 2025

It is better to decouple the JVMCI deferred locals support from JVMTI at this point of time. Of course, it is always nice to align support for virtual and platform threads. But in this case there are some risks involved as Alan explained above. It would be relatively easy to add JVMTI support later if we decide to do so.

@tkrodriguez
Copy link
Contributor Author

The only way to fully decouple it would be to duplicate the deferred locals frame data structure for use by JVMCI. Is that what you're suggesting? It would have to be something somewhat restricted, like it was only used for virtual threads, while the existing data structure was used for regular threads. Otherwise there would be some major duplication.

@sspitsyn
Copy link
Contributor

sspitsyn commented Aug 7, 2025

The only way to fully decouple it would be to duplicate the deferred locals frame data structure for use by JVMCI. Is that what you're suggesting? It would have to be something somewhat restricted, like it was only used for virtual threads, while the existing data structure was used for regular threads. Otherwise there would be some major duplication.

Now I see that my comment was very confusing, sorry. I wanted to say that we do not want JVMTI support of deferred locals for virtual threads other than just for top frame when suspended at an event. This will keep JVMTI for virtual threads as it is. Also, it is related to the following suggestion in the PR description:

The JDK issue has a more full description but basically I'd like some feedback on whether the strategy seems ok and whether full JVMTI support for deferred locals would be a desired outcome. If it's not then I might be able to recast this in a way that is more JVMCI specific so it requires fewer changes to the core JVMTI deferred locals support which is probably the scariest looking part.

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

Successfully merging this pull request may close these issues.

4 participants