summaryrefslogtreecommitdiff
path: root/deps/v8/src/runtime-profiler.h
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2011-07-08 16:40:11 -0700
committerRyan Dahl <ry@tinyclouds.org>2011-07-08 16:40:11 -0700
commite5564a3f29e0a818832a97c7c3b28d7c8b3b0460 (patch)
tree4b48a6577080d5e44da4d2cbebb7fe7951660de8 /deps/v8/src/runtime-profiler.h
parent0df2f74d364826053641395b01c2fcb1345057a9 (diff)
downloadandroid-node-v8-e5564a3f29e0a818832a97c7c3b28d7c8b3b0460.tar.gz
android-node-v8-e5564a3f29e0a818832a97c7c3b28d7c8b3b0460.tar.bz2
android-node-v8-e5564a3f29e0a818832a97c7c3b28d7c8b3b0460.zip
Upgrade V8 to 3.4.10
Diffstat (limited to 'deps/v8/src/runtime-profiler.h')
-rw-r--r--deps/v8/src/runtime-profiler.h142
1 files changed, 123 insertions, 19 deletions
diff --git a/deps/v8/src/runtime-profiler.h b/deps/v8/src/runtime-profiler.h
index 02defc9b2c..3f3ab0773a 100644
--- a/deps/v8/src/runtime-profiler.h
+++ b/deps/v8/src/runtime-profiler.h
@@ -28,50 +28,154 @@
#ifndef V8_RUNTIME_PROFILER_H_
#define V8_RUNTIME_PROFILER_H_
-#include "v8.h"
#include "allocation.h"
+#include "atomicops.h"
namespace v8 {
namespace internal {
-class RuntimeProfiler : public AllStatic {
+class Isolate;
+class JSFunction;
+class Object;
+class Semaphore;
+
+class RuntimeProfiler {
public:
- static bool IsEnabled() { return V8::UseCrankshaft() && FLAG_opt; }
+ explicit RuntimeProfiler(Isolate* isolate);
+
+ static void GlobalSetup();
+
+ static inline bool IsEnabled() {
+ ASSERT(has_been_globally_setup_);
+ return enabled_;
+ }
+
+ void OptimizeNow();
+
+ void NotifyTick();
+
+ void Setup();
+ void Reset();
+ void TearDown();
+
+ Object** SamplerWindowAddress();
+ int SamplerWindowSize();
+
+ // Rate limiting support.
+
+ // VM thread interface.
+ //
+ // Called by isolates when their states change.
+ static inline void IsolateEnteredJS(Isolate* isolate);
+ static inline void IsolateExitedJS(Isolate* isolate);
+
+ // Profiler thread interface.
+ //
+ // IsSomeIsolateInJS():
+ // The profiler thread can query whether some isolate is currently
+ // running JavaScript code.
+ //
+ // WaitForSomeIsolateToEnterJS():
+ // When no isolates are running JavaScript code for some time the
+ // profiler thread suspends itself by calling the wait function. The
+ // wait function returns true after it waited or false immediately.
+ // While the function was waiting the profiler may have been
+ // disabled so it *must check* whether it is allowed to continue.
+ static bool IsSomeIsolateInJS();
+ static bool WaitForSomeIsolateToEnterJS();
+
+ // Stops the runtime profiler thread when profiling support is being
+ // turned off.
+ static void StopRuntimeProfilerThreadBeforeShutdown(Thread* thread);
+
+ void UpdateSamplesAfterScavenge();
+ void RemoveDeadSamples();
+ void UpdateSamplesAfterCompact(ObjectVisitor* visitor);
+
+ private:
+ static const int kSamplerWindowSize = 16;
+ static const int kStateWindowSize = 128;
+
+ enum SamplerState {
+ IN_NON_JS_STATE = 0,
+ IN_JS_STATE = 1
+ };
+
+ static void HandleWakeUp(Isolate* isolate);
+
+ void Optimize(JSFunction* function);
+
+ void AttemptOnStackReplacement(JSFunction* function);
+
+ void ClearSampleBuffer();
+
+ void ClearSampleBufferNewSpaceEntries();
+
+ int LookupSample(JSFunction* function);
- static void OptimizeNow();
- static void OptimizeSoon(JSFunction* function);
+ void AddSample(JSFunction* function, int weight);
- static void NotifyTick();
+ Isolate* isolate_;
- static void Setup();
- static void Reset();
- static void TearDown();
+ int sampler_threshold_;
+ int sampler_threshold_size_factor_;
+ int sampler_ticks_until_threshold_adjustment_;
- static int SamplerWindowSize();
- static void UpdateSamplesAfterScavenge();
- static void RemoveDeadSamples();
- static void UpdateSamplesAfterCompact(ObjectVisitor* visitor);
+ Object* sampler_window_[kSamplerWindowSize];
+ int sampler_window_position_;
+ int sampler_window_weight_[kSamplerWindowSize];
+
+ // Possible state values:
+ // -1 => the profiler thread is waiting on the semaphore
+ // 0 or positive => the number of isolates running JavaScript code.
+ static Atomic32 state_;
+ static Semaphore* semaphore_;
+
+#ifdef DEBUG
+ static bool has_been_globally_setup_;
+#endif
+ static bool enabled_;
};
// Rate limiter intended to be used in the profiler thread.
class RuntimeProfilerRateLimiter BASE_EMBEDDED {
public:
- RuntimeProfilerRateLimiter() : non_js_ticks_(0) { }
+ RuntimeProfilerRateLimiter() {}
- // Suspends the current thread when not executing JavaScript to
- // minimize CPU usage. Returns whether this thread was suspended
- // (and so might have to check whether profiling is still active.)
+ // Suspends the current thread (which must be the profiler thread)
+ // when not executing JavaScript to minimize CPU usage. Returns
+ // whether the thread was suspended (and so must check whether
+ // profiling is still active.)
//
// Does nothing when runtime profiling is not enabled.
bool SuspendIfNecessary();
private:
- int non_js_ticks_;
-
DISALLOW_COPY_AND_ASSIGN(RuntimeProfilerRateLimiter);
};
+
+// Implementation of RuntimeProfiler inline functions.
+
+void RuntimeProfiler::IsolateEnteredJS(Isolate* isolate) {
+ Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, 1);
+ if (new_state == 0) {
+ // Just incremented from -1 to 0. -1 can only be set by the
+ // profiler thread before it suspends itself and starts waiting on
+ // the semaphore.
+ HandleWakeUp(isolate);
+ }
+ ASSERT(new_state >= 0);
+}
+
+
+void RuntimeProfiler::IsolateExitedJS(Isolate* isolate) {
+ Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, -1);
+ ASSERT(new_state >= 0);
+ USE(new_state);
+}
+
} } // namespace v8::internal
#endif // V8_RUNTIME_PROFILER_H_