On Sat, 30 Jul 2022 11:07:25 GMT, Peter Levart <[email protected]> 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