Skip to content

8320370: NMT: Change MallocMemorySnapshot to simplify code. #16724

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

Closed
wants to merge 5 commits into from

Conversation

jdksjolen
Copy link
Contributor

@jdksjolen jdksjolen commented Nov 18, 2023

Hi,

MallocMemorySnapshot used to be initialized in a quite non-standard way, using global placement new on an array of size_t of the size required to fit MallocMemorySnapshot. This looks like it was intended to circumvent some ResourceObj internals, but I'm unsure of its purpose. This change does what you expect a regular initialization of a global variable to look like.

Currently running through tier1. GHA passed and so did tier1 on Oracle CI.


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-8320370: NMT: Change MallocMemorySnapshot to simplify code. (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16724

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 18, 2023

👋 Welcome back jsjolen! 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 Nov 18, 2023

@jdksjolen To determine the appropriate audience for reviewing this pull request, one or more labels corresponding to different subsystems will normally be applied automatically. However, no automatic labelling rule matches the changes in this pull request. In order to have an "RFR" email sent to the correct mailing list, you will need to add one or more applicable labels manually using the /label pull request command.

Applicable Labels
  • build
  • client
  • compiler
  • core-libs
  • graal
  • hotspot
  • hotspot-compiler
  • hotspot-gc
  • hotspot-jfr
  • hotspot-runtime
  • i18n
  • ide-support
  • javadoc
  • jdk
  • jmx
  • kulla
  • net
  • nio
  • security
  • serviceability
  • shenandoah

@jdksjolen jdksjolen marked this pull request as ready for review November 19, 2023 12:34
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 19, 2023
@jdksjolen
Copy link
Contributor Author

/label hotspot-runtime

@openjdk openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Nov 20, 2023
@openjdk
Copy link

openjdk bot commented Nov 20, 2023

@jdksjolen
The hotspot-runtime label was successfully added.

@mlbridge
Copy link

mlbridge bot commented Nov 20, 2023

Webrevs

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.

Looks good, smaller nits.

@@ -43,7 +43,7 @@
#include "utilities/ostream.hpp"
#include "utilities/vmError.hpp"

size_t MallocMemorySummary::_snapshot[CALC_OBJ_SIZE_IN_TYPE(MallocMemorySnapshot, size_t)];
MallocMemorySnapshot MallocMemorySummary::_snapshot{};
Copy link
Member

Choose a reason for hiding this comment

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

Why the curly braces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're not necessary, I just have a tendency to explicitly use brace/"uniform" initialization everywhere. I've removed them.

@@ -49,9 +49,6 @@ void VirtualMemory::update_peak(size_t size) {
#endif // ASSERT

void VirtualMemorySummary::initialize() {
assert(sizeof(_snapshot) >= sizeof(VirtualMemorySnapshot), "Sanity Check");
// Use placement operator new to initialize static data area.
::new ((void*)_snapshot) VirtualMemorySnapshot();
}
Copy link
Member

Choose a reason for hiding this comment

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

Can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, thanks! Should've seen that :-).

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.

Good

@openjdk
Copy link

openjdk bot commented Nov 20, 2023

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

8320370: NMT: Change MallocMemorySnapshot to simplify code.

Reviewed-by: stuefe, gziemski, stefank

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 375 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 ready Pull request is ready to be integrated label Nov 20, 2023
@tstuefe
Copy link
Member

tstuefe commented Nov 20, 2023

I believe the reason for the original shape of this code was to avoid initialization altogether if NMT was disabled. @zhengyu123 ?

Copy link

@gerard-ziemski gerard-ziemski left a comment

Choose a reason for hiding this comment

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

Nice clean up!

Just one question: I'm probably missing something here, but did we have to change from ResourceObj to AnyObj for this change to work?

@jdksjolen
Copy link
Contributor Author

Nice clean up!

Just one question: I'm probably missing something here, but did we have to change from ResourceObj to AnyObj for this change to work?

Hi Gerard, no I think it is unnecessary to do this change to make it work (I haven't checked). I do think keeping it as AnyObj is a good idea however, as MallocMemorySnapshot is never resource allocated.

@tstuefe
Copy link
Member

tstuefe commented Nov 21, 2023

Nice clean up!
Just one question: I'm probably missing something here, but did we have to change from ResourceObj to AnyObj for this change to work?

Hi Gerard, no I think it is unnecessary to do this change to make it work (I haven't checked). I do think keeping it as AnyObj is a good idea however, as MallocMemorySnapshot is never resource allocated.

Why not make it a simple object then? Why derive from anything at all?

(Update: I am fine with the current state of the patch; up to you)

@jdksjolen
Copy link
Contributor Author

Nice clean up!
Just one question: I'm probably missing something here, but did we have to change from ResourceObj to AnyObj for this change to work?

Hi Gerard, no I think it is unnecessary to do this change to make it work (I haven't checked). I do think keeping it as AnyObj is a good idea however, as MallocMemorySnapshot is never resource allocated.

Why not make it a simple object then? Why derive from anything at all?

(Update: I am fine with the current state of the patch; up to you)

It's not clear to me what the rules are on this matter. To what degree are plain global classes allowed in HotSpot? I thought that they all need to inherit from AnyObj,CHeapObj, etc. Seems like we're more OK with internal (structs and classes within other classes) being "undecorated" with their allocation capabilities.

@tstuefe
Copy link
Member

tstuefe commented Nov 21, 2023

Nice clean up!
Just one question: I'm probably missing something here, but did we have to change from ResourceObj to AnyObj for this change to work?

Hi Gerard, no I think it is unnecessary to do this change to make it work (I haven't checked). I do think keeping it as AnyObj is a good idea however, as MallocMemorySnapshot is never resource allocated.

Why not make it a simple object then? Why derive from anything at all?
(Update: I am fine with the current state of the patch; up to you)

It's not clear to me what the rules are on this matter. To what degree are plain global classes allowed in HotSpot? I thought that they all need to inherit from AnyObj,CHeapObj, etc. Seems like we're more OK with internal (structs and classes within other classes) being "undecorated" with their allocation capabilities.

I would hope so. Why increase compiler load and force inclusion of unrelated headers for stuff that is really not necessary.
(as I said, I'm fine with the patch as it is. Feel free to push)

@zhengyu123
Copy link
Contributor

zhengyu123 commented Nov 21, 2023

I believe the reason for the original shape of this code was to avoid initialization altogether if NMT was disabled. @zhengyu123 ?

I believe it was coded this way to avoid memory allocation (malloc) during NMT initialization, before tracking infrastructure is ready, e.g. MallocSiteTable is initialized.

IIRC, not using static variable was to workaround the order of static variable initialization by linker, cannot remember the details.

@stefank
Copy link
Member

stefank commented Nov 21, 2023

Nice clean up!
Just one question: I'm probably missing something here, but did we have to change from ResourceObj to AnyObj for this change to work?

Hi Gerard, no I think it is unnecessary to do this change to make it work (I haven't checked). I do think keeping it as AnyObj is a good idea however, as MallocMemorySnapshot is never resource allocated.

Why not make it a simple object then? Why derive from anything at all?

(Update: I am fine with the current state of the patch; up to you)

+1 Please don't use AnyObj unless you really need multiple allocation strategies.

@tstuefe
Copy link
Member

tstuefe commented Nov 21, 2023

I believe the reason for the original shape of this code was to avoid initialization altogether if NMT was disabled. @zhengyu123 ?

I believe it was coded this way to avoid memory allocation (malloc) during NMT initialization, before tracking infrastructure is ready, e.g. MallocSiteTable is initialized.

IIRC, not using static variable was to workaround the order of static variable initialization by linker, cannot remember the details.

That makes a lot of sense. Its a moot point now since https://bugs.openjdk.org/browse/JDK-8256844

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.

Still looks good. Nice simplificaiton.

@jdksjolen
Copy link
Contributor Author

Still looks good. Nice simplificaiton.

Thanks for the re-approval!

Nice clean up!
Just one question: I'm probably missing something here, but did we have to change from ResourceObj to AnyObj for this change to work?

Hi Gerard, no I think it is unnecessary to do this change to make it work (I haven't checked). I do think keeping it as AnyObj is a good idea however, as MallocMemorySnapshot is never resource allocated.

Why not make it a simple object then? Why derive from anything at all?
(Update: I am fine with the current state of the patch; up to you)

+1 Please don't use AnyObj unless you really need multiple allocation strategies.

I'm very happy to hear this :).

@gerard-ziemski, would you mind re-approving also?

@gerard-ziemski
Copy link

Still looks good. Nice simplificaiton.

Thanks for the re-approval!

Nice clean up!
Just one question: I'm probably missing something here, but did we have to change from ResourceObj to AnyObj for this change to work?

Hi Gerard, no I think it is unnecessary to do this change to make it work (I haven't checked). I do think keeping it as AnyObj is a good idea however, as MallocMemorySnapshot is never resource allocated.

Why not make it a simple object then? Why derive from anything at all?
(Update: I am fine with the current state of the patch; up to you)

+1 Please don't use AnyObj unless you really need multiple allocation strategies.

I'm very happy to hear this :).

@gerard-ziemski, would you mind re-approving also?

We currently have:

class MallocMemorySnapshot : public AnyObj {

which used to be:

class MallocMemorySnapshot : public ResourceObj {

Are we OK with using AnyObj here?

Copy link
Member

@stefank stefank left a comment

Choose a reason for hiding this comment

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

With this change it now seems unnecessary to keep the as_snapshot() functions. Right?

@tstuefe
Copy link
Member

tstuefe commented Dec 1, 2023

I'm fine with it either way, but would prefer the object not to inherit from anything if its only used inline or as stack object. In any case, lets ship this.

@jdksjolen
Copy link
Contributor Author

Hi,

Keeping the as_snapshot but removed the inheritance. Thanks for your patience with this PR.

@jdksjolen
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Dec 7, 2023

Going to push as commit a7f6016.
Since your change was applied there have been 375 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 Dec 7, 2023
@openjdk openjdk bot closed this Dec 7, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 7, 2023
@openjdk
Copy link

openjdk bot commented Dec 7, 2023

@jdksjolen Pushed as commit a7f6016.

💡 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.

5 participants