Skip to content

Conversation

@veresov
Copy link
Contributor

@veresov veresov commented Jun 3, 2025

Simplify KlassTrainingData constructor. The lines in question come from the old pre-CDS world. They are not needed anymore.


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-8358003: KlassTrainingData initializer reads garbage holder (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25623

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@veresov
Copy link
Contributor Author

veresov commented Jun 3, 2025

mach5 testing in progress, will report back once it's done.

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 3, 2025

👋 Welcome back iveresov! 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 Jun 3, 2025

@veresov 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:

8358003: KlassTrainingData initializer reads garbage holder

Reviewed-by: coleenp, shade, vlivanov

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 60 new commits pushed to the master branch:

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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 3, 2025
Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

Makes sense. I was dumbfounded what was "previous handle", when we are in constructor. I suspected it was something about placement-new code somewhere.

@openjdk
Copy link

openjdk bot commented Jun 3, 2025

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

  • hotspot

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 hotspot hotspot-dev@openjdk.org label Jun 3, 2025
@mlbridge
Copy link

mlbridge bot commented Jun 3, 2025

Webrevs

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 3, 2025
Copy link
Contributor

@iwanowww iwanowww left a comment

Choose a reason for hiding this comment

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

Looks good.

@veresov
Copy link
Contributor Author

veresov commented Jun 3, 2025

It seems like we don't need these release_stores either since the constructor is always run under a lock.
I'll run some testing.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jun 3, 2025
Atomic::release_store(&_holder, const_cast<InstanceKlass*>(klass));
assert(klass != nullptr, "");
Handle hm(JavaThread::current(), klass->java_mirror());
jobject hmj = JNIHandles::make_global(hm);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't you use OopStorage for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are there any advantages?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, transitioned to OopStrage. Please take a look if correctly. I'll be back when the testing is done.

Copy link
Contributor

Choose a reason for hiding this comment

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

The advantage of OopStorage is that jni handles aren't trusted because they come from outside jni calls so have some safefetch code, but OopStorage are trusted so presumably faster.

@veresov
Copy link
Contributor Author

veresov commented Jun 3, 2025

Testing is ok

@veresov
Copy link
Contributor Author

veresov commented Jun 4, 2025

Ok, testing was clean. Please take another look.

@veresov veresov requested review from coleenp, iwanowww and shipilev June 4, 2025 08:43
Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

Right off the bat, before I look at the rest of it: I don't think there is a need to introduce another OopStorage class just for these handles. We already see it would probably require touchups in other code that enumerates OopStorages. So instead, use VM Global one? I.e. do:

 handle = OopHandle(Universe::vm_global(), obj);

Also I cannot spot where we clean these. Note that for OopHandle-s, you have to explicitly call .release, likely in KlassTrainingData destructor.

@veresov
Copy link
Contributor Author

veresov commented Jun 4, 2025

We don't need to release them. KTDs are never destroyed. They just die with the process.
As for OopStorage @coleenp wants it. I gives a bit of an advantage that we can remove the handle field from KTD (since again, we don't ever need to free them).

@veresov
Copy link
Contributor Author

veresov commented Jun 4, 2025

I kind of need to push it today before the fork. Let's try making changes to this minimal. I'm also fine reverting back to before @coleenp suggested OopStorage. And we can address the remaining concerns later.

@shipilev
Copy link
Member

shipilev commented Jun 4, 2025

I kind of need to push it today before the fork. Let's try making changes to this minimal. I'm also fine reverting back to before @coleenp suggested OopStorage. And we can address the remaining concerns later.

Yeah, let's do OopStorage rewrite as the followup.

@veresov
Copy link
Contributor Author

veresov commented Jun 4, 2025

Ok, I reverted this to before the OopStorage changes. And filed https://bugs.openjdk.org/browse/JDK-8358580 to rethink it later. @coleenp are you ok with that?

Copy link
Contributor

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

I'm fine with this and the follow-up issue.

Atomic::release_store(&_holder, const_cast<InstanceKlass*>(klass));
assert(klass != nullptr, "");
Handle hm(JavaThread::current(), klass->java_mirror());
jobject hmj = JNIHandles::make_global(hm);
Copy link
Contributor

Choose a reason for hiding this comment

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

The advantage of OopStorage is that jni handles aren't trusted because they come from outside jni calls so have some safefetch code, but OopStorage are trusted so presumably faster.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 4, 2025
@veresov
Copy link
Contributor Author

veresov commented Jun 4, 2025

/integrate

@openjdk
Copy link

openjdk bot commented Jun 4, 2025

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

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 4, 2025
@openjdk openjdk bot closed this Jun 4, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 4, 2025
@openjdk
Copy link

openjdk bot commented Jun 4, 2025

@veresov Pushed as commit ae1892f.

💡 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 hotspot-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants