OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 class OptimizingCompilerThread : public Thread { | 46 class OptimizingCompilerThread : public Thread { |
47 public: | 47 public: |
48 explicit OptimizingCompilerThread(Isolate *isolate) : | 48 explicit OptimizingCompilerThread(Isolate *isolate) : |
49 Thread("OptimizingCompilerThread"), | 49 Thread("OptimizingCompilerThread"), |
50 #ifdef DEBUG | 50 #ifdef DEBUG |
51 thread_id_(0), | 51 thread_id_(0), |
52 #endif | 52 #endif |
53 isolate_(isolate), | 53 isolate_(isolate), |
54 stop_semaphore_(0), | 54 stop_semaphore_(0), |
55 input_queue_semaphore_(0), | 55 input_queue_semaphore_(0), |
56 osr_candidates_(2), | 56 osr_cursor_(0), |
57 ready_for_osr_(2), | |
58 osr_hits_(0), | 57 osr_hits_(0), |
59 osr_attempts_(0) { | 58 osr_attempts_(0) { |
60 NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(CONTINUE)); | 59 NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(CONTINUE)); |
61 NoBarrier_Store(&queue_length_, static_cast<AtomicWord>(0)); | 60 NoBarrier_Store(&queue_length_, static_cast<AtomicWord>(0)); |
| 61 if (FLAG_concurrent_osr) { |
| 62 osr_buffer_size_ = FLAG_concurrent_recompilation_queue_length + 4; |
| 63 osr_buffer_ = NewArray<OptimizingCompiler*>(osr_buffer_size_); |
| 64 for (int i = 0; i < osr_buffer_size_; i++) osr_buffer_[i] = NULL; |
| 65 } |
62 } | 66 } |
63 ~OptimizingCompilerThread() {} | 67 |
| 68 ~OptimizingCompilerThread() { |
| 69 if (FLAG_concurrent_osr) DeleteArray(osr_buffer_); |
| 70 } |
64 | 71 |
65 void Run(); | 72 void Run(); |
66 void Stop(); | 73 void Stop(); |
67 void Flush(); | 74 void Flush(); |
68 void QueueForOptimization(OptimizingCompiler* optimizing_compiler); | 75 void QueueForOptimization(OptimizingCompiler* optimizing_compiler); |
69 void InstallOptimizedFunctions(); | 76 void InstallOptimizedFunctions(); |
70 OptimizingCompiler* FindReadyOSRCandidate(Handle<JSFunction> function, | 77 OptimizingCompiler* FindReadyOSRCandidate(Handle<JSFunction> function, |
71 uint32_t osr_pc_offset); | 78 uint32_t osr_pc_offset); |
72 bool IsQueuedForOSR(Handle<JSFunction> function, uint32_t osr_pc_offset); | 79 bool IsQueuedForOSR(Handle<JSFunction> function, uint32_t osr_pc_offset); |
73 | 80 |
(...skipping 13 matching lines...) Expand all Loading... |
87 return (current_length < FLAG_concurrent_recompilation_queue_length); | 94 return (current_length < FLAG_concurrent_recompilation_queue_length); |
88 } | 95 } |
89 | 96 |
90 #ifdef DEBUG | 97 #ifdef DEBUG |
91 bool IsOptimizerThread(); | 98 bool IsOptimizerThread(); |
92 #endif | 99 #endif |
93 | 100 |
94 private: | 101 private: |
95 enum StopFlag { CONTINUE, STOP, FLUSH }; | 102 enum StopFlag { CONTINUE, STOP, FLUSH }; |
96 | 103 |
97 // Remove the oldest OSR candidates that are ready so that we | |
98 // only have |limit| left waiting. | |
99 void RemoveStaleOSRCandidates(int limit = kReadyForOSRLimit); | |
100 | |
101 void FlushInputQueue(bool restore_function_code); | 104 void FlushInputQueue(bool restore_function_code); |
102 void FlushOutputQueue(bool restore_function_code); | 105 void FlushOutputQueue(bool restore_function_code); |
| 106 void FlushOsrBuffer(bool restore_function_code); |
103 void CompileNext(); | 107 void CompileNext(); |
104 | 108 |
| 109 // Add a recompilation task for OSR to the cyclic buffer, awaiting OSR entry. |
| 110 // Tasks evicted from the cyclic buffer are discarded. |
| 111 void AddToOsrBuffer(OptimizingCompiler* compiler); |
| 112 void AdvanceOsrCursor() { |
| 113 osr_cursor_ = (osr_cursor_ + 1) % osr_buffer_size_; |
| 114 } |
| 115 |
105 #ifdef DEBUG | 116 #ifdef DEBUG |
106 int thread_id_; | 117 int thread_id_; |
107 Mutex thread_id_mutex_; | 118 Mutex thread_id_mutex_; |
108 #endif | 119 #endif |
109 | 120 |
110 Isolate* isolate_; | 121 Isolate* isolate_; |
111 Semaphore stop_semaphore_; | 122 Semaphore stop_semaphore_; |
112 Semaphore input_queue_semaphore_; | 123 Semaphore input_queue_semaphore_; |
113 | 124 |
114 // Queue of incoming recompilation tasks (including OSR). | 125 // Queue of incoming recompilation tasks (including OSR). |
115 UnboundQueue<OptimizingCompiler*> input_queue_; | 126 UnboundQueue<OptimizingCompiler*> input_queue_; |
116 // Queue of recompilation tasks ready to be installed (excluding OSR). | 127 // Queue of recompilation tasks ready to be installed (excluding OSR). |
117 UnboundQueue<OptimizingCompiler*> output_queue_; | 128 UnboundQueue<OptimizingCompiler*> output_queue_; |
118 // List of recompilation tasks for OSR in the input queue. | 129 // Cyclic buffer of recompilation tasks for OSR. |
119 List<OptimizingCompiler*> osr_candidates_; | 130 // TODO(yangguo): This may keep zombie tasks indefinitely, holding on to |
120 // List of recompilation tasks ready for OSR. | 131 // a lot of memory. Fix this. |
121 List<OptimizingCompiler*> ready_for_osr_; | 132 OptimizingCompiler** osr_buffer_; |
| 133 // Cursor for the cyclic buffer. |
| 134 int osr_cursor_; |
| 135 int osr_buffer_size_; |
122 | 136 |
123 volatile AtomicWord stop_thread_; | 137 volatile AtomicWord stop_thread_; |
124 volatile Atomic32 queue_length_; | 138 volatile Atomic32 queue_length_; |
125 TimeDelta time_spent_compiling_; | 139 TimeDelta time_spent_compiling_; |
126 TimeDelta time_spent_total_; | 140 TimeDelta time_spent_total_; |
127 | 141 |
128 // TODO(yangguo): remove this once the memory leak has been figured out. | 142 // TODO(yangguo): remove this once the memory leak has been figured out. |
129 Mutex queue_mutex_; | 143 Mutex queue_mutex_; |
130 Mutex osr_list_mutex_; | |
131 int osr_hits_; | 144 int osr_hits_; |
132 int osr_attempts_; | 145 int osr_attempts_; |
133 | |
134 static const int kReadyForOSRLimit = 4; | |
135 }; | 146 }; |
136 | 147 |
137 } } // namespace v8::internal | 148 } } // namespace v8::internal |
138 | 149 |
139 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ | 150 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ |
OLD | NEW |