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

Side by Side Diff: src/runtime-profiler.h

Issue 7274024: Suspend runtime profiler as soon as we exit JS. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 5 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
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 19 matching lines...) Expand all
30 30
31 #include "allocation.h" 31 #include "allocation.h"
32 #include "atomicops.h" 32 #include "atomicops.h"
33 33
34 namespace v8 { 34 namespace v8 {
35 namespace internal { 35 namespace internal {
36 36
37 class Isolate; 37 class Isolate;
38 class JSFunction; 38 class JSFunction;
39 class Object; 39 class Object;
40 class PendingListNode;
41 class Semaphore; 40 class Semaphore;
42 41
43 class RuntimeProfiler { 42 class RuntimeProfiler {
44 public: 43 public:
45 explicit RuntimeProfiler(Isolate* isolate); 44 explicit RuntimeProfiler(Isolate* isolate);
46 45
47 static void GlobalSetup(); 46 static void GlobalSetup();
48 47
49 static inline bool IsEnabled() { 48 static inline bool IsEnabled() {
50 ASSERT(has_been_globally_setup_); 49 ASSERT(has_been_globally_setup_);
51 return enabled_; 50 return enabled_;
52 } 51 }
53 52
54 void OptimizeNow(); 53 void OptimizeNow();
55 void OptimizeSoon(JSFunction* function);
56 54
57 void NotifyTick(); 55 void NotifyTick();
58 56
59 void Setup(); 57 void Setup();
60 void Reset(); 58 void Reset();
61 void TearDown(); 59 void TearDown();
62 60
63 Object** SamplerWindowAddress(); 61 Object** SamplerWindowAddress();
64 int SamplerWindowSize(); 62 int SamplerWindowSize();
65 63
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 static const int kSamplerWindowSize = 16; 97 static const int kSamplerWindowSize = 16;
100 static const int kStateWindowSize = 128; 98 static const int kStateWindowSize = 128;
101 99
102 enum SamplerState { 100 enum SamplerState {
103 IN_NON_JS_STATE = 0, 101 IN_NON_JS_STATE = 0,
104 IN_JS_STATE = 1 102 IN_JS_STATE = 1
105 }; 103 };
106 104
107 static void HandleWakeUp(Isolate* isolate); 105 static void HandleWakeUp(Isolate* isolate);
108 106
109 void Optimize(JSFunction* function, bool eager, int delay); 107 void Optimize(JSFunction* function);
110 108
111 void AttemptOnStackReplacement(JSFunction* function); 109 void AttemptOnStackReplacement(JSFunction* function);
112 110
113 void ClearSampleBuffer(); 111 void ClearSampleBuffer();
114 112
115 void ClearSampleBufferNewSpaceEntries(); 113 void ClearSampleBufferNewSpaceEntries();
116 114
117 int LookupSample(JSFunction* function); 115 int LookupSample(JSFunction* function);
118 116
119 void AddSample(JSFunction* function, int weight); 117 void AddSample(JSFunction* function, int weight);
120 118
121 #ifdef ENABLE_LOGGING_AND_PROFILING
122 void UpdateStateRatio(SamplerState current_state);
123 #endif
124
125 Isolate* isolate_; 119 Isolate* isolate_;
126 120
127 int sampler_threshold_; 121 int sampler_threshold_;
128 int sampler_threshold_size_factor_; 122 int sampler_threshold_size_factor_;
129 int sampler_ticks_until_threshold_adjustment_; 123 int sampler_ticks_until_threshold_adjustment_;
130 124
131 // The ratio of ticks spent in JS code in percent.
132 Atomic32 js_ratio_;
133
134 Object* sampler_window_[kSamplerWindowSize]; 125 Object* sampler_window_[kSamplerWindowSize];
135 int sampler_window_position_; 126 int sampler_window_position_;
136 int sampler_window_weight_[kSamplerWindowSize]; 127 int sampler_window_weight_[kSamplerWindowSize];
137 128
138 // Support for pending 'optimize soon' requests.
139 PendingListNode* optimize_soon_list_;
140
141 SamplerState state_window_[kStateWindowSize];
142 int state_window_position_;
143 int state_window_ticks_;
144 int state_counts_[2];
145
146 // Possible state values: 129 // Possible state values:
147 // -1 => the profiler thread is waiting on the semaphore 130 // -1 => the profiler thread is waiting on the semaphore
148 // 0 or positive => the number of isolates running JavaScript code. 131 // 0 or positive => the number of isolates running JavaScript code.
149 static Atomic32 state_; 132 static Atomic32 state_;
150 static Semaphore* semaphore_; 133 static Semaphore* semaphore_;
151 134
152 #ifdef DEBUG 135 #ifdef DEBUG
153 static bool has_been_globally_setup_; 136 static bool has_been_globally_setup_;
154 #endif 137 #endif
155 static bool enabled_; 138 static bool enabled_;
156 }; 139 };
157 140
158 141
159 // Rate limiter intended to be used in the profiler thread. 142 // Rate limiter intended to be used in the profiler thread.
160 class RuntimeProfilerRateLimiter BASE_EMBEDDED { 143 class RuntimeProfilerRateLimiter BASE_EMBEDDED {
161 public: 144 public:
162 RuntimeProfilerRateLimiter() : non_js_ticks_(0) { } 145 RuntimeProfilerRateLimiter() {}
163 146
164 // Suspends the current thread (which must be the profiler thread) 147 // Suspends the current thread (which must be the profiler thread)
165 // when not executing JavaScript to minimize CPU usage. Returns 148 // when not executing JavaScript to minimize CPU usage. Returns
166 // whether the thread was suspended (and so must check whether 149 // whether the thread was suspended (and so must check whether
167 // profiling is still active.) 150 // profiling is still active.)
168 // 151 //
169 // Does nothing when runtime profiling is not enabled. 152 // Does nothing when runtime profiling is not enabled.
170 bool SuspendIfNecessary(); 153 bool SuspendIfNecessary();
171 154
172 private: 155 private:
173 int non_js_ticks_;
174
175 DISALLOW_COPY_AND_ASSIGN(RuntimeProfilerRateLimiter); 156 DISALLOW_COPY_AND_ASSIGN(RuntimeProfilerRateLimiter);
176 }; 157 };
177 158
178 159
179 // Implementation of RuntimeProfiler inline functions. 160 // Implementation of RuntimeProfiler inline functions.
180 161
181 void RuntimeProfiler::IsolateEnteredJS(Isolate* isolate) { 162 void RuntimeProfiler::IsolateEnteredJS(Isolate* isolate) {
182 Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, 1); 163 Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, 1);
183 if (new_state == 0) { 164 if (new_state == 0) {
184 // Just incremented from -1 to 0. -1 can only be set by the 165 // Just incremented from -1 to 0. -1 can only be set by the
185 // profiler thread before it suspends itself and starts waiting on 166 // profiler thread before it suspends itself and starts waiting on
186 // the semaphore. 167 // the semaphore.
187 HandleWakeUp(isolate); 168 HandleWakeUp(isolate);
188 } 169 }
189 ASSERT(new_state >= 0); 170 ASSERT(new_state >= 0);
190 } 171 }
191 172
192 173
193 void RuntimeProfiler::IsolateExitedJS(Isolate* isolate) { 174 void RuntimeProfiler::IsolateExitedJS(Isolate* isolate) {
194 Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, -1); 175 Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, -1);
195 ASSERT(new_state >= 0); 176 ASSERT(new_state >= 0);
196 USE(new_state); 177 USE(new_state);
197 } 178 }
198 179
199 } } // namespace v8::internal 180 } } // namespace v8::internal
200 181
201 #endif // V8_RUNTIME_PROFILER_H_ 182 #endif // V8_RUNTIME_PROFILER_H_
OLDNEW
« src/compilation-cache.cc ('K') | « src/runtime.cc ('k') | src/runtime-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698