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

Side by Side Diff: src/platform-openbsd.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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // variety of ASLR modes (PAE kernel, NX compat mode, etc). 93 // variety of ASLR modes (PAE kernel, NX compat mode, etc).
94 raw_addr &= 0x3ffff000; 94 raw_addr &= 0x3ffff000;
95 raw_addr += 0x20000000; 95 raw_addr += 0x20000000;
96 #endif 96 #endif
97 return reinterpret_cast<void*>(raw_addr); 97 return reinterpret_cast<void*>(raw_addr);
98 } 98 }
99 return NULL; 99 return NULL;
100 } 100 }
101 101
102 102
103 void OS::SetUp() {
104 // Seed the random number generator. We preserve microsecond resolution.
105 uint64_t seed = Ticks() ^ (getpid() << 16);
106 srandom(static_cast<unsigned int>(seed));
107 limit_mutex = CreateMutex();
108 }
109
110
111 void OS::PostSetUp() { 103 void OS::PostSetUp() {
112 // Math functions depend on CPU features therefore they are initialized after 104 POSIXPostSetUp();
113 // CPU.
114 MathSetup();
115 } 105 }
116 106
117 107
118 uint64_t OS::CpuFeaturesImpliedByPlatform() { 108 uint64_t OS::CpuFeaturesImpliedByPlatform() {
119 return 0; 109 return 0;
120 } 110 }
121 111
122 112
123 int OS::ActivationFrameAlignment() { 113 int OS::ActivationFrameAlignment() {
124 // With gcc 4.4 the tree vectorization optimizer can generate code 114 // With gcc 4.4 the tree vectorization optimizer can generate code
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 FULL_INTERVAL 786 FULL_INTERVAL
797 }; 787 };
798 788
799 static const int kSignalSenderStackSize = 64 * KB; 789 static const int kSignalSenderStackSize = 64 * KB;
800 790
801 explicit SignalSender(int interval) 791 explicit SignalSender(int interval)
802 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), 792 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)),
803 vm_tgid_(getpid()), 793 vm_tgid_(getpid()),
804 interval_(interval) {} 794 interval_(interval) {}
805 795
796 static void SetUp() {
797 if (!mutex_) {
798 mutex_ = OS::CreateMutex();
799 }
800 }
801
806 static void InstallSignalHandler() { 802 static void InstallSignalHandler() {
807 struct sigaction sa; 803 struct sigaction sa;
808 sa.sa_sigaction = ProfilerSignalHandler; 804 sa.sa_sigaction = ProfilerSignalHandler;
809 sigemptyset(&sa.sa_mask); 805 sigemptyset(&sa.sa_mask);
810 sa.sa_flags = SA_RESTART | SA_SIGINFO; 806 sa.sa_flags = SA_RESTART | SA_SIGINFO;
811 signal_handler_installed_ = 807 signal_handler_installed_ =
812 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); 808 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0);
813 } 809 }
814 810
815 static void RestoreSignalHandler() { 811 static void RestoreSignalHandler() {
816 if (signal_handler_installed_) { 812 if (signal_handler_installed_) {
817 sigaction(SIGPROF, &old_signal_handler_, 0); 813 sigaction(SIGPROF, &old_signal_handler_, 0);
818 signal_handler_installed_ = false; 814 signal_handler_installed_ = false;
819 } 815 }
820 } 816 }
821 817
822 static void AddActiveSampler(Sampler* sampler) { 818 static void AddActiveSampler(Sampler* sampler) {
823 ScopedLock lock(mutex_.Pointer()); 819 ScopedLock lock(mutex_);
824 SamplerRegistry::AddActiveSampler(sampler); 820 SamplerRegistry::AddActiveSampler(sampler);
825 if (instance_ == NULL) { 821 if (instance_ == NULL) {
826 // Start a thread that will send SIGPROF signal to VM threads, 822 // Start a thread that will send SIGPROF signal to VM threads,
827 // when CPU profiling will be enabled. 823 // when CPU profiling will be enabled.
828 instance_ = new SignalSender(sampler->interval()); 824 instance_ = new SignalSender(sampler->interval());
829 instance_->Start(); 825 instance_->Start();
830 } else { 826 } else {
831 ASSERT(instance_->interval_ == sampler->interval()); 827 ASSERT(instance_->interval_ == sampler->interval());
832 } 828 }
833 } 829 }
834 830
835 static void RemoveActiveSampler(Sampler* sampler) { 831 static void RemoveActiveSampler(Sampler* sampler) {
836 ScopedLock lock(mutex_.Pointer()); 832 ScopedLock lock(mutex_);
837 SamplerRegistry::RemoveActiveSampler(sampler); 833 SamplerRegistry::RemoveActiveSampler(sampler);
838 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { 834 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
839 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); 835 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
840 delete instance_; 836 delete instance_;
841 instance_ = NULL; 837 instance_ = NULL;
842 RestoreSignalHandler(); 838 RestoreSignalHandler();
843 } 839 }
844 } 840 }
845 841
846 // Implement Thread::Run(). 842 // Implement Thread::Run().
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 } 916 }
921 #endif 917 #endif
922 USE(result); 918 USE(result);
923 } 919 }
924 920
925 const int vm_tgid_; 921 const int vm_tgid_;
926 const int interval_; 922 const int interval_;
927 RuntimeProfilerRateLimiter rate_limiter_; 923 RuntimeProfilerRateLimiter rate_limiter_;
928 924
929 // Protects the process wide state below. 925 // Protects the process wide state below.
930 static LazyMutex mutex_; 926 static Mutex* mutex_;
931 static SignalSender* instance_; 927 static SignalSender* instance_;
932 static bool signal_handler_installed_; 928 static bool signal_handler_installed_;
933 static struct sigaction old_signal_handler_; 929 static struct sigaction old_signal_handler_;
934 930
935 private: 931 private:
936 DISALLOW_COPY_AND_ASSIGN(SignalSender); 932 DISALLOW_COPY_AND_ASSIGN(SignalSender);
937 }; 933 };
938 934
939 935
940 LazyMutex SignalSender::mutex_ = LAZY_MUTEX_INITIALIZER; 936 Mutex* SignalSender::mutex_ = NULL;
941 SignalSender* SignalSender::instance_ = NULL; 937 SignalSender* SignalSender::instance_ = NULL;
942 struct sigaction SignalSender::old_signal_handler_; 938 struct sigaction SignalSender::old_signal_handler_;
943 bool SignalSender::signal_handler_installed_ = false; 939 bool SignalSender::signal_handler_installed_ = false;
944 940
945 941
942 void OS::SetUp() {
943 // Seed the random number generator. We preserve microsecond resolution.
944 uint64_t seed = Ticks() ^ (getpid() << 16);
945 srandom(static_cast<unsigned int>(seed));
946 limit_mutex = CreateMutex();
947 SignalSender::SetUp();
948 }
949
950
946 Sampler::Sampler(Isolate* isolate, int interval) 951 Sampler::Sampler(Isolate* isolate, int interval)
947 : isolate_(isolate), 952 : isolate_(isolate),
948 interval_(interval), 953 interval_(interval),
949 profiling_(false), 954 profiling_(false),
950 active_(false), 955 active_(false),
951 samples_taken_(0) { 956 samples_taken_(0) {
952 data_ = new PlatformData; 957 data_ = new PlatformData;
953 } 958 }
954 959
955 960
(...skipping 11 matching lines...) Expand all
967 972
968 973
969 void Sampler::Stop() { 974 void Sampler::Stop() {
970 ASSERT(IsActive()); 975 ASSERT(IsActive());
971 SignalSender::RemoveActiveSampler(this); 976 SignalSender::RemoveActiveSampler(this);
972 SetActive(false); 977 SetActive(false);
973 } 978 }
974 979
975 980
976 } } // namespace v8::internal 981 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-macos.cc ('k') | src/platform-posix.h » ('j') | src/v8.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698