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

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

Issue 7348008: Merge up to 8597 to experimental/gc from the bleeding edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
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
« no previous file with comments | « src/runtime.cc ('k') | src/runtime-profiler.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 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 13 matching lines...) Expand all
79 // 77 //
80 // WaitForSomeIsolateToEnterJS(): 78 // WaitForSomeIsolateToEnterJS():
81 // When no isolates are running JavaScript code for some time the 79 // When no isolates are running JavaScript code for some time the
82 // profiler thread suspends itself by calling the wait function. The 80 // profiler thread suspends itself by calling the wait function. The
83 // wait function returns true after it waited or false immediately. 81 // wait function returns true after it waited or false immediately.
84 // While the function was waiting the profiler may have been 82 // While the function was waiting the profiler may have been
85 // disabled so it *must check* whether it is allowed to continue. 83 // disabled so it *must check* whether it is allowed to continue.
86 static bool IsSomeIsolateInJS(); 84 static bool IsSomeIsolateInJS();
87 static bool WaitForSomeIsolateToEnterJS(); 85 static bool WaitForSomeIsolateToEnterJS();
88 86
89 // When shutting down we join the profiler thread. Doing so while 87 // Stops the runtime profiler thread when profiling support is being
90 // it's waiting on a semaphore will cause a deadlock, so we have to 88 // turned off.
91 // wake it up first. 89 static void StopRuntimeProfilerThreadBeforeShutdown(Thread* thread);
92 static void WakeUpRuntimeProfilerThreadBeforeShutdown();
93 90
94 void UpdateSamplesAfterScavenge(); 91 void UpdateSamplesAfterScavenge();
95 void RemoveDeadSamples(); 92 void RemoveDeadSamples();
96 void UpdateSamplesAfterCompact(ObjectVisitor* visitor); 93 void UpdateSamplesAfterCompact(ObjectVisitor* visitor);
97 94
98 private: 95 private:
99 static const int kSamplerWindowSize = 16; 96 static const int kSamplerWindowSize = 16;
100 static const int kStateWindowSize = 128; 97 static const int kStateWindowSize = 128;
101 98
102 enum SamplerState { 99 enum SamplerState {
103 IN_NON_JS_STATE = 0, 100 IN_NON_JS_STATE = 0,
104 IN_JS_STATE = 1 101 IN_JS_STATE = 1
105 }; 102 };
106 103
107 static void HandleWakeUp(Isolate* isolate); 104 static void HandleWakeUp(Isolate* isolate);
108 105
109 void Optimize(JSFunction* function, bool eager, int delay); 106 void Optimize(JSFunction* function);
110 107
111 void AttemptOnStackReplacement(JSFunction* function); 108 void AttemptOnStackReplacement(JSFunction* function);
112 109
113 void ClearSampleBuffer(); 110 void ClearSampleBuffer();
114 111
115 void ClearSampleBufferNewSpaceEntries(); 112 void ClearSampleBufferNewSpaceEntries();
116 113
117 int LookupSample(JSFunction* function); 114 int LookupSample(JSFunction* function);
118 115
119 void AddSample(JSFunction* function, int weight); 116 void AddSample(JSFunction* function, int weight);
120 117
121 #ifdef ENABLE_LOGGING_AND_PROFILING
122 void UpdateStateRatio(SamplerState current_state);
123 #endif
124
125 Isolate* isolate_; 118 Isolate* isolate_;
126 119
127 int sampler_threshold_; 120 int sampler_threshold_;
128 int sampler_threshold_size_factor_; 121 int sampler_threshold_size_factor_;
129 int sampler_ticks_until_threshold_adjustment_; 122 int sampler_ticks_until_threshold_adjustment_;
130 123
131 // The ratio of ticks spent in JS code in percent.
132 Atomic32 js_ratio_;
133
134 Object* sampler_window_[kSamplerWindowSize]; 124 Object* sampler_window_[kSamplerWindowSize];
135 int sampler_window_position_; 125 int sampler_window_position_;
136 int sampler_window_weight_[kSamplerWindowSize]; 126 int sampler_window_weight_[kSamplerWindowSize];
137 127
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: 128 // Possible state values:
147 // -1 => the profiler thread is waiting on the semaphore 129 // -1 => the profiler thread is waiting on the semaphore
148 // 0 or positive => the number of isolates running JavaScript code. 130 // 0 or positive => the number of isolates running JavaScript code.
149 static Atomic32 state_; 131 static Atomic32 state_;
150 static Semaphore* semaphore_; 132 static Semaphore* semaphore_;
151 133
152 #ifdef DEBUG 134 #ifdef DEBUG
153 static bool has_been_globally_setup_; 135 static bool has_been_globally_setup_;
154 #endif 136 #endif
155 static bool enabled_; 137 static bool enabled_;
156 }; 138 };
157 139
158 140
159 // Rate limiter intended to be used in the profiler thread. 141 // Rate limiter intended to be used in the profiler thread.
160 class RuntimeProfilerRateLimiter BASE_EMBEDDED { 142 class RuntimeProfilerRateLimiter BASE_EMBEDDED {
161 public: 143 public:
162 RuntimeProfilerRateLimiter() : non_js_ticks_(0) { } 144 RuntimeProfilerRateLimiter() {}
163 145
164 // Suspends the current thread (which must be the profiler thread) 146 // Suspends the current thread (which must be the profiler thread)
165 // when not executing JavaScript to minimize CPU usage. Returns 147 // when not executing JavaScript to minimize CPU usage. Returns
166 // whether the thread was suspended (and so must check whether 148 // whether the thread was suspended (and so must check whether
167 // profiling is still active.) 149 // profiling is still active.)
168 // 150 //
169 // Does nothing when runtime profiling is not enabled. 151 // Does nothing when runtime profiling is not enabled.
170 bool SuspendIfNecessary(); 152 bool SuspendIfNecessary();
171 153
172 private: 154 private:
173 int non_js_ticks_;
174
175 DISALLOW_COPY_AND_ASSIGN(RuntimeProfilerRateLimiter); 155 DISALLOW_COPY_AND_ASSIGN(RuntimeProfilerRateLimiter);
176 }; 156 };
177 157
178 158
179 // Implementation of RuntimeProfiler inline functions. 159 // Implementation of RuntimeProfiler inline functions.
180 160
181 void RuntimeProfiler::IsolateEnteredJS(Isolate* isolate) { 161 void RuntimeProfiler::IsolateEnteredJS(Isolate* isolate) {
182 Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, 1); 162 Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, 1);
183 if (new_state == 0) { 163 if (new_state == 0) {
184 // Just incremented from -1 to 0. -1 can only be set by the 164 // Just incremented from -1 to 0. -1 can only be set by the
185 // profiler thread before it suspends itself and starts waiting on 165 // profiler thread before it suspends itself and starts waiting on
186 // the semaphore. 166 // the semaphore.
187 HandleWakeUp(isolate); 167 HandleWakeUp(isolate);
188 } 168 }
189 ASSERT(new_state >= 0); 169 ASSERT(new_state >= 0);
190 } 170 }
191 171
192 172
193 void RuntimeProfiler::IsolateExitedJS(Isolate* isolate) { 173 void RuntimeProfiler::IsolateExitedJS(Isolate* isolate) {
194 Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, -1); 174 Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, -1);
195 ASSERT(new_state >= 0); 175 ASSERT(new_state >= 0);
196 USE(new_state); 176 USE(new_state);
197 } 177 }
198 178
199 } } // namespace v8::internal 179 } } // namespace v8::internal
200 180
201 #endif // V8_RUNTIME_PROFILER_H_ 181 #endif // V8_RUNTIME_PROFILER_H_
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | src/runtime-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698