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

Side by Side Diff: src/platform-win32.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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 134
135 double ceiling(double x) { 135 double ceiling(double x) {
136 return ceil(x); 136 return ceil(x);
137 } 137 }
138 138
139 139
140 static Mutex* limit_mutex = NULL; 140 static Mutex* limit_mutex = NULL;
141 141
142 #if defined(V8_TARGET_ARCH_IA32) 142 #if defined(V8_TARGET_ARCH_IA32)
143 static OS::MemCopyFunction memcopy_function = NULL; 143 static OS::MemCopyFunction memcopy_function = NULL;
144 static LazyMutex memcopy_function_mutex = LAZY_MUTEX_INITIALIZER;
145 // Defined in codegen-ia32.cc. 144 // Defined in codegen-ia32.cc.
146 OS::MemCopyFunction CreateMemCopyFunction(); 145 OS::MemCopyFunction CreateMemCopyFunction();
147 146
148 // Copy memory area to disjoint memory area. 147 // Copy memory area to disjoint memory area.
149 void OS::MemCopy(void* dest, const void* src, size_t size) { 148 void OS::MemCopy(void* dest, const void* src, size_t size) {
150 if (memcopy_function == NULL) {
151 ScopedLock lock(memcopy_function_mutex.Pointer());
152 if (memcopy_function == NULL) {
153 OS::MemCopyFunction temp = CreateMemCopyFunction();
154 MemoryBarrier();
155 memcopy_function = temp;
156 }
157 }
158 // Note: here we rely on dependent reads being ordered. This is true 149 // Note: here we rely on dependent reads being ordered. This is true
159 // on all architectures we currently support. 150 // on all architectures we currently support.
160 (*memcopy_function)(dest, src, size); 151 (*memcopy_function)(dest, src, size);
161 #ifdef DEBUG 152 #ifdef DEBUG
162 CHECK_EQ(0, memcmp(dest, src, size)); 153 CHECK_EQ(0, memcmp(dest, src, size));
163 #endif 154 #endif
164 } 155 }
165 #endif // V8_TARGET_ARCH_IA32 156 #endif // V8_TARGET_ARCH_IA32
166 157
167 #ifdef _WIN64 158 #ifdef _WIN64
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 547
557 // Returns a string identifying the current timezone for the 548 // Returns a string identifying the current timezone for the
558 // timestamp taking into account daylight saving. 549 // timestamp taking into account daylight saving.
559 char* Time::LocalTimezone() { 550 char* Time::LocalTimezone() {
560 // Return the standard or DST time zone name based on whether daylight 551 // Return the standard or DST time zone name based on whether daylight
561 // saving is in effect at the given time. 552 // saving is in effect at the given time.
562 return InDST() ? dst_tz_name_ : std_tz_name_; 553 return InDST() ? dst_tz_name_ : std_tz_name_;
563 } 554 }
564 555
565 556
566 void OS::SetUp() {
567 // Seed the random number generator.
568 // Convert the current time to a 64-bit integer first, before converting it
569 // to an unsigned. Going directly can cause an overflow and the seed to be
570 // set to all ones. The seed will be identical for different instances that
571 // call this setup code within the same millisecond.
572 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
573 srand(static_cast<unsigned int>(seed));
574 limit_mutex = CreateMutex();
575 }
576
577
578 void OS::PostSetUp() { 557 void OS::PostSetUp() {
579 // Math functions depend on CPU features therefore they are initialized after 558 // Math functions depend on CPU features therefore they are initialized after
580 // CPU. 559 // CPU.
581 MathSetup(); 560 MathSetup();
561 #if defined(V8_TARGET_ARCH_IA32)
562 memcopy_function = CreateMemCopyFunction();
563 #endif
582 } 564 }
583 565
584 566
585 // Returns the accumulated user time for thread. 567 // Returns the accumulated user time for thread.
586 int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) { 568 int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) {
587 FILETIME dummy; 569 FILETIME dummy;
588 uint64_t usertime; 570 uint64_t usertime;
589 571
590 // Get the amount of time that the thread has executed in user mode. 572 // Get the amount of time that the thread has executed in user mode.
591 if (!GetThreadTimes(GetCurrentThread(), &dummy, &dummy, &dummy, 573 if (!GetThreadTimes(GetCurrentThread(), &dummy, &dummy, &dummy,
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 1942
1961 1943
1962 class SamplerThread : public Thread { 1944 class SamplerThread : public Thread {
1963 public: 1945 public:
1964 static const int kSamplerThreadStackSize = 64 * KB; 1946 static const int kSamplerThreadStackSize = 64 * KB;
1965 1947
1966 explicit SamplerThread(int interval) 1948 explicit SamplerThread(int interval)
1967 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), 1949 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)),
1968 interval_(interval) {} 1950 interval_(interval) {}
1969 1951
1952 static void SetUp() {
1953 if (!mutex_) {
1954 mutex_ = OS::CreateMutex();
1955 }
1956 }
1957
1970 static void AddActiveSampler(Sampler* sampler) { 1958 static void AddActiveSampler(Sampler* sampler) {
1971 ScopedLock lock(mutex_.Pointer()); 1959 ScopedLock lock(mutex_);
1972 SamplerRegistry::AddActiveSampler(sampler); 1960 SamplerRegistry::AddActiveSampler(sampler);
1973 if (instance_ == NULL) { 1961 if (instance_ == NULL) {
1974 instance_ = new SamplerThread(sampler->interval()); 1962 instance_ = new SamplerThread(sampler->interval());
1975 instance_->Start(); 1963 instance_->Start();
1976 } else { 1964 } else {
1977 ASSERT(instance_->interval_ == sampler->interval()); 1965 ASSERT(instance_->interval_ == sampler->interval());
1978 } 1966 }
1979 } 1967 }
1980 1968
1981 static void RemoveActiveSampler(Sampler* sampler) { 1969 static void RemoveActiveSampler(Sampler* sampler) {
1982 ScopedLock lock(mutex_.Pointer()); 1970 ScopedLock lock(mutex_);
1983 SamplerRegistry::RemoveActiveSampler(sampler); 1971 SamplerRegistry::RemoveActiveSampler(sampler);
1984 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { 1972 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
1985 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); 1973 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
1986 delete instance_; 1974 delete instance_;
1987 instance_ = NULL; 1975 instance_ = NULL;
1988 } 1976 }
1989 } 1977 }
1990 1978
1991 // Implement Thread::Run(). 1979 // Implement Thread::Run().
1992 virtual void Run() { 1980 virtual void Run() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 sampler->SampleStack(sample); 2046 sampler->SampleStack(sample);
2059 sampler->Tick(sample); 2047 sampler->Tick(sample);
2060 } 2048 }
2061 ResumeThread(profiled_thread); 2049 ResumeThread(profiled_thread);
2062 } 2050 }
2063 2051
2064 const int interval_; 2052 const int interval_;
2065 RuntimeProfilerRateLimiter rate_limiter_; 2053 RuntimeProfilerRateLimiter rate_limiter_;
2066 2054
2067 // Protects the process wide state below. 2055 // Protects the process wide state below.
2068 static LazyMutex mutex_; 2056 static Mutex* mutex_;
2069 static SamplerThread* instance_; 2057 static SamplerThread* instance_;
2070 2058
2071 private: 2059 private:
2072 DISALLOW_COPY_AND_ASSIGN(SamplerThread); 2060 DISALLOW_COPY_AND_ASSIGN(SamplerThread);
2073 }; 2061 };
2074 2062
2075 2063
2076 LazyMutex SamplerThread::mutex_ = LAZY_MUTEX_INITIALIZER; 2064 Mutex* SamplerThread::mutex_ = NULL;
2077 SamplerThread* SamplerThread::instance_ = NULL; 2065 SamplerThread* SamplerThread::instance_ = NULL;
2078 2066
2079 2067
2068 void OS::SetUp() {
2069 // Seed the random number generator.
2070 // Convert the current time to a 64-bit integer first, before converting it
2071 // to an unsigned. Going directly can cause an overflow and the seed to be
2072 // set to all ones. The seed will be identical for different instances that
2073 // call this setup code within the same millisecond.
2074 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
2075 srand(static_cast<unsigned int>(seed));
2076 limit_mutex = CreateMutex();
2077 SamplerThread::SetUp();
2078 }
2079
2080
2080 Sampler::Sampler(Isolate* isolate, int interval) 2081 Sampler::Sampler(Isolate* isolate, int interval)
2081 : isolate_(isolate), 2082 : isolate_(isolate),
2082 interval_(interval), 2083 interval_(interval),
2083 profiling_(false), 2084 profiling_(false),
2084 active_(false), 2085 active_(false),
2085 samples_taken_(0) { 2086 samples_taken_(0) {
2086 data_ = new PlatformData; 2087 data_ = new PlatformData;
2087 } 2088 }
2088 2089
2089 2090
(...skipping 11 matching lines...) Expand all
2101 2102
2102 2103
2103 void Sampler::Stop() { 2104 void Sampler::Stop() {
2104 ASSERT(IsActive()); 2105 ASSERT(IsActive());
2105 SamplerThread::RemoveActiveSampler(this); 2106 SamplerThread::RemoveActiveSampler(this);
2106 SetActive(false); 2107 SetActive(false);
2107 } 2108 }
2108 2109
2109 2110
2110 } } // namespace v8::internal 2111 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-solaris.cc ('k') | src/runtime-profiler.h » ('j') | src/v8.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698