On Thu, 30 Jun 2022 15:53:10 GMT, Roger Riggs <rri...@openjdk.org> wrote:

>> Xue-Lei Andrew Fan has updated the pull request with a new target base due 
>> to a merge or a rebase. The pull request now contains 13 commits:
>> 
>>  - Master
>>  - use Reference.refersTo
>>  - remove trailing whitespaces
>>  - use timeout factor
>>  - Merge
>>  - Merge master
>>  - Merge
>>  - add timeout parameter
>>  - rollback is not in this branch
>>  - rollback JDK-8287384
>>  - ... and 3 more: https://git.openjdk.org/jdk/compare/47b86690...0f196282
>
> test/lib/jdk/test/lib/util/ForceGC.java line 70:
> 
>> 68:                 // But it is fine.  For most cases, the 1st GC is 
>> sufficient
>> 69:                 // to trigger and complete the cleanup.
>> 70:                 queue.remove(200L);
> 
> If `remove()` returns a non-null value, then it is safe to break out of the 
> loop.
> The GC has cleared the ref. And the final `getAsBoolean()` below will return 
> the condition.

I'm not sure if all unused object will be collected in one GC call always.  The 
gc() specification says "When control returns from the method call, the Java 
Virtual Machine has made a best effort to reclaim space from all unused 
objects. ... There is also no guarantee that this effort will determine the 
change of reachability in any particular number of objects, or that any 
particular number of {@link java.lang.ref.Reference Reference} objects will be 
cleared and enqueued."  But from the spec, I did not get a clear answer for the 
question.

If the `booleanSupplier` object could be cleared in a collection other than the 
`ref` collection, the current code may be safer.

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

PR: https://git.openjdk.org/jdk/pull/8979

Reply via email to