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

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

Issue 358363002: Move platform abstraction to base library (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 6 years, 5 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
OLDNEW
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/optimizing-compiler-thread.h" 5 #include "src/optimizing-compiler-thread.h"
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/base/atomicops.h" 9 #include "src/base/atomicops.h"
10 #include "src/full-codegen.h" 10 #include "src/full-codegen.h"
(...skipping 13 matching lines...) Expand all
24 CHECK_EQ(NULL, osr_buffer_[i]); 24 CHECK_EQ(NULL, osr_buffer_[i]);
25 } 25 }
26 #endif 26 #endif
27 DeleteArray(osr_buffer_); 27 DeleteArray(osr_buffer_);
28 } 28 }
29 } 29 }
30 30
31 31
32 void OptimizingCompilerThread::Run() { 32 void OptimizingCompilerThread::Run() {
33 #ifdef DEBUG 33 #ifdef DEBUG
34 { LockGuard<Mutex> lock_guard(&thread_id_mutex_); 34 { base::LockGuard<base::Mutex> lock_guard(&thread_id_mutex_);
35 thread_id_ = ThreadId::Current().ToInteger(); 35 thread_id_ = ThreadId::Current().ToInteger();
36 } 36 }
37 #endif 37 #endif
38 Isolate::SetIsolateThreadLocals(isolate_, NULL); 38 Isolate::SetIsolateThreadLocals(isolate_, NULL);
39 DisallowHeapAllocation no_allocation; 39 DisallowHeapAllocation no_allocation;
40 DisallowHandleAllocation no_handles; 40 DisallowHandleAllocation no_handles;
41 DisallowHandleDereference no_deref; 41 DisallowHandleDereference no_deref;
42 42
43 ElapsedTimer total_timer; 43 base::ElapsedTimer total_timer;
44 if (FLAG_trace_concurrent_recompilation) total_timer.Start(); 44 if (FLAG_trace_concurrent_recompilation) total_timer.Start();
45 45
46 while (true) { 46 while (true) {
47 input_queue_semaphore_.Wait(); 47 input_queue_semaphore_.Wait();
48 Logger::TimerEventScope timer( 48 Logger::TimerEventScope timer(
49 isolate_, Logger::TimerEventScope::v8_recompile_concurrent); 49 isolate_, Logger::TimerEventScope::v8_recompile_concurrent);
50 50
51 if (FLAG_concurrent_recompilation_delay != 0) { 51 if (FLAG_concurrent_recompilation_delay != 0) {
52 OS::Sleep(FLAG_concurrent_recompilation_delay); 52 base::OS::Sleep(FLAG_concurrent_recompilation_delay);
53 } 53 }
54 54
55 switch (static_cast<StopFlag>(base::Acquire_Load(&stop_thread_))) { 55 switch (static_cast<StopFlag>(base::Acquire_Load(&stop_thread_))) {
56 case CONTINUE: 56 case CONTINUE:
57 break; 57 break;
58 case STOP: 58 case STOP:
59 if (FLAG_trace_concurrent_recompilation) { 59 if (FLAG_trace_concurrent_recompilation) {
60 time_spent_total_ = total_timer.Elapsed(); 60 time_spent_total_ = total_timer.Elapsed();
61 } 61 }
62 stop_semaphore_.Signal(); 62 stop_semaphore_.Signal();
63 return; 63 return;
64 case FLUSH: 64 case FLUSH:
65 // The main thread is blocked, waiting for the stop semaphore. 65 // The main thread is blocked, waiting for the stop semaphore.
66 { AllowHandleDereference allow_handle_dereference; 66 { AllowHandleDereference allow_handle_dereference;
67 FlushInputQueue(true); 67 FlushInputQueue(true);
68 } 68 }
69 base::Release_Store(&stop_thread_, 69 base::Release_Store(&stop_thread_,
70 static_cast<base::AtomicWord>(CONTINUE)); 70 static_cast<base::AtomicWord>(CONTINUE));
71 stop_semaphore_.Signal(); 71 stop_semaphore_.Signal();
72 // Return to start of consumer loop. 72 // Return to start of consumer loop.
73 continue; 73 continue;
74 } 74 }
75 75
76 ElapsedTimer compiling_timer; 76 base::ElapsedTimer compiling_timer;
77 if (FLAG_trace_concurrent_recompilation) compiling_timer.Start(); 77 if (FLAG_trace_concurrent_recompilation) compiling_timer.Start();
78 78
79 CompileNext(); 79 CompileNext();
80 80
81 if (FLAG_trace_concurrent_recompilation) { 81 if (FLAG_trace_concurrent_recompilation) {
82 time_spent_compiling_ += compiling_timer.Elapsed(); 82 time_spent_compiling_ += compiling_timer.Elapsed();
83 } 83 }
84 } 84 }
85 } 85 }
86 86
87 87
88 OptimizedCompileJob* OptimizingCompilerThread::NextInput() { 88 OptimizedCompileJob* OptimizingCompilerThread::NextInput() {
89 LockGuard<Mutex> access_input_queue_(&input_queue_mutex_); 89 base::LockGuard<base::Mutex> access_input_queue_(&input_queue_mutex_);
90 if (input_queue_length_ == 0) return NULL; 90 if (input_queue_length_ == 0) return NULL;
91 OptimizedCompileJob* job = input_queue_[InputQueueIndex(0)]; 91 OptimizedCompileJob* job = input_queue_[InputQueueIndex(0)];
92 ASSERT_NE(NULL, job); 92 ASSERT_NE(NULL, job);
93 input_queue_shift_ = InputQueueIndex(1); 93 input_queue_shift_ = InputQueueIndex(1);
94 input_queue_length_--; 94 input_queue_length_--;
95 return job; 95 return job;
96 } 96 }
97 97
98 98
99 void OptimizingCompilerThread::CompileNext() { 99 void OptimizingCompilerThread::CompileNext() {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 250
251 251
252 void OptimizingCompilerThread::QueueForOptimization(OptimizedCompileJob* job) { 252 void OptimizingCompilerThread::QueueForOptimization(OptimizedCompileJob* job) {
253 ASSERT(IsQueueAvailable()); 253 ASSERT(IsQueueAvailable());
254 ASSERT(!IsOptimizerThread()); 254 ASSERT(!IsOptimizerThread());
255 CompilationInfo* info = job->info(); 255 CompilationInfo* info = job->info();
256 if (info->is_osr()) { 256 if (info->is_osr()) {
257 osr_attempts_++; 257 osr_attempts_++;
258 AddToOsrBuffer(job); 258 AddToOsrBuffer(job);
259 // Add job to the front of the input queue. 259 // Add job to the front of the input queue.
260 LockGuard<Mutex> access_input_queue(&input_queue_mutex_); 260 base::LockGuard<base::Mutex> access_input_queue(&input_queue_mutex_);
261 ASSERT_LT(input_queue_length_, input_queue_capacity_); 261 ASSERT_LT(input_queue_length_, input_queue_capacity_);
262 // Move shift_ back by one. 262 // Move shift_ back by one.
263 input_queue_shift_ = InputQueueIndex(input_queue_capacity_ - 1); 263 input_queue_shift_ = InputQueueIndex(input_queue_capacity_ - 1);
264 input_queue_[InputQueueIndex(0)] = job; 264 input_queue_[InputQueueIndex(0)] = job;
265 input_queue_length_++; 265 input_queue_length_++;
266 } else { 266 } else {
267 // Add job to the back of the input queue. 267 // Add job to the back of the input queue.
268 LockGuard<Mutex> access_input_queue(&input_queue_mutex_); 268 base::LockGuard<base::Mutex> access_input_queue(&input_queue_mutex_);
269 ASSERT_LT(input_queue_length_, input_queue_capacity_); 269 ASSERT_LT(input_queue_length_, input_queue_capacity_);
270 input_queue_[InputQueueIndex(input_queue_length_)] = job; 270 input_queue_[InputQueueIndex(input_queue_length_)] = job;
271 input_queue_length_++; 271 input_queue_length_++;
272 } 272 }
273 if (FLAG_block_concurrent_recompilation) { 273 if (FLAG_block_concurrent_recompilation) {
274 blocked_jobs_++; 274 blocked_jobs_++;
275 } else { 275 } else {
276 input_queue_semaphore_.Signal(); 276 input_queue_semaphore_.Signal();
277 } 277 }
278 } 278 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 357
358 358
359 #ifdef DEBUG 359 #ifdef DEBUG
360 bool OptimizingCompilerThread::IsOptimizerThread(Isolate* isolate) { 360 bool OptimizingCompilerThread::IsOptimizerThread(Isolate* isolate) {
361 return isolate->concurrent_recompilation_enabled() && 361 return isolate->concurrent_recompilation_enabled() &&
362 isolate->optimizing_compiler_thread()->IsOptimizerThread(); 362 isolate->optimizing_compiler_thread()->IsOptimizerThread();
363 } 363 }
364 364
365 365
366 bool OptimizingCompilerThread::IsOptimizerThread() { 366 bool OptimizingCompilerThread::IsOptimizerThread() {
367 LockGuard<Mutex> lock_guard(&thread_id_mutex_); 367 base::LockGuard<base::Mutex> lock_guard(&thread_id_mutex_);
368 return ThreadId::Current().ToInteger() == thread_id_; 368 return ThreadId::Current().ToInteger() == thread_id_;
369 } 369 }
370 #endif 370 #endif
371 371
372 372
373 } } // namespace v8::internal 373 } } // namespace v8::internal
OLDNEW
« src/base/macros.h ('K') | « src/optimizing-compiler-thread.h ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698