Skip to content

Conversation

@jdksjolen
Copy link
Contributor

@jdksjolen jdksjolen commented Sep 2, 2025

Hi,

This PR adds the missing locks for the tests and MemMapPrinter, also fixes a small bug in walk_virtual_memory. See inline review comments.

Passes tier1.


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-8366658: Add missing locks when accessing the VirtualMemoryTracker instance in tests and MemMapPrinter (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27038

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 2, 2025

👋 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 Sep 2, 2025

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

8366658: Add missing locks when accessing the VirtualMemoryTracker instance in tests and MemMapPrinter

Reviewed-by: azafari, phubner

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 242 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 changed the title 8366658 8366658: Add missing locks when accessing the VirtualMemoryTracker instance in tests and MemMapPrinter Sep 2, 2025
@openjdk
Copy link

openjdk bot commented Sep 2, 2025

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

@openjdk openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Sep 2, 2025
Comment on lines 346 to 349
class VirtualMemoryWalker : public StackObj {
public:
virtual bool do_allocation_site(const ReservedMemoryRegion* rgn) { return false; }
public:
virtual bool do_allocation_site(const ReservedMemoryRegion* rgn) { return false; }
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indentation fix

Comment on lines 61 to 63
LOG("In reserved region " PTR_FORMAT ", size %X:", p2i(rmr.base()), rmr.size());
VirtualMemoryTracker::Instance::tree()->visit_committed_regions(rmr, [&](CommittedMemoryRegion& region) {
vmt.tree()->visit_committed_regions(rmr, [&](CommittedMemoryRegion& region) {
LOG(" committed region: " PTR_FORMAT ", size %X", p2i(region.base()), region.size());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here the VMT was passed along but never actually used for printing

Comment on lines 211 to 221
bool VirtualMemoryTracker::walk_virtual_memory(VirtualMemoryWalker* walker) {
MemTracker::NmtVirtualMemoryLocker nvml;
bool ret = true;
tree()->visit_reserved_regions([&](ReservedMemoryRegion& rgn) {
if (!walker->do_allocation_site(&rgn)) {
ret = false;
return false;
}
return true;
});
return true;
return ret;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A VirtualMemoryWalker returned true or false depending on whether or not its operation succeeded, and we are meant to pass that along as the return value of walk_virtual_memory. That was missing, now fixed.

Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!

Comment on lines +176 to +182
static inline bool walk_virtual_memory(VirtualMemoryWalker* walker) {
assert_post_init();
if (!enabled()) return false;
MemTracker::NmtVirtualMemoryLocker nvml;
return VirtualMemoryTracker::Instance::walk_virtual_memory(walker);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this so that we can do the usual checks and lock taking in the place where we typically take the lock.

@jdksjolen jdksjolen marked this pull request as ready for review September 11, 2025 10:08
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 11, 2025
@mlbridge
Copy link

mlbridge bot commented Sep 11, 2025

Webrevs

Comment on lines 41 to 50
{
MemTracker::NmtVirtualMemoryLocker nvml;
VirtualMemoryTracker::Instance::add_reserved_region(stack_end, stack_size, CALLER_PC, mtThreadStack);
}

// snapshot current stack usage
VirtualMemoryTracker::Instance::snapshot_thread_stacks();
{
MemTracker::NmtVirtualMemoryLocker nvml;
VirtualMemoryTracker::Instance::snapshot_thread_stacks();
}
Copy link
Member

Choose a reason for hiding this comment

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

Why two separate locking blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No reason, let's merge them.

}
}

static inline bool walk_virtual_memory(VirtualMemoryWalker* walker) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: should probably be in memTracker.inline.hpp?

return VirtualMemoryTracker::Instance::walk_virtual_memory(walker);
}

static inline MemoryFileTracker::MemoryFile* register_file(const char* descriptive_name) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here. I wonder why we have the inline header when it only contains MemTracker::check_exceeds_limit...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, so do I. I've never used the inline header myself. I think moving stuff over to the inline header is something we should think about in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

I'm okay with that.

Comment on lines 211 to 221
bool VirtualMemoryTracker::walk_virtual_memory(VirtualMemoryWalker* walker) {
MemTracker::NmtVirtualMemoryLocker nvml;
bool ret = true;
tree()->visit_reserved_regions([&](ReservedMemoryRegion& rgn) {
if (!walker->do_allocation_site(&rgn)) {
ret = false;
return false;
}
return true;
});
return true;
return ret;
}
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!

Copy link
Member

@Arraying Arraying left a comment

Choose a reason for hiding this comment

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

Happy to address the inline header refactoring separately.

@openjdk
Copy link

openjdk bot commented Sep 12, 2025

⚠️ @jdksjolen This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

Copy link
Contributor

@afshin-zafari afshin-zafari 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.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 12, 2025
@jdksjolen
Copy link
Contributor Author

/integrate

Thanks!

@openjdk
Copy link

openjdk bot commented Sep 15, 2025

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

openjdk bot commented Sep 15, 2025

@jdksjolen Pushed as commit a7dc011.

💡 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