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

8326615: C1/C2 don't handle allocation failure properly during initialization (RuntimeStub::new_runtime_stub fatal crash) #19280

Closed
wants to merge 29 commits into from

Conversation

dafedafe
Copy link
Contributor

@dafedafe dafedafe commented May 17, 2024

Issue

The test compiler/startup/StartupOutput.java fails intermittently due to a crash after correctly printing the error Initial size of CodeCache is too small (the test limits the code cache using -XX:InitialCodeCacheSize=1024K -XX:ReservedCodeCacheSize=1200k).
The appearance of the issue is very dependent on thread scheduling. The original report happens during C1 initialization but C2 initialization is affected as well.

Causes

There is one occurrence during C1 initialization and one during C2 initialization where a call to RuntimeStub::new_runtime_stub can fail fatally if there is not enough space left.
For C1: Compiler::init_c1_runtime -> Runtime1::initialize -> Runtime1::generate_blob_for -> Runtime1::generate_blob -> RuntimeStub::new_runtime_stub.
For C2: C2Compiler::initialize -> OptoRuntime::generate -> OptoRuntime::generate_stub -> Compile::Compile -> Compile::Code_Gen -> PhaseOutput::install -> PhaseOutput::install_stub -> RuntimeStub::new_runtime_stub.

Solution

Instead of avoiding the crash it makes more sense to increase the minimum code cache size by adding the size of the minimal code cache needed for C1 and C2 to CodeCacheMinimumUseSpace.


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-8326615: C1/C2 don't handle allocation failure properly during initialization (RuntimeStub::new_runtime_stub fatal crash) (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 19280

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 17, 2024

👋 Welcome back dfenacci! 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 May 17, 2024

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

8326615: C1/C2 don't handle allocation failure properly during initialization (RuntimeStub::new_runtime_stub fatal crash)

Reviewed-by: thartmann, kvn

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

  • 6f3e3fd: 8339411: [PPC64] cmpxchgw/h/b doesn't handle external Label
  • ed422ed: 8338817: Wrong indent in API docs for java.lang.management.ManagementFactory
  • 288fa60: 8338891: HotSpotDiagnosticsMXBean missing @SInCE tag
  • dc4fd89: 8339359: RISC-V: Use auipc explicitly in far_jump and far_call macro assembler routines
  • 3a88fd4: 8334724: C2: remove PhaseIdealLoop::cast_incr_before_loop()
  • 62dad3a: 8339351: Remove duplicate line in FileMapHeader::print
  • 0e6bb51: 8339063: [aarch64] Skip verify_sve_vector_length after native calls if SVE supports 128 bits VL only
  • b1163bc: 8256211: assert fired in java/net/httpclient/DependentPromiseActionsTest (infrequent)
  • 03ba37e: 8339169: Remove NaiveHuffman coder
  • a136a85: 8338768: Introduce runtime lookup to check for static builds
  • ... and 27 more: https://git.openjdk.org/jdk/compare/ff59532ddd3002df61e46d58b3f29d26c78295da...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 openjdk bot changed the title JDK-8326615: C1/C2 don't handle allocation failure properly during initialization (RuntimeStub::new_runtime_stub fatal crash) 8326615: C1/C2 don't handle allocation failure properly during initialization (RuntimeStub::new_runtime_stub fatal crash) May 17, 2024
@openjdk
Copy link

openjdk bot commented May 17, 2024

@dafedafe this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout JDK-8326615
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label May 17, 2024
@openjdk
Copy link

openjdk bot commented May 17, 2024

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

  • hotspot-compiler

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-compiler hotspot-compiler-dev@openjdk.org label May 17, 2024
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label May 17, 2024
@dafedafe dafedafe marked this pull request as ready for review May 21, 2024 06:45
@openjdk openjdk bot added the rfr Pull request is ready for review label May 21, 2024
@mlbridge
Copy link

mlbridge bot commented May 21, 2024

Copy link
Member

@TobiHartmann TobiHartmann left a comment

Choose a reason for hiding this comment

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

This is not a regression in JDK 23, right? Could you please adjust the affects versions in JIRA accordingly?

Looks good to me otherwise.

src/hotspot/share/c1/c1_Compiler.cpp Outdated Show resolved Hide resolved
src/hotspot/share/c1/c1_Runtime1.cpp Outdated Show resolved Hide resolved
@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 21, 2024
dafedafe and others added 2 commits May 21, 2024 11:17
Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
@dafedafe
Copy link
Contributor Author

This is not a regression in JDK 23, right? Could you please adjust the affects versions in JIRA accordingly?

It is not. Fixing the version.
Thanks a lot for reviewing @TobiHartmann.

Copy link
Member

@TobiHartmann TobiHartmann left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -280,6 +285,7 @@ void Runtime1::initialize(BufferBlob* blob) {
#endif
BarrierSetC1* bs = BarrierSet::barrier_set()->barrier_set_c1();
bs->generate_c1_runtime_stubs(blob);
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to handle failures in generate_c1_runtime_stubs? With the assert removed, I think we'll get a nullptr crash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, you're right. Actually that call could potentially fail too.
I've added code to handle that case as well.
Thanks @dean-long!

Copy link
Member

@TobiHartmann TobiHartmann 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 otherwise.

src/hotspot/share/gc/x/c1/xBarrierSetC1.cpp Outdated Show resolved Hide resolved
src/hotspot/share/gc/z/c1/zBarrierSetC1.cpp Outdated Show resolved Hide resolved
src/hotspot/share/gc/z/c1/zBarrierSetC1.cpp Outdated Show resolved Hide resolved
dafedafe and others added 3 commits May 28, 2024 09:11
Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
@dafedafe
Copy link
Contributor Author

Looks good to me otherwise.

Thanks for the review @TobiHartmann!

@dean-long
Copy link
Member

This looks OK, but isn't it a lot of changes just to get this test to pass? Aren't all of these allocation failures ultimately fatal? Is there a simpler way to handle this problem?

@dafedafe
Copy link
Contributor Author

dafedafe commented Jun 4, 2024

This looks OK, but isn't it a lot of changes just to get this test to pass? Aren't all of these allocation failures ultimately fatal? Is there a simpler way to handle this problem?

It seems a bit much indeed but I think there is potentially always the possibility of not failing but only disabling the compiler. @dean-long do you think the VM would anyway fail later on?

@openjdk openjdk bot added rfr Pull request is ready for review and removed merge-conflict Pull request has merge conflict with target branch labels Aug 27, 2024
Comment on lines 28 to 29
#include "c1/c1_Compiler.hpp"
#include "opto/c2compiler.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

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

These should be also under COMPILER*_PRESENT macros.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right! Fixed. Thanks @vnkozlov.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Good.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 30, 2024
Copy link
Member

@TobiHartmann TobiHartmann left a comment

Choose a reason for hiding this comment

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

That looks good to me too.

@dafedafe
Copy link
Contributor Author

dafedafe commented Sep 3, 2024

Thanks @vnkozlov @TobiHartmann for your reviews!

@dafedafe
Copy link
Contributor Author

dafedafe commented Sep 3, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Sep 3, 2024

Going to push as commit 633fad8.
Since your change was applied there have been 37 commits pushed to the master branch:

  • 6f3e3fd: 8339411: [PPC64] cmpxchgw/h/b doesn't handle external Label
  • ed422ed: 8338817: Wrong indent in API docs for java.lang.management.ManagementFactory
  • 288fa60: 8338891: HotSpotDiagnosticsMXBean missing @SInCE tag
  • dc4fd89: 8339359: RISC-V: Use auipc explicitly in far_jump and far_call macro assembler routines
  • 3a88fd4: 8334724: C2: remove PhaseIdealLoop::cast_incr_before_loop()
  • 62dad3a: 8339351: Remove duplicate line in FileMapHeader::print
  • 0e6bb51: 8339063: [aarch64] Skip verify_sve_vector_length after native calls if SVE supports 128 bits VL only
  • b1163bc: 8256211: assert fired in java/net/httpclient/DependentPromiseActionsTest (infrequent)
  • 03ba37e: 8339169: Remove NaiveHuffman coder
  • a136a85: 8338768: Introduce runtime lookup to check for static builds
  • ... and 27 more: https://git.openjdk.org/jdk/compare/ff59532ddd3002df61e46d58b3f29d26c78295da...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Sep 3, 2024

@dafedafe Pushed as commit 633fad8.

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

Successfully merging this pull request may close these issues.

4 participants