Skip to content

Commit

Permalink
8319879: Stress mode to randomize incremental inlining decision
Browse files Browse the repository at this point in the history
Reviewed-by: kvn, roland
  • Loading branch information
TobiHartmann committed Nov 21, 2023
1 parent 099a8f5 commit 303757b
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/hotspot/share/compiler/compilerDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ void CompilerConfig::ergo_initialize() {
IncrementalInline = false;
IncrementalInlineMH = false;
IncrementalInlineVirtual = false;
StressIncrementalInlining = false;
}
#ifndef PRODUCT
if (!IncrementalInline) {
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/opto/c2_globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
product(bool, StressCCP, false, DIAGNOSTIC, \
"Randomize worklist traversal in CCP") \
\
product(bool, StressIncrementalInlining, false, DIAGNOSTIC, \
"Randomize the incremental inlining decision") \
\
product(uint, StressSeed, 0, DIAGNOSTIC, \
"Seed for randomized stress testing (if unset, a random one is " \
"generated). The seed is recorded in the compilation log, if " \
Expand Down
9 changes: 5 additions & 4 deletions src/hotspot/share/opto/callGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ bool LateInlineMHCallGenerator::do_late_inline_check(Compile* C, JVMState* jvms)
assert(!input_not_const, "sanity"); // shouldn't have been scheduled for inlining in the first place

if (cg != nullptr) {
assert(!cg->is_late_inline() || cg->is_mh_late_inline() || AlwaysIncrementalInline, "we're doing late inlining");
assert(!cg->is_late_inline() || cg->is_mh_late_inline() || AlwaysIncrementalInline || StressIncrementalInlining, "we're doing late inlining");
_inline_cg = cg;
C->dec_number_of_mh_late_inlines();
return true;
Expand Down Expand Up @@ -554,7 +554,7 @@ bool LateInlineVirtualCallGenerator::do_late_inline_check(Compile* C, JVMState*
true /*allow_intrinsics*/);

if (cg != nullptr) {
assert(!cg->is_late_inline() || cg->is_mh_late_inline() || AlwaysIncrementalInline, "we're doing late inlining");
assert(!cg->is_late_inline() || cg->is_mh_late_inline() || AlwaysIncrementalInline || StressIncrementalInlining, "we're doing late inlining");
_inline_cg = cg;
return true;
} else {
Expand Down Expand Up @@ -989,8 +989,9 @@ CallGenerator* CallGenerator::for_method_handle_call(JVMState* jvms, ciMethod* c
bool input_not_const;
CallGenerator* cg = CallGenerator::for_method_handle_inline(jvms, caller, callee, allow_inline, input_not_const);
Compile* C = Compile::current();
bool should_delay = C->should_delay_inlining();
if (cg != nullptr) {
if (AlwaysIncrementalInline) {
if (should_delay) {
return CallGenerator::for_late_inline(callee, cg);
} else {
return cg;
Expand All @@ -1001,7 +1002,7 @@ CallGenerator* CallGenerator::for_method_handle_call(JVMState* jvms, ciMethod* c
int call_site_count = caller->scale_count(profile.count());

if (IncrementalInlineMH && call_site_count > 0 &&
(input_not_const || !C->inlining_incrementally() || C->over_inlining_cutoff())) {
(should_delay || input_not_const || !C->inlining_incrementally() || C->over_inlining_cutoff())) {
return CallGenerator::for_mh_late_inline(caller, callee, input_not_const);
} else {
// Out-of-line call.
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/opto/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ Compile::Compile( ciEnv* ci_env, ciMethod* target, int osr_bci,

// If any phase is randomized for stress testing, seed random number
// generation and log the seed for repeatability.
if (StressLCM || StressGCM || StressIGVN || StressCCP) {
if (StressLCM || StressGCM || StressIGVN || StressCCP || StressIncrementalInlining) {
if (FLAG_IS_DEFAULT(StressSeed) || (FLAG_IS_ERGO(StressSeed) && directive->RepeatCompilationOption)) {
_stress_seed = static_cast<uint>(Ticks::now().nanoseconds());
FLAG_SET_ERGO(StressSeed, _stress_seed);
Expand Down Expand Up @@ -2262,7 +2262,7 @@ void Compile::Optimize() {

if (failing()) return;

if (AlwaysIncrementalInline) {
if (AlwaysIncrementalInline || StressIncrementalInlining) {
inline_incrementally(igvn);
}

Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/opto/compile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@ class Compile : public Phase {
bool inline_incrementally_one();
void inline_incrementally_cleanup(PhaseIterGVN& igvn);
void inline_incrementally(PhaseIterGVN& igvn);
bool should_delay_inlining() { return AlwaysIncrementalInline || (StressIncrementalInlining && (random() % 2) == 0); }
void inline_string_calls(bool parse_time);
void inline_boxing_calls(PhaseIterGVN& igvn);
bool optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode);
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/opto/doCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ CallGenerator* Compile::call_generator(ciMethod* callee, int vtable_index, bool
// Try inlining a bytecoded method:
if (!call_does_dispatch) {
InlineTree* ilt = InlineTree::find_subtree_from_root(this->ilt(), jvms->caller(), jvms->method());
bool should_delay = AlwaysIncrementalInline;
bool should_delay = C->should_delay_inlining();
if (ilt->ok_to_inline(callee, jvms, profile, should_delay)) {
CallGenerator* cg = CallGenerator::for_inline(callee, expected_uses);
// For optimized virtual calls assert at runtime that receiver object
Expand All @@ -204,14 +204,14 @@ CallGenerator* Compile::call_generator(ciMethod* callee, int vtable_index, bool
// Delay the inlining of this method to give us the
// opportunity to perform some high level optimizations
// first.
if (should_delay_string_inlining(callee, jvms)) {
if (should_delay) {
return CallGenerator::for_late_inline(callee, cg);
} else if (should_delay_string_inlining(callee, jvms)) {
return CallGenerator::for_string_late_inline(callee, cg);
} else if (should_delay_boxing_inlining(callee, jvms)) {
return CallGenerator::for_boxing_late_inline(callee, cg);
} else if (should_delay_vector_reboxing_inlining(callee, jvms)) {
return CallGenerator::for_vector_reboxing_late_inline(callee, cg);
} else if (should_delay) {
return CallGenerator::for_late_inline(callee, cg);
} else {
return cg;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static void main(String[] args) {
commandLineNormal.add("-XX:+WhiteBoxAPI");
commandLineNormal.add("-XX:MaxInlineLevel=2");
commandLineNormal.add("-XX:-AlwaysIncrementalInline");
commandLineNormal.add("-XX:-StressIncrementalInlining");
runTest();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* -Xmixed -XX:-BackgroundCompilation -XX:-TieredCompilation -XX:CompileThreshold=1000
* -XX:+UnlockExperimentalVMOptions -XX:PerMethodTrapLimit=100 -XX:-StressReflectiveCode
* -XX:+UncommonNullCast -XX:-StressMethodHandleLinkerInlining -XX:TypeProfileLevel=0
* -XX:-AlwaysIncrementalInline
* -XX:-AlwaysIncrementalInline -XX:-StressIncrementalInlining
* -XX:CompileCommand=exclude,compiler.intrinsics.klass.CastNullCheckDroppingsTest::runTest
* compiler.intrinsics.klass.CastNullCheckDroppingsTest
*/
Expand Down
2 changes: 1 addition & 1 deletion test/hotspot/jtreg/compiler/uncommontrap/Decompile.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* -Xbatch -XX:-UseOnStackReplacement -XX:-TieredCompilation
* -XX:+UnlockExperimentalVMOptions -XX:PerMethodTrapLimit=100 -XX:PerBytecodeTrapLimit=4
* -XX:TypeProfileLevel=0
* -XX:+IgnoreUnrecognizedVMOptions -XX:-AlwaysIncrementalInline
* -XX:+IgnoreUnrecognizedVMOptions -XX:-AlwaysIncrementalInline -XX:-StressIncrementalInlining
* -XX:CompileCommand=compileonly,compiler.uncommontrap.Decompile::uncommonTrap
* -XX:CompileCommand=inline,compiler.uncommontrap.Decompile*::foo
* compiler.uncommontrap.Decompile
Expand Down

3 comments on commit 303757b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 303757b Dec 30, 2023

Choose a reason for hiding this comment

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

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 303757b Dec 30, 2023

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch backport-GoeLin-303757b3 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 303757b3 from the openjdk/jdk repository.

The commit being backported was authored by Tobias Hartmann on 21 Nov 2023 and was reviewed by Vladimir Kozlov and Roland Westrelin.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-303757b3:backport-GoeLin-303757b3
$ git checkout backport-GoeLin-303757b3
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-303757b3

Please sign in to comment.