On Tue, 1 Dec 2026 22:49:29 GMT, Shiv Shah <[email protected]> wrote:

> instances003 disables collection on 50 instances, enables it on 25 and checks 
> that the other 25 survive a GC. To get rid of those it asks instances() again 
> and calls enableCollection() on what comes back.
> 
> JDI keeps the disable count in the ObjectReference object and holds 
> ObjectReferences only softly. If the debugger VM clears them in between, 
> instances() returns new ones with no count and enableCollection() sends 
> nothing. The 25 stay disabled. The last check then sees 25, expected 0.
> 
> Interpreted, the test's own lists keep them alive. With 
> -XX:CompileThresholdScaling=0.01 testClass is compiled early and the lists 
> are dead after their last use. With C1 only the VM also ages soft references 
> by the free space in the current heap, not the max heap. In a failing run the 
> debugger VM had an 8M heap and a young GC cleared 63 soft references between 
> the test's two forced GCs.
> 
> The last loop now uses the ObjectReferences the test kept from 
> disableCollection(). No other test under vmTestbase/nsk or 
> test/jdk/com/sun/jdi gets them again like this. JDI losing the count when an 
> ObjectReference is collected is not touched here.
> 
> ---
> 
> Testing:
> - [x] instances003, instances004, heapwalking001/002 and mixed001/002 on 
> linux-x64 debug with default options, Serial, Parallel, ZGC (instances003 
> excluded by @ requires), -Xcomp, the virtual thread factory and the failing 
> flags (20 times each, mixed001 100 more, 1 of 20 failed before). Default and 
> virtual also on linux-aarch64 debug. tier1-3 on both, only VerifyCACerts 
> fails as in mainline.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

This is interesting because when the debugger side clears the soft reference to 
the ObjectReference (actually an ObjectReferenceImpl), that queues up the the 
ObjectRefernce to be "disposed of". I've been working on a document to describe 
how all this works (amount other booking of ObjectReferences and ObjectIDs. 
This paragraph is pertinent:

"When the JDI client no longer has any references to the ObjectReferenceImpl, 
this eventually results in the GC clearing the SoftObjectReference’s referent 
to the ObjectReferenceImpl and putting the SoftObjectReference instance on the 
referenceQueue, which in turn allows for the eventual collection of the 
ObjectReferenceImpl. JDI will periodically process the referenceQueue in 
VirtualMachine.processQueue(). Each SoftObjectReference found on the queue is 
placed on the batchedDisposeRequests queue, and the objectID entry is removed 
from the objectsByID hashmap. More on batchedDisposeRequests later."

and

"When an ObjectReferenceImpl is collected, this eventually leads to its 
encapsulating SoftObjectReference being put on the batchedDisposeRequests 
queue. Periodically JDI will process the batchedDisposeRequests. It uses the 
queue’s contents to create a JDWP VirtualMachine.DisposeObjects command. This 
command takes a list of objectIDs that are being disposed of, plus the refcount 
of each objectID. The debug agent subtracts this refcount from the 
RefNode.count field, and if it reaches 0, the RefNode (and therefore the 
objectID) is disposed of. Typically, the objectID refcount on the JDI side 
(SoftObjectReference.count) will match RefNode.count on the debug agent side so 
the RefNode will be freed, but not always because there can be a race between 
disposing the objectID and generating a new reference to it."

VirtualMachine.DisposeObjects will do an implicit "enableCollection", so the 
issue with this bug is that the SoftObjectReference has been queued up to be 
included in an upcoming VirtualMachine.DisposeObjects, but until that 
VirtualMachine.DisposeObjects is done, the "disableCollection" is still in 
place and prevents the object from being collected. Meanwhile the 
ObjectReference that did the disableCollection is no longer cached, so a new 
one gets created that does not know about the disableCollection.

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

PR Comment: https://git.openjdk.org/jdk/pull/34172#issuecomment-7333788469

Reply via email to