-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8340631: assert(reserved_rgn->contain_region(base_addr, size)) failed: Reserved CDS region should contain this mapping region #22743
Conversation
…: Reserved CDS region should contain this mapping region
👋 Welcome back matsaave! A progress list of the required criteria for merging this PR into |
@matias9927 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:
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 25 new commits pushed to the
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 |
@matias9927 The following label will be automatically applied to this pull request:
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. |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice solution for fixing the difference between Windows and the rest of the platforms!
I've added one nit below that you can ignore if you want to. I've also added a request/wish for an assert.
src/hotspot/share/cds/filemap.cpp
Outdated
// If the region is inside an active ReservedSpace, its memory and address space will be | ||
// freed when the ReservedSpace is released. | ||
if (!rs.is_reserved()) { | ||
unmap_region(idx); | ||
} else { | ||
// Treat this region as if it has been unmapped | ||
region_at(idx)->set_mapped_base(nullptr); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal taste, but I tend to think that the code becomes easier to read if you remove the negation in if/else statements.
// If the region is inside an active ReservedSpace, its memory and address space will be | |
// freed when the ReservedSpace is released. | |
if (!rs.is_reserved()) { | |
unmap_region(idx); | |
} else { | |
// Treat this region as if it has been unmapped | |
region_at(idx)->set_mapped_base(nullptr); | |
} | |
// If the region is inside an active ReservedSpace, its memory and address space will be | |
// freed when the ReservedSpace is released. | |
if (rs.is_reserved()) { | |
// Treat this region as if it has been unmapped | |
region_at(idx)->set_mapped_base(nullptr); | |
} else { | |
unmap_region(idx); | |
} |
It would also be good to have an assert to check that the unmapped region actually is within the provided ReservedSpace.
Thank you for the reviews and discussion @iklam @jdksjolen and @stefank! |
@matias9927 This pull request has not yet been marked as ready for integration. |
src/hotspot/share/cds/filemap.cpp
Outdated
char* mapped_base = r->mapped_base(); | ||
size_t size = r->used_aligned(); | ||
|
||
assert(rs.is_reserved(), "must be"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already checked in the if-statement.
I would like to propose that we push the assert into unmap_region so that we don't have to duplicate the logic to decide if we should assert or unmap. Please take a look at this version of the fix and see what you think about it: |
I think this is better. Stefan's change also reveals a new bug -- This failure should be very very rare: The bitmap region is very small. If the process can't even map that, it's on the verge of dying due to OOM anyway. That's why we haven't caught this in the wild, but we should fix it nonetheless. |
src/hotspot/share/cds/filemap.cpp
Outdated
// This region was mapped inside a ReservedSpace. Its memory will be freed when the ReservedSpace | ||
// is released. Zero it so that we don't accidentally read its content. | ||
log_info(cds)("Region #%d (%s) is in a reserved space, it will be freed when the space is released", i, shared_region_name[i]); | ||
r->set_mapped_base(nullptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need for this line as it will be set to nullptr below line line 2450.
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved. | |||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only change in this file.
@@ -1889,7 +1889,7 @@ MapArchiveResult FileMapInfo::map_region(int i, intx addr_delta, char* mapped_ba | |||
FileMapRegion* r = region_at(i); | |||
size_t size = r->used_aligned(); | |||
char *requested_addr = mapped_base_address + r->mapping_offset(); | |||
assert(r->mapped_base() == nullptr, "must be not mapped yet"); | |||
assert(!is_mapped(), "must be not mapped yet"); | |||
assert(requested_addr != nullptr, "must be specified"); | |||
|
|||
r->set_mapped_from_file(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add r->set_in_reserved_space(false);
here, as the r
can be used twice (first map at requested location; if that fails, map at random location).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that belong here or should it be placed in init()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FileMapRegion::init()
is called once, during dump time. r->set_in_reserved_space(false)
should be called there as well.
During run time, FileMapInfo::map_region()
can be called twice, on the same index i
, so the _in_reserved_space
needs to be reset at the beginning of each call. That would be similar to what we do with _mapped_from_file
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks for the reviews and discussion @iklam, @stefank. and @jdksjolen! |
Going to push as commit 931914a.
Your commit was automatically rebased without conflicts. |
@matias9927 Pushed as commit 931914a. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
What testing with
UseCompressedClassPointers
set to false, this assert is hit due to memory being released twice during the failure path of CDS archive mapping. This patch makes it so the RW and RO regions are only released once at the end inMetaspaceShared::release_reserved_spaces()
.This patch hides
unmap_region
as the method should not be called on regions that were reserved. Instead, the region is skipped and we verify that it is indeed in the reserved space. Verified` with tier 1-4 tests.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22743/head:pull/22743
$ git checkout pull/22743
Update a local copy of the PR:
$ git checkout pull/22743
$ git pull https://git.openjdk.org/jdk.git pull/22743/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 22743
View PR using the GUI difftool:
$ git pr show -t 22743
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22743.diff
Using Webrev
Link to Webrev Comment