| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 return -0.0; | 73 return -0.0; |
| 74 } else { | 74 } else { |
| 75 return ceil(x); | 75 return ceil(x); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 | 79 |
| 80 static Mutex* limit_mutex = NULL; | 80 static Mutex* limit_mutex = NULL; |
| 81 | 81 |
| 82 | 82 |
| 83 void OS::SetUp() { | 83 void OS::PostSetUp() { |
| 84 // Seed the random number generator. | 84 POSIXPostSetUp(); |
| 85 // Convert the current time to a 64-bit integer first, before converting it | |
| 86 // to an unsigned. Going directly can cause an overflow and the seed to be | |
| 87 // set to all ones. The seed will be identical for different instances that | |
| 88 // call this setup code within the same millisecond. | |
| 89 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); | |
| 90 srandom(static_cast<unsigned int>(seed)); | |
| 91 limit_mutex = CreateMutex(); | |
| 92 } | 85 } |
| 93 | 86 |
| 94 | 87 |
| 95 void OS::PostSetUp() { | |
| 96 // Math functions depend on CPU features therefore they are initialized after | |
| 97 // CPU. | |
| 98 MathSetup(); | |
| 99 } | |
| 100 | |
| 101 | |
| 102 void OS::ReleaseStore(volatile AtomicWord* ptr, AtomicWord value) { | 88 void OS::ReleaseStore(volatile AtomicWord* ptr, AtomicWord value) { |
| 103 __asm__ __volatile__("" : : : "memory"); | 89 __asm__ __volatile__("" : : : "memory"); |
| 104 *ptr = value; | 90 *ptr = value; |
| 105 } | 91 } |
| 106 | 92 |
| 107 | 93 |
| 108 uint64_t OS::CpuFeaturesImpliedByPlatform() { | 94 uint64_t OS::CpuFeaturesImpliedByPlatform() { |
| 109 return 0; // FreeBSD runs on anything. | 95 return 0; // FreeBSD runs on anything. |
| 110 } | 96 } |
| 111 | 97 |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 HALF_INTERVAL, | 709 HALF_INTERVAL, |
| 724 FULL_INTERVAL | 710 FULL_INTERVAL |
| 725 }; | 711 }; |
| 726 | 712 |
| 727 static const int kSignalSenderStackSize = 64 * KB; | 713 static const int kSignalSenderStackSize = 64 * KB; |
| 728 | 714 |
| 729 explicit SignalSender(int interval) | 715 explicit SignalSender(int interval) |
| 730 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), | 716 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), |
| 731 interval_(interval) {} | 717 interval_(interval) {} |
| 732 | 718 |
| 719 static void SetUp() { |
| 720 if (!mutex_) { |
| 721 mutex_ = OS::CreateMutex(); |
| 722 } |
| 723 } |
| 724 |
| 733 static void AddActiveSampler(Sampler* sampler) { | 725 static void AddActiveSampler(Sampler* sampler) { |
| 734 ScopedLock lock(mutex_.Pointer()); | 726 ScopedLock lock(mutex_); |
| 735 SamplerRegistry::AddActiveSampler(sampler); | 727 SamplerRegistry::AddActiveSampler(sampler); |
| 736 if (instance_ == NULL) { | 728 if (instance_ == NULL) { |
| 737 // Install a signal handler. | 729 // Install a signal handler. |
| 738 struct sigaction sa; | 730 struct sigaction sa; |
| 739 sa.sa_sigaction = ProfilerSignalHandler; | 731 sa.sa_sigaction = ProfilerSignalHandler; |
| 740 sigemptyset(&sa.sa_mask); | 732 sigemptyset(&sa.sa_mask); |
| 741 sa.sa_flags = SA_RESTART | SA_SIGINFO; | 733 sa.sa_flags = SA_RESTART | SA_SIGINFO; |
| 742 signal_handler_installed_ = | 734 signal_handler_installed_ = |
| 743 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); | 735 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); |
| 744 | 736 |
| 745 // Start a thread that sends SIGPROF signal to VM threads. | 737 // Start a thread that sends SIGPROF signal to VM threads. |
| 746 instance_ = new SignalSender(sampler->interval()); | 738 instance_ = new SignalSender(sampler->interval()); |
| 747 instance_->Start(); | 739 instance_->Start(); |
| 748 } else { | 740 } else { |
| 749 ASSERT(instance_->interval_ == sampler->interval()); | 741 ASSERT(instance_->interval_ == sampler->interval()); |
| 750 } | 742 } |
| 751 } | 743 } |
| 752 | 744 |
| 753 static void RemoveActiveSampler(Sampler* sampler) { | 745 static void RemoveActiveSampler(Sampler* sampler) { |
| 754 ScopedLock lock(mutex_.Pointer()); | 746 ScopedLock lock(mutex_); |
| 755 SamplerRegistry::RemoveActiveSampler(sampler); | 747 SamplerRegistry::RemoveActiveSampler(sampler); |
| 756 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { | 748 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
| 757 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); | 749 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); |
| 758 delete instance_; | 750 delete instance_; |
| 759 instance_ = NULL; | 751 instance_ = NULL; |
| 760 | 752 |
| 761 // Restore the old signal handler. | 753 // Restore the old signal handler. |
| 762 if (signal_handler_installed_) { | 754 if (signal_handler_installed_) { |
| 763 sigaction(SIGPROF, &old_signal_handler_, 0); | 755 sigaction(SIGPROF, &old_signal_handler_, 0); |
| 764 signal_handler_installed_ = false; | 756 signal_handler_installed_ = false; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 ASSERT(result == 0 || errno == EINTR); | 829 ASSERT(result == 0 || errno == EINTR); |
| 838 } | 830 } |
| 839 #endif | 831 #endif |
| 840 USE(result); | 832 USE(result); |
| 841 } | 833 } |
| 842 | 834 |
| 843 const int interval_; | 835 const int interval_; |
| 844 RuntimeProfilerRateLimiter rate_limiter_; | 836 RuntimeProfilerRateLimiter rate_limiter_; |
| 845 | 837 |
| 846 // Protects the process wide state below. | 838 // Protects the process wide state below. |
| 847 static LazyMutex mutex_; | 839 static Mutex* mutex_; |
| 848 static SignalSender* instance_; | 840 static SignalSender* instance_; |
| 849 static bool signal_handler_installed_; | 841 static bool signal_handler_installed_; |
| 850 static struct sigaction old_signal_handler_; | 842 static struct sigaction old_signal_handler_; |
| 851 | 843 |
| 852 private: | 844 private: |
| 853 DISALLOW_COPY_AND_ASSIGN(SignalSender); | 845 DISALLOW_COPY_AND_ASSIGN(SignalSender); |
| 854 }; | 846 }; |
| 855 | 847 |
| 856 LazyMutex SignalSender::mutex_ = LAZY_MUTEX_INITIALIZER; | 848 Mutex* SignalSender::mutex_ = NULL; |
| 857 SignalSender* SignalSender::instance_ = NULL; | 849 SignalSender* SignalSender::instance_ = NULL; |
| 858 struct sigaction SignalSender::old_signal_handler_; | 850 struct sigaction SignalSender::old_signal_handler_; |
| 859 bool SignalSender::signal_handler_installed_ = false; | 851 bool SignalSender::signal_handler_installed_ = false; |
| 860 | 852 |
| 861 | 853 |
| 854 void OS::SetUp() { |
| 855 // Seed the random number generator. |
| 856 // Convert the current time to a 64-bit integer first, before converting it |
| 857 // to an unsigned. Going directly can cause an overflow and the seed to be |
| 858 // set to all ones. The seed will be identical for different instances that |
| 859 // call this setup code within the same millisecond. |
| 860 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); |
| 861 srandom(static_cast<unsigned int>(seed)); |
| 862 limit_mutex = CreateMutex(); |
| 863 SignalSender::SetUp(); |
| 864 } |
| 865 |
| 866 |
| 862 Sampler::Sampler(Isolate* isolate, int interval) | 867 Sampler::Sampler(Isolate* isolate, int interval) |
| 863 : isolate_(isolate), | 868 : isolate_(isolate), |
| 864 interval_(interval), | 869 interval_(interval), |
| 865 profiling_(false), | 870 profiling_(false), |
| 866 active_(false), | 871 active_(false), |
| 867 samples_taken_(0) { | 872 samples_taken_(0) { |
| 868 data_ = new PlatformData; | 873 data_ = new PlatformData; |
| 869 } | 874 } |
| 870 | 875 |
| 871 | 876 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 883 | 888 |
| 884 | 889 |
| 885 void Sampler::Stop() { | 890 void Sampler::Stop() { |
| 886 ASSERT(IsActive()); | 891 ASSERT(IsActive()); |
| 887 SignalSender::RemoveActiveSampler(this); | 892 SignalSender::RemoveActiveSampler(this); |
| 888 SetActive(false); | 893 SetActive(false); |
| 889 } | 894 } |
| 890 | 895 |
| 891 | 896 |
| 892 } } // namespace v8::internal | 897 } } // namespace v8::internal |
| OLD | NEW |