Skip to content

Conversation

@plummercj
Copy link
Contributor

@plummercj plummercj commented Dec 4, 2025

With JDI tracing enabled, an attempt to trace an event when using SUSPEND_NONE can result in an ObjectCollectedException because the thread is still running and objects that are part of the trace can be collected already. In this case were were dealing with trying to print the thread name for a VirtualThreadEndEvent, and the virtual thread has already exited and been gc'd.

Tested by running test case before change (verified failure) and after change (50 runs without a failure). Will also run tier1 and tier5 svc just to be sure.


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-8373102: com/sun/jdi/MethodInvokeWithTraceOnTest.java can fail with ObjectCollectedException when run with a small heap (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28666

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 4, 2025

👋 Welcome back cjplummer! 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 Dec 4, 2025

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

8373102: com/sun/jdi/MethodInvokeWithTraceOnTest.java can fail with ObjectCollectedException when run with a small heap

Reviewed-by: amenkov, sspitsyn

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

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 changed the title 8373102 8373102: com/sun/jdi/MethodInvokeWithTraceOnTest.java can fail with ObjectCollectedException when run with a small heap Dec 4, 2025
@openjdk openjdk bot added the serviceability serviceability-dev@openjdk.org label Dec 4, 2025
@openjdk
Copy link

openjdk bot commented Dec 4, 2025

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

  • serviceability

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 rfr Pull request is ready for review label Dec 4, 2025
@mlbridge
Copy link

mlbridge bot commented Dec 4, 2025

Webrevs

Copy link
Contributor

@sspitsyn sspitsyn left a comment

Choose a reason for hiding this comment

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

Looks good.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 4, 2025
Copy link

@alexmenkov alexmenkov left a comment

Choose a reason for hiding this comment

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

I think better solution would be to catch ObjectCollectedException in EventSetImpl.toString implementations (and print al least event name).
But it might not be worth the effort, so it's up to you

@plummercj
Copy link
Contributor Author

plummercj commented Dec 4, 2025

I think better solution would be to catch ObjectCollectedException in EventSetImpl.toString implementations (and print al least event name).
But it might not be worth the effort, so it's up to you

I think you're suggesting to implement it in all of the Event subclasses implemented as inner classes of EventSetImpl, right?

@plummercj
Copy link
Contributor Author

plummercj commented Dec 5, 2025

I think you're suggesting to implement it in all of the Event subclasses implemented as inner classes of EventSetImpl, right?

ThreadedEventImpl has the following for toString():

        return eventName() + " in thread " + thread.name();

This is the one being triggerd by the test via the thread.name() call. LocatableEventImpl inherits from ThreadedEventImpl and has its own toString() with the same thread.name() reference, so it also needs to be fixed. I think that might be it.

@alexmenkov
Copy link

I think better solution would be to catch ObjectCollectedException in EventSetImpl.toString implementations (and print al least event name).
But it might not be worth the effort, so it's up to you

I think your suggesting to implement it in all of the Event subclasses implemented as inner classes of EventSetImpl, right?

It would be more complete solution, but even fixing only EventSetImpl.toString (for each event, printing event name (or class name of the event) + "" on the exception ) should be good enough

@plummercj
Copy link
Contributor Author

It would be more complete solution, but even fixing only EventSetImpl.toString (for each event, printing event name (or class name of the event) + "" on the exception ) should be good enough

I don't think EventSetImpl.toString() is involved at all, although if called it can suffer the same ObjectCollectedException, which would be fixed if the issue is addressed in the toString() method of the Event sub-classes instead.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Dec 5, 2025
@plummercj
Copy link
Contributor Author

I've updated the implementation so now the event type is printed even if there is an ObjectCollectedException. Turns out I was worng about this being triggered by a VirtualThreadEndEvent. It was actually a ClassPrepareEvent, but it was for the class VirtualThreadEndEvent. Here's all the output for the event set, including the handling of the ObjectCollectedException (2nd to last line).

[JDI: Receiving:                suspendPolicy(byte): 0]
[JDI: Receiving:                events(Events[]): ]
[JDI: Receiving:                    events[i](Events): ]
[JDI: Receiving:                    eventKind(byte): 8]
[JDI: Receiving:                        requestID(int): 2]
[JDI: Receiving:                        thread(ThreadReferenceImpl): ref=151]
[JDI: Receiving:                        refTypeTag(byte): 1]
[JDI: Receiving:                        typeID(long): ref=231]
[JDI: Receiving:                        signature(String): Ljdk/internal/event/VirtualThreadEndEvent;]
[JDI: Receiving:                        status(int): 3]
[JDI: EventSet: SUSPEND_NONE]
[JDI: Looking up Class, signature='Ljdk/internal/event/VirtualThreadEndEvent;', id=231]
[JDI: Caching new ReferenceType, sig=Ljdk/internal/event/VirtualThreadEndEvent;, id=231]
[JDI: Sending Command(id=438) JDWP.ThreadReference.Name]
[JDI: Sending:                 thread(ThreadReferenceImpl): ref=151]
[JDI: Event: ClassPrepareEvent in thread <thread collected>]
[JDI: Handled Prepare Event for jdk.internal.event.VirtualThreadEndEvent]```

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 5, 2025
@plummercj
Copy link
Contributor Author

Thank you for the reviews Alex and Serguei!

/integrate

@openjdk
Copy link

openjdk bot commented Dec 5, 2025

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

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Dec 5, 2025

@plummercj Pushed as commit ee0b8a7.

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

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

Labels

integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

3 participants