On Mon, 16 Mar 2026 19:19:25 GMT, Alex Menkov <[email protected]> wrote:

> I don't think `commonRef_compact` should handle value object in a different 
> way.
> If we decide to free the nodes when refcount reaches 0, it should be done for 
> all nodes (value and instance objects).

After thinking about this more, I don't believe we can free ObjectIDs when the 
refcnt is 0, even for value objects. Debuggers relying on ObjectIDs being valid 
until either the object is collected or the debugger calls 
VirtualMachine.DisposeObjects. For the latter, JDI only does this when it 
detects there are no more references to the ObjectReference instance, so that 
also means it is no longer caching the ObjectID, thus making it ok for the 
debug agent to dispose of it.

Note there is no relationship between JDI's caching of the ObjectID in the 
ObjectReference instance and the debug agent's refcnt tracking of the ObjectID. 
The later is just an internal debug agent mechanism needed during the short 
periods of time in needs to know about the ObjectID (while sending a reply 
packet). The refcnt is almost always 0, even when JDI has an ObjectRefernece 
that is caching the ObjectID.

If we free the ObjectID as suggested, Debuggers (and our tests) will sometimes 
get ObjectCollectedException even if the object has not actually been 
collected. The assumption is that if the debugger passes an ObjectID to the 
debug agent and the ObjectID is no longer valid, it is because the object has 
been collected. We would be breaking that assumption with this change.

-------------

PR Comment: https://git.openjdk.org/valhalla/pull/2229#issuecomment-4070224182

Reply via email to