OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler-dispatcher/optimizing-compile-dispatcher.h" | 5 #include "src/compiler-dispatcher/optimizing-compile-dispatcher.h" |
6 | 6 |
7 #include "src/base/atomicops.h" | 7 #include "src/base/atomicops.h" |
8 #include "src/compilation-info.h" | 8 #include "src/compilation-info.h" |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/full-codegen/full-codegen.h" | 10 #include "src/full-codegen/full-codegen.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 // sometimes runs on the worker thread! | 26 // sometimes runs on the worker thread! |
27 // JSFunction::EnsureLiterals(function); | 27 // JSFunction::EnsureLiterals(function); |
28 } | 28 } |
29 delete job; | 29 delete job; |
30 } | 30 } |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 class OptimizingCompileDispatcher::CompileTask : public v8::Task { | 34 class OptimizingCompileDispatcher::CompileTask : public v8::Task { |
35 public: | 35 public: |
36 explicit CompileTask(Isolate* isolate) : isolate_(isolate) { | 36 explicit CompileTask(Isolate* isolate, |
37 OptimizingCompileDispatcher* dispatcher = | 37 OptimizingCompileDispatcher* dispatcher) |
38 isolate_->optimizing_compile_dispatcher(); | 38 : isolate_(isolate), dispatcher_(dispatcher) { |
39 base::LockGuard<base::Mutex> lock_guard(&dispatcher->ref_count_mutex_); | 39 base::LockGuard<base::Mutex> lock_guard(&dispatcher_->ref_count_mutex_); |
40 ++dispatcher->ref_count_; | 40 ++dispatcher_->ref_count_; |
41 } | 41 } |
42 | 42 |
43 virtual ~CompileTask() {} | 43 virtual ~CompileTask() {} |
44 | 44 |
45 private: | 45 private: |
46 // v8::Task overrides. | 46 // v8::Task overrides. |
47 void Run() override { | 47 void Run() override { |
48 DisallowHeapAllocation no_allocation; | 48 DisallowHeapAllocation no_allocation; |
49 DisallowHandleAllocation no_handles; | 49 DisallowHandleAllocation no_handles; |
50 DisallowHandleDereference no_deref; | 50 DisallowHandleDereference no_deref; |
51 | 51 |
52 OptimizingCompileDispatcher* dispatcher = | |
53 isolate_->optimizing_compile_dispatcher(); | |
54 { | 52 { |
55 TimerEventScope<TimerEventRecompileConcurrent> timer(isolate_); | 53 TimerEventScope<TimerEventRecompileConcurrent> timer(isolate_); |
56 | 54 |
57 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), | 55 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), |
58 "V8.RecompileConcurrent"); | 56 "V8.RecompileConcurrent"); |
59 | 57 |
60 if (dispatcher->recompilation_delay_ != 0) { | 58 if (dispatcher_->recompilation_delay_ != 0) { |
61 base::OS::Sleep(base::TimeDelta::FromMilliseconds( | 59 base::OS::Sleep(base::TimeDelta::FromMilliseconds( |
62 dispatcher->recompilation_delay_)); | 60 dispatcher_->recompilation_delay_)); |
63 } | 61 } |
64 | 62 |
65 dispatcher->CompileNext(dispatcher->NextInput(true)); | 63 dispatcher_->CompileNext(dispatcher_->NextInput(true)); |
66 } | 64 } |
67 { | 65 { |
68 base::LockGuard<base::Mutex> lock_guard(&dispatcher->ref_count_mutex_); | 66 base::LockGuard<base::Mutex> lock_guard(&dispatcher_->ref_count_mutex_); |
69 if (--dispatcher->ref_count_ == 0) { | 67 if (--dispatcher_->ref_count_ == 0) { |
70 dispatcher->ref_count_zero_.NotifyOne(); | 68 dispatcher_->ref_count_zero_.NotifyOne(); |
71 } | 69 } |
72 } | 70 } |
73 } | 71 } |
74 | 72 |
75 Isolate* isolate_; | 73 Isolate* isolate_; |
| 74 OptimizingCompileDispatcher* dispatcher_; |
76 | 75 |
77 DISALLOW_COPY_AND_ASSIGN(CompileTask); | 76 DISALLOW_COPY_AND_ASSIGN(CompileTask); |
78 }; | 77 }; |
79 | 78 |
80 OptimizingCompileDispatcher::~OptimizingCompileDispatcher() { | 79 OptimizingCompileDispatcher::~OptimizingCompileDispatcher() { |
81 #ifdef DEBUG | 80 #ifdef DEBUG |
82 { | 81 { |
83 base::LockGuard<base::Mutex> lock_guard(&ref_count_mutex_); | 82 base::LockGuard<base::Mutex> lock_guard(&ref_count_mutex_); |
84 DCHECK_EQ(0, ref_count_); | 83 DCHECK_EQ(0, ref_count_); |
85 } | 84 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 // Add job to the back of the input queue. | 214 // Add job to the back of the input queue. |
216 base::LockGuard<base::Mutex> access_input_queue(&input_queue_mutex_); | 215 base::LockGuard<base::Mutex> access_input_queue(&input_queue_mutex_); |
217 DCHECK_LT(input_queue_length_, input_queue_capacity_); | 216 DCHECK_LT(input_queue_length_, input_queue_capacity_); |
218 input_queue_[InputQueueIndex(input_queue_length_)] = job; | 217 input_queue_[InputQueueIndex(input_queue_length_)] = job; |
219 input_queue_length_++; | 218 input_queue_length_++; |
220 } | 219 } |
221 if (FLAG_block_concurrent_recompilation) { | 220 if (FLAG_block_concurrent_recompilation) { |
222 blocked_jobs_++; | 221 blocked_jobs_++; |
223 } else { | 222 } else { |
224 V8::GetCurrentPlatform()->CallOnBackgroundThread( | 223 V8::GetCurrentPlatform()->CallOnBackgroundThread( |
225 new CompileTask(isolate_), v8::Platform::kShortRunningTask); | 224 new CompileTask(isolate_, this), v8::Platform::kShortRunningTask); |
226 } | 225 } |
227 } | 226 } |
228 | 227 |
229 void OptimizingCompileDispatcher::Unblock() { | 228 void OptimizingCompileDispatcher::Unblock() { |
230 while (blocked_jobs_ > 0) { | 229 while (blocked_jobs_ > 0) { |
231 V8::GetCurrentPlatform()->CallOnBackgroundThread( | 230 V8::GetCurrentPlatform()->CallOnBackgroundThread( |
232 new CompileTask(isolate_), v8::Platform::kShortRunningTask); | 231 new CompileTask(isolate_, this), v8::Platform::kShortRunningTask); |
233 blocked_jobs_--; | 232 blocked_jobs_--; |
234 } | 233 } |
235 } | 234 } |
236 | 235 |
237 } // namespace internal | 236 } // namespace internal |
238 } // namespace v8 | 237 } // namespace v8 |
OLD | NEW |