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

Side by Side Diff: src/optimizing-compiler-thread.cc

Issue 19500022: Reland "Flush parallel recompilation queues on context dispose notification." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: comment addressed Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/optimizing-compiler-thread.h ('k') | src/runtime.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 while (true) { 54 while (true) {
55 input_queue_semaphore_->Wait(); 55 input_queue_semaphore_->Wait();
56 Logger::TimerEventScope timer( 56 Logger::TimerEventScope timer(
57 isolate_, Logger::TimerEventScope::v8_recompile_parallel); 57 isolate_, Logger::TimerEventScope::v8_recompile_parallel);
58 58
59 if (FLAG_parallel_recompilation_delay != 0) { 59 if (FLAG_parallel_recompilation_delay != 0) {
60 OS::Sleep(FLAG_parallel_recompilation_delay); 60 OS::Sleep(FLAG_parallel_recompilation_delay);
61 } 61 }
62 62
63 if (Acquire_Load(&stop_thread_)) { 63 switch (static_cast<StopFlag>(Acquire_Load(&stop_thread_))) {
64 stop_semaphore_->Signal(); 64 case CONTINUE:
65 if (FLAG_trace_parallel_recompilation) { 65 break;
66 time_spent_total_ = OS::Ticks() - epoch; 66 case STOP:
67 } 67 if (FLAG_trace_parallel_recompilation) {
68 return; 68 time_spent_total_ = OS::Ticks() - epoch;
69 }
70 stop_semaphore_->Signal();
71 return;
72 case FLUSH:
73 // Reset input queue semaphore.
74 delete input_queue_semaphore_;
75 input_queue_semaphore_ = OS::CreateSemaphore(0);
76 // Signal for main thread to start flushing.
77 stop_semaphore_->Signal();
78 // Return to start of consumer loop.
79 continue;
69 } 80 }
70 81
71 int64_t compiling_start = 0; 82 int64_t compiling_start = 0;
72 if (FLAG_trace_parallel_recompilation) compiling_start = OS::Ticks(); 83 if (FLAG_trace_parallel_recompilation) compiling_start = OS::Ticks();
73 84
74 CompileNext(); 85 CompileNext();
75 86
76 if (FLAG_trace_parallel_recompilation) { 87 if (FLAG_trace_parallel_recompilation) {
77 time_spent_compiling_ += OS::Ticks() - compiling_start; 88 time_spent_compiling_ += OS::Ticks() - compiling_start;
78 } 89 }
(...skipping 16 matching lines...) Expand all
95 // are always also queued. 106 // are always also queued.
96 ScopedLock mark_and_queue(install_mutex_); 107 ScopedLock mark_and_queue(install_mutex_);
97 { Heap::RelocationLock relocation_lock(isolate_->heap()); 108 { Heap::RelocationLock relocation_lock(isolate_->heap());
98 AllowHandleDereference ahd; 109 AllowHandleDereference ahd;
99 optimizing_compiler->info()->closure()->MarkForInstallingRecompiledCode(); 110 optimizing_compiler->info()->closure()->MarkForInstallingRecompiledCode();
100 } 111 }
101 output_queue_.Enqueue(optimizing_compiler); 112 output_queue_.Enqueue(optimizing_compiler);
102 } 113 }
103 114
104 115
116 void OptimizingCompilerThread::FlushQueue(
117 UnboundQueue<OptimizingCompiler*>* queue,
118 bool restore_function_code) {
119 ASSERT(!IsOptimizerThread());
120 OptimizingCompiler* optimizing_compiler;
121 // The optimizing compiler is allocated in the CompilationInfo's zone.
122 while (queue->Dequeue(&optimizing_compiler)) {
123 CompilationInfo* info = optimizing_compiler->info();
124 if (restore_function_code) {
125 Handle<JSFunction> function = info->closure();
126 function->ReplaceCode(function->shared()->code());
127 }
128 delete info;
129 }
130 }
131
132
133 void OptimizingCompilerThread::Flush() {
134 ASSERT(!IsOptimizerThread());
135 Release_Store(&stop_thread_, static_cast<AtomicWord>(FLUSH));
136 input_queue_semaphore_->Signal();
137
138 FlushQueue(&input_queue_, true);
139 NoBarrier_Store(&queue_length_, static_cast<AtomicWord>(0));
140
141 stop_semaphore_->Wait();
142 Release_Store(&stop_thread_, static_cast<AtomicWord>(CONTINUE));
143
144 FlushQueue(&output_queue_, true);
145 }
146
147
105 void OptimizingCompilerThread::Stop() { 148 void OptimizingCompilerThread::Stop() {
106 ASSERT(!IsOptimizerThread()); 149 ASSERT(!IsOptimizerThread());
107 Release_Store(&stop_thread_, static_cast<AtomicWord>(true)); 150 Release_Store(&stop_thread_, static_cast<AtomicWord>(STOP));
108 input_queue_semaphore_->Signal(); 151 input_queue_semaphore_->Signal();
109 stop_semaphore_->Wait(); 152 stop_semaphore_->Wait();
110 153
111 if (FLAG_parallel_recompilation_delay != 0) { 154 if (FLAG_parallel_recompilation_delay != 0) {
112 // Barrier when loading queue length is not necessary since the write 155 // Barrier when loading queue length is not necessary since the write
113 // happens in CompileNext on the same thread. 156 // happens in CompileNext on the same thread.
114 while (NoBarrier_Load(&queue_length_) > 0) CompileNext(); 157 while (NoBarrier_Load(&queue_length_) > 0) CompileNext();
115 InstallOptimizedFunctions(); 158 InstallOptimizedFunctions();
116 } else { 159 } else {
117 OptimizingCompiler* optimizing_compiler; 160 FlushQueue(&input_queue_, false);
118 // The optimizing compiler is allocated in the CompilationInfo's zone. 161 FlushQueue(&output_queue_, false);
119 while (input_queue_.Dequeue(&optimizing_compiler)) {
120 delete optimizing_compiler->info();
121 }
122 while (output_queue_.Dequeue(&optimizing_compiler)) {
123 delete optimizing_compiler->info();
124 }
125 } 162 }
126 163
127 if (FLAG_trace_parallel_recompilation) { 164 if (FLAG_trace_parallel_recompilation) {
128 double compile_time = static_cast<double>(time_spent_compiling_); 165 double compile_time = static_cast<double>(time_spent_compiling_);
129 double total_time = static_cast<double>(time_spent_total_); 166 double total_time = static_cast<double>(time_spent_total_);
130 double percentage = (compile_time * 100) / total_time; 167 double percentage = (compile_time * 100) / total_time;
131 PrintF(" ** Compiler thread did %.2f%% useful work\n", percentage); 168 PrintF(" ** Compiler thread did %.2f%% useful work\n", percentage);
132 } 169 }
133 170
134 Join(); 171 Join();
(...skipping 28 matching lines...) Expand all
163 #ifdef DEBUG 200 #ifdef DEBUG
164 bool OptimizingCompilerThread::IsOptimizerThread() { 201 bool OptimizingCompilerThread::IsOptimizerThread() {
165 if (!FLAG_parallel_recompilation) return false; 202 if (!FLAG_parallel_recompilation) return false;
166 ScopedLock lock(thread_id_mutex_); 203 ScopedLock lock(thread_id_mutex_);
167 return ThreadId::Current().ToInteger() == thread_id_; 204 return ThreadId::Current().ToInteger() == thread_id_;
168 } 205 }
169 #endif 206 #endif
170 207
171 208
172 } } // namespace v8::internal 209 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/optimizing-compiler-thread.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698