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

8301564: Non-C-heap allocated ResourceHashtable keys and values must have trivial destructor #12355

Conversation

iklam
Copy link
Member

@iklam iklam commented Jan 31, 2023

To ensure we don't have memory leaks or other more serious memory management bugs, I added static asserts to check that the K and V types for ResourceHashtableBase must have trivial destructors if the table is not C_HEAP allocated. Thanks to @JornVernee for the original assert code.

The asserts actually found a problem with ClassLoaderStatsClosure::StatsTable. The space used by the oop in the freed hashtable may be trashed when -XX:+CheckUnhandledOops is enabled, so live objects that reuse the same space may be corrupted. (I tried but couldn't get it to fail).

I also had to change CodeBuffer::SharedTrampolineRequests because it's V type is LinkListImpl<int>, which has a non-trivial destructor. (Note: in this case, the destructor doesn't do anything; we can probably make it go away with C++-20. See https://stackoverflow.com/questions/40094871/sfinae-away-a-destructor)

Testing with tier1~4 + builds-tier5


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-8301564: Non-C-heap allocated ResourceHashtable keys and values must have trivial destructor

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12355

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 31, 2023

👋 Welcome back iklam! 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 Jan 31, 2023

@iklam 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 Jan 31, 2023
@iklam iklam marked this pull request as ready for review February 1, 2023 19:05
@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 1, 2023
@mlbridge
Copy link

mlbridge bot commented Feb 1, 2023

Webrevs

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.

Looks good. Glad there weren't more hashtables breaking this assumption.

@@ -112,7 +112,7 @@ class ClassLoaderStatsClosure : public CLDClosure {
}

typedef ResourceHashtable<oop, ClassLoaderStats,
256, AnyObj::RESOURCE_AREA, mtInternal,
256, AnyObj::C_HEAP, mtInternal,
Copy link
Contributor

Choose a reason for hiding this comment

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

There's an mtStatistics NMT category, can you use that for this? and the instance below?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@openjdk
Copy link

openjdk bot commented Feb 1, 2023

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

8301564: Non-C-heap allocated ResourceHashtable keys and values must have trivial destructor

Reviewed-by: coleenp, jvernee

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 no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential 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 ready Pull request is ready to be integrated label Feb 1, 2023
Copy link
Member

@JornVernee JornVernee left a comment

Choose a reason for hiding this comment

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

This looks good, thanks.

I'll put this here for posterity: we discussed changing ResourceHashtable to always call the destructor of the key and value (sketch here). That would allow using K and V with non-trivial destructors as well. But, this discussion didn't reach a conclusion yet (in particular, there were some doubts expressed over whether a container should be calling destructors at all).

In the mean time, this patch improves upon the status quo.

@iklam
Copy link
Member Author

iklam commented Feb 2, 2023

Thanks @JornVernee and @coleenp for the review.
/integrate

@openjdk
Copy link

openjdk bot commented Feb 2, 2023

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

  • b00b70c: 8286907: keytool should warn about weak PBE algorithms
  • ee0f5b5: 8301392: Port fdlibm log1p to Java
  • f696785: 8300869: Make use of the Double.toString(double) algorithm in java.util.Formatter
  • cf6b9eb: 8301637: ThreadLocalRandom.current().doubles().parallel() contention
  • c647ae6: 8301149: Parallel: Refactor MutableNUMASpace::update_layout

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Feb 2, 2023

@iklam Pushed as commit 04278e6.

💡 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
3 participants