Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8329850: [AIX] Allow loading of different members of same shared library archive #18676

Closed
wants to merge 5 commits into from

Conversation

JoKern65
Copy link
Contributor

@JoKern65 JoKern65 commented Apr 8, 2024

With JDK-8320890 we introduced the capability not to load shared libraries twice if the application wants to do that. Instead we just rise a ref counter. Unfortunately this also suppresses the loading of a second member of a shared library.
This fix introduces an additionally stored hash value for each loaded member and only suppresses duplicate loading if the same member is loaded twice.
If a shared library has no member a hash value of 0 is used to make the code orthogonal.


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-8329850: [AIX] Allow loading of different members of same shared library archive (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 18676

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 8, 2024

👋 Welcome back jkern! 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 Apr 8, 2024

@JoKern65 This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8329850: [AIX] Allow loading of different members of same shared library archive

Reviewed-by: mdoerr, mbaesken, stuefe

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 273 new commits pushed to the master branch:

  • ffd850f: 8309881: Qualified name of a type element depends on its origin (source vs class)
  • 377f2e5: 8329862: libjli GetApplicationHome cleanups and enhance jli tracing
  • 006f090: 8331150: RISC-V: Fix "bad AD file" bug
  • a407dc9: 8327512: JShell does not work correctly when a class named Object or Throwable is defined
  • ea06129: 8322847: java.lang.classfile.BufWriter should specify @throws for its writeXXX methods
  • b3bcc49: 8330181: Move PcDesc cache from nmethod header
  • 1c238d4: 8319990: Update CLDR to Version 45.0
  • ce9eac3: 8331113: createJMHBundle.sh support configurable maven repo mirror
  • 5af6b45: 8330615: avoid signed integer overflows in zip_util.c readCen / hashN
  • 4dfaa9b: 8329805: Deprecate for removal ObjectOutputStream.PutField.write
  • ... and 263 more: https://git.openjdk.org/jdk/compare/be45de1f93e918f928c6bb8bebc3697487adf602...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@TheRealMDoerr, @MBaesken, @tstuefe) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 8, 2024
@openjdk
Copy link

openjdk bot commented Apr 8, 2024

@JoKern65 The following label will be automatically applied to this pull request:

  • hotspot-runtime

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.

@mlbridge
Copy link

mlbridge bot commented Apr 8, 2024

Webrevs

while (*substr) {
hash = (hash << 5) - hash + (unsigned long)*substr++;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should work in practical cases, but what if a hash collision occurs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How likely is a hash collision? My first thought was to store the member string in an additional array. But there is no length limitation. So I cannot just add an char array of e.g. 20 chars, but have to use a pointer to an external dynamically loaded memory holding the string. I came to the conclusion that a hash is much more elegant with a neglectable small risk of a hash collision.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess extremely unlikely. But if it happens, it will be an extremely annoying problem.
I'd probably use strdup, but let's hear what other reviewers think.

@openjdk openjdk bot changed the title JDK-8329850: [AIX] Allow loading of different members of same shared library archive 8329850: [AIX] Allow loading of different members of same shared library archive Apr 10, 2024
@JoKern65
Copy link
Contributor Author

@tstuefe Would you be so kind and please take a look?

@openjdk openjdk bot removed the rfr Pull request is ready for review label Apr 25, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 25, 2024
Copy link
Contributor

@TheRealMDoerr TheRealMDoerr left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for fixing it and for the update!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 25, 2024
Copy link
Member

@MBaesken MBaesken left a comment

Choose a reason for hiding this comment

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

Looks okay to me.

But I think it would be really beneficial to have a (jtreg) test for this.

Copy link
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

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

Had a brief skim over this change.

This would be a lot simpler had we just used string comparison instead of using inodes for equality. Then, we could have just used file name plus member name as key in the table.

Remind me again, why do we compare inodes instead of just file names?

unsigned i = 0;
TableLocker lock;
// check if library belonging to filename is already loaded.
// If yes use stored handle from previous ::dlopen() and increase refcount
for (i = 0; i < g_handletable_used; i++) {
if ((p_handletable + i)->handle &&
(p_handletable + i)->inode == libstat.st_ino &&
(p_handletable + i)->devid == libstat.st_dev) {
(p_handletable + i)->devid == libstat.st_dev &&
(((p_handletable + i)->member == member) ||
Copy link
Member

Choose a reason for hiding this comment

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

If this ever fires (wildly unlikely), its a bug. You are comparing a stack address with something that lives in C heap right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I discussed this with Martin. The meaning of the line is: Check if both are nullptr.
My original implementation was:
(((p_handletable + i)->member == nullptr && member == nullptr) ||
Martin favoured the shorter version above which will have the same result.

Copy link
Member

Choose a reason for hiding this comment

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

It is, to me, not obvious where the member is reset. We delete it, but don't set the pointer to NULL.So, its not obvious that entry->member could not point to a former stale c heap address.

In any case, I prefer the cleanly written out logic. The generated code will be the same anyway, so this brevity just obfuscates your intent and confuses casual readers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Back to the roots.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that Thomas' point is that member = nullptr; is missing after the free operation. I agree with that.

@tstuefe
Copy link
Member

tstuefe commented Apr 25, 2024

One simplification, maybe: Is there some limitation as to the length of the member name, and if yes, reasonably short? If yes, just make the member name inline ion the table entry and save the malloc/strdup and free.

@JoKern65
Copy link
Contributor Author

One simplification, maybe: Is there some limitation as to the length of the member name, and if yes, reasonably short? If yes, just make the member name inline ion the table entry and save the malloc/strdup and free.

I marked this already (see above). Unfortunately there seems to be no length limitation.

Copy link
Contributor

@TheRealMDoerr TheRealMDoerr left a comment

Choose a reason for hiding this comment

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

"Back to the roots" doesn't address the missing member = nullptr;.

Copy link
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

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

LGTM

@JoKern65
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Apr 26, 2024
@openjdk
Copy link

openjdk bot commented Apr 26, 2024

@JoKern65
Your change (at version 97ad367) is now ready to be sponsored by a Committer.

@TheRealMDoerr
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Apr 26, 2024

Going to push as commit cfd19f0.
Since your change was applied there have been 273 commits pushed to the master branch:

  • ffd850f: 8309881: Qualified name of a type element depends on its origin (source vs class)
  • 377f2e5: 8329862: libjli GetApplicationHome cleanups and enhance jli tracing
  • 006f090: 8331150: RISC-V: Fix "bad AD file" bug
  • a407dc9: 8327512: JShell does not work correctly when a class named Object or Throwable is defined
  • ea06129: 8322847: java.lang.classfile.BufWriter should specify @throws for its writeXXX methods
  • b3bcc49: 8330181: Move PcDesc cache from nmethod header
  • 1c238d4: 8319990: Update CLDR to Version 45.0
  • ce9eac3: 8331113: createJMHBundle.sh support configurable maven repo mirror
  • 5af6b45: 8330615: avoid signed integer overflows in zip_util.c readCen / hashN
  • 4dfaa9b: 8329805: Deprecate for removal ObjectOutputStream.PutField.write
  • ... and 263 more: https://git.openjdk.org/jdk/compare/be45de1f93e918f928c6bb8bebc3697487adf602...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 26, 2024
@openjdk openjdk bot closed this Apr 26, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Apr 26, 2024
@openjdk
Copy link

openjdk bot commented Apr 26, 2024

@TheRealMDoerr @JoKern65 Pushed as commit cfd19f0.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants