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). ------------- Commit messages: - Enable collection through the same ObjectReferences that were disabled Changes: https://git.openjdk.org/jdk/pull/34172/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=34172&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8397698 Stats: 5 lines in 1 file changed: 1 ins; 0 del; 4 mod Patch: https://git.openjdk.org/jdk/pull/34172.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/34172/head:pull/34172 PR: https://git.openjdk.org/jdk/pull/34172
