Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: runtime/vm/compiler.cc

Issue 1541073002: Implement safepointing of threads (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-review-comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/compiler.h" 5 #include "vm/compiler.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 8
9 #include "vm/ast_printer.h" 9 #include "vm/ast_printer.h"
10 #include "vm/block_scheduler.h" 10 #include "vm/block_scheduler.h"
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 compiler_timeline, 1043 compiler_timeline,
1044 "CompileGraph"); 1044 "CompileGraph");
1045 graph_compiler.CompileGraph(); 1045 graph_compiler.CompileGraph();
1046 pipeline->FinalizeCompilation(); 1046 pipeline->FinalizeCompilation();
1047 } 1047 }
1048 { 1048 {
1049 TimelineDurationScope tds(thread(), 1049 TimelineDurationScope tds(thread(),
1050 compiler_timeline, 1050 compiler_timeline,
1051 "FinalizeCompilation"); 1051 "FinalizeCompilation");
1052 // This part of compilation must be at a safepoint. 1052 // This part of compilation must be at a safepoint.
1053 if (!thread()->IsMutatorThread()) { 1053 if (thread()->IsMutatorThread()) {
1054 FinalizeCompilation(&assembler, &graph_compiler, flow_graph);
1055 } else {
1054 // Stop mutator thread before creating the instruction object and 1056 // Stop mutator thread before creating the instruction object and
1055 // installing code. 1057 // installing code.
1056 // Mutator thread may not run code while we are creating the 1058 // Mutator thread may not run code while we are creating the
1057 // instruction object, since the creation of instruction object 1059 // instruction object, since the creation of instruction object
1058 // changes code page access permissions (makes them temporary not 1060 // changes code page access permissions (makes them temporary not
1059 // executable). 1061 // executable).
1060 isolate()->thread_registry()->SafepointThreads(); 1062 SafepointOperationScope safepoint_scope(thread());
1061 } 1063 FinalizeCompilation(&assembler, &graph_compiler, flow_graph);
1062
1063 FinalizeCompilation(&assembler, &graph_compiler, flow_graph);
1064
1065 if (!thread()->IsMutatorThread()) {
1066 // Background compilation.
1067 isolate()->thread_registry()->ResumeAllThreads();
1068 } 1064 }
1069 } 1065 }
1070 // Mark that this isolate now has compiled code. 1066 // Mark that this isolate now has compiled code.
1071 isolate()->set_has_compiled_code(true); 1067 isolate()->set_has_compiled_code(true);
1072 // Exit the loop and the function with the correct result value. 1068 // Exit the loop and the function with the correct result value.
1073 is_compiled = true; 1069 is_compiled = true;
1074 done = true; 1070 done = true;
1075 } else { 1071 } else {
1076 // We bailed out or we encountered an error. 1072 // We bailed out or we encountered an error.
1077 const Error& error = Error::Handle( 1073 const Error& error = Error::Handle(
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 MonitorLocker ml(task->queue_monitor_); 1883 MonitorLocker ml(task->queue_monitor_);
1888 task->running_ = false; 1884 task->running_ = false;
1889 // 'task' will be deleted by thread pool. 1885 // 'task' will be deleted by thread pool.
1890 task = NULL; 1886 task = NULL;
1891 ml.Notify(); // Stop waiting for the queue. 1887 ml.Notify(); // Stop waiting for the queue.
1892 } 1888 }
1893 1889
1894 { 1890 {
1895 MonitorLocker ml_done(done_monitor); 1891 MonitorLocker ml_done(done_monitor);
1896 while (!(*task_done)) { 1892 while (!(*task_done)) {
1897 // In case that the compiler is waiting for safepoint. 1893 ml_done.WaitWithSafepointCheck(Thread::Current());
1898 Isolate::Current()->thread_registry()->CheckSafepoint();
1899 ml_done.Wait(1);
1900 } 1894 }
1901 } 1895 }
1902 delete task_done; 1896 delete task_done;
1903 delete done_monitor; 1897 delete done_monitor;
1904 delete queue_monitor; 1898 delete queue_monitor;
1905 delete function_queue; 1899 delete function_queue;
1906 Isolate::Current()->set_background_compiler(NULL); 1900 Isolate::Current()->set_background_compiler(NULL);
1907 } 1901 }
1908 1902
1909 1903
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2037 } 2031 }
2038 2032
2039 2033
2040 void BackgroundCompiler::EnsureInit(Thread* thread) { 2034 void BackgroundCompiler::EnsureInit(Thread* thread) {
2041 UNREACHABLE(); 2035 UNREACHABLE();
2042 } 2036 }
2043 2037
2044 #endif // DART_PRECOMPILED 2038 #endif // DART_PRECOMPILED
2045 2039
2046 } // namespace dart 2040 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698