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

8298720: Insufficient error handling when CodeBuffer is exhausted #11839

Closed
wants to merge 7 commits into from

Conversation

TobiHartmann
Copy link
Member

@TobiHartmann TobiHartmann commented Jan 4, 2023

This patch fixes various places in C1 and C2 on Aarch64 and RISC-V that miss proper error handling when the code buffer is exhausted, leading to crashes. Similar but incomplete patches went in with JDK-8130309, JDK-8248411 and JDK-8272094 in the past.

These issues are extremely hard to reproduce, even with the -XX:+StressCodeBuffers option, because code buffer expansion needs to fail at the exact moment when a specific (unhandled) instruction is emitted. Even with the stress option, we expand the code buffer such that multiple instructions will fit and in addition, chances are high that we simply bail out from compilation before emitting the problematic instruction. I attached a patch to JDK-8298720, that makes -XX:+StressCodeBuffers randomized and more aggressive. With that, I can reproduce the issue reliably but it's extremely slow and therefore not well suited for integration.

I now went over all usages of CodeBuffer::expand to make sure that we have proper error handling in place and found some remaining issues in JVMCI code. I filed JDK-8299570 to address them.

I would need help to test the RISC-V specific changes.

Thanks,
Tobias


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-8298720: Insufficient error handling when CodeBuffer is exhausted

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11839

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 4, 2023

👋 Welcome back thartmann! 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 Jan 4, 2023

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

  • hotspot

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 hotspot-dev@openjdk.org label Jan 4, 2023
@TobiHartmann TobiHartmann reopened this Jan 4, 2023
@openjdk openjdk bot added the rfr Pull request is ready for review label Jan 4, 2023
@mlbridge
Copy link

mlbridge bot commented Jan 4, 2023

Webrevs

@RealFYang
Copy link
Member

RealFYang commented Jan 4, 2023

Hi! Thanks for handling RISC-V at the same time. I can help arrange some necessary tests on linux-riscv64 for those changes.

@TobiHartmann
Copy link
Member Author

Thanks @RealFYang! It's mostly about verifying that I did not miss any label in the reset_labels calls. You should be able to hardcode the bailout to always true and check if we don't hit any assert.

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.

My main question is: can we do bailout in MacroAssembler::trampoline_call() instead of later in all over places?
In c1_LIRAssembler_ppc.cpp it bailout in emit_trampoline_stub_for_call().

src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp Outdated Show resolved Hide resolved
@TobiHartmann
Copy link
Member Author

Thanks for the review, Vladimir.

can we do bailout in MacroAssembler::trampoline_call() instead of later in all over places?

We could access the current C1 Compilation via Compilation::current() and trigger the bailout from the C1 MacroAssembler. We can't push it further down into the MacroAssembler methods because they are shared and also used by the stubGenerator.

I updated the patch accordingly. Do you prefer that solution?

@RealFYang
Copy link
Member

RealFYang commented Jan 5, 2023

Thanks @RealFYang! It's mostly about verifying that I did not miss any label in the reset_labels calls. You should be able to hardcode the bailout to always true and check if we don't hit any assert.

Hi, fastdebug bootcycle is fine on linux-riscv64 platform.
And If I hardcoded the bailout to always true, I got following assertion error when I do native fastdebug build on both aarch64 and riscv64 platforms:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/realfyang/openjdk-jdk/src/hotspot/share/opto/output.cpp:3241), pid=2565744, tid=2566009
#  assert(!C->failing()) failed: Must not have pending failure. Reason is: CodeCache is full
#
# JRE version: OpenJDK Runtime Environment (21.0) (fastdebug build 21-internal-adhoc.realfyang.openjdk-jdk)
# Java VM: OpenJDK 64-Bit Server VM (fastdebug 21-internal-adhoc.realfyang.openjdk-jdk, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-aarch64)
# Problematic frame:
# V  [libjvm.so+0x14fa71c]  PhaseOutput::scratch_emit_size(Node const*)+0x314

@TobiHartmann
Copy link
Member Author

Thanks for testing, @RealFYang. That assert is expected as the code assumes that the scratch buffer is always large enough in size and code emission should never fail. Of course, that's not true when hardcoding the bailout.

Missing to reset a label before the bailout would lead to a "Label was never bound to a location, but it was used as a jmp target" assert. Thanks for verifying that this is not the case.

Copy link
Member

@RealFYang RealFYang 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.

@openjdk
Copy link

openjdk bot commented Jan 5, 2023

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

8298720: Insufficient error handling when CodeBuffer is exhausted

Reviewed-by: kvn, fyang

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

  • b908388: 8298449: Unnecessary Vector usage in MetaData.ProxyPersistenceDelegate
  • be64bf8: 8299329: Assertion failure with fastdebug build when trying to use CDS without classpath
  • 8723847: 8298848: C2: clone all of (CmpP (LoadKlass (AddP down at split if
  • 1ca31d3: 8299657: sun/tools/jhsdb/SAGetoptTest.java fails after 8299470
  • e7361cb: 8299430: Cleanup: delete unnecessary semicolons in java.desktop module
  • c929d8b: 8299475: Enhance SocketException by cause where it is missing in net and nio area
  • 2ccdefc: 8299470: sun/jvm/hotspot/SALauncher.java handling of negative rmiport args
  • 578c287: 8081507: Open or Save button in JFileChooser has OK title in GTK LaF
  • 5ae6de8: 8299296: Write a test to verify the components selection sends ItemEvent
  • 3b374c0: 8299439: java/text/Format/NumberFormat/CurrencyFormat.java fails for hr_HR
  • ... and 25 more: https://git.openjdk.org/jdk/compare/a9ce7726a722c9deba659dff3f87b7e72d6c4997...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 added the ready Pull request is ready to be integrated label Jan 5, 2023
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.

Looks good.

@TobiHartmann
Copy link
Member Author

Thanks, Vladimir!

@TobiHartmann
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jan 6, 2023

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

  • b5b7948: 8298240: Replace the usage of ImageLayoutException by the CMMException
  • 99be740: 8299306: Test "javax/swing/JFileChooser/FileSystemView/CustomFSVLinkTest.java" fails on Windows 10 x64 because there are some buttons did not display button name
  • 775da84: 8299412: JNI call of getAccessibleActionCount on a wrong thread
  • 7845b0d: 8296934: Write a test to verify whether Undecorated Frame can be iconified or not
  • 4b6809b: 8299693: Change to Xcode12.4+1.1 devkit for building on macOS at Oracle
  • dfdbd0f: 8299343: Windows: Invalid thread_native_entry declaration
  • 3e2314d: 8299254: Support dealing with standard assert macro
  • a49ccb9: 8299292: Missing elements in aliased String array
  • b908388: 8298449: Unnecessary Vector usage in MetaData.ProxyPersistenceDelegate
  • be64bf8: 8299329: Assertion failure with fastdebug build when trying to use CDS without classpath
  • ... and 33 more: https://git.openjdk.org/jdk/compare/a9ce7726a722c9deba659dff3f87b7e72d6c4997...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jan 6, 2023

@TobiHartmann Pushed as commit cc4936a.

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