Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/platform-solaris.cc

Issue 9976003: Minimize uses of lazy initialization by adding explicit initialization functions. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address Daniel's comments. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // subsequent have their ids incremented from there 84 // subsequent have their ids incremented from there
85 static const pthread_t kNoThread = (pthread_t) 0; 85 static const pthread_t kNoThread = (pthread_t) 0;
86 86
87 87
88 double ceiling(double x) { 88 double ceiling(double x) {
89 return ceil(x); 89 return ceil(x);
90 } 90 }
91 91
92 92
93 static Mutex* limit_mutex = NULL; 93 static Mutex* limit_mutex = NULL;
94 void OS::SetUp() { 94
95 // Seed the random number generator. 95
96 // Convert the current time to a 64-bit integer first, before converting it 96 void OS::PostSetUp() {
97 // to an unsigned. Going directly will cause an overflow and the seed to be 97 POSIXPostSetUp();
98 // set to all ones. The seed will be identical for different instances that
99 // call this setup code within the same millisecond.
100 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
101 srandom(static_cast<unsigned int>(seed));
102 limit_mutex = CreateMutex();
103 } 98 }
104 99
105 100
106 void OS::PostSetUp() {
107 // Math functions depend on CPU features therefore they are initialized after
108 // CPU.
109 MathSetup();
110 }
111
112
113 uint64_t OS::CpuFeaturesImpliedByPlatform() { 101 uint64_t OS::CpuFeaturesImpliedByPlatform() {
114 return 0; // Solaris runs on a lot of things. 102 return 0; // Solaris runs on a lot of things.
115 } 103 }
116 104
117 105
118 int OS::ActivationFrameAlignment() { 106 int OS::ActivationFrameAlignment() {
119 // GCC generates code that requires 16 byte alignment such as movdqa. 107 // GCC generates code that requires 16 byte alignment such as movdqa.
120 return Max(STACK_ALIGN, 16); 108 return Max(STACK_ALIGN, 16);
121 } 109 }
122 110
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 HALF_INTERVAL, 705 HALF_INTERVAL,
718 FULL_INTERVAL 706 FULL_INTERVAL
719 }; 707 };
720 708
721 static const int kSignalSenderStackSize = 64 * KB; 709 static const int kSignalSenderStackSize = 64 * KB;
722 710
723 explicit SignalSender(int interval) 711 explicit SignalSender(int interval)
724 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), 712 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)),
725 interval_(interval) {} 713 interval_(interval) {}
726 714
715 static void SetUp() {
716 if (!mutex_) {
717 mutex_ = OS::CreateMutex();
718 }
719 }
720
727 static void InstallSignalHandler() { 721 static void InstallSignalHandler() {
728 struct sigaction sa; 722 struct sigaction sa;
729 sa.sa_sigaction = ProfilerSignalHandler; 723 sa.sa_sigaction = ProfilerSignalHandler;
730 sigemptyset(&sa.sa_mask); 724 sigemptyset(&sa.sa_mask);
731 sa.sa_flags = SA_RESTART | SA_SIGINFO; 725 sa.sa_flags = SA_RESTART | SA_SIGINFO;
732 signal_handler_installed_ = 726 signal_handler_installed_ =
733 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); 727 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0);
734 } 728 }
735 729
736 static void RestoreSignalHandler() { 730 static void RestoreSignalHandler() {
737 if (signal_handler_installed_) { 731 if (signal_handler_installed_) {
738 sigaction(SIGPROF, &old_signal_handler_, 0); 732 sigaction(SIGPROF, &old_signal_handler_, 0);
739 signal_handler_installed_ = false; 733 signal_handler_installed_ = false;
740 } 734 }
741 } 735 }
742 736
743 static void AddActiveSampler(Sampler* sampler) { 737 static void AddActiveSampler(Sampler* sampler) {
744 ScopedLock lock(mutex_.Pointer()); 738 ScopedLock lock(mutex_);
745 SamplerRegistry::AddActiveSampler(sampler); 739 SamplerRegistry::AddActiveSampler(sampler);
746 if (instance_ == NULL) { 740 if (instance_ == NULL) {
747 // Start a thread that will send SIGPROF signal to VM threads, 741 // Start a thread that will send SIGPROF signal to VM threads,
748 // when CPU profiling will be enabled. 742 // when CPU profiling will be enabled.
749 instance_ = new SignalSender(sampler->interval()); 743 instance_ = new SignalSender(sampler->interval());
750 instance_->Start(); 744 instance_->Start();
751 } else { 745 } else {
752 ASSERT(instance_->interval_ == sampler->interval()); 746 ASSERT(instance_->interval_ == sampler->interval());
753 } 747 }
754 } 748 }
755 749
756 static void RemoveActiveSampler(Sampler* sampler) { 750 static void RemoveActiveSampler(Sampler* sampler) {
757 ScopedLock lock(mutex_.Pointer()); 751 ScopedLock lock(mutex_);
758 SamplerRegistry::RemoveActiveSampler(sampler); 752 SamplerRegistry::RemoveActiveSampler(sampler);
759 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { 753 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
760 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); 754 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
761 delete instance_; 755 delete instance_;
762 instance_ = NULL; 756 instance_ = NULL;
763 RestoreSignalHandler(); 757 RestoreSignalHandler();
764 } 758 }
765 } 759 }
766 760
767 // Implement Thread::Run(). 761 // Implement Thread::Run().
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 ASSERT(result == 0 || errno == EINTR); 835 ASSERT(result == 0 || errno == EINTR);
842 } 836 }
843 #endif 837 #endif
844 USE(result); 838 USE(result);
845 } 839 }
846 840
847 const int interval_; 841 const int interval_;
848 RuntimeProfilerRateLimiter rate_limiter_; 842 RuntimeProfilerRateLimiter rate_limiter_;
849 843
850 // Protects the process wide state below. 844 // Protects the process wide state below.
851 static LazyMutex mutex_; 845 static Mutex* mutex_;
852 static SignalSender* instance_; 846 static SignalSender* instance_;
853 static bool signal_handler_installed_; 847 static bool signal_handler_installed_;
854 static struct sigaction old_signal_handler_; 848 static struct sigaction old_signal_handler_;
855 849
856 private: 850 private:
857 DISALLOW_COPY_AND_ASSIGN(SignalSender); 851 DISALLOW_COPY_AND_ASSIGN(SignalSender);
858 }; 852 };
859 853
860 LazyMutex SignalSender::mutex_ = LAZY_MUTEX_INITIALIZER; 854 Mutex* SignalSender::mutex_ = NULL;
861 SignalSender* SignalSender::instance_ = NULL; 855 SignalSender* SignalSender::instance_ = NULL;
862 struct sigaction SignalSender::old_signal_handler_; 856 struct sigaction SignalSender::old_signal_handler_;
863 bool SignalSender::signal_handler_installed_ = false; 857 bool SignalSender::signal_handler_installed_ = false;
864 858
865 859
860 void OS::SetUp() {
861 // Seed the random number generator.
862 // Convert the current time to a 64-bit integer first, before converting it
863 // to an unsigned. Going directly will cause an overflow and the seed to be
864 // set to all ones. The seed will be identical for different instances that
865 // call this setup code within the same millisecond.
866 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
867 srandom(static_cast<unsigned int>(seed));
868 limit_mutex = CreateMutex();
869 SignalSender::SetUp();
870 }
871
872
866 Sampler::Sampler(Isolate* isolate, int interval) 873 Sampler::Sampler(Isolate* isolate, int interval)
867 : isolate_(isolate), 874 : isolate_(isolate),
868 interval_(interval), 875 interval_(interval),
869 profiling_(false), 876 profiling_(false),
870 active_(false), 877 active_(false),
871 samples_taken_(0) { 878 samples_taken_(0) {
872 data_ = new PlatformData; 879 data_ = new PlatformData;
873 } 880 }
874 881
875 882
(...skipping 10 matching lines...) Expand all
886 } 893 }
887 894
888 895
889 void Sampler::Stop() { 896 void Sampler::Stop() {
890 ASSERT(IsActive()); 897 ASSERT(IsActive());
891 SignalSender::RemoveActiveSampler(this); 898 SignalSender::RemoveActiveSampler(this);
892 SetActive(false); 899 SetActive(false);
893 } 900 }
894 901
895 } } // namespace v8::internal 902 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-posix.cc ('k') | src/platform-win32.cc » ('j') | src/v8.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698