Skip to content

Conversation

@bchristi-git
Copy link
Member

@bchristi-git bchristi-git commented May 14, 2025

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

(The first PR for this fix started some substantial discussions, leading to, among other things, the 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.

Edit: (Re)viewers: due to there being a lot of indentation changes, you might consider enabling the "Hide whitespace" option on the "Files changed" tab. To my eye, it gives a better view of the changes.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8283660: Convert com/sun/jndi/ldap/AbstractLdapNamingEnumeration.java finalizer to Cleaner (Sub-task - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25242/head:pull/25242
$ git checkout pull/25242

Update a local copy of the PR:
$ git checkout pull/25242
$ git pull https://git.openjdk.org/jdk.git pull/25242/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25242

View PR using the GUI difftool:
$ git pr show -t 25242

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25242.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 14, 2025

👋 Welcome back bchristi! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented May 14, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the rfr Pull request is ready for review label May 14, 2025
@openjdk
Copy link

openjdk bot commented May 14, 2025

@bchristi-git The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label May 14, 2025
@mlbridge
Copy link

mlbridge bot commented May 14, 2025

Webrevs

this.homeCtx = homeCtx;
homeCtx.incEnumCount();
enumClnt = homeCtx.clnt; // remember
this.enumCtx.homeCtx.incEnumCount();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bchristi-git Would it make sense to increment this in the EnumCtx ctor instead?

Comment on lines -393 to -394
protected final void finalize() {
cleanup();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

Comment on lines +56 to +59
// No reachabilityFence here for now.
// super() call (aka AbstrctLdapNamingEnumeration ctor) keeps 'this'
// reachable until end of Cleaner registration. Code after that
// clearly does not touch cleanable state.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bchristi-git I fear this could be a brittle assumption. Would an extra reachabilityFence here hurt?

Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good. I haven't verified whether all methods that need a reachabilityFence have it. This will require further analysis (from me).
As Alan noted it would be really good if we could use try-with-resource, but I am not expert enough in LDAP search implementation to figure out whether that's feasible.

Your proposed fix preseves the status quo - where a finalizer has been replaced by a cleaner - and asserting that the two are equivalent seems more trackable for now.

errEx = ne.errEx;
try {
// Cleanup previous context first
getHomeCtx().decEnumCount();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for calling getHomeCtx() here when we use enumCtxt.homeCtx a few lines below?

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 8, 2025

@bchristi-git This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 6, 2025

@bchristi-git This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

@bridgekeeper bridgekeeper bot closed this Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-libs core-libs-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

4 participants