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

Brent Christian bchristi at openjdk.org
Wed May 14 23:56:05 UTC 2025


Please review this change to replace the finalizer in `AbstractLdapNamingEnumeration` with Cleaner.

(The [first PR](https://github.com/openjdk/jdk/pull/8311) for this fix started some substantial discussions, leading to, among other things, the [8314480](https://bugs.openjdk.org/browse/JDK-8314480) `java.lang.ref` memory ordering spec update.)

In standard fashion, pieces of state required for cleanup (`LdapCtx homeCtx`, `LdapResult res`, and `LdapClient enumClnt`) are moved into a _Context_ object. From there, the change is fairly mechanical.

Details of note:

1. Some operations need to change the state values (the `update()` method is probably the most interesting). Use of `reachabilityFence()` ensures memory visibility on the Cleaner thread (per the aforementioned spec update).
2. Subclasses need to access `homeCtx`; I added a `homeCtx()` method to read `homeCtx` from the superclass's state.

The test case is based on a copy of `com/sun/jndi/ldap/blits/AddTests/AddNewEntry.java`. It confirms that the use of Cleaner does not keep an `LdapSearchEnumeration` object reachable. The other `AbstractLdapNamingEnumeration` subclasses (`LdapNamingEnumeration` and `LdapBindingEnumeration`) can be expected to behave the same.

Thanks.

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

Commit messages:
 - small comment update
 - simplify test
 - update test to use WhiteBox, and use volatile read for enumCount
 - improve test to give cleaning action a chance to run
 - remove unneeded fullFence()s, fix copyright years, update some comments
 - more hasMoreReferrals() merge error fixing
 - fix hasMoreReferrals() merge error
 - update EnumCtx comment
 - remove fullFence() calls, fix reachabilityFence() arguments, remove some unneeded comments
 - simplify some comments
 - ... and 19 more: https://git.openjdk.org/jdk/compare/b6b5ac1e...e36cf5db

Changes: https://git.openjdk.org/jdk/pull/25242/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=25242&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8283660
  Stats: 718 lines in 7 files changed: 391 ins; 90 del; 237 mod
  Patch: https://git.openjdk.org/jdk/pull/25242.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/25242/head:pull/25242

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


More information about the core-libs-dev mailing list