Skip to content

Commit 89671aa

Browse files
author
Igor Veresov
committed
8273712: C2: Add mechanism for rejecting inlining of low frequency call sites and deprecate MinInliningThreshold.
Reviewed-by: kvn, rbackman
1 parent 3221a14 commit 89671aa

File tree

6 files changed

+34
-22
lines changed

6 files changed

+34
-22
lines changed

src/hotspot/share/compiler/compilationPolicy.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ class CompilationPolicy : AllStatic {
237237
// m must be compiled before executing it
238238
static bool must_be_compiled(const methodHandle& m, int comp_level = CompLevel_any);
239239
public:
240+
static int min_invocations() { return Tier4MinInvocationThreshold; }
240241
static int c1_count() { return _c1_count; }
241242
static int c2_count() { return _c2_count; }
242243
static int compiler_count(CompLevel comp_level);

src/hotspot/share/opto/bytecodeInfo.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "precompiled.hpp"
2626
#include "ci/ciReplay.hpp"
2727
#include "classfile/vmSymbols.hpp"
28+
#include "compiler/compilationPolicy.hpp"
2829
#include "compiler/compileBroker.hpp"
2930
#include "compiler/compilerEvent.hpp"
3031
#include "compiler/compileLog.hpp"
@@ -152,8 +153,8 @@ bool InlineTree::should_inline(ciMethod* callee_method, ciMethod* caller_method,
152153
int inline_small_code_size = InlineSmallCode / 4;
153154
int max_inline_size = default_max_inline_size;
154155

155-
int call_site_count = method()->scale_count(profile.count());
156-
int invoke_count = method()->interpreter_invocation_count();
156+
int call_site_count = caller_method->scale_count(profile.count());
157+
int invoke_count = caller_method->interpreter_invocation_count();
157158

158159
assert(invoke_count != 0, "require invocation count greater than zero");
159160
double freq = (double)call_site_count / (double)invoke_count;
@@ -192,10 +193,8 @@ bool InlineTree::should_inline(ciMethod* callee_method, ciMethod* caller_method,
192193

193194

194195
// negative filter: should callee NOT be inlined?
195-
bool InlineTree::should_not_inline(ciMethod *callee_method,
196-
ciMethod* caller_method,
197-
JVMState* jvms) {
198-
196+
bool InlineTree::should_not_inline(ciMethod* callee_method, ciMethod* caller_method,
197+
int caller_bci, ciCallProfile& profile) {
199198
const char* fail_msg = NULL;
200199

201200
// First check all inlining restrictions which are required for correctness
@@ -233,7 +232,6 @@ bool InlineTree::should_not_inline(ciMethod *callee_method,
233232
}
234233

235234
#ifndef PRODUCT
236-
int caller_bci = jvms->bci();
237235
int inline_depth = inline_level()+1;
238236
if (ciReplay::should_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth)) {
239237
set_msg("force inline by ciReplay");
@@ -289,7 +287,6 @@ bool InlineTree::should_not_inline(ciMethod *callee_method,
289287

290288
// don't use counts with -Xcomp
291289
if (UseInterpreter) {
292-
293290
if (!callee_method->has_compiled_code() &&
294291
!callee_method->was_executed_more_than(0)) {
295292
set_msg("never executed");
@@ -299,15 +296,23 @@ bool InlineTree::should_not_inline(ciMethod *callee_method,
299296
if (is_init_with_ea(callee_method, caller_method, C)) {
300297
// Escape Analysis: inline all executed constructors
301298
return false;
302-
} else {
303-
intx counter_high_value;
304-
// Tiered compilation uses a different "high value" than non-tiered compilation.
305-
// Determine the right value to use.
306-
if (TieredCompilation) {
307-
counter_high_value = InvocationCounter::count_limit / 2;
308-
} else {
309-
counter_high_value = CompileThreshold / 2;
299+
}
300+
301+
if (MinInlineFrequencyRatio > 0) {
302+
int call_site_count = caller_method->scale_count(profile.count());
303+
int invoke_count = caller_method->interpreter_invocation_count();
304+
assert(invoke_count != 0, "require invocation count greater than zero");
305+
double freq = (double)call_site_count / (double)invoke_count;
306+
double min_freq = MAX2(MinInlineFrequencyRatio, 1.0 / CompilationPolicy::min_invocations());
307+
308+
if (freq < min_freq) {
309+
set_msg("low call site frequency");
310+
return true;
310311
}
312+
}
313+
314+
if (MinInliningThreshold > 0) { // Deprecated heuristic
315+
intx counter_high_value = TieredCompilation ? InvocationCounter::count_limit / 2 : CompileThreshold / 2;
311316
if (!callee_method->was_executed_more_than(MIN2(MinInliningThreshold, counter_high_value))) {
312317
set_msg("executed < MinInliningThreshold times");
313318
return true;
@@ -367,7 +372,7 @@ bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method,
367372
if (!should_inline(callee_method, caller_method, caller_bci, profile)) {
368373
return false;
369374
}
370-
if (should_not_inline(callee_method, caller_method, jvms)) {
375+
if (should_not_inline(callee_method, caller_method, caller_bci, profile)) {
371376
return false;
372377
}
373378

src/hotspot/share/opto/parse.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ class InlineTree : public ResourceObj {
7878
ciCallProfile& profile);
7979
bool should_not_inline(ciMethod* callee_method,
8080
ciMethod* caller_method,
81-
JVMState* jvms);
81+
int caller_bci,
82+
ciCallProfile& profile);
8283
bool is_not_reached(ciMethod* callee_method,
8384
ciMethod* caller_method,
8485
int caller_bci,

src/hotspot/share/runtime/arguments.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ static SpecialFlag const special_jvm_flags[] = {
527527
{ "AllowRedefinitionToAddDeleteMethods", JDK_Version::jdk(13), JDK_Version::undefined(), JDK_Version::undefined() },
528528
{ "FlightRecorder", JDK_Version::jdk(13), JDK_Version::undefined(), JDK_Version::undefined() },
529529
{ "FilterSpuriousWakeups", JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::jdk(20) },
530+
{ "MinInliningThreshold", JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::jdk(20) },
530531

531532
// --- Deprecated alias flags (see also aliased_jvm_flags) - sorted by obsolete_in then expired_in:
532533
{ "DefaultMaxRAMFraction", JDK_Version::jdk(8), JDK_Version::undefined(), JDK_Version::undefined() },

src/hotspot/share/runtime/globals.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,9 +1348,9 @@ const intx ObjectAlignmentInBytes = 8;
13481348
"(using CompileCommand or marked w/ @ForceInline)") \
13491349
range(0, max_jint) \
13501350
\
1351-
product(intx, MinInliningThreshold, 250, \
1352-
"The minimum invocation count a method needs to have to be " \
1353-
"inlined") \
1351+
product(intx, MinInliningThreshold, 0, \
1352+
"(Deprecated) The minimum invocation count a method needs to" \
1353+
"have to be inlined") \
13541354
range(0, max_jint) \
13551355
\
13561356
develop(intx, MethodHistogramCutoff, 100, \
@@ -1404,6 +1404,10 @@ const intx ObjectAlignmentInBytes = 8;
14041404
product(double, InlineFrequencyRatio, 0.25, DIAGNOSTIC, \
14051405
"Ratio of call site execution to caller method invocation") \
14061406
\
1407+
product(double, MinInlineFrequencyRatio, 0.0085, DIAGNOSTIC, \
1408+
"Minimum ratio of call site execution to caller method" \
1409+
"invocation to be considered for inlining") \
1410+
\
14071411
develop(intx, InlineThrowCount, 50, \
14081412
"Force inlining of interpreted methods that throw this often") \
14091413
range(0, max_jint) \

test/hotspot/jtreg/compiler/intrinsics/string/TestStringIntrinsics2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* -XX:+WhiteBoxAPI
4040
* -XX:+IgnoreUnrecognizedVMOptions
4141
* -XX:MaxInlineSize=70
42-
* -XX:MinInliningThreshold=0
42+
* -XX:MinInlineFrequencyRatio=0
4343
* compiler.intrinsics.string.TestStringIntrinsics2
4444
*/
4545

0 commit comments

Comments
 (0)