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

8340631: assert(reserved_rgn->contain_region(base_addr, size)) failed: Reserved CDS region should contain this mapping region #22743

Closed
wants to merge 18 commits into from

Conversation

matias9927
Copy link
Contributor

@matias9927 matias9927 commented Dec 13, 2024

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 in MetaspaceShared::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

  • 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-8340631: assert(reserved_rgn->contain_region(base_addr, size)) failed: Reserved CDS region should contain this mapping region (Bug - P4)

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

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 13, 2024

👋 Welcome back matsaave! 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 Dec 13, 2024

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

8340631: assert(reserved_rgn->contain_region(base_addr, size)) failed: Reserved CDS region should contain this mapping region

Reviewed-by: iklam, jsjolen, 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 25 new commits pushed to the master branch:

  • 9f3c5f9: 8344907: NullPointerException in Win32ShellFolder2.getSystemIcon when "icon" is null
  • 22f70a7: 8321413: IllegalArgumentException: Code length outside the allowed range while creating a jlink image
  • 3bfa952: 8283795: Add TLSv1.3 and CNSA 1.0 algorithms to implementation requirements
  • 1ef77cd: 8347171: (dc) java/nio/channels/DatagramChannel/InterruptibleOrNot.java fails with virtual thread factory
  • 72f1114: 8346705: SNI not sent with Java 22+ using java.net.http.HttpClient.Builder#sslParameters
  • cb9a98b: 8347141: Several javac tests compile with an unnecessary -Xlint:-path flag
  • f9b1133: 8346880: [aix] java/lang/ProcessHandle/InfoTest.java still fails: "reported cputime less than expected"
  • 9c72ded: 8346036: Unnecessary Hashtable usage in javax.swing.text.html.parser.Entity
  • 3024a73: 8345782: Refining the cases that libjsig deprecation warning is issued
  • 2801bc6: 8346460: NotifyFramePop should return JVMTI_ERROR_DUPLICATE
  • ... and 15 more: https://git.openjdk.org/jdk/compare/ea49537726db6530f0ddcc04d9938df3d6d18250...master

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
Copy link

openjdk bot commented Dec 13, 2024

@matias9927 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 Dec 13, 2024
@matias9927 matias9927 marked this pull request as ready for review December 13, 2024 19:55
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 13, 2024
@mlbridge
Copy link

mlbridge bot commented Dec 13, 2024

Copy link
Member

@iklam iklam left a comment

Choose a reason for hiding this comment

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

LGTM

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 16, 2024
Copy link
Contributor

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

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.

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.

Comment on lines 2416 to 2423
// 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);
}
Copy link
Member

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.

Suggested change
// 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.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Dec 17, 2024
@matias9927
Copy link
Contributor Author

Thank you for the reviews and discussion @iklam @jdksjolen and @stefank!
/integrate

@openjdk
Copy link

openjdk bot commented Dec 17, 2024

@matias9927 This pull request has not yet been marked as ready for integration.

char* mapped_base = r->mapped_base();
size_t size = r->used_aligned();

assert(rs.is_reserved(), "must be");
Copy link
Member

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.

@stefank
Copy link
Member

stefank commented Dec 20, 2024

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:
master...stefank:jdk:pull/22743

@iklam
Copy link
Member

iklam commented Jan 2, 2025

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: master...stefank:jdk:pull/22743

I think this is better.

Stefan's change also reveals a new bug -- unmap_stand_alone_region(MetaspaceShared::hp) shouldn't be called by FileMapInfo::map_heap_region_impl(), as it will unreserve a block of memory inside the reserved heap region. This call should be removed.

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.

// 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);
Copy link
Member

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.
Copy link
Member

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);
Copy link
Member

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

Copy link
Contributor Author

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()?

Copy link
Member

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.

Copy link
Member

@iklam iklam left a comment

Choose a reason for hiding this comment

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

LGTM!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 9, 2025
@matias9927
Copy link
Contributor Author

Thanks for the reviews and discussion @iklam, @stefank. and @jdksjolen!
/integrate

@openjdk
Copy link

openjdk bot commented Jan 9, 2025

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

  • 665c39c: 8347375: Extra

    tag in robot specification

  • b335ea9: 8347122: Add missing @serial tags to module java.desktop
  • df28cec: 8345144: Robot does not specify all causes of IllegalThreadStateException
  • 9f3c5f9: 8344907: NullPointerException in Win32ShellFolder2.getSystemIcon when "icon" is null
  • 22f70a7: 8321413: IllegalArgumentException: Code length outside the allowed range while creating a jlink image
  • 3bfa952: 8283795: Add TLSv1.3 and CNSA 1.0 algorithms to implementation requirements
  • 1ef77cd: 8347171: (dc) java/nio/channels/DatagramChannel/InterruptibleOrNot.java fails with virtual thread factory
  • 72f1114: 8346705: SNI not sent with Java 22+ using java.net.http.HttpClient.Builder#sslParameters
  • cb9a98b: 8347141: Several javac tests compile with an unnecessary -Xlint:-path flag
  • f9b1133: 8346880: [aix] java/lang/ProcessHandle/InfoTest.java still fails: "reported cputime less than expected"
  • ... and 18 more: https://git.openjdk.org/jdk/compare/ea49537726db6530f0ddcc04d9938df3d6d18250...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jan 9, 2025

@matias9927 Pushed as commit 931914a.

💡 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