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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // Rate limiting support. | 64 // Rate limiting support. |
65 | 65 |
66 // VM thread interface. | 66 // VM thread interface. |
67 // | 67 // |
68 // Called by isolates when their states change. | 68 // Called by isolates when their states change. |
69 static inline void IsolateEnteredJS(Isolate* isolate); | 69 static inline void IsolateEnteredJS(Isolate* isolate); |
70 static inline void IsolateExitedJS(Isolate* isolate); | 70 static inline void IsolateExitedJS(Isolate* isolate); |
71 | 71 |
72 // Profiler thread interface. | 72 // Profiler thread interface. |
73 // | 73 // |
74 // IsSomeIsolateInJS(): | |
75 // The profiler thread can query whether some isolate is currently | |
76 // running JavaScript code. | |
77 // | |
78 // WaitForSomeIsolateToEnterJS(): | 74 // WaitForSomeIsolateToEnterJS(): |
79 // When no isolates are running JavaScript code for some time the | 75 // When no isolates are running JavaScript code for some time the |
80 // profiler thread suspends itself by calling the wait function. The | 76 // profiler thread suspends itself by calling the wait function. The |
81 // wait function returns true after it waited or false immediately. | 77 // wait function returns true after it waited or false immediately. |
82 // While the function was waiting the profiler may have been | 78 // While the function was waiting the profiler may have been |
83 // disabled so it *must check* whether it is allowed to continue. | 79 // disabled so it *must check* whether it is allowed to continue. |
84 static bool IsSomeIsolateInJS(); | |
85 static bool WaitForSomeIsolateToEnterJS(); | 80 static bool WaitForSomeIsolateToEnterJS(); |
86 | 81 |
87 // Stops the runtime profiler thread when profiling support is being | 82 // Stops the runtime profiler thread when profiling support is being |
88 // turned off. | 83 // turned off. |
89 static void StopRuntimeProfilerThreadBeforeShutdown(Thread* thread); | 84 static void StopRuntimeProfilerThreadBeforeShutdown(Thread* thread); |
90 | 85 |
91 void UpdateSamplesAfterScavenge(); | 86 void UpdateSamplesAfterScavenge(); |
92 void RemoveDeadSamples(); | 87 void RemoveDeadSamples(); |
93 void UpdateSamplesAfterCompact(ObjectVisitor* visitor); | 88 void UpdateSamplesAfterCompact(ObjectVisitor* visitor); |
94 | 89 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // 0 or positive => the number of isolates running JavaScript code. | 122 // 0 or positive => the number of isolates running JavaScript code. |
128 static Atomic32 state_; | 123 static Atomic32 state_; |
129 | 124 |
130 #ifdef DEBUG | 125 #ifdef DEBUG |
131 static bool has_been_globally_set_up_; | 126 static bool has_been_globally_set_up_; |
132 #endif | 127 #endif |
133 static bool enabled_; | 128 static bool enabled_; |
134 }; | 129 }; |
135 | 130 |
136 | 131 |
137 // Rate limiter intended to be used in the profiler thread. | |
138 class RuntimeProfilerRateLimiter BASE_EMBEDDED { | |
139 public: | |
140 RuntimeProfilerRateLimiter() {} | |
141 | |
142 // Suspends the current thread (which must be the profiler thread) | |
143 // when not executing JavaScript to minimize CPU usage. Returns | |
144 // whether the thread was suspended (and so must check whether | |
145 // profiling is still active.) | |
146 // | |
147 // Does nothing when runtime profiling is not enabled. | |
148 bool SuspendIfNecessary(); | |
149 | |
150 private: | |
151 DISALLOW_COPY_AND_ASSIGN(RuntimeProfilerRateLimiter); | |
152 }; | |
153 | |
154 | |
155 // Implementation of RuntimeProfiler inline functions. | 132 // Implementation of RuntimeProfiler inline functions. |
156 | 133 |
157 void RuntimeProfiler::IsolateEnteredJS(Isolate* isolate) { | 134 void RuntimeProfiler::IsolateEnteredJS(Isolate* isolate) { |
158 Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, 1); | 135 Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, 1); |
159 if (new_state == 0) { | 136 if (new_state == 0) { |
160 // Just incremented from -1 to 0. -1 can only be set by the | 137 // Just incremented from -1 to 0. -1 can only be set by the |
161 // profiler thread before it suspends itself and starts waiting on | 138 // profiler thread before it suspends itself and starts waiting on |
162 // the semaphore. | 139 // the semaphore. |
163 HandleWakeUp(isolate); | 140 HandleWakeUp(isolate); |
164 } | 141 } |
165 ASSERT(new_state >= 0); | 142 ASSERT(new_state >= 0); |
166 } | 143 } |
167 | 144 |
168 | 145 |
169 void RuntimeProfiler::IsolateExitedJS(Isolate* isolate) { | 146 void RuntimeProfiler::IsolateExitedJS(Isolate* isolate) { |
170 Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, -1); | 147 Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, -1); |
171 ASSERT(new_state >= 0); | 148 ASSERT(new_state >= 0); |
172 USE(new_state); | 149 USE(new_state); |
173 } | 150 } |
174 | 151 |
175 } } // namespace v8::internal | 152 } } // namespace v8::internal |
176 | 153 |
177 #endif // V8_RUNTIME_PROFILER_H_ | 154 #endif // V8_RUNTIME_PROFILER_H_ |
OLD | NEW |