V8 Project
optimizing-compiler-thread.h
Go to the documentation of this file.
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
3 // found in the LICENSE file.
4 
5 #ifndef V8_OPTIMIZING_COMPILER_THREAD_H_
6 #define V8_OPTIMIZING_COMPILER_THREAD_H_
7 
8 #include "src/base/atomicops.h"
11 #include "src/base/platform/time.h"
12 #include "src/flags.h"
13 #include "src/list.h"
14 #include "src/unbound-queue-inl.h"
15 
16 namespace v8 {
17 namespace internal {
18 
19 class HOptimizedGraphBuilder;
20 class OptimizedCompileJob;
21 class SharedFunctionInfo;
22 
24  public:
25  explicit OptimizingCompilerThread(Isolate* isolate)
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  }
50 
52 
53  void Run();
54  void Stop();
55  void Flush();
56  void QueueForOptimization(OptimizedCompileJob* optimizing_compiler);
57  void Unblock();
60  BailoutId osr_ast_id);
61  bool IsQueuedForOSR(Handle<JSFunction> function, BailoutId osr_ast_id);
62 
63  bool IsQueuedForOSR(JSFunction* function);
64 
65  inline bool IsQueueAvailable() {
66  base::LockGuard<base::Mutex> access_input_queue(&input_queue_mutex_);
68  }
69 
70  inline void AgeBufferedOsrJobs() {
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  }
76 
77  static bool Enabled(int max_available) {
78  return (FLAG_concurrent_recompilation && max_available > 1);
79  }
80 
81 #ifdef DEBUG
82  static bool IsOptimizerThread(Isolate* isolate);
83  bool IsOptimizerThread();
84 #endif
85 
86  private:
88 
89  void FlushInputQueue(bool restore_function_code);
90  void FlushOutputQueue(bool restore_function_code);
91  void FlushOsrBuffer(bool restore_function_code);
92  void CompileNext();
94 
95  // Add a recompilation task for OSR to the cyclic buffer, awaiting OSR entry.
96  // Tasks evicted from the cyclic buffer are discarded.
97  void AddToOsrBuffer(OptimizedCompileJob* compiler);
98 
99  inline int InputQueueIndex(int i) {
100  int result = (i + input_queue_shift_) % input_queue_capacity_;
101  DCHECK_LE(0, result);
103  return result;
104  }
105 
106 #ifdef DEBUG
107  int thread_id_;
108  base::Mutex thread_id_mutex_;
109 #endif
110 
112  base::Semaphore stop_semaphore_;
113  base::Semaphore input_queue_semaphore_;
114 
115  // Circular queue of incoming recompilation tasks (including OSR).
120  base::Mutex input_queue_mutex_;
121 
122  // Queue of recompilation tasks ready to be installed (excluding OSR).
123  UnboundQueue<OptimizedCompileJob*> output_queue_;
124 
125  // Cyclic buffer of recompilation tasks for OSR.
129 
131  base::TimeDelta time_spent_compiling_;
132  base::TimeDelta time_spent_total_;
133 
136 
138 };
139 
140 } } // namespace v8::internal
141 
142 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_
Thread(const Options &options)
void FlushInputQueue(bool restore_function_code)
UnboundQueue< OptimizedCompileJob * > output_queue_
void AddToOsrBuffer(OptimizedCompileJob *compiler)
bool IsQueuedForOSR(Handle< JSFunction > function, BailoutId osr_ast_id)
void FlushOsrBuffer(bool restore_function_code)
void FlushOutputQueue(bool restore_function_code)
OptimizedCompileJob * FindReadyOSRCandidate(Handle< JSFunction > function, BailoutId osr_ast_id)
void QueueForOptimization(OptimizedCompileJob *optimizing_compiler)
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
#define DCHECK_LE(v1, v2)
Definition: logging.h:210
#define DCHECK_LT(v1, v2)
Definition: logging.h:209
intptr_t AtomicWord
Definition: atomicops.h:57
void NoBarrier_Store(volatile Atomic8 *ptr, Atomic8 value)
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20