Skip to content

Conversation

walulyai
Copy link
Member

@walulyai walulyai commented Mar 26, 2025

Hi,

Please review this change to ensure that G1 provisions for at least one Eden region after a GC when computing the young length target.

The issue reported in the CR occurs at the end of a GC, after successfully expanding the heap, an allocation fails because policy()->should_allocate_mutator_region() returns false. This happens because the computation did not properly account for young regions already allocated as survivor regions, leading to an Eden region target of zero.

With this change, we factor in the young regions that have already been allocated as survivor regions and ensure that at least one region is targeted for Eden.

Testing: Tier 1-3
Reproducer in the CR.


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-8352765: G1CollectedHeap::expand_and_allocate() may fail to allocate even after heap expansion succeeds (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24257

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@walulyai walulyai changed the title 8352765 : G1CollectedHeap::expand_and_allocate() may fail to allocate even after heap expansion succeeds 8352765: G1CollectedHeap::expand_and_allocate() may fail to allocate even after heap expansion succeeds Mar 26, 2025
@bridgekeeper
Copy link

bridgekeeper bot commented Mar 26, 2025

👋 Welcome back iwalulya! 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 Mar 26, 2025

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

8352765: G1CollectedHeap::expand_and_allocate() may fail to allocate even after heap expansion succeeds

Reviewed-by: tschatzl, manc

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 109 new commits pushed to the master branch:

  • 2592513: 8350577: Fix missing Assertion Predicates when splitting loops
  • 59629f8: 8351040: [REDO] Protection zone for easier detection of accidental zero-nKlass use
  • 8cbadf7: 8317976: Optimize SIMD sort for AMD Zen 4
  • b9d7a75: 8352879: TestPeriod.java and TestGetContentType.java run wrong test class
  • 895aabc: 8351233: [ASAN] avx2-emu-funcs.hpp:151:20: error: ‘D.82188’ is used uninitialized
  • 3d2c3cd: 8352970: Remove unnecessary Windows version check in Win32ShellFolderManager2
  • c70ad6a: 8352906: stdout/err.encoding on Windows set by incorrect Win32 call
  • da3bb06: 8352685: Opensource JInternalFrame tests - series2
  • d809033: 8341775: Duplicate manifest files are removed by jarsigner after signing
  • a269bef: 8350459: MontgomeryIntegerPolynomialP256 multiply intrinsic with AVX2 on x86_64
  • ... and 99 more: https://git.openjdk.org/jdk/compare/a8757332667df3fe41a29a7eedb2a7234d23c2a0...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 Mar 26, 2025

@walulyai The following label will be automatically applied to this pull request:

  • hotspot-gc

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-gc hotspot-gc-dev@openjdk.org label Mar 26, 2025
@walulyai walulyai marked this pull request as ready for review March 26, 2025 15:27
@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 26, 2025
@mlbridge
Copy link

mlbridge bot commented Mar 26, 2025

Webrevs

Comment on lines 359 to 360
"receiving young %u receiving additional eden %u",
receiving_young,
receiving_eden,
Copy link
Contributor

Choose a reason for hiding this comment

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

the log message reads "receiving young" still.

"receiving additional eden %u",
free_outside_reserve, receiving_within_reserve,
receiving_young, receiving_additional_eden);
receiving_eden, receiving_additional_eden);
Copy link
Contributor

Choose a reason for hiding this comment

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

Log message needs update.

Copy link
Contributor

@caoman caoman left a comment

Choose a reason for hiding this comment

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

Thank you for the quick fix!

I just have a two questions, which probably does not need to be addressed in this PR.

  1. Is it possible for expand_and_allocate() to run into the receiving_additional_eden = 0; situation under the if (allocated_young_length >= desired_young_length) branch?
  2. It feels like G1 should recalculate young list length parameters after a successful expand() or shrink(). Currently G1Policy::record_new_heap_size() only recalculates the min/max young lengths. Is it reasonable to run calculate_young_desired_length() and calculate_young_target_length() inside G1Policy::record_new_heap_size()?

@walulyai
Copy link
Member Author

walulyai commented Mar 28, 2025

I just have a two questions, which probably does not need to be addressed in this PR.

1. Is it possible for `expand_and_allocate()` to run into the [`receiving_additional_eden = 0;`](https://github.com/openjdk/jdk/blob/2ea1557a0fdaf551d75365d1351bfbd73319dcfb/src/hotspot/share/gc/g1/g1Policy.cpp#L320) situation under the `if (allocated_young_length >= desired_young_length)` branch?

2. It feels like G1 should recalculate young list length parameters after a successful `expand()` or `shrink()`. Currently `G1Policy::record_new_heap_size()` only recalculates the min/max young lengths. Is it reasonable to run `calculate_young_desired_length()` and `calculate_young_target_length()` inside `G1Policy::record_new_heap_size()`?

Yes, I think we need to do the recalculation after expand as the expansion changes the number of free regions available and so should affect the young_[desired,target]_lengths. Otherwise, it is possible to expand and fail allocation. This can be addressed in a separate PR though.

No, scratch that; after GC, the desired_young_length > allocated_young_length.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Mar 31, 2025
@walulyai
Copy link
Member Author

Thanks @caoman and @tschatzl for the reviews!

/integrate

@openjdk
Copy link

openjdk bot commented Mar 31, 2025

Going to push as commit 804a8fa.
Since your change was applied there have been 113 commits pushed to the master branch:

  • 22f630c: 8352415: x86: Tighten up template interpreter method entry code
  • 6fbaa06: 8353176: C1: x86 patching stub always calls Thread::current()
  • 79d0c94: 8352114: New test runtime/interpreter/CountBytecodesTest.java is failing
  • 23e3b3f: 8351156: C1: Remove FPU stack support after 32-bit x86 removal
  • 2592513: 8350577: Fix missing Assertion Predicates when splitting loops
  • 59629f8: 8351040: [REDO] Protection zone for easier detection of accidental zero-nKlass use
  • 8cbadf7: 8317976: Optimize SIMD sort for AMD Zen 4
  • b9d7a75: 8352879: TestPeriod.java and TestGetContentType.java run wrong test class
  • 895aabc: 8351233: [ASAN] avx2-emu-funcs.hpp:151:20: error: ‘D.82188’ is used uninitialized
  • 3d2c3cd: 8352970: Remove unnecessary Windows version check in Win32ShellFolderManager2
  • ... and 103 more: https://git.openjdk.org/jdk/compare/a8757332667df3fe41a29a7eedb2a7234d23c2a0...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Mar 31, 2025

@walulyai Pushed as commit 804a8fa.

💡 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-gc hotspot-gc-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants