RFR: 8284855: Update needed to Cleaners added to jdk.crypto.cryptoki [v2]

Xue-Lei Andrew Fan xuelei at openjdk.java.net
Thu Apr 14 22:03:53 UTC 2022


On Thu, 14 Apr 2022 19:26:53 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> Xue-Lei Andrew Fan has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   use static cleaner, and clean up swp file
>
> src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11.java line 168:
> 
>> 166:         // Calls disconnect() to cleanup the native part of the wrapper.
>> 167:         Cleaner.create().register(this,
>> 168:             () -> PKCS11.disconnect(pNativeData));
> 
> If I'm not mistaken each new call to Cleaner.create() will create a new cleaner and a new deamon thread for it, so it's not recommended to create one cleaner per object.
> Also it might be worth double checking that the lambda created here doesn't capture `this`: IIRC there were some subtle cases where a lambda could unexpectedly capture `this`.
> 
> Also probably the cleaner itself can't be GC'ed while its thread is running but you might be relying on undocumented behavior. It would be more prudent to stick it in a static variable to retain a strong reference.

Good points.  I may change to use a static method instead in the next commit.

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

PR: https://git.openjdk.java.net/jdk/pull/8248



More information about the security-dev mailing list