| Index: src/platform-linux.cc
|
| ===================================================================
|
| --- src/platform-linux.cc (revision 8618)
|
| +++ src/platform-linux.cc (working copy)
|
| @@ -686,17 +686,15 @@
|
| pthread_t thread_; // Thread handle for pthread.
|
| };
|
|
|
| -Thread::Thread(Isolate* isolate, const Options& options)
|
| +Thread::Thread(const Options& options)
|
| : data_(new PlatformData()),
|
| - isolate_(isolate),
|
| stack_size_(options.stack_size) {
|
| set_name(options.name);
|
| }
|
|
|
|
|
| -Thread::Thread(Isolate* isolate, const char* name)
|
| +Thread::Thread(const char* name)
|
| : data_(new PlatformData()),
|
| - isolate_(isolate),
|
| stack_size_(0) {
|
| set_name(name);
|
| }
|
| @@ -717,7 +715,6 @@
|
| 0, 0, 0);
|
| thread->data()->thread_ = pthread_self();
|
| ASSERT(thread->data()->thread_ != kNoThread);
|
| - Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
|
| thread->Run();
|
| return NULL;
|
| }
|
| @@ -783,7 +780,6 @@
|
|
|
| class LinuxMutex : public Mutex {
|
| public:
|
| -
|
| LinuxMutex() {
|
| pthread_mutexattr_t attrs;
|
| int result = pthread_mutexattr_init(&attrs);
|
| @@ -1008,23 +1004,32 @@
|
| };
|
|
|
| explicit SignalSender(int interval)
|
| - : Thread(NULL, "SignalSender"),
|
| + : Thread("SignalSender"),
|
| vm_tgid_(getpid()),
|
| interval_(interval) {}
|
|
|
| + static void InstallSignalHandler() {
|
| + struct sigaction sa;
|
| + sa.sa_sigaction = ProfilerSignalHandler;
|
| + sigemptyset(&sa.sa_mask);
|
| + sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
| + signal_handler_installed_ =
|
| + (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0);
|
| + }
|
| +
|
| + static void RestoreSignalHandler() {
|
| + if (signal_handler_installed_) {
|
| + sigaction(SIGPROF, &old_signal_handler_, 0);
|
| + signal_handler_installed_ = false;
|
| + }
|
| + }
|
| +
|
| static void AddActiveSampler(Sampler* sampler) {
|
| ScopedLock lock(mutex_);
|
| SamplerRegistry::AddActiveSampler(sampler);
|
| if (instance_ == NULL) {
|
| - // Install a signal handler.
|
| - struct sigaction sa;
|
| - sa.sa_sigaction = ProfilerSignalHandler;
|
| - sigemptyset(&sa.sa_mask);
|
| - sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
| - signal_handler_installed_ =
|
| - (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0);
|
| -
|
| - // Start a thread that sends SIGPROF signal to VM threads.
|
| + // Start a thread that will send SIGPROF signal to VM threads,
|
| + // when CPU profiling will be enabled.
|
| instance_ = new SignalSender(sampler->interval());
|
| instance_->Start();
|
| } else {
|
| @@ -1036,16 +1041,10 @@
|
| ScopedLock lock(mutex_);
|
| SamplerRegistry::RemoveActiveSampler(sampler);
|
| if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
|
| - RuntimeProfiler::WakeUpRuntimeProfilerThreadBeforeShutdown();
|
| - instance_->Join();
|
| + RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
|
| delete instance_;
|
| instance_ = NULL;
|
| -
|
| - // Restore the old signal handler.
|
| - if (signal_handler_installed_) {
|
| - sigaction(SIGPROF, &old_signal_handler_, 0);
|
| - signal_handler_installed_ = false;
|
| - }
|
| + RestoreSignalHandler();
|
| }
|
| }
|
|
|
| @@ -1057,6 +1056,11 @@
|
| bool cpu_profiling_enabled =
|
| (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS);
|
| bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled();
|
| + if (cpu_profiling_enabled && !signal_handler_installed_) {
|
| + InstallSignalHandler();
|
| + } else if (!cpu_profiling_enabled && signal_handler_installed_) {
|
| + RestoreSignalHandler();
|
| + }
|
| // When CPU profiling is enabled both JavaScript and C++ code is
|
| // profiled. We must not suspend.
|
| if (!cpu_profiling_enabled) {
|
|
|