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

Side by Side Diff: src/platform-macos.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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 return -0.0; 87 return -0.0;
88 } else { 88 } else {
89 return ceil(x); 89 return ceil(x);
90 } 90 }
91 } 91 }
92 92
93 93
94 static Mutex* limit_mutex = NULL; 94 static Mutex* limit_mutex = NULL;
95 95
96 96
97 void OS::SetUp() { 97 void OS::PostSetUp() {
98 // Seed the random number generator. We preserve microsecond resolution. 98 POSIXPostSetUp();
99 uint64_t seed = Ticks() ^ (getpid() << 16);
100 srandom(static_cast<unsigned int>(seed));
101 limit_mutex = CreateMutex();
102 } 99 }
103 100
104 101
105 void OS::PostSetUp() {
106 // Math functions depend on CPU features therefore they are initialized after
107 // CPU.
108 MathSetup();
109 }
110
111
112 // We keep the lowest and highest addresses mapped as a quick way of 102 // We keep the lowest and highest addresses mapped as a quick way of
113 // determining that pointers are outside the heap (used mostly in assertions 103 // determining that pointers are outside the heap (used mostly in assertions
114 // and verification). The estimate is conservative, i.e., not all addresses in 104 // and verification). The estimate is conservative, i.e., not all addresses in
115 // 'allocated' space are actually allocated to our heap. The range is 105 // 'allocated' space are actually allocated to our heap. The range is
116 // [lowest, highest), inclusive on the low and and exclusive on the high end. 106 // [lowest, highest), inclusive on the low and and exclusive on the high end.
117 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1); 107 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1);
118 static void* highest_ever_allocated = reinterpret_cast<void*>(0); 108 static void* highest_ever_allocated = reinterpret_cast<void*>(0);
119 109
120 110
121 static void UpdateAllocatedSpaceLimits(void* address, int size) { 111 static void UpdateAllocatedSpaceLimits(void* address, int size) {
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 736
747 737
748 class SamplerThread : public Thread { 738 class SamplerThread : public Thread {
749 public: 739 public:
750 static const int kSamplerThreadStackSize = 64 * KB; 740 static const int kSamplerThreadStackSize = 64 * KB;
751 741
752 explicit SamplerThread(int interval) 742 explicit SamplerThread(int interval)
753 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), 743 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)),
754 interval_(interval) {} 744 interval_(interval) {}
755 745
746 static void SetUp() {
747 if (!mutex_) {
748 mutex_ = OS::CreateMutex();
749 }
750 }
751
756 static void AddActiveSampler(Sampler* sampler) { 752 static void AddActiveSampler(Sampler* sampler) {
757 ScopedLock lock(mutex_.Pointer()); 753 ScopedLock lock(mutex_);
758 SamplerRegistry::AddActiveSampler(sampler); 754 SamplerRegistry::AddActiveSampler(sampler);
759 if (instance_ == NULL) { 755 if (instance_ == NULL) {
760 instance_ = new SamplerThread(sampler->interval()); 756 instance_ = new SamplerThread(sampler->interval());
761 instance_->Start(); 757 instance_->Start();
762 } else { 758 } else {
763 ASSERT(instance_->interval_ == sampler->interval()); 759 ASSERT(instance_->interval_ == sampler->interval());
764 } 760 }
765 } 761 }
766 762
767 static void RemoveActiveSampler(Sampler* sampler) { 763 static void RemoveActiveSampler(Sampler* sampler) {
768 ScopedLock lock(mutex_.Pointer()); 764 ScopedLock lock(mutex_);
769 SamplerRegistry::RemoveActiveSampler(sampler); 765 SamplerRegistry::RemoveActiveSampler(sampler);
770 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { 766 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
771 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); 767 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
772 delete instance_; 768 delete instance_;
773 instance_ = NULL; 769 instance_ = NULL;
774 } 770 }
775 } 771 }
776 772
777 // Implement Thread::Run(). 773 // Implement Thread::Run().
778 virtual void Run() { 774 virtual void Run() {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 sampler->SampleStack(sample); 851 sampler->SampleStack(sample);
856 sampler->Tick(sample); 852 sampler->Tick(sample);
857 } 853 }
858 thread_resume(profiled_thread); 854 thread_resume(profiled_thread);
859 } 855 }
860 856
861 const int interval_; 857 const int interval_;
862 RuntimeProfilerRateLimiter rate_limiter_; 858 RuntimeProfilerRateLimiter rate_limiter_;
863 859
864 // Protects the process wide state below. 860 // Protects the process wide state below.
865 static LazyMutex mutex_; 861 static Mutex* mutex_;
866 static SamplerThread* instance_; 862 static SamplerThread* instance_;
867 863
868 private: 864 private:
869 DISALLOW_COPY_AND_ASSIGN(SamplerThread); 865 DISALLOW_COPY_AND_ASSIGN(SamplerThread);
870 }; 866 };
871 867
872 #undef REGISTER_FIELD 868 #undef REGISTER_FIELD
873 869
874 870
875 LazyMutex SamplerThread::mutex_ = LAZY_MUTEX_INITIALIZER; 871 Mutex* SamplerThread::mutex_ = NULL;
876 SamplerThread* SamplerThread::instance_ = NULL; 872 SamplerThread* SamplerThread::instance_ = NULL;
877 873
878 874
875 void OS::SetUp() {
876 // Seed the random number generator. We preserve microsecond resolution.
877 uint64_t seed = Ticks() ^ (getpid() << 16);
878 srandom(static_cast<unsigned int>(seed));
879 limit_mutex = CreateMutex();
880 SamplerThread::SetUp();
881 }
882
883
879 Sampler::Sampler(Isolate* isolate, int interval) 884 Sampler::Sampler(Isolate* isolate, int interval)
880 : isolate_(isolate), 885 : isolate_(isolate),
881 interval_(interval), 886 interval_(interval),
882 profiling_(false), 887 profiling_(false),
883 active_(false), 888 active_(false),
884 samples_taken_(0) { 889 samples_taken_(0) {
885 data_ = new PlatformData; 890 data_ = new PlatformData;
886 } 891 }
887 892
888 893
(...skipping 11 matching lines...) Expand all
900 905
901 906
902 void Sampler::Stop() { 907 void Sampler::Stop() {
903 ASSERT(IsActive()); 908 ASSERT(IsActive());
904 SamplerThread::RemoveActiveSampler(this); 909 SamplerThread::RemoveActiveSampler(this);
905 SetActive(false); 910 SetActive(false);
906 } 911 }
907 912
908 913
909 } } // namespace v8::internal 914 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-openbsd.cc » ('j') | src/v8.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698