This is a test bug. The gets the first region, gets top() for the that region, and then uses that top() address to get the region that top() is in. It expects it to be the same region. However, when the region is full, top() is actually the next address beyond the end of the region, so marks the start of the next region. The fix is to simply subtract 1 from top() when it equals end(). Note top() is where the next allocation comes from in the region and end() is the end of region space.
I improved the test by adding printing of the G1 heap, including all regions. I also improved the test by making it test every region, not just the first one. During local testing the first region was always free, so did not make for a very good test, and would not reproduce the issue. When I started testing every region, it failed every time. All you need is one full region for failures. I ran the test 100 times on all supported platforms. --------- - [x] I confirm that I make this contribution in accordance with the [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). ------------- Commit messages: - fix issue with dealing with top() == end() Changes: https://git.openjdk.org/jdk/pull/31469/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=31469&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8386124 Stats: 40 lines in 1 file changed: 35 ins; 0 del; 5 mod Patch: https://git.openjdk.org/jdk/pull/31469.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/31469/head:pull/31469 PR: https://git.openjdk.org/jdk/pull/31469
