Removed RuntimeProfilerRateLimiter class and RuntimeProfiler::IsSomeIsolateInJS.

Removing the former was basically a consequence of removing the latter. The net
effect is, apart from less code, that the signal sender thread is much more
explicit about its logic now.

Review URL: https://codereview.chromium.org/11543020

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13212 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent facad070
...@@ -1015,7 +1015,6 @@ class Isolate { ...@@ -1015,7 +1015,6 @@ class Isolate {
RuntimeProfiler::IsolateEnteredJS(this); RuntimeProfiler::IsolateEnteredJS(this);
} else if (current_state == JS && state != JS) { } else if (current_state == JS && state != JS) {
// JS -> non-JS transition. // JS -> non-JS transition.
ASSERT(RuntimeProfiler::IsSomeIsolateInJS());
RuntimeProfiler::IsolateExitedJS(this); RuntimeProfiler::IsolateExitedJS(this);
} else { } else {
// Other types of state transitions are not interesting to the // Other types of state transitions are not interesting to the
......
...@@ -660,7 +660,7 @@ class SamplerThread : public Thread { ...@@ -660,7 +660,7 @@ class SamplerThread : public Thread {
if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) { if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this); SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else { } else {
if (rate_limiter_.SuspendIfNecessary()) continue; if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
} }
OS::Sleep(interval_); OS::Sleep(interval_);
} }
...@@ -708,7 +708,6 @@ class SamplerThread : public Thread { ...@@ -708,7 +708,6 @@ class SamplerThread : public Thread {
} }
const int interval_; const int interval_;
RuntimeProfilerRateLimiter rate_limiter_;
// Protects the process wide state below. // Protects the process wide state below.
static Mutex* mutex_; static Mutex* mutex_;
......
...@@ -767,7 +767,7 @@ class SignalSender : public Thread { ...@@ -767,7 +767,7 @@ class SignalSender : public Thread {
if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) { if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this); SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else { } else {
if (rate_limiter_.SuspendIfNecessary()) continue; if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
} }
Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough. Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough.
} }
...@@ -802,7 +802,6 @@ class SignalSender : public Thread { ...@@ -802,7 +802,6 @@ class SignalSender : public Thread {
} }
const int interval_; const int interval_;
RuntimeProfilerRateLimiter rate_limiter_;
// Protects the process wide state below. // Protects the process wide state below.
static Mutex* mutex_; static Mutex* mutex_;
......
...@@ -1153,7 +1153,7 @@ class SignalSender : public Thread { ...@@ -1153,7 +1153,7 @@ class SignalSender : public Thread {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this); SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else { } else {
if (signal_handler_installed_) RestoreSignalHandler(); if (signal_handler_installed_) RestoreSignalHandler();
if (rate_limiter_.SuspendIfNecessary()) continue; if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
} }
Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough. Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough.
} }
...@@ -1198,7 +1198,6 @@ class SignalSender : public Thread { ...@@ -1198,7 +1198,6 @@ class SignalSender : public Thread {
const int vm_tgid_; const int vm_tgid_;
const int interval_; const int interval_;
RuntimeProfilerRateLimiter rate_limiter_;
// Protects the process wide state below. // Protects the process wide state below.
static Mutex* mutex_; static Mutex* mutex_;
......
...@@ -792,7 +792,7 @@ class SamplerThread : public Thread { ...@@ -792,7 +792,7 @@ class SamplerThread : public Thread {
if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) { if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this); SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else { } else {
if (rate_limiter_.SuspendIfNecessary()) continue; if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
} }
OS::Sleep(interval_); OS::Sleep(interval_);
} }
...@@ -851,7 +851,6 @@ class SamplerThread : public Thread { ...@@ -851,7 +851,6 @@ class SamplerThread : public Thread {
} }
const int interval_; const int interval_;
RuntimeProfilerRateLimiter rate_limiter_;
// Protects the process wide state below. // Protects the process wide state below.
static Mutex* mutex_; static Mutex* mutex_;
......
...@@ -846,7 +846,7 @@ class SignalSender : public Thread { ...@@ -846,7 +846,7 @@ class SignalSender : public Thread {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this); SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else { } else {
if (signal_handler_installed_) RestoreSignalHandler(); if (signal_handler_installed_) RestoreSignalHandler();
if (rate_limiter_.SuspendIfNecessary()) continue; if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
} }
Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough. Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough.
} }
...@@ -882,7 +882,6 @@ class SignalSender : public Thread { ...@@ -882,7 +882,6 @@ class SignalSender : public Thread {
const int vm_tgid_; const int vm_tgid_;
const int interval_; const int interval_;
RuntimeProfilerRateLimiter rate_limiter_;
// Protects the process wide state below. // Protects the process wide state below.
static Mutex* mutex_; static Mutex* mutex_;
......
...@@ -762,7 +762,7 @@ class SignalSender : public Thread { ...@@ -762,7 +762,7 @@ class SignalSender : public Thread {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this); SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else { } else {
if (signal_handler_installed_) RestoreSignalHandler(); if (signal_handler_installed_) RestoreSignalHandler();
if (rate_limiter_.SuspendIfNecessary()) continue; if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
} }
Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough. Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough.
} }
...@@ -797,7 +797,6 @@ class SignalSender : public Thread { ...@@ -797,7 +797,6 @@ class SignalSender : public Thread {
} }
const int interval_; const int interval_;
RuntimeProfilerRateLimiter rate_limiter_;
// Protects the process wide state below. // Protects the process wide state below.
static Mutex* mutex_; static Mutex* mutex_;
......
...@@ -2015,7 +2015,7 @@ class SamplerThread : public Thread { ...@@ -2015,7 +2015,7 @@ class SamplerThread : public Thread {
if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) { if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this); SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else { } else {
if (rate_limiter_.SuspendIfNecessary()) continue; if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
} }
OS::Sleep(interval_); OS::Sleep(interval_);
} }
...@@ -2063,7 +2063,6 @@ class SamplerThread : public Thread { ...@@ -2063,7 +2063,6 @@ class SamplerThread : public Thread {
} }
const int interval_; const int interval_;
RuntimeProfilerRateLimiter rate_limiter_;
// Protects the process wide state below. // Protects the process wide state below.
static Mutex* mutex_; static Mutex* mutex_;
......
...@@ -430,11 +430,6 @@ void RuntimeProfiler::HandleWakeUp(Isolate* isolate) { ...@@ -430,11 +430,6 @@ void RuntimeProfiler::HandleWakeUp(Isolate* isolate) {
} }
bool RuntimeProfiler::IsSomeIsolateInJS() {
return NoBarrier_Load(&state_) > 0;
}
bool RuntimeProfiler::WaitForSomeIsolateToEnterJS() { bool RuntimeProfiler::WaitForSomeIsolateToEnterJS() {
Atomic32 old_state = NoBarrier_CompareAndSwap(&state_, 0, -1); Atomic32 old_state = NoBarrier_CompareAndSwap(&state_, 0, -1);
ASSERT(old_state >= -1); ASSERT(old_state >= -1);
...@@ -484,12 +479,4 @@ void RuntimeProfiler::UpdateSamplesAfterCompact(ObjectVisitor* visitor) { ...@@ -484,12 +479,4 @@ void RuntimeProfiler::UpdateSamplesAfterCompact(ObjectVisitor* visitor) {
} }
bool RuntimeProfilerRateLimiter::SuspendIfNecessary() {
if (!RuntimeProfiler::IsSomeIsolateInJS()) {
return RuntimeProfiler::WaitForSomeIsolateToEnterJS();
}
return false;
}
} } // namespace v8::internal } } // namespace v8::internal
...@@ -71,17 +71,12 @@ class RuntimeProfiler { ...@@ -71,17 +71,12 @@ class RuntimeProfiler {
// Profiler thread interface. // Profiler thread interface.
// //
// IsSomeIsolateInJS():
// The profiler thread can query whether some isolate is currently
// running JavaScript code.
//
// WaitForSomeIsolateToEnterJS(): // WaitForSomeIsolateToEnterJS():
// When no isolates are running JavaScript code for some time the // When no isolates are running JavaScript code for some time the
// profiler thread suspends itself by calling the wait function. The // profiler thread suspends itself by calling the wait function. The
// wait function returns true after it waited or false immediately. // wait function returns true after it waited or false immediately.
// While the function was waiting the profiler may have been // While the function was waiting the profiler may have been
// disabled so it *must check* whether it is allowed to continue. // disabled so it *must check* whether it is allowed to continue.
static bool IsSomeIsolateInJS();
static bool WaitForSomeIsolateToEnterJS(); static bool WaitForSomeIsolateToEnterJS();
// Stops the runtime profiler thread when profiling support is being // Stops the runtime profiler thread when profiling support is being
...@@ -134,24 +129,6 @@ class RuntimeProfiler { ...@@ -134,24 +129,6 @@ class RuntimeProfiler {
}; };
// Rate limiter intended to be used in the profiler thread.
class RuntimeProfilerRateLimiter BASE_EMBEDDED {
public:
RuntimeProfilerRateLimiter() {}
// 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:
DISALLOW_COPY_AND_ASSIGN(RuntimeProfilerRateLimiter);
};
// Implementation of RuntimeProfiler inline functions. // Implementation of RuntimeProfiler inline functions.
void RuntimeProfiler::IsolateEnteredJS(Isolate* isolate) { void RuntimeProfiler::IsolateEnteredJS(Isolate* isolate) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment