On Thu, 4 Dec 2025 21:00:41 GMT, Chris Plummer <[email protected]> wrote:
> 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. 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 Command(id=188) JDWP.Event.Composite] [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]``` ------------- PR Comment: https://git.openjdk.org/jdk/pull/28666#issuecomment-3614923760
