RFR: 8283660: Convert com/sun/jndi/ldap/AbstractLdapNamingEnumeration.java finalizer to Cleaner [v8]

Peter Levart plevart at openjdk.org
Sat Jul 30 11:47:13 UTC 2022


On Sat, 30 Jul 2022 11:07:25 GMT, Peter Levart <plevart at openjdk.org> wrote:

>> src/java.naming/share/classes/com/sun/jndi/ldap/AbstractLdapNamingEnumeration.java line 216:
>> 
>>> 214:         } finally {
>>> 215:             // Ensure Cleaner does not run until after this method completes
>>> 216:             Reference.reachabilityFence(this);
>> 
>> I don't think there is any benefit to the `try{} finally {fence}`.
>> The reachabilityFence has no executable code. Its only purpose is to keep the reference in scope alive.
>
>> I don't think there is any benefit to the `try{} finally {fence}`. The reachabilityFence has no executable code. Its only purpose is to keep the reference in scope alive.
> 
> ...reachability fence has no code, but puting it into finally block makes the compiler see it on all possible exit paths from the try block (any possible exceptions, returns, etc.) so the argument 'this' is protected from being GC-ed until every possible code in try block is finished.

The memory fence is not needed though (as explained above).

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

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


More information about the core-libs-dev mailing list