v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
optimizing-compiler-thread.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_OPTIMIZING_COMPILER_THREAD_H_
29 #define V8_OPTIMIZING_COMPILER_THREAD_H_
30 
31 #include "atomicops.h"
32 #include "platform.h"
33 #include "flags.h"
34 #include "unbound-queue.h"
35 
36 namespace v8 {
37 namespace internal {
38 
39 class HGraphBuilder;
40 class OptimizingCompiler;
41 
43  public:
44  explicit OptimizingCompilerThread(Isolate *isolate) :
45  Thread("OptimizingCompilerThread"),
46  isolate_(isolate),
47  stop_semaphore_(OS::CreateSemaphore(0)),
48  input_queue_semaphore_(OS::CreateSemaphore(0)),
49  time_spent_compiling_(0),
50  time_spent_total_(0) {
51  NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(false));
52  NoBarrier_Store(&queue_length_, static_cast<AtomicWord>(0));
53  }
54 
55  void Run();
56  void Stop();
57  void QueueForOptimization(OptimizingCompiler* optimizing_compiler);
59 
60  inline bool IsQueueAvailable() {
61  // We don't need a barrier since we have a data dependency right
62  // after.
63  Atomic32 current_length = NoBarrier_Load(&queue_length_);
64 
65  // This can be queried only from the execution thread.
66  ASSERT(!IsOptimizerThread());
67  // Since only the execution thread increments queue_length_ and
68  // only one thread can run inside an Isolate at one time, a direct
69  // doesn't introduce a race -- queue_length_ may decreased in
70  // meantime, but not increased.
71  return (current_length < FLAG_parallel_recompilation_queue_length);
72  }
73 
74 #ifdef DEBUG
75  bool IsOptimizerThread();
76 #endif
77 
79  delete input_queue_semaphore_;
80  delete stop_semaphore_;
81  }
82 
83  private:
84  Isolate* isolate_;
85  Semaphore* stop_semaphore_;
86  Semaphore* input_queue_semaphore_;
87  UnboundQueue<OptimizingCompiler*> input_queue_;
88  UnboundQueue<OptimizingCompiler*> output_queue_;
89  volatile AtomicWord stop_thread_;
90  volatile Atomic32 queue_length_;
91  int64_t time_spent_compiling_;
92  int64_t time_spent_total_;
93 
94 #ifdef DEBUG
95  int thread_id_;
96 #endif
97 };
98 
99 } } // namespace v8::internal
100 
101 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_
#define ASSERT(condition)
Definition: checks.h:270
void QueueForOptimization(OptimizingCompiler *optimizing_compiler)
void NoBarrier_Store(volatile Atomic32 *ptr, Atomic32 value)
intptr_t AtomicWord
Definition: atomicops.h:75
Atomic32 NoBarrier_Load(volatile const Atomic32 *ptr)
int32_t Atomic32
Definition: atomicops.h:57