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

JDK-8318016: Per-compilation memory ceiling #16220

Closed

Conversation

tstuefe
Copy link
Member

@tstuefe tstuefe commented Oct 17, 2023

This RFE introduces a new compile command to limit memory usage per compilation. It complements and is based upon the JIT memory statistic introduced with https://bugs.openjdk.org/browse/JDK-8317683.

This new memory limit is applied during compilation for either C1 or C2. It has one of two modes:

  • crash mode (mainly for compiler devs), which aborts with hs-err file when the ceiling is reached, right in the compiler thread at the allocation point that triggered the ceiling
  • stop mode, which stops the compilation similarly to how hitting the node limit in C2 would stop the compilation.

Usage

The compile command takes the form -XX:CompileCommand:MemLimit,<method>,<memory size>[~<option>]

The memory size that can be specified as usual. The command also takes an optional trailing option, separated from the memory size by a tilde (odd choice but needed because of https://bugs.openjdk.org/browse/JDK-8318214).

The <suboption> can be either crash or stop and distinguishes between the aforementioned modes. If omitted, the default is "stop".

Since MemLimit is based on the JIT statistic, it is implicitly enabled, so there is no need to explicitly enable it with MemStat.

Usage examples:

  • crash when reaching 100m for a single compilation:
-XX:CompileCommand='MemLimit,*.*,100m~crash'
  • limit all methods to a 2m footprint and print a trailing record at VM shutdown
-XX:CompileCommand='MemLimit,*.*,2m' -XX:CompileCommand='MemStat,*.*,print'

The JIT statistic table (printed either at VM shutdown or via jcmd <pid> Compiler.memory) now has a new column "result" that shows if the compilation was completed successfully or had an error or an oom:

                              vvvvv                                                                                                                                                                                                                                                
total     NA        RA        result  #nodes  time    type  #rc thread              method
3036016   687328    1757456   oom     2607    0,320   c2    1   0x00007fcf1c181550  java/lang/invoke/StringConcatFactory::<clinit>(()V)

Implementation notes

The crash variant works immediately.

The stop variant works delayed: If arena memory reaches the limit in the scope of a compilation, we signal the Compile object (Compile for c2, Compilation for c1) that an oom has occurred.

For C1, we set the bailout string right here. That causes the C1 compilation to fail at the next bailout check.

For C2, we cannot just set Compile::_failure_reason since I found that the C2 is not well prepared to bail out from wherever it is tested. So I incorporated the oom check in the nodelimit check C2 does. Note that even that needs some preparatory work (see #16205, a prerequisite for this RFE).

Due to this delay, the actual memory used per compilation may be somewhat higher than the limit. In practice the limit works reasonably well, though.


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-8318016: Per-compilation memory ceiling (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16220

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 17, 2023

👋 Welcome back stuefe! 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.

@tstuefe tstuefe force-pushed the JDK-8318016-compiler-memory-ceiling branch from e2ca348 to 9c2b498 Compare October 17, 2023 13:32
@openjdk
Copy link

openjdk bot commented Oct 17, 2023

@tstuefe 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 Oct 17, 2023
@tstuefe
Copy link
Member Author

tstuefe commented Oct 17, 2023

/label add hotspot-compiler
/label remove hotspot

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Oct 17, 2023
@openjdk
Copy link

openjdk bot commented Oct 17, 2023

@tstuefe
The hotspot-compiler label was successfully added.

@openjdk openjdk bot removed the hotspot hotspot-dev@openjdk.org label Oct 17, 2023
@openjdk
Copy link

openjdk bot commented Oct 17, 2023

@tstuefe
The hotspot label was successfully removed.

@tstuefe tstuefe force-pushed the JDK-8318016-compiler-memory-ceiling branch 4 times, most recently from 3312263 to 9cddbec Compare October 19, 2023 14:40
@tstuefe tstuefe force-pushed the JDK-8318016-compiler-memory-ceiling branch from c39c0c7 to e807fec Compare October 23, 2023 11:41
@tstuefe tstuefe force-pushed the JDK-8318016-compiler-memory-ceiling branch from e807fec to 976d011 Compare October 23, 2023 15:55
@tstuefe tstuefe marked this pull request as ready for review October 24, 2023 05:48
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 24, 2023
@mlbridge
Copy link

mlbridge bot commented Oct 24, 2023

Webrevs

Copy link
Contributor

@rwestrel rwestrel 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.
Have you done any stress testing? Maybe running compile the world with a low memory limit.

@@ -368,6 +395,20 @@ void CompilationMemoryStatistic::on_end_compilation() {
arena_stat->print_on(tty);
tty->cr();
}

// Store result
// For this to work, we must call on_end_compilatio()n at a point where
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: on_end_compilatio()n

@openjdk
Copy link

openjdk bot commented Oct 27, 2023

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

8318016: Per-compilation memory ceiling

Reviewed-by: roland, thartmann

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

  • 2a76ad9: 8318683: compiler/c2/irTests/TestPhiDuplicatedConversion.java "Failed IR Rules (2) of Methods (2)"
  • b3fec6b: 8306980: Generated docs should contain correct Legal Documents
  • 1139482: 8316132: CDSProtectionDomain::get_shared_protection_domain should check for exception
  • 2182c93: 8313643: Update HarfBuzz to 8.2.2
  • 613a3cc: 8301846: Invalid TargetDataLine after screen lock when using JFileChooser or COM library
  • 613d32c: 8169475: WheelModifier.java fails by timeout
  • f1e8787: 8317609: Classfile API fails to verify /jdk.jcmd/sun/tools/jstat/Alignment.class
  • 47624f6: 8299058: AssertionError in sun.net.httpserver.ServerImpl when connection is idle
  • 2d5829a: 8239508: JFR: @RemoveFields
  • 0064cf9: 8311596: Add separate system properties for TLS server and client for maximum chain length
  • ... and 58 more: https://git.openjdk.org/jdk/compare/d96f38b80c1606b54b9f3dbfe9717ab9653a0605...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 Oct 27, 2023
@tstuefe
Copy link
Member Author

tstuefe commented Oct 27, 2023

That looks good to me. Have you done any stress testing? Maybe running compile the world with a low memory limit.

Many thanks @rwestrel .

I did stress testing by adding a random (low) limit and running GHAs with it. I also ran with -Xcomp -Xbatch. I found a bunch of missing bailout chains, which I took care of before posting this PR (https://bugs.openjdk.org/browse/JDK-8318445, https://bugs.openjdk.org/browse/JDK-8318183).

But there are more (e.g. #16375). We have been discussing a better way to care for these errors (I should have done this on the mailing list, sorry) and maybe introduce a semi-automatic way. Experiments of mine are here: #16289 - but I try to find a way that is less invasive.

Finally, there is #16247, which adds better diagnostic information to the hs-err file when we miss a bailout.

Bottom line, there are still outstanding issues with missing bailouts, and possibly a better solution at some point. In my view this does not prevent this RFE from going forward.

@rwestrel
Copy link
Contributor

Bottom line, there are still outstanding issues with missing bailouts, and possibly a better solution at some point. In my view this does not prevent this RFE from going forward.

Thanks for the details. That sounds reasonable to me.

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's a very useful feature, the implementation looks good to me. I've submitted some testing and will report back once it passed.

@TobiHartmann
Copy link
Member

All tests passed.

Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
tstuefe and others added 2 commits November 1, 2023 09:11
Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
@tstuefe
Copy link
Member Author

tstuefe commented Nov 1, 2023

Many thanks @TobiHartmann!

/integrate

@openjdk
Copy link

openjdk bot commented Nov 1, 2023

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

  • 2a76ad9: 8318683: compiler/c2/irTests/TestPhiDuplicatedConversion.java "Failed IR Rules (2) of Methods (2)"
  • b3fec6b: 8306980: Generated docs should contain correct Legal Documents
  • 1139482: 8316132: CDSProtectionDomain::get_shared_protection_domain should check for exception
  • 2182c93: 8313643: Update HarfBuzz to 8.2.2
  • 613a3cc: 8301846: Invalid TargetDataLine after screen lock when using JFileChooser or COM library
  • 613d32c: 8169475: WheelModifier.java fails by timeout
  • f1e8787: 8317609: Classfile API fails to verify /jdk.jcmd/sun/tools/jstat/Alignment.class
  • 47624f6: 8299058: AssertionError in sun.net.httpserver.ServerImpl when connection is idle
  • 2d5829a: 8239508: JFR: @RemoveFields
  • 0064cf9: 8311596: Add separate system properties for TLS server and client for maximum chain length
  • ... and 58 more: https://git.openjdk.org/jdk/compare/d96f38b80c1606b54b9f3dbfe9717ab9653a0605...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 1, 2023

@tstuefe Pushed as commit 0461d9a.

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

3 participants