OLD | NEW |
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 21 matching lines...) Expand all Loading... |
32 #include "hydrogen.h" | 32 #include "hydrogen.h" |
33 #include "isolate.h" | 33 #include "isolate.h" |
34 #include "v8threads.h" | 34 #include "v8threads.h" |
35 | 35 |
36 namespace v8 { | 36 namespace v8 { |
37 namespace internal { | 37 namespace internal { |
38 | 38 |
39 | 39 |
40 void OptimizingCompilerThread::Run() { | 40 void OptimizingCompilerThread::Run() { |
41 #ifdef DEBUG | 41 #ifdef DEBUG |
42 thread_id_ = ThreadId::Current().ToInteger(); | 42 { ScopedLock lock(thread_id_mutex_); |
| 43 thread_id_ = ThreadId::Current().ToInteger(); |
| 44 } |
43 #endif | 45 #endif |
44 Isolate::SetIsolateThreadLocals(isolate_, NULL); | 46 Isolate::SetIsolateThreadLocals(isolate_, NULL); |
45 DisallowHeapAllocation no_allocation; | 47 DisallowHeapAllocation no_allocation; |
46 DisallowHandleAllocation no_handles; | 48 DisallowHandleAllocation no_handles; |
47 DisallowHandleDereference no_deref; | 49 DisallowHandleDereference no_deref; |
48 | 50 |
49 int64_t epoch = 0; | 51 int64_t epoch = 0; |
50 if (FLAG_trace_parallel_recompilation) epoch = OS::Ticks(); | 52 if (FLAG_trace_parallel_recompilation) epoch = OS::Ticks(); |
51 | 53 |
52 while (true) { | 54 while (true) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 input_queue_semaphore_->Signal(); | 108 input_queue_semaphore_->Signal(); |
107 stop_semaphore_->Wait(); | 109 stop_semaphore_->Wait(); |
108 | 110 |
109 if (FLAG_parallel_recompilation_delay != 0) { | 111 if (FLAG_parallel_recompilation_delay != 0) { |
110 // Barrier when loading queue length is not necessary since the write | 112 // Barrier when loading queue length is not necessary since the write |
111 // happens in CompileNext on the same thread. | 113 // happens in CompileNext on the same thread. |
112 while (NoBarrier_Load(&queue_length_) > 0) CompileNext(); | 114 while (NoBarrier_Load(&queue_length_) > 0) CompileNext(); |
113 InstallOptimizedFunctions(); | 115 InstallOptimizedFunctions(); |
114 } else { | 116 } else { |
115 OptimizingCompiler* optimizing_compiler; | 117 OptimizingCompiler* optimizing_compiler; |
| 118 // The optimizing compiler is allocated in the CompilationInfo's zone. |
116 while (input_queue_.Dequeue(&optimizing_compiler)) { | 119 while (input_queue_.Dequeue(&optimizing_compiler)) { |
117 // The optimizing compiler is allocated in the CompilationInfo's zone. | 120 delete optimizing_compiler->info(); |
| 121 } |
| 122 while (output_queue_.Dequeue(&optimizing_compiler)) { |
118 delete optimizing_compiler->info(); | 123 delete optimizing_compiler->info(); |
119 } | 124 } |
120 } | 125 } |
121 | 126 |
122 if (FLAG_trace_parallel_recompilation) { | 127 if (FLAG_trace_parallel_recompilation) { |
123 double compile_time = static_cast<double>(time_spent_compiling_); | 128 double compile_time = static_cast<double>(time_spent_compiling_); |
124 double total_time = static_cast<double>(time_spent_total_); | 129 double total_time = static_cast<double>(time_spent_total_); |
125 double percentage = (compile_time * 100) / total_time; | 130 double percentage = (compile_time * 100) / total_time; |
126 PrintF(" ** Compiler thread did %.2f%% useful work\n", percentage); | 131 PrintF(" ** Compiler thread did %.2f%% useful work\n", percentage); |
127 } | 132 } |
| 133 |
| 134 Join(); |
128 } | 135 } |
129 | 136 |
130 | 137 |
131 void OptimizingCompilerThread::InstallOptimizedFunctions() { | 138 void OptimizingCompilerThread::InstallOptimizedFunctions() { |
132 ASSERT(!IsOptimizerThread()); | 139 ASSERT(!IsOptimizerThread()); |
133 HandleScope handle_scope(isolate_); | 140 HandleScope handle_scope(isolate_); |
134 OptimizingCompiler* compiler; | 141 OptimizingCompiler* compiler; |
135 while (true) { | 142 while (true) { |
136 { // Memory barrier to ensure marked functions are queued. | 143 { // Memory barrier to ensure marked functions are queued. |
137 ScopedLock marked_and_queued(install_mutex_); | 144 ScopedLock marked_and_queued(install_mutex_); |
(...skipping 11 matching lines...) Expand all Loading... |
149 Barrier_AtomicIncrement(&queue_length_, static_cast<Atomic32>(1)); | 156 Barrier_AtomicIncrement(&queue_length_, static_cast<Atomic32>(1)); |
150 optimizing_compiler->info()->closure()->MarkInRecompileQueue(); | 157 optimizing_compiler->info()->closure()->MarkInRecompileQueue(); |
151 input_queue_.Enqueue(optimizing_compiler); | 158 input_queue_.Enqueue(optimizing_compiler); |
152 input_queue_semaphore_->Signal(); | 159 input_queue_semaphore_->Signal(); |
153 } | 160 } |
154 | 161 |
155 | 162 |
156 #ifdef DEBUG | 163 #ifdef DEBUG |
157 bool OptimizingCompilerThread::IsOptimizerThread() { | 164 bool OptimizingCompilerThread::IsOptimizerThread() { |
158 if (!FLAG_parallel_recompilation) return false; | 165 if (!FLAG_parallel_recompilation) return false; |
| 166 ScopedLock lock(thread_id_mutex_); |
159 return ThreadId::Current().ToInteger() == thread_id_; | 167 return ThreadId::Current().ToInteger() == thread_id_; |
160 } | 168 } |
161 #endif | 169 #endif |
162 | 170 |
163 | 171 |
164 } } // namespace v8::internal | 172 } } // namespace v8::internal |
OLD | NEW |