V8 Project
v8::internal::OptimizingCompilerThread Class Reference

#include <optimizing-compiler-thread.h>

+ Inheritance diagram for v8::internal::OptimizingCompilerThread:
+ Collaboration diagram for v8::internal::OptimizingCompilerThread:

Public Member Functions

 OptimizingCompilerThread (Isolate *isolate)
 
 ~OptimizingCompilerThread ()
 
void Run ()
 
void Stop ()
 
void Flush ()
 
void QueueForOptimization (OptimizedCompileJob *optimizing_compiler)
 
void Unblock ()
 
void InstallOptimizedFunctions ()
 
OptimizedCompileJobFindReadyOSRCandidate (Handle< JSFunction > function, BailoutId osr_ast_id)
 
bool IsQueuedForOSR (Handle< JSFunction > function, BailoutId osr_ast_id)
 
bool IsQueuedForOSR (JSFunction *function)
 
bool IsQueueAvailable ()
 
void AgeBufferedOsrJobs ()
 
- Public Member Functions inherited from v8::base::Thread
 Thread (const Options &options)
 
virtual ~Thread ()
 
void Start ()
 
void StartSynchronously ()
 
void Join ()
 
const char * name () const
 
PlatformDatadata ()
 
void NotifyStartedAndRun ()
 

Static Public Member Functions

static bool Enabled (int max_available)
 
- Static Public Member Functions inherited from v8::base::Thread
static LocalStorageKey CreateThreadLocalKey ()
 
static void DeleteThreadLocalKey (LocalStorageKey key)
 
static void * GetThreadLocal (LocalStorageKey key)
 
static int GetThreadLocalInt (LocalStorageKey key)
 
static void SetThreadLocal (LocalStorageKey key, void *value)
 
static void SetThreadLocalInt (LocalStorageKey key, int value)
 
static bool HasThreadLocal (LocalStorageKey key)
 
static void * GetExistingThreadLocal (LocalStorageKey key)
 
static void YieldCPU ()
 

Private Types

enum  StopFlag { CONTINUE , STOP , FLUSH }
 

Private Member Functions

void FlushInputQueue (bool restore_function_code)
 
void FlushOutputQueue (bool restore_function_code)
 
void FlushOsrBuffer (bool restore_function_code)
 
void CompileNext ()
 
OptimizedCompileJobNextInput ()
 
void AddToOsrBuffer (OptimizedCompileJob *compiler)
 
int InputQueueIndex (int i)
 

Private Attributes

Isolateisolate_
 
base::Semaphore stop_semaphore_
 
base::Semaphore input_queue_semaphore_
 
OptimizedCompileJob ** input_queue_
 
int input_queue_capacity_
 
int input_queue_length_
 
int input_queue_shift_
 
base::Mutex input_queue_mutex_
 
UnboundQueue< OptimizedCompileJob * > output_queue_
 
OptimizedCompileJob ** osr_buffer_
 
int osr_buffer_capacity_
 
int osr_buffer_cursor_
 
volatile base::AtomicWord stop_thread_
 
base::TimeDelta time_spent_compiling_
 
base::TimeDelta time_spent_total_
 
int osr_hits_
 
int osr_attempts_
 
int blocked_jobs_
 

Additional Inherited Members

- Public Types inherited from v8::base::Thread
typedef int32_t LocalStorageKey
 
- Static Public Attributes inherited from v8::base::Thread
static const int kMaxThreadNameLength = 16
 

Detailed Description

Definition at line 23 of file optimizing-compiler-thread.h.

Member Enumeration Documentation

◆ StopFlag

Constructor & Destructor Documentation

◆ OptimizingCompilerThread()

v8::internal::OptimizingCompilerThread::OptimizingCompilerThread ( Isolate isolate)
inlineexplicit

Definition at line 25 of file optimizing-compiler-thread.h.

26  : Thread(Options("OptimizingCompilerThread")),
27 #ifdef DEBUG
28  thread_id_(0),
29 #endif
30  isolate_(isolate),
31  stop_semaphore_(0),
33  input_queue_capacity_(FLAG_concurrent_recompilation_queue_length),
36  osr_buffer_capacity_(FLAG_concurrent_recompilation_queue_length + 4),
38  osr_hits_(0),
39  osr_attempts_(0),
40  blocked_jobs_(0) {
42  static_cast<base::AtomicWord>(CONTINUE));
43  input_queue_ = NewArray<OptimizedCompileJob*>(input_queue_capacity_);
44  if (FLAG_concurrent_osr) {
45  // Allocate and mark OSR buffer slots as empty.
46  osr_buffer_ = NewArray<OptimizedCompileJob*>(osr_buffer_capacity_);
47  for (int i = 0; i < osr_buffer_capacity_; i++) osr_buffer_[i] = NULL;
48  }
49  }
Thread(const Options &options)
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
intptr_t AtomicWord
Definition: atomicops.h:57
void NoBarrier_Store(volatile Atomic8 *ptr, Atomic8 value)

References CONTINUE, input_queue_, input_queue_capacity_, v8::base::NoBarrier_Store(), NULL, osr_buffer_, osr_buffer_capacity_, and stop_thread_.

+ Here is the call graph for this function:

◆ ~OptimizingCompilerThread()

v8::internal::OptimizingCompilerThread::~OptimizingCompilerThread ( )

Definition at line 18 of file optimizing-compiler-thread.cc.

18  {
21  if (FLAG_concurrent_osr) {
22 #ifdef DEBUG
23  for (int i = 0; i < osr_buffer_capacity_; i++) {
25  }
26 #endif
28  }
29 }
#define CHECK_EQ(expected, value)
Definition: logging.h:169
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206
void DeleteArray(T *array)
Definition: allocation.h:68

References CHECK_EQ, DCHECK_EQ, v8::internal::DeleteArray(), input_queue_, input_queue_length_, NULL, osr_buffer_, and osr_buffer_capacity_.

+ Here is the call graph for this function:

Member Function Documentation

◆ AddToOsrBuffer()

void v8::internal::OptimizingCompilerThread::AddToOsrBuffer ( OptimizedCompileJob compiler)
private

Definition at line 337 of file optimizing-compiler-thread.cc.

337  {
338  DCHECK(!IsOptimizerThread());
339  // Find the next slot that is empty or has a stale job.
340  OptimizedCompileJob* stale = NULL;
341  while (true) {
343  if (stale == NULL || stale->IsWaitingForInstall()) break;
345  }
346 
347  // Add to found slot and dispose the evicted job.
348  if (stale != NULL) {
349  DCHECK(stale->IsWaitingForInstall());
350  CompilationInfo* info = stale->info();
351  if (FLAG_trace_osr) {
352  PrintF("[COSR - Discarded ");
353  info->closure()->PrintName();
354  PrintF(", AST id %d]\n", info->osr_ast_id().ToInt());
355  }
356  DisposeOptimizedCompileJob(stale, false);
357  }
360 }
#define DCHECK(condition)
Definition: logging.h:205
void PrintF(const char *format,...)
Definition: utils.cc:80
static void DisposeOptimizedCompileJob(OptimizedCompileJob *job, bool restore_function_code)

References v8::internal::CompilationInfo::closure(), DCHECK, v8::internal::DisposeOptimizedCompileJob(), v8::internal::OptimizedCompileJob::info(), v8::internal::OptimizedCompileJob::IsWaitingForInstall(), NULL, v8::internal::CompilationInfo::osr_ast_id(), osr_buffer_, osr_buffer_capacity_, osr_buffer_cursor_, v8::internal::PrintF(), and v8::internal::BailoutId::ToInt().

Referenced by AgeBufferedOsrJobs(), and QueueForOptimization().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AgeBufferedOsrJobs()

void v8::internal::OptimizingCompilerThread::AgeBufferedOsrJobs ( )
inline

Definition at line 70 of file optimizing-compiler-thread.h.

70  {
71  // Advance cursor of the cyclic buffer to next empty slot or stale OSR job.
72  // Dispose said OSR job in the latter case. Calling this on every GC
73  // should make sure that we do not hold onto stale jobs indefinitely.
75  }
void AddToOsrBuffer(OptimizedCompileJob *compiler)

References AddToOsrBuffer(), and NULL.

Referenced by v8::internal::Heap::GarbageCollectionPrologue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CompileNext()

void v8::internal::OptimizingCompilerThread::CompileNext ( )
private

Definition at line 98 of file optimizing-compiler-thread.cc.

98  {
99  OptimizedCompileJob* job = NextInput();
100  DCHECK_NE(NULL, job);
101 
102  // The function may have already been optimized by OSR. Simply continue.
103  OptimizedCompileJob::Status status = job->OptimizeGraph();
104  USE(status); // Prevent an unused-variable error in release mode.
106 
107  // The function may have already been optimized by OSR. Simply continue.
108  // Use a mutex to make sure that functions marked for install
109  // are always also queued.
110  output_queue_.Enqueue(job);
111  isolate_->stack_guard()->RequestInstallCode();
112 }
StackGuard * stack_guard()
Definition: isolate.h:872
UnboundQueue< OptimizedCompileJob * > output_queue_
#define DCHECK_NE(v1, v2)
Definition: logging.h:207
void USE(T)
Definition: macros.h:322

References DCHECK, DCHECK_NE, v8::internal::OptimizedCompileJob::FAILED, isolate_, NextInput(), NULL, v8::internal::OptimizedCompileJob::OptimizeGraph(), output_queue_, v8::internal::Isolate::stack_guard(), and USE().

Referenced by Run(), and Stop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Enabled()

static bool v8::internal::OptimizingCompilerThread::Enabled ( int  max_available)
inlinestatic

Definition at line 77 of file optimizing-compiler-thread.h.

77  {
78  return (FLAG_concurrent_recompilation && max_available > 1);
79  }

Referenced by v8::internal::Isolate::Init().

+ Here is the caller graph for this function:

◆ FindReadyOSRCandidate()

OptimizedCompileJob * v8::internal::OptimizingCompilerThread::FindReadyOSRCandidate ( Handle< JSFunction function,
BailoutId  osr_ast_id 
)

Definition at line 294 of file optimizing-compiler-thread.cc.

295  {
296  DCHECK(!IsOptimizerThread());
297  for (int i = 0; i < osr_buffer_capacity_; i++) {
298  OptimizedCompileJob* current = osr_buffer_[i];
299  if (current != NULL &&
300  current->IsWaitingForInstall() &&
301  current->info()->HasSameOsrEntry(function, osr_ast_id)) {
302  osr_hits_++;
303  osr_buffer_[i] = NULL;
304  return current;
305  }
306  }
307  return NULL;
308 }

References DCHECK, v8::internal::CompilationInfo::HasSameOsrEntry(), v8::internal::OptimizedCompileJob::info(), v8::internal::OptimizedCompileJob::IsWaitingForInstall(), NULL, osr_buffer_, osr_buffer_capacity_, and osr_hits_.

Referenced by v8::internal::RUNTIME_FUNCTION().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Flush()

void v8::internal::OptimizingCompilerThread::Flush ( )

Definition at line 171 of file optimizing-compiler-thread.cc.

171  {
172  DCHECK(!IsOptimizerThread());
174  if (FLAG_block_concurrent_recompilation) Unblock();
175  input_queue_semaphore_.Signal();
176  stop_semaphore_.Wait();
177  FlushOutputQueue(true);
178  if (FLAG_concurrent_osr) FlushOsrBuffer(true);
179  if (FLAG_trace_concurrent_recompilation) {
180  PrintF(" ** Flushed concurrent recompilation queues.\n");
181  }
182 }
void FlushOsrBuffer(bool restore_function_code)
void FlushOutputQueue(bool restore_function_code)
void Release_Store(volatile Atomic32 *ptr, Atomic32 value)

References DCHECK, FLUSH, FlushOsrBuffer(), FlushOutputQueue(), input_queue_semaphore_, v8::internal::PrintF(), v8::base::Release_Store(), stop_semaphore_, stop_thread_, and Unblock().

Referenced by v8::internal::Heap::CollectAllAvailableGarbage(), v8::internal::Heap::NotifyContextDisposed(), and v8::internal::Debug::PrepareForBreakPoints().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FlushInputQueue()

void v8::internal::OptimizingCompilerThread::FlushInputQueue ( bool  restore_function_code)
private

Definition at line 136 of file optimizing-compiler-thread.cc.

136  {
137  OptimizedCompileJob* job;
138  while ((job = NextInput())) {
139  // This should not block, since we have one signal on the input queue
140  // semaphore corresponding to each element in the input queue.
141  input_queue_semaphore_.Wait();
142  // OSR jobs are dealt with separately.
143  if (!job->info()->is_osr()) {
144  DisposeOptimizedCompileJob(job, restore_function_code);
145  }
146  }
147 }

References v8::internal::DisposeOptimizedCompileJob(), v8::internal::OptimizedCompileJob::info(), input_queue_semaphore_, v8::internal::CompilationInfo::is_osr(), and NextInput().

Referenced by Run(), and Stop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FlushOsrBuffer()

void v8::internal::OptimizingCompilerThread::FlushOsrBuffer ( bool  restore_function_code)
private

Definition at line 161 of file optimizing-compiler-thread.cc.

161  {
162  for (int i = 0; i < osr_buffer_capacity_; i++) {
163  if (osr_buffer_[i] != NULL) {
164  DisposeOptimizedCompileJob(osr_buffer_[i], restore_function_code);
165  osr_buffer_[i] = NULL;
166  }
167  }
168 }

References v8::internal::DisposeOptimizedCompileJob(), NULL, osr_buffer_, and osr_buffer_capacity_.

Referenced by Flush(), and Stop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FlushOutputQueue()

void v8::internal::OptimizingCompilerThread::FlushOutputQueue ( bool  restore_function_code)
private

Definition at line 150 of file optimizing-compiler-thread.cc.

150  {
151  OptimizedCompileJob* job;
152  while (output_queue_.Dequeue(&job)) {
153  // OSR jobs are dealt with separately.
154  if (!job->info()->is_osr()) {
155  DisposeOptimizedCompileJob(job, restore_function_code);
156  }
157  }
158 }

References v8::internal::DisposeOptimizedCompileJob(), v8::internal::OptimizedCompileJob::info(), v8::internal::CompilationInfo::is_osr(), and output_queue_.

Referenced by Flush(), and Stop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ InputQueueIndex()

int v8::internal::OptimizingCompilerThread::InputQueueIndex ( int  i)
inlineprivate

Definition at line 99 of file optimizing-compiler-thread.h.

99  {
100  int result = (i + input_queue_shift_) % input_queue_capacity_;
101  DCHECK_LE(0, result);
103  return result;
104  }
#define DCHECK_LE(v1, v2)
Definition: logging.h:210
#define DCHECK_LT(v1, v2)
Definition: logging.h:209

References DCHECK_LE, DCHECK_LT, input_queue_capacity_, and input_queue_shift_.

Referenced by NextInput(), and QueueForOptimization().

+ Here is the caller graph for this function:

◆ InstallOptimizedFunctions()

void v8::internal::OptimizingCompilerThread::InstallOptimizedFunctions ( )

Definition at line 218 of file optimizing-compiler-thread.cc.

218  {
219  DCHECK(!IsOptimizerThread());
220  HandleScope handle_scope(isolate_);
221 
222  OptimizedCompileJob* job;
223  while (output_queue_.Dequeue(&job)) {
224  CompilationInfo* info = job->info();
225  Handle<JSFunction> function(*info->closure());
226  if (info->is_osr()) {
227  if (FLAG_trace_osr) {
228  PrintF("[COSR - ");
229  function->ShortPrint();
230  PrintF(" is ready for install and entry at AST id %d]\n",
231  info->osr_ast_id().ToInt());
232  }
233  job->WaitForInstall();
234  // Remove stack check that guards OSR entry on original code.
235  Handle<Code> code = info->unoptimized_code();
236  uint32_t offset = code->TranslateAstIdToPcOffset(info->osr_ast_id());
237  BackEdgeTable::RemoveStackCheck(code, offset);
238  } else {
239  if (function->IsOptimized()) {
240  if (FLAG_trace_concurrent_recompilation) {
241  PrintF(" ** Aborting compilation for ");
242  function->ShortPrint();
243  PrintF(" as it has already been optimized.\n");
244  }
245  DisposeOptimizedCompileJob(job, false);
246  } else {
247  Handle<Code> code = Compiler::GetConcurrentlyOptimizedCode(job);
248  function->ReplaceCode(
249  code.is_null() ? function->shared()->code() : *code);
250  }
251  }
252  }
253 }
static void RemoveStackCheck(Handle< Code > code, uint32_t pc_offset)
static Handle< Code > GetConcurrentlyOptimizedCode(OptimizedCompileJob *job)
Definition: compiler.cc:1354

References v8::internal::CompilationInfo::closure(), DCHECK, v8::internal::DisposeOptimizedCompileJob(), v8::internal::Compiler::GetConcurrentlyOptimizedCode(), v8::internal::OptimizedCompileJob::info(), v8::internal::Handle< T >::is_null(), v8::internal::CompilationInfo::is_osr(), isolate_, v8::internal::CompilationInfo::osr_ast_id(), output_queue_, v8::internal::PrintF(), v8::internal::BackEdgeTable::RemoveStackCheck(), v8::internal::BailoutId::ToInt(), v8::internal::CompilationInfo::unoptimized_code(), and v8::internal::OptimizedCompileJob::WaitForInstall().

Referenced by Stop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsQueueAvailable()

bool v8::internal::OptimizingCompilerThread::IsQueueAvailable ( )
inline

Definition at line 65 of file optimizing-compiler-thread.h.

65  {
66  base::LockGuard<base::Mutex> access_input_queue(&input_queue_mutex_);
68  }

References input_queue_capacity_, input_queue_length_, and input_queue_mutex_.

Referenced by v8::internal::GetOptimizedCodeLater(), and QueueForOptimization().

+ Here is the caller graph for this function:

◆ IsQueuedForOSR() [1/2]

bool v8::internal::OptimizingCompilerThread::IsQueuedForOSR ( Handle< JSFunction function,
BailoutId  osr_ast_id 
)

Definition at line 311 of file optimizing-compiler-thread.cc.

312  {
313  DCHECK(!IsOptimizerThread());
314  for (int i = 0; i < osr_buffer_capacity_; i++) {
315  OptimizedCompileJob* current = osr_buffer_[i];
316  if (current != NULL &&
317  current->info()->HasSameOsrEntry(function, osr_ast_id)) {
318  return !current->IsWaitingForInstall();
319  }
320  }
321  return false;
322 }

References DCHECK, v8::internal::CompilationInfo::HasSameOsrEntry(), v8::internal::OptimizedCompileJob::info(), v8::internal::OptimizedCompileJob::IsWaitingForInstall(), NULL, osr_buffer_, and osr_buffer_capacity_.

Referenced by v8::internal::RuntimeProfiler::Optimize(), and v8::internal::RUNTIME_FUNCTION().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsQueuedForOSR() [2/2]

bool v8::internal::OptimizingCompilerThread::IsQueuedForOSR ( JSFunction function)

Definition at line 325 of file optimizing-compiler-thread.cc.

325  {
326  DCHECK(!IsOptimizerThread());
327  for (int i = 0; i < osr_buffer_capacity_; i++) {
328  OptimizedCompileJob* current = osr_buffer_[i];
329  if (current != NULL && *current->info()->closure() == function) {
330  return !current->IsWaitingForInstall();
331  }
332  }
333  return false;
334 }

References v8::internal::CompilationInfo::closure(), DCHECK, v8::internal::OptimizedCompileJob::info(), v8::internal::OptimizedCompileJob::IsWaitingForInstall(), NULL, osr_buffer_, and osr_buffer_capacity_.

+ Here is the call graph for this function:

◆ NextInput()

OptimizedCompileJob * v8::internal::OptimizingCompilerThread::NextInput ( )
private

Definition at line 87 of file optimizing-compiler-thread.cc.

87  {
88  base::LockGuard<base::Mutex> access_input_queue_(&input_queue_mutex_);
89  if (input_queue_length_ == 0) return NULL;
90  OptimizedCompileJob* job = input_queue_[InputQueueIndex(0)];
91  DCHECK_NE(NULL, job);
94  return job;
95 }

References DCHECK_NE, input_queue_, input_queue_length_, input_queue_mutex_, input_queue_shift_, InputQueueIndex(), and NULL.

Referenced by CompileNext(), and FlushInputQueue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ QueueForOptimization()

void v8::internal::OptimizingCompilerThread::QueueForOptimization ( OptimizedCompileJob optimizing_compiler)

Definition at line 256 of file optimizing-compiler-thread.cc.

256  {
258  DCHECK(!IsOptimizerThread());
259  CompilationInfo* info = job->info();
260  if (info->is_osr()) {
261  osr_attempts_++;
262  AddToOsrBuffer(job);
263  // Add job to the front of the input queue.
264  base::LockGuard<base::Mutex> access_input_queue(&input_queue_mutex_);
266  // Move shift_ back by one.
268  input_queue_[InputQueueIndex(0)] = job;
270  } else {
271  // Add job to the back of the input queue.
272  base::LockGuard<base::Mutex> access_input_queue(&input_queue_mutex_);
276  }
277  if (FLAG_block_concurrent_recompilation) {
278  blocked_jobs_++;
279  } else {
280  input_queue_semaphore_.Signal();
281  }
282 }

References AddToOsrBuffer(), blocked_jobs_, DCHECK, DCHECK_LT, v8::internal::OptimizedCompileJob::info(), input_queue_, input_queue_capacity_, input_queue_length_, input_queue_mutex_, input_queue_semaphore_, input_queue_shift_, InputQueueIndex(), v8::internal::CompilationInfo::is_osr(), IsQueueAvailable(), and osr_attempts_.

Referenced by v8::internal::GetOptimizedCodeLater().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Run()

void v8::internal::OptimizingCompilerThread::Run ( )
virtual

Implements v8::base::Thread.

Definition at line 32 of file optimizing-compiler-thread.cc.

32  {
33 #ifdef DEBUG
34  { base::LockGuard<base::Mutex> lock_guard(&thread_id_mutex_);
35  thread_id_ = ThreadId::Current().ToInteger();
36  }
37 #endif
39  DisallowHeapAllocation no_allocation;
40  DisallowHandleAllocation no_handles;
42 
43  base::ElapsedTimer total_timer;
44  if (FLAG_trace_concurrent_recompilation) total_timer.Start();
45 
46  while (true) {
48  TimerEventScope<TimerEventRecompileConcurrent> timer(isolate_);
49 
50  if (FLAG_concurrent_recompilation_delay != 0) {
51  base::OS::Sleep(FLAG_concurrent_recompilation_delay);
52  }
53 
54  switch (static_cast<StopFlag>(base::Acquire_Load(&stop_thread_))) {
55  case CONTINUE:
56  break;
57  case STOP:
58  if (FLAG_trace_concurrent_recompilation) {
59  time_spent_total_ = total_timer.Elapsed();
60  }
61  stop_semaphore_.Signal();
62  return;
63  case FLUSH:
64  // The main thread is blocked, waiting for the stop semaphore.
65  { AllowHandleDereference allow_handle_dereference;
66  FlushInputQueue(true);
67  }
69  static_cast<base::AtomicWord>(CONTINUE));
70  stop_semaphore_.Signal();
71  // Return to start of consumer loop.
72  continue;
73  }
74 
75  base::ElapsedTimer compiling_timer;
76  if (FLAG_trace_concurrent_recompilation) compiling_timer.Start();
77 
78  CompileNext();
79 
80  if (FLAG_trace_concurrent_recompilation) {
81  time_spent_compiling_ += compiling_timer.Elapsed();
82  }
83  }
84 }
static void Sleep(const int milliseconds)
static void SetIsolateThreadLocals(Isolate *isolate, PerIsolateThreadData *data)
Definition: isolate.cc:1676
void FlushInputQueue(bool restore_function_code)
int ToInteger() const
Definition: isolate.h:202
static ThreadId Current()
Definition: isolate.h:185
Atomic32 Acquire_Load(volatile const Atomic32 *ptr)
PerThreadAssertScopeDebugOnly< HEAP_ALLOCATION_ASSERT, false > DisallowHeapAllocation
Definition: assert-scope.h:110
PerThreadAssertScopeDebugOnly< HANDLE_DEREFERENCE_ASSERT, true > AllowHandleDereference
Definition: assert-scope.h:122
PerThreadAssertScopeDebugOnly< HANDLE_DEREFERENCE_ASSERT, false > DisallowHandleDereference
Definition: assert-scope.h:118
PerThreadAssertScopeDebugOnly< HANDLE_ALLOCATION_ASSERT, false > DisallowHandleAllocation
Definition: assert-scope.h:102

References v8::base::Acquire_Load(), CompileNext(), CONTINUE, v8::internal::ThreadId::Current(), FLUSH, FlushInputQueue(), input_queue_semaphore_, isolate_, NULL, v8::base::Release_Store(), v8::internal::Isolate::SetIsolateThreadLocals(), v8::base::OS::Sleep(), STOP, stop_semaphore_, stop_thread_, time_spent_compiling_, time_spent_total_, and v8::internal::ThreadId::ToInteger().

+ Here is the call graph for this function:

◆ Stop()

void v8::internal::OptimizingCompilerThread::Stop ( )

Definition at line 185 of file optimizing-compiler-thread.cc.

185  {
186  DCHECK(!IsOptimizerThread());
188  if (FLAG_block_concurrent_recompilation) Unblock();
189  input_queue_semaphore_.Signal();
190  stop_semaphore_.Wait();
191 
192  if (FLAG_concurrent_recompilation_delay != 0) {
193  // At this point the optimizing compiler thread's event loop has stopped.
194  // There is no need for a mutex when reading input_queue_length_.
195  while (input_queue_length_ > 0) CompileNext();
197  } else {
198  FlushInputQueue(false);
199  FlushOutputQueue(false);
200  }
201 
202  if (FLAG_concurrent_osr) FlushOsrBuffer(false);
203 
204  if (FLAG_trace_concurrent_recompilation) {
205  double percentage = time_spent_compiling_.PercentOf(time_spent_total_);
206  PrintF(" ** Compiler thread did %.2f%% useful work\n", percentage);
207  }
208 
209  if ((FLAG_trace_osr || FLAG_trace_concurrent_recompilation) &&
210  FLAG_concurrent_osr) {
211  PrintF("[COSR hit rate %d / %d]\n", osr_hits_, osr_attempts_);
212  }
213 
214  Join();
215 }

References CompileNext(), DCHECK, FlushInputQueue(), FlushOsrBuffer(), FlushOutputQueue(), input_queue_length_, input_queue_semaphore_, InstallOptimizedFunctions(), v8::base::Thread::Join(), osr_attempts_, osr_hits_, v8::internal::PrintF(), v8::base::Release_Store(), STOP, stop_semaphore_, stop_thread_, time_spent_compiling_, time_spent_total_, and Unblock().

Referenced by v8::internal::Isolate::Deinit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Unblock()

void v8::internal::OptimizingCompilerThread::Unblock ( )

Definition at line 285 of file optimizing-compiler-thread.cc.

285  {
286  DCHECK(!IsOptimizerThread());
287  while (blocked_jobs_ > 0) {
288  input_queue_semaphore_.Signal();
289  blocked_jobs_--;
290  }
291 }

References blocked_jobs_, DCHECK, and input_queue_semaphore_.

Referenced by Flush(), and Stop().

+ Here is the caller graph for this function:

Member Data Documentation

◆ blocked_jobs_

int v8::internal::OptimizingCompilerThread::blocked_jobs_
private

Definition at line 137 of file optimizing-compiler-thread.h.

Referenced by QueueForOptimization(), and Unblock().

◆ input_queue_

OptimizedCompileJob** v8::internal::OptimizingCompilerThread::input_queue_
private

◆ input_queue_capacity_

int v8::internal::OptimizingCompilerThread::input_queue_capacity_
private

◆ input_queue_length_

int v8::internal::OptimizingCompilerThread::input_queue_length_
private

◆ input_queue_mutex_

base::Mutex v8::internal::OptimizingCompilerThread::input_queue_mutex_
private

Definition at line 120 of file optimizing-compiler-thread.h.

Referenced by IsQueueAvailable(), NextInput(), and QueueForOptimization().

◆ input_queue_semaphore_

base::Semaphore v8::internal::OptimizingCompilerThread::input_queue_semaphore_
private

◆ input_queue_shift_

int v8::internal::OptimizingCompilerThread::input_queue_shift_
private

Definition at line 119 of file optimizing-compiler-thread.h.

Referenced by InputQueueIndex(), NextInput(), and QueueForOptimization().

◆ isolate_

Isolate* v8::internal::OptimizingCompilerThread::isolate_
private

Definition at line 111 of file optimizing-compiler-thread.h.

Referenced by CompileNext(), InstallOptimizedFunctions(), and Run().

◆ osr_attempts_

int v8::internal::OptimizingCompilerThread::osr_attempts_
private

Definition at line 135 of file optimizing-compiler-thread.h.

Referenced by QueueForOptimization(), and Stop().

◆ osr_buffer_

OptimizedCompileJob** v8::internal::OptimizingCompilerThread::osr_buffer_
private

◆ osr_buffer_capacity_

int v8::internal::OptimizingCompilerThread::osr_buffer_capacity_
private

◆ osr_buffer_cursor_

int v8::internal::OptimizingCompilerThread::osr_buffer_cursor_
private

Definition at line 128 of file optimizing-compiler-thread.h.

Referenced by AddToOsrBuffer().

◆ osr_hits_

int v8::internal::OptimizingCompilerThread::osr_hits_
private

Definition at line 134 of file optimizing-compiler-thread.h.

Referenced by FindReadyOSRCandidate(), and Stop().

◆ output_queue_

UnboundQueue<OptimizedCompileJob*> v8::internal::OptimizingCompilerThread::output_queue_
private

◆ stop_semaphore_

base::Semaphore v8::internal::OptimizingCompilerThread::stop_semaphore_
private

Definition at line 112 of file optimizing-compiler-thread.h.

Referenced by Flush(), Run(), and Stop().

◆ stop_thread_

volatile base::AtomicWord v8::internal::OptimizingCompilerThread::stop_thread_
private

Definition at line 130 of file optimizing-compiler-thread.h.

Referenced by Flush(), OptimizingCompilerThread(), Run(), and Stop().

◆ time_spent_compiling_

base::TimeDelta v8::internal::OptimizingCompilerThread::time_spent_compiling_
private

Definition at line 131 of file optimizing-compiler-thread.h.

Referenced by Run(), and Stop().

◆ time_spent_total_

base::TimeDelta v8::internal::OptimizingCompilerThread::time_spent_total_
private

Definition at line 132 of file optimizing-compiler-thread.h.

Referenced by Run(), and Stop().


The documentation for this class was generated from the following files: