Commit 46508ec2 authored by yurys@chromium.org's avatar yurys@chromium.org

Remove profiler thread related methods from RuntimeProfiler

Now that V8 doesn't use sampling thread for optimizations
the methods can be removed.

BUG=None

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14214 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent fecd8bbe
......@@ -1556,9 +1556,6 @@ Handle<Context> Isolate::GetCallingNativeContext() {
char* Isolate::ArchiveThread(char* to) {
if (RuntimeProfiler::IsEnabled() && current_vm_state() == JS) {
RuntimeProfiler::IsolateExitedJS(this);
}
memcpy(to, reinterpret_cast<char*>(thread_local_top()),
sizeof(ThreadLocalTop));
InitializeThreadLocal();
......@@ -1581,9 +1578,6 @@ char* Isolate::RestoreThread(char* from) {
thread_local_top()->simulator_ = Simulator::current(this);
#endif
#endif
if (RuntimeProfiler::IsEnabled() && current_vm_state() == JS) {
RuntimeProfiler::IsolateEnteredJS(this);
}
ASSERT(context() == NULL || context()->IsContext());
return from + sizeof(ThreadLocalTop);
}
......
......@@ -1027,23 +1027,6 @@ class Isolate {
}
void SetCurrentVMState(StateTag state) {
if (RuntimeProfiler::IsEnabled()) {
// Make sure thread local top is initialized.
ASSERT(thread_local_top_.isolate_ == this);
StateTag current_state = thread_local_top_.current_vm_state_;
if (current_state != JS && state == JS) {
// Non-JS -> JS transition.
RuntimeProfiler::IsolateEnteredJS(this);
} else if (current_state == JS && state != JS) {
// JS -> non-JS transition.
RuntimeProfiler::IsolateExitedJS(this);
} else {
// Other types of state transitions are not interesting to the
// runtime profiler, because they don't affect whether we're
// in JS or not.
ASSERT((current_state == JS) == (state == JS));
}
}
thread_local_top_.current_vm_state_ = state;
}
......
......@@ -650,7 +650,7 @@ class SamplerThread : public Thread {
ScopedLock lock(mutex_);
SamplerRegistry::RemoveActiveSampler(sampler);
if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
instance_->Join();
delete instance_;
instance_ = NULL;
}
......@@ -665,8 +665,6 @@ class SamplerThread : public Thread {
// profiled. We must not suspend.
if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else {
if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
}
OS::Sleep(interval_);
}
......
......@@ -776,7 +776,7 @@ class SignalSender : public Thread {
ScopedLock lock(mutex_);
SamplerRegistry::RemoveActiveSampler(sampler);
if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
instance_->Join();
delete instance_;
instance_ = NULL;
......@@ -797,8 +797,6 @@ class SignalSender : public Thread {
// profiled. We must not suspend.
if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else {
if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
}
Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough.
}
......
......@@ -1194,7 +1194,7 @@ class SignalSender : public Thread {
ScopedLock lock(mutex_);
SamplerRegistry::RemoveActiveSampler(sampler);
if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
instance_->Join();
delete instance_;
instance_ = NULL;
RestoreSignalHandler();
......@@ -1213,7 +1213,6 @@ class SignalSender : public Thread {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else {
if (signal_handler_installed_) RestoreSignalHandler();
if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
}
Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough.
}
......
......@@ -787,7 +787,7 @@ class SamplerThread : public Thread {
ScopedLock lock(mutex_);
SamplerRegistry::RemoveActiveSampler(sampler);
if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
instance_->Join();
delete instance_;
instance_ = NULL;
}
......@@ -802,8 +802,6 @@ class SamplerThread : public Thread {
// profiled. We must not suspend.
if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else {
if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
}
OS::Sleep(interval_);
}
......
......@@ -838,7 +838,7 @@ class SignalSender : public Thread {
ScopedLock lock(mutex_);
SamplerRegistry::RemoveActiveSampler(sampler);
if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
instance_->Join();
delete instance_;
instance_ = NULL;
RestoreSignalHandler();
......@@ -855,9 +855,8 @@ class SignalSender : public Thread {
if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) {
if (!signal_handler_installed_) InstallSignalHandler();
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else {
if (signal_handler_installed_) RestoreSignalHandler();
if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
} else if (signal_handler_installed_) {
RestoreSignalHandler();
}
Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough.
}
......
......@@ -754,7 +754,7 @@ class SignalSender : public Thread {
ScopedLock lock(mutex_);
SamplerRegistry::RemoveActiveSampler(sampler);
if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
instance_->Join();
delete instance_;
instance_ = NULL;
RestoreSignalHandler();
......@@ -771,9 +771,8 @@ class SignalSender : public Thread {
if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) {
if (!signal_handler_installed_) InstallSignalHandler();
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else {
if (signal_handler_installed_) RestoreSignalHandler();
if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
} else if (signal_handler_installed_) {
RestoreSignalHandler();
}
Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough.
}
......
......@@ -2027,7 +2027,7 @@ class SamplerThread : public Thread {
ScopedLock lock(mutex_);
SamplerRegistry::RemoveActiveSampler(sampler);
if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
instance_->Join();
delete instance_;
instance_ = NULL;
}
......@@ -2042,8 +2042,6 @@ class SamplerThread : public Thread {
// profiled. We must not suspend.
if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else {
if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
}
OS::Sleep(interval_);
}
......
......@@ -86,17 +86,6 @@ static const int kMaxSizeEarlyOpt =
5 * FullCodeGenerator::kBackEdgeDistanceUnit;
Atomic32 RuntimeProfiler::state_ = 0;
// TODO(isolates): Clean up the semaphore when it is no longer required.
static LazySemaphore<0>::type semaphore = LAZY_SEMAPHORE_INITIALIZER;
#ifdef DEBUG
bool RuntimeProfiler::has_been_globally_set_up_ = false;
#endif
bool RuntimeProfiler::enabled_ = false;
RuntimeProfiler::RuntimeProfiler(Isolate* isolate)
: isolate_(isolate),
sampler_threshold_(kSamplerThresholdInit),
......@@ -110,15 +99,6 @@ RuntimeProfiler::RuntimeProfiler(Isolate* isolate)
}
void RuntimeProfiler::GlobalSetUp() {
ASSERT(!has_been_globally_set_up_);
enabled_ = V8::UseCrankshaft() && FLAG_opt;
#ifdef DEBUG
has_been_globally_set_up_ = true;
#endif
}
static void GetICCounts(JSFunction* function,
int* ic_with_type_info_count,
int* ic_total_count,
......@@ -386,7 +366,6 @@ void RuntimeProfiler::OptimizeNow() {
void RuntimeProfiler::SetUp() {
ASSERT(has_been_globally_set_up_);
if (!FLAG_watch_ic_patching) {
ClearSampleBuffer();
}
......@@ -429,48 +408,6 @@ void RuntimeProfiler::UpdateSamplesAfterScavenge() {
}
void RuntimeProfiler::HandleWakeUp(Isolate* isolate) {
// The profiler thread must still be waiting.
ASSERT(NoBarrier_Load(&state_) >= 0);
// In IsolateEnteredJS we have already incremented the counter and
// undid the decrement done by the profiler thread. Increment again
// to get the right count of active isolates.
NoBarrier_AtomicIncrement(&state_, 1);
semaphore.Pointer()->Signal();
}
bool RuntimeProfiler::WaitForSomeIsolateToEnterJS() {
Atomic32 old_state = NoBarrier_CompareAndSwap(&state_, 0, -1);
ASSERT(old_state >= -1);
if (old_state != 0) return false;
semaphore.Pointer()->Wait();
return true;
}
void RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(Thread* thread) {
// Do a fake increment. If the profiler is waiting on the semaphore,
// the returned state is 0, which can be left as an initial state in
// case profiling is restarted later. If the profiler is not
// waiting, the increment will prevent it from waiting, but has to
// be undone after the profiler is stopped.
Atomic32 new_state = NoBarrier_AtomicIncrement(&state_, 1);
ASSERT(new_state >= 0);
if (new_state == 0) {
// The profiler thread is waiting. Wake it up. It must check for
// stop conditions before attempting to wait again.
semaphore.Pointer()->Signal();
}
thread->Join();
// The profiler thread is now stopped. Undo the increment in case it
// was not waiting.
if (new_state != 0) {
NoBarrier_AtomicIncrement(&state_, -1);
}
}
void RuntimeProfiler::RemoveDeadSamples() {
for (int i = 0; i < kSamplerWindowSize; i++) {
Object* function = sampler_window_[i];
......
......@@ -43,13 +43,6 @@ class RuntimeProfiler {
public:
explicit RuntimeProfiler(Isolate* isolate);
static void GlobalSetUp();
static inline bool IsEnabled() {
ASSERT(has_been_globally_set_up_);
return enabled_;
}
void OptimizeNow();
void SetUp();
......@@ -63,26 +56,6 @@ class RuntimeProfiler {
// 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.
//
// 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 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);
......@@ -92,8 +65,6 @@ class RuntimeProfiler {
private:
static const int kSamplerWindowSize = 16;
static void HandleWakeUp(Isolate* isolate);
void Optimize(JSFunction* function, const char* reason);
void ClearSampleBuffer();
......@@ -116,39 +87,8 @@ class RuntimeProfiler {
bool any_ic_changed_;
bool code_generated_;
// 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_;
#ifdef DEBUG
static bool has_been_globally_set_up_;
#endif
static bool enabled_;
};
// 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_
......@@ -275,7 +275,6 @@ void V8::InitializeOncePerProcessImpl() {
&& !Serializer::enabled()
&& CPU::SupportsCrankshaft();
OS::PostSetUp();
RuntimeProfiler::GlobalSetUp();
ElementsAccessor::InitializeOncePerProcess();
LOperand::SetUpCaches();
SetUpJSCallerSavedCodeData();
......
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