Skip to content

Commit fc55cb9

Browse files
author
Srdjan Mitrovic
committed
Add a stress testing flag --background-compilation-stop-alot; add an extra check if background compilation is being stopped.
BUG= [email protected] Review URL: https://codereview.chromium.org/1904153002 .
1 parent 3c37d20 commit fc55cb9

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

runtime/vm/code_generator.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,9 @@ DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) {
14051405
if (FLAG_enable_inlining_annotations) {
14061406
FATAL("Cannot enable inlining annotations and background compilation");
14071407
}
1408+
if (FLAG_background_compilation_stop_alot) {
1409+
BackgroundCompiler::Stop(isolate);
1410+
}
14081411
// Reduce the chance of triggering optimization while the function is
14091412
// being optimized in the background. INT_MIN should ensure that it takes
14101413
// long time to trigger optimization.

runtime/vm/compiler.cc

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ class CompileParsedFunctionHelper : public ValueObject {
473473
void FinalizeCompilation(Assembler* assembler,
474474
FlowGraphCompiler* graph_compiler,
475475
FlowGraph* flow_graph);
476+
void CheckIfBackgroundCompilerIsBeingStopped();
476477

477478
ParsedFunction* parsed_function_;
478479
const bool optimized_;
@@ -666,6 +667,16 @@ NOT_IN_PRODUCT(
666667
}
667668

668669

670+
void CompileParsedFunctionHelper::CheckIfBackgroundCompilerIsBeingStopped() {
671+
ASSERT(Compiler::IsBackgroundCompilation());
672+
if (!isolate()->background_compiler()->is_running()) {
673+
// The background compiler is being stopped.
674+
Compiler::AbortBackgroundCompilation(Thread::kNoDeoptId,
675+
"Background compilation is being stopped");
676+
}
677+
}
678+
679+
669680
// Return false if bailed out.
670681
// If optimized_result_code is not NULL then it is caller's responsibility
671682
// to install code.
@@ -1133,19 +1144,17 @@ bool CompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) {
11331144
// changes code page access permissions (makes them temporary not
11341145
// executable).
11351146
{
1147+
CheckIfBackgroundCompilerIsBeingStopped();
11361148
SafepointOperationScope safepoint_scope(thread());
11371149
// Do not Garbage collect during this stage and instead allow the
11381150
// heap to grow.
11391151
NoHeapGrowthControlScope no_growth_control;
1140-
if (!isolate()->background_compiler()->is_running()) {
1141-
// The background compiler is being stopped.
1142-
Compiler::AbortBackgroundCompilation(Thread::kNoDeoptId,
1143-
"Background compilation is being stopped");
1144-
}
1152+
CheckIfBackgroundCompilerIsBeingStopped();
11451153
FinalizeCompilation(&assembler, &graph_compiler, flow_graph);
11461154
}
11471155
// TODO(srdjan): Enable this and remove the one from
1148-
// 'BackgroundCompiler::CompileOptimized'
1156+
// 'BackgroundCompiler::CompileOptimized' once cause of time-outs
1157+
// is resolved.
11491158
// if (isolate()->heap()->NeedsGarbageCollection()) {
11501159
// isolate()->heap()->CollectAllGarbage();
11511160
// }
@@ -1916,7 +1925,10 @@ void BackgroundCompiler::VisitPointers(ObjectPointerVisitor* visitor) {
19161925

19171926
void BackgroundCompiler::Stop(Isolate* isolate) {
19181927
BackgroundCompiler* task = isolate->background_compiler();
1919-
ASSERT(task != NULL);
1928+
if (task == NULL) {
1929+
// Nothing to stop.
1930+
return;
1931+
}
19201932
BackgroundCompilationQueue* function_queue = task->function_queue();
19211933

19221934
Monitor* queue_monitor = task->queue_monitor_;

runtime/vm/flag_list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ P(always_megamorphic_calls, bool, false, \
3333
"Instance call always as megamorphic.") \
3434
C(background_compilation, false, true, bool, true, \
3535
"Run optimizing compilation in background") \
36+
R(background_compilation_stop_alot, false, bool, false, \
37+
"Stress test system: stop background compiler often.") \
3638
R(break_at_isolate_spawn, false, bool, false, \
3739
"Insert a one-time breakpoint at the entrypoint for all spawned isolates") \
3840
C(collect_code, false, true, bool, true, \

runtime/vm/isolate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ class Isolate : public BaseIsolate {
381381
return background_compiler_;
382382
}
383383
void set_background_compiler(BackgroundCompiler* value) {
384+
// Do not overwrite a background compiler (memory leak).
385+
ASSERT((value == NULL) || (background_compiler_ == NULL));
384386
background_compiler_ = value;
385387
}
386388

0 commit comments

Comments
 (0)