OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 FULL_INTERVAL | 716 FULL_INTERVAL |
717 }; | 717 }; |
718 | 718 |
719 static const int kSignalSenderStackSize = 64 * KB; | 719 static const int kSignalSenderStackSize = 64 * KB; |
720 | 720 |
721 explicit SignalSender(int interval) | 721 explicit SignalSender(int interval) |
722 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), | 722 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), |
723 interval_(interval) {} | 723 interval_(interval) {} |
724 | 724 |
725 static void AddActiveSampler(Sampler* sampler) { | 725 static void AddActiveSampler(Sampler* sampler) { |
726 ScopedLock lock(mutex_); | 726 ScopedLock lock(mutex_.Pointer()); |
727 SamplerRegistry::AddActiveSampler(sampler); | 727 SamplerRegistry::AddActiveSampler(sampler); |
728 if (instance_ == NULL) { | 728 if (instance_ == NULL) { |
729 // Install a signal handler. | 729 // Install a signal handler. |
730 struct sigaction sa; | 730 struct sigaction sa; |
731 sa.sa_sigaction = ProfilerSignalHandler; | 731 sa.sa_sigaction = ProfilerSignalHandler; |
732 sigemptyset(&sa.sa_mask); | 732 sigemptyset(&sa.sa_mask); |
733 sa.sa_flags = SA_RESTART | SA_SIGINFO; | 733 sa.sa_flags = SA_RESTART | SA_SIGINFO; |
734 signal_handler_installed_ = | 734 signal_handler_installed_ = |
735 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); | 735 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); |
736 | 736 |
737 // Start a thread that sends SIGPROF signal to VM threads. | 737 // Start a thread that sends SIGPROF signal to VM threads. |
738 instance_ = new SignalSender(sampler->interval()); | 738 instance_ = new SignalSender(sampler->interval()); |
739 instance_->Start(); | 739 instance_->Start(); |
740 } else { | 740 } else { |
741 ASSERT(instance_->interval_ == sampler->interval()); | 741 ASSERT(instance_->interval_ == sampler->interval()); |
742 } | 742 } |
743 } | 743 } |
744 | 744 |
745 static void RemoveActiveSampler(Sampler* sampler) { | 745 static void RemoveActiveSampler(Sampler* sampler) { |
746 ScopedLock lock(mutex_); | 746 ScopedLock lock(mutex_.Pointer()); |
747 SamplerRegistry::RemoveActiveSampler(sampler); | 747 SamplerRegistry::RemoveActiveSampler(sampler); |
748 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { | 748 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
749 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); | 749 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); |
750 delete instance_; | 750 delete instance_; |
751 instance_ = NULL; | 751 instance_ = NULL; |
752 | 752 |
753 // Restore the old signal handler. | 753 // Restore the old signal handler. |
754 if (signal_handler_installed_) { | 754 if (signal_handler_installed_) { |
755 sigaction(SIGPROF, &old_signal_handler_, 0); | 755 sigaction(SIGPROF, &old_signal_handler_, 0); |
756 signal_handler_installed_ = false; | 756 signal_handler_installed_ = false; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 ASSERT(result == 0 || errno == EINTR); | 829 ASSERT(result == 0 || errno == EINTR); |
830 } | 830 } |
831 #endif | 831 #endif |
832 USE(result); | 832 USE(result); |
833 } | 833 } |
834 | 834 |
835 const int interval_; | 835 const int interval_; |
836 RuntimeProfilerRateLimiter rate_limiter_; | 836 RuntimeProfilerRateLimiter rate_limiter_; |
837 | 837 |
838 // Protects the process wide state below. | 838 // Protects the process wide state below. |
839 static Mutex* mutex_; | 839 static LazyMutex mutex_; |
840 static SignalSender* instance_; | 840 static SignalSender* instance_; |
841 static bool signal_handler_installed_; | 841 static bool signal_handler_installed_; |
842 static struct sigaction old_signal_handler_; | 842 static struct sigaction old_signal_handler_; |
843 | 843 |
844 private: | 844 private: |
845 DISALLOW_COPY_AND_ASSIGN(SignalSender); | 845 DISALLOW_COPY_AND_ASSIGN(SignalSender); |
846 }; | 846 }; |
847 | 847 |
848 Mutex* SignalSender::mutex_ = OS::CreateMutex(); | 848 LazyMutex SignalSender::mutex_ = LAZY_MUTEX_INITIALIZER; |
849 SignalSender* SignalSender::instance_ = NULL; | 849 SignalSender* SignalSender::instance_ = NULL; |
850 struct sigaction SignalSender::old_signal_handler_; | 850 struct sigaction SignalSender::old_signal_handler_; |
851 bool SignalSender::signal_handler_installed_ = false; | 851 bool SignalSender::signal_handler_installed_ = false; |
852 | 852 |
853 | 853 |
854 Sampler::Sampler(Isolate* isolate, int interval) | 854 Sampler::Sampler(Isolate* isolate, int interval) |
855 : isolate_(isolate), | 855 : isolate_(isolate), |
856 interval_(interval), | 856 interval_(interval), |
857 profiling_(false), | 857 profiling_(false), |
858 active_(false), | 858 active_(false), |
(...skipping 16 matching lines...) Expand all Loading... |
875 | 875 |
876 | 876 |
877 void Sampler::Stop() { | 877 void Sampler::Stop() { |
878 ASSERT(IsActive()); | 878 ASSERT(IsActive()); |
879 SignalSender::RemoveActiveSampler(this); | 879 SignalSender::RemoveActiveSampler(this); |
880 SetActive(false); | 880 SetActive(false); |
881 } | 881 } |
882 | 882 |
883 | 883 |
884 } } // namespace v8::internal | 884 } } // namespace v8::internal |
OLD | NEW |