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

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

Issue 153953005: A64: Synchronize with r16993. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 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
« no previous file with comments | « src/objects-inl.h ('k') | src/optimizing-compiler-thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 22 matching lines...) Expand all
33 #include "list.h" 33 #include "list.h"
34 #include "platform.h" 34 #include "platform.h"
35 #include "platform/mutex.h" 35 #include "platform/mutex.h"
36 #include "platform/time.h" 36 #include "platform/time.h"
37 #include "unbound-queue-inl.h" 37 #include "unbound-queue-inl.h"
38 38
39 namespace v8 { 39 namespace v8 {
40 namespace internal { 40 namespace internal {
41 41
42 class HOptimizedGraphBuilder; 42 class HOptimizedGraphBuilder;
43 class OptimizingCompiler; 43 class RecompileJob;
44 class SharedFunctionInfo; 44 class SharedFunctionInfo;
45 45
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<RecompileJob*>(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(RecompileJob* optimizing_compiler);
69 void InstallOptimizedFunctions(); 76 void InstallOptimizedFunctions();
70 OptimizingCompiler* FindReadyOSRCandidate(Handle<JSFunction> function, 77 RecompileJob* 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
74 bool IsQueuedForOSR(JSFunction* function); 81 bool IsQueuedForOSR(JSFunction* function);
75 82
76 inline bool IsQueueAvailable() { 83 inline bool IsQueueAvailable() {
77 // We don't need a barrier since we have a data dependency right 84 // We don't need a barrier since we have a data dependency right
78 // after. 85 // after.
79 Atomic32 current_length = NoBarrier_Load(&queue_length_); 86 Atomic32 current_length = NoBarrier_Load(&queue_length_);
80 87
81 // This can be queried only from the execution thread. 88 // This can be queried only from the execution thread.
82 ASSERT(!IsOptimizerThread()); 89 ASSERT(!IsOptimizerThread());
83 // Since only the execution thread increments queue_length_ and 90 // Since only the execution thread increments queue_length_ and
84 // only one thread can run inside an Isolate at one time, a direct 91 // only one thread can run inside an Isolate at one time, a direct
85 // doesn't introduce a race -- queue_length_ may decreased in 92 // doesn't introduce a race -- queue_length_ may decreased in
86 // meantime, but not increased. 93 // meantime, but not increased.
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(RecompileJob* 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<RecompileJob*> 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<RecompileJob*> 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 RecompileJob** 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_
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/optimizing-compiler-thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698