[gardening] Make --optimization-counter-threshold= not affect system isolates
We have many tests that explicitly use --optimization-counter-threshold= flag. We also have a CI builder that uses this flag for all tests. This is an issue for cases where `kernel-isolate` is not AppJIT'ed, which is the case for simulators and ia32. Especially in debug builds this causes a very-very slow time-to main due to JIT'ing the CFE code in `kernel-isolate` and running flow graph checker etc (in debug mode). This causes various tests to sporadically hit the timeout limit, become flaky and require gardening attention. As workarounds: the actual threshold was modified in tests, status files were updated to mark tests as Pass,Slow etc. => This Cl will make `kernel-isolate` no longer be affected by the `--optimization-counter-threshold` => This should make the cycle times faster on those modes and avoid flaky timeouts that gardeners constantly have to pay attention to. TEST=ci Change-Id: Ia58e807b22f69f924315a43c6764427afe398ee6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/266683 Reviewed-by: Slava Egorov <vegorov@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
This commit is contained in:
committed by
Commit Queue
parent
49e0a9b19e
commit
ef8a308669
@@ -249,8 +249,8 @@ void FlowGraphCompiler::InitCompiler() {
|
||||
}
|
||||
}
|
||||
|
||||
bool FlowGraphCompiler::CanOptimize() {
|
||||
return FLAG_optimization_counter_threshold >= 0;
|
||||
bool FlowGraphCompiler::CanOptimize() const {
|
||||
return thread()->isolate_group()->optimization_counter_threshold() >= 0;
|
||||
}
|
||||
|
||||
bool FlowGraphCompiler::CanOptimizeFunction() const {
|
||||
@@ -2207,16 +2207,16 @@ intptr_t FlowGraphCompiler::GetOptimizationThreshold() const {
|
||||
threshold = FLAG_reoptimization_counter_threshold;
|
||||
} else if (parsed_function_.function().IsIrregexpFunction()) {
|
||||
threshold = FLAG_regexp_optimization_counter_threshold;
|
||||
} else if (FLAG_randomize_optimization_counter) {
|
||||
threshold = Thread::Current()->random()->NextUInt64() %
|
||||
FLAG_optimization_counter_threshold;
|
||||
} else {
|
||||
const auto configured_optimization_counter_threshold =
|
||||
IsolateGroup::Current()->optimization_counter_threshold();
|
||||
|
||||
const intptr_t basic_blocks = flow_graph().preorder().length();
|
||||
ASSERT(basic_blocks > 0);
|
||||
threshold = FLAG_optimization_counter_scale * basic_blocks +
|
||||
FLAG_min_optimization_counter_threshold;
|
||||
if (threshold > FLAG_optimization_counter_threshold) {
|
||||
threshold = FLAG_optimization_counter_threshold;
|
||||
if (threshold > configured_optimization_counter_threshold) {
|
||||
threshold = configured_optimization_counter_threshold;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -509,7 +509,7 @@ class FlowGraphCompiler : public ValueObject {
|
||||
|
||||
Instruction* current_instruction() const { return current_instruction_; }
|
||||
|
||||
static bool CanOptimize();
|
||||
bool CanOptimize() const;
|
||||
bool CanOptimizeFunction() const;
|
||||
bool CanOSRFunction() const;
|
||||
bool is_optimizing() const { return is_optimizing_; }
|
||||
|
||||
@@ -705,18 +705,18 @@ Cids* Cids::CreateForArgument(Zone* zone,
|
||||
return cids;
|
||||
}
|
||||
|
||||
static intptr_t Usage(const Function& function) {
|
||||
static intptr_t Usage(Thread* thread, const Function& function) {
|
||||
intptr_t count = function.usage_counter();
|
||||
if (count < 0) {
|
||||
if (function.HasCode()) {
|
||||
// 'function' is queued for optimized compilation
|
||||
count = FLAG_optimization_counter_threshold;
|
||||
count = thread->isolate_group()->optimization_counter_threshold();
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
} else if (Code::IsOptimized(function.CurrentCode())) {
|
||||
// 'function' was optimized and stopped counting
|
||||
count = FLAG_optimization_counter_threshold;
|
||||
count = thread->isolate_group()->optimization_counter_threshold();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
@@ -770,7 +770,7 @@ void CallTargets::CreateHelper(Zone* zone, const ICData& ic_data) {
|
||||
const intptr_t filled_entry_count = cache.filled_entry_count();
|
||||
ASSERT(filled_entry_count > 0);
|
||||
cid_ranges_.Add(new (zone) TargetInfo(
|
||||
id, id, &function, Usage(function) / filled_entry_count,
|
||||
id, id, &function, Usage(thread, function) / filled_entry_count,
|
||||
StaticTypeExactnessState::NotTracking()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3300,8 +3300,10 @@ void CheckStackOverflowInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
// stack checks. Use progressively higher thresholds for more deeply
|
||||
// nested loops to attempt to hit outer loops with OSR when possible.
|
||||
__ LoadObject(function, compiler->parsed_function().function());
|
||||
intptr_t threshold =
|
||||
FLAG_optimization_counter_threshold * (loop_depth() + 1);
|
||||
const intptr_t configured_optimization_counter_threshold =
|
||||
compiler->thread()->isolate_group()->optimization_counter_threshold();
|
||||
const int32_t threshold =
|
||||
configured_optimization_counter_threshold * (loop_depth() + 1);
|
||||
__ ldr(count,
|
||||
compiler::FieldAddress(
|
||||
function, compiler::target::Function::usage_counter_offset()));
|
||||
|
||||
@@ -2935,8 +2935,10 @@ void CheckStackOverflowInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
// stack checks. Use progressively higher thresholds for more deeply
|
||||
// nested loops to attempt to hit outer loops with OSR when possible.
|
||||
__ LoadObject(function, compiler->parsed_function().function());
|
||||
intptr_t threshold =
|
||||
FLAG_optimization_counter_threshold * (loop_depth() + 1);
|
||||
const intptr_t configured_optimization_counter_threshold =
|
||||
compiler->thread()->isolate_group()->optimization_counter_threshold();
|
||||
const int32_t threshold =
|
||||
configured_optimization_counter_threshold * (loop_depth() + 1);
|
||||
__ LoadFieldFromOffset(TMP, function, Function::usage_counter_offset(),
|
||||
compiler::kFourBytes);
|
||||
__ add(TMP, TMP, compiler::Operand(1));
|
||||
|
||||
@@ -2548,8 +2548,10 @@ void CheckStackOverflowInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
// stack checks. Use progressively higher thresholds for more deeply
|
||||
// nested loops to attempt to hit outer loops with OSR when possible.
|
||||
__ LoadObject(EDI, compiler->parsed_function().function());
|
||||
intptr_t threshold =
|
||||
FLAG_optimization_counter_threshold * (loop_depth() + 1);
|
||||
const intptr_t configured_optimization_counter_threshold =
|
||||
compiler->thread()->isolate_group()->optimization_counter_threshold();
|
||||
const int32_t threshold =
|
||||
configured_optimization_counter_threshold * (loop_depth() + 1);
|
||||
__ incl(compiler::FieldAddress(EDI, Function::usage_counter_offset()));
|
||||
__ cmpl(compiler::FieldAddress(EDI, Function::usage_counter_offset()),
|
||||
compiler::Immediate(threshold));
|
||||
|
||||
@@ -3282,8 +3282,10 @@ void CheckStackOverflowInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
// stack checks. Use progressively higher thresholds for more deeply
|
||||
// nested loops to attempt to hit outer loops with OSR when possible.
|
||||
__ LoadObject(function, compiler->parsed_function().function());
|
||||
intptr_t threshold =
|
||||
FLAG_optimization_counter_threshold * (loop_depth() + 1);
|
||||
const intptr_t configured_optimization_counter_threshold =
|
||||
compiler->thread()->isolate_group()->optimization_counter_threshold();
|
||||
const int32_t threshold =
|
||||
configured_optimization_counter_threshold * (loop_depth() + 1);
|
||||
__ LoadFieldFromOffset(TMP, function, Function::usage_counter_offset(),
|
||||
compiler::kFourBytes);
|
||||
__ addi(TMP, TMP, 1);
|
||||
|
||||
@@ -2952,8 +2952,10 @@ void CheckStackOverflowInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
|
||||
// stack checks. Use progressively higher thresholds for more deeply
|
||||
// nested loops to attempt to hit outer loops with OSR when possible.
|
||||
__ LoadObject(temp, compiler->parsed_function().function());
|
||||
int32_t threshold =
|
||||
FLAG_optimization_counter_threshold * (loop_depth() + 1);
|
||||
const intptr_t configured_optimization_counter_threshold =
|
||||
compiler->thread()->isolate_group()->optimization_counter_threshold();
|
||||
const int32_t threshold =
|
||||
configured_optimization_counter_threshold * (loop_depth() + 1);
|
||||
__ incl(compiler::FieldAddress(temp, Function::usage_counter_offset()));
|
||||
__ cmpl(compiler::FieldAddress(temp, Function::usage_counter_offset()),
|
||||
compiler::Immediate(threshold));
|
||||
|
||||
@@ -234,7 +234,7 @@ bool Compiler::CanOptimizeFunction(Thread* thread, const Function& function) {
|
||||
// immediately, causing an infinite compilation loop. The compiler raises
|
||||
// the threshold for functions with breakpoints, so we drop the unoptimized
|
||||
// to force it to be recompiled.
|
||||
if (CanOptimizeImmediately()) {
|
||||
if (thread->isolate_group()->optimization_counter_threshold() < 2) {
|
||||
function.ClearCode();
|
||||
}
|
||||
return false;
|
||||
@@ -433,7 +433,8 @@ CodePtr CompileParsedFunctionHelper::FinalizeCompilation(
|
||||
function.SetUsageCounter(0);
|
||||
} else {
|
||||
// Trigger another optimization pass soon.
|
||||
function.SetUsageCounter(FLAG_optimization_counter_threshold - 100);
|
||||
function.SetUsageCounter(
|
||||
thread()->isolate_group()->optimization_counter_threshold() - 100);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -732,7 +733,8 @@ static ObjectPtr CompileFunctionHelper(CompilationPipeline* pipeline,
|
||||
}
|
||||
|
||||
// Trigger another optimization pass soon.
|
||||
function.SetUsageCounter(FLAG_optimization_counter_threshold - 100);
|
||||
function.SetUsageCounter(
|
||||
thread->isolate_group()->optimization_counter_threshold() - 100);
|
||||
return Error::null();
|
||||
} else if (error.IsLanguageError() &&
|
||||
LanguageError::Cast(error).kind() == Report::kBailout) {
|
||||
|
||||
@@ -76,15 +76,6 @@ class Compiler : public AllStatic {
|
||||
// The result for a function may change if debugging gets turned on/off.
|
||||
static bool CanOptimizeFunction(Thread* thread, const Function& function);
|
||||
|
||||
#if !defined(PRODUCT)
|
||||
// Whether it's possible for unoptimized code to optimize immediately on entry
|
||||
// (can happen with random or very low optimization counter thresholds)
|
||||
static bool CanOptimizeImmediately() {
|
||||
return FLAG_optimization_counter_threshold < 2 ||
|
||||
FLAG_randomize_optimization_counter;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Generates code for given function without optimization and sets its code
|
||||
// field.
|
||||
//
|
||||
|
||||
@@ -27,6 +27,8 @@ constexpr bool kDartUseBackgroundCompilation = false;
|
||||
constexpr bool kDartUseBackgroundCompilation = true;
|
||||
#endif
|
||||
|
||||
constexpr intptr_t kDefaultOptimizationCounterThreshold = 30000;
|
||||
|
||||
// The disassembler might be force included even in product builds so we need
|
||||
// to conditionally make these into product flags to make the disassembler
|
||||
// usable in product mode.
|
||||
@@ -156,11 +158,8 @@ constexpr bool FLAG_support_il_printer = false;
|
||||
"Max size of new gen semi space in MB") \
|
||||
P(new_gen_semi_initial_size, int, (kWordSize <= 4) ? 1 : 2, \
|
||||
"Initial size of new gen semi space in MB") \
|
||||
P(optimization_counter_threshold, int, 30000, \
|
||||
P(optimization_counter_threshold, int, kDefaultOptimizationCounterThreshold, \
|
||||
"Function's usage-counter value before it is optimized, -1 means never") \
|
||||
R(randomize_optimization_counter, false, bool, false, \
|
||||
"Randomize optimization counter thresholds on a per-function basis (for " \
|
||||
"testing).") \
|
||||
P(optimization_level, int, 2, \
|
||||
"Optimization level: 1 (favor size), 2 (default), 3 (favor speed)") \
|
||||
P(old_gen_heap_size, int, kDefaultMaxOldGenHeapSize, \
|
||||
|
||||
@@ -324,6 +324,14 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
|
||||
return background_compiler_.get();
|
||||
#endif
|
||||
}
|
||||
#if !defined(DART_PRECOMPILED_RUNTIME)
|
||||
intptr_t optimization_counter_threshold() const {
|
||||
if (IsSystemIsolateGroup(this)) {
|
||||
return kDefaultOptimizationCounterThreshold;
|
||||
}
|
||||
return FLAG_optimization_counter_threshold;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(PRODUCT)
|
||||
GroupDebugger* debugger() const { return debugger_; }
|
||||
|
||||
Reference in New Issue
Block a user