[crac] RFR: Update Reference Handling for CRaC [v2]

Dan Heidinga heidinga at openjdk.java.net
Wed Apr 20 20:24:51 UTC 2022


On Tue, 19 Apr 2022 07:44:47 GMT, Anton Kozlov <akozlov at openjdk.org> wrote:

>> This change updates Reference Handling after Alan's comments [1].
>> * The new API is moved to the CRaC-related classes to avoid polluting or changing standard classes. This should make EA builds more attractive.
>> * The method for waiting threads now accepts timeout, as turns to be needed by CleanerImpl.beforeCheckpoint().
>> * Now reference handling outside of the JDK code is supported, see the supplied test update. The handing does not depend on the first-level reference processing thread's beforeCheckpoint is called first. After that, it was possible to remove the resource and the corresponding REFERENCE_HANDLER priority.
>> 
>> The methods for waiting threads cannot guarantee that a reference handling is complete for a particular queue and a set of threads, as nothing prevents an another concurrent thread to change the reachability of a random object that will end up in the queue after the method returns. The method is designed to synchronize reference handling and checkpoint. That is, to ensure that objects that are on the way to be enqueued are indeed enqueued and corresponding clean-up is performed, as demonstrated by the test.
>> 
>> [1] https://github.com/openjdk/crac/pull/13#issuecomment-1028024855
>
> Anton Kozlov has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision:
> 
>  - Merge remote-tracking branch 'jdk/crac/crac' into refqueue-2
>  - Update ReferenceHandle for CRaC
>    
>    * Hide new API for internal use
>    * Add timeout
>    * Remove REFERENCE_HANDLER resource

I'm less certain of the test as it requires System.gc() to cause the reference to be enqueued.  This tests tend to be flaky across different GC policies but I don't have a great suggestion on how to make it more reliable

src/java.base/share/classes/java/lang/ref/Reference.java line 331:

> 329: 
> 330:             @Override
> 331:             public boolean waitForQueueProcessed(ReferenceQueue<?> queue,

Should this method be static as it doesn't use the instance's state?  

Alternatively, if it's for *this* reference's queue, then the instance variable should be used and the queue parameter can be removed.

Actually, I'm starting to think this method shouldn't exist on reference.  It belongs on the ReferenceQueue rather than here.  Possibly as a static helper method if there's a need to expose the version that takes a queue.

src/java.base/share/classes/jdk/crac/Misc.java line 10:

> 8:  * Additional utilities.
> 9:  */
> 10: public class Misc {

Given this is a utility class, it should probably be final.  No use in allowing subclasses

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

PR: https://git.openjdk.java.net/crac/pull/22


More information about the crac-dev mailing list