From 517f05aa44b0605da44c286c9d0a98afd7a94cee Mon Sep 17 00:00:00 2001 From: "ager@chromium.org" Date: Fri, 1 Jul 2011 05:50:14 +0000 Subject: [PATCH] Fixes the build for the shell on illumos and Solaris. -D__C99FEATURES__ was added to mirror how the build is done on the normal platform. The changes in the platform code are a follow up to a prior review and has the Solaris implementation be more similar to the Linux version as opposed to the FreeBSD. Contributed by Robert Mustacchi TEST=Note the test suite uncovered a bug in libm where pow(3M) was not doing the right thing on edge cases. The only test failures are related to this bug. Review URL: http://codereview.chromium.org/7282034 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@8502 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- AUTHORS | 1 + SConstruct | 3 ++ src/platform-solaris.cc | 62 ++++++++++++++++++++++++----------------- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/AUTHORS b/AUTHORS index d2dab733d21..d4e35fe8002 100644 --- a/AUTHORS +++ b/AUTHORS @@ -36,6 +36,7 @@ Patrick Gansterer Peter Varga Rafal Krypa Rene Rebe +Robert Mustacchi Rodolph Perfetta Ryan Dahl Sanjoy Das diff --git a/SConstruct b/SConstruct index e678bd421c2..f7c644a7706 100644 --- a/SConstruct +++ b/SConstruct @@ -475,6 +475,9 @@ SAMPLE_FLAGS = { 'LIBS': ['execinfo', 'pthread'] }, 'os:solaris': { + # On Solaris, to get isinf, INFINITY, fpclassify and other macros one + # needs to define __C99FEATURES__. + 'CPPDEFINES': ['__C99FEATURES__'], 'LIBPATH' : ['/usr/local/lib'], 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'], 'LINKFLAGS': ['-mt'] diff --git a/src/platform-solaris.cc b/src/platform-solaris.cc index cc1a4fb7ce3..bbd982c319f 100644 --- a/src/platform-solaris.cc +++ b/src/platform-solaris.cc @@ -595,17 +595,6 @@ static pthread_t GetThreadID() { return pthread_self(); } -class Sampler::PlatformData : public Malloced { - public: - PlatformData() : vm_tid_(GetThreadID()) {} - - pthread_t vm_tid() const { return vm_tid_; } - - private: - pthread_t vm_tid_; -}; - - static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { USE(info); if (signal != SIGPROF) return; @@ -639,6 +628,17 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { sampler->Tick(sample); } +class Sampler::PlatformData : public Malloced { + public: + PlatformData() : vm_tid_(GetThreadID()) {} + + pthread_t vm_tid() const { return vm_tid_; } + + private: + pthread_t vm_tid_; +}; + + class SignalSender : public Thread { public: enum SleepInterval { @@ -650,19 +650,28 @@ class SignalSender : public Thread { : Thread("SignalSender"), 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 { @@ -678,12 +687,7 @@ class SignalSender : public Thread { instance_->Join(); delete instance_; instance_ = NULL; - - // Restore the old signal handler. - if (signal_handler_installed_) { - sigaction(SIGPROF, &old_signal_handler_, 0); - signal_handler_installed_ = false; - } + RestoreSignalHandler(); } } @@ -695,6 +699,12 @@ class SignalSender : public Thread { 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) {