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

Side by Side Diff: src/v8.cc

Issue 9455088: Remove static initializers in v8. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Lint. Created 8 years, 10 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 18 matching lines...) Expand all
29 29
30 #include "isolate.h" 30 #include "isolate.h"
31 #include "elements.h" 31 #include "elements.h"
32 #include "bootstrapper.h" 32 #include "bootstrapper.h"
33 #include "debug.h" 33 #include "debug.h"
34 #include "deoptimizer.h" 34 #include "deoptimizer.h"
35 #include "heap-profiler.h" 35 #include "heap-profiler.h"
36 #include "hydrogen.h" 36 #include "hydrogen.h"
37 #include "lithium-allocator.h" 37 #include "lithium-allocator.h"
38 #include "log.h" 38 #include "log.h"
39 #include "once.h"
40 #include "platform.h"
39 #include "runtime-profiler.h" 41 #include "runtime-profiler.h"
40 #include "serialize.h" 42 #include "serialize.h"
41 #include "store-buffer.h" 43 #include "store-buffer.h"
42 44
43 namespace v8 { 45 namespace v8 {
44 namespace internal { 46 namespace internal {
45 47
46 static Mutex* init_once_mutex = OS::CreateMutex(); 48 V8_DECLARE_ONCE(init_once);
47 static bool init_once_called = false;
48 49
49 bool V8::is_running_ = false; 50 bool V8::is_running_ = false;
50 bool V8::has_been_set_up_ = false; 51 bool V8::has_been_set_up_ = false;
51 bool V8::has_been_disposed_ = false; 52 bool V8::has_been_disposed_ = false;
52 bool V8::has_fatal_error_ = false; 53 bool V8::has_fatal_error_ = false;
53 bool V8::use_crankshaft_ = true; 54 bool V8::use_crankshaft_ = true;
54 List<CallCompletedCallback>* V8::call_completed_callbacks_ = NULL; 55 List<CallCompletedCallback>* V8::call_completed_callbacks_ = NULL;
55 56
56 static Mutex* entropy_mutex = OS::CreateMutex(); 57 static LazyMutex entropy_mutex = LAZY_MUTEX_INITIALIZER;
58
57 static EntropySource entropy_source; 59 static EntropySource entropy_source;
58 60
59 61
60 bool V8::Initialize(Deserializer* des) { 62 bool V8::Initialize(Deserializer* des) {
61 FlagList::EnforceFlagImplications(); 63 FlagList::EnforceFlagImplications();
62 64
63 InitializeOncePerProcess(); 65 InitializeOncePerProcess();
64 66
65 // The current thread may not yet had entered an isolate to run. 67 // The current thread may not yet had entered an isolate to run.
66 // Note the Isolate::Current() may be non-null because for various 68 // Note the Isolate::Current() may be non-null because for various
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 call_completed_callbacks_ = NULL; 112 call_completed_callbacks_ = NULL;
111 } 113 }
112 114
113 115
114 static void seed_random(uint32_t* state) { 116 static void seed_random(uint32_t* state) {
115 for (int i = 0; i < 2; ++i) { 117 for (int i = 0; i < 2; ++i) {
116 if (FLAG_random_seed != 0) { 118 if (FLAG_random_seed != 0) {
117 state[i] = FLAG_random_seed; 119 state[i] = FLAG_random_seed;
118 } else if (entropy_source != NULL) { 120 } else if (entropy_source != NULL) {
119 uint32_t val; 121 uint32_t val;
120 ScopedLock lock(entropy_mutex); 122 ScopedLock lock(entropy_mutex.Pointer());
121 entropy_source(reinterpret_cast<unsigned char*>(&val), sizeof(uint32_t)); 123 entropy_source(reinterpret_cast<unsigned char*>(&val), sizeof(uint32_t));
122 state[i] = val; 124 state[i] = val;
123 } else { 125 } else {
124 state[i] = random(); 126 state[i] = random();
125 } 127 }
126 } 128 }
127 } 129 }
128 130
129 131
130 // Random number generator using George Marsaglia's MWC algorithm. 132 // Random number generator using George Marsaglia's MWC algorithm.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // by computing: 228 // by computing:
227 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). 229 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
228 const double binary_million = 1048576.0; 230 const double binary_million = 1048576.0;
229 r->double_value = binary_million; 231 r->double_value = binary_million;
230 r->uint64_t_value |= random_bits; 232 r->uint64_t_value |= random_bits;
231 r->double_value -= binary_million; 233 r->double_value -= binary_million;
232 234
233 return heap_number; 235 return heap_number;
234 } 236 }
235 237
236 238 void V8::InitializeOncePerProcessImpl() {
237 void V8::InitializeOncePerProcess() {
238 ScopedLock lock(init_once_mutex);
239 if (init_once_called) return;
240 init_once_called = true;
241
242 // Set up the platform OS support. 239 // Set up the platform OS support.
243 OS::SetUp(); 240 OS::SetUp();
244 241
245 use_crankshaft_ = FLAG_crankshaft; 242 use_crankshaft_ = FLAG_crankshaft;
246 243
247 if (Serializer::enabled()) { 244 if (Serializer::enabled()) {
248 use_crankshaft_ = false; 245 use_crankshaft_ = false;
249 } 246 }
250 247
251 CPU::SetUp(); 248 CPU::SetUp();
252 if (!CPU::SupportsCrankshaft()) { 249 if (!CPU::SupportsCrankshaft()) {
253 use_crankshaft_ = false; 250 use_crankshaft_ = false;
254 } 251 }
255 252
256 RuntimeProfiler::GlobalSetup(); 253 RuntimeProfiler::GlobalSetup();
257 254
258 ElementsAccessor::InitializeOncePerProcess(); 255 ElementsAccessor::InitializeOncePerProcess();
259 256
260 if (FLAG_stress_compaction) { 257 if (FLAG_stress_compaction) {
261 FLAG_force_marking_deque_overflows = true; 258 FLAG_force_marking_deque_overflows = true;
262 FLAG_gc_global = true; 259 FLAG_gc_global = true;
263 FLAG_max_new_space_size = (1 << (kPageSizeBits - 10)) * 2; 260 FLAG_max_new_space_size = (1 << (kPageSizeBits - 10)) * 2;
264 } 261 }
265 } 262 }
266 263
264 void V8::InitializeOncePerProcess() {
265 CallOnce(&init_once, &InitializeOncePerProcessImpl);
266 }
267
267 } } // namespace v8::internal 268 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698