| OLD | NEW | 
|---|
| 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  Loading... | 
| 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  Loading... | 
| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 232   // by computing: | 234   // by computing: | 
| 233   // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). | 235   // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). | 
| 234   const double binary_million = 1048576.0; | 236   const double binary_million = 1048576.0; | 
| 235   r->double_value = binary_million; | 237   r->double_value = binary_million; | 
| 236   r->uint64_t_value |=  random_bits; | 238   r->uint64_t_value |=  random_bits; | 
| 237   r->double_value -= binary_million; | 239   r->double_value -= binary_million; | 
| 238 | 240 | 
| 239   return heap_number; | 241   return heap_number; | 
| 240 } | 242 } | 
| 241 | 243 | 
| 242 | 244 void V8::InitializeOncePerProcessImpl() { | 
| 243 void V8::InitializeOncePerProcess() { |  | 
| 244   ScopedLock lock(init_once_mutex); |  | 
| 245   if (init_once_called) return; |  | 
| 246   init_once_called = true; |  | 
| 247 |  | 
| 248   // Set up the platform OS support. | 245   // Set up the platform OS support. | 
| 249   OS::SetUp(); | 246   OS::SetUp(); | 
| 250 | 247 | 
| 251   use_crankshaft_ = FLAG_crankshaft; | 248   use_crankshaft_ = FLAG_crankshaft; | 
| 252 | 249 | 
| 253   if (Serializer::enabled()) { | 250   if (Serializer::enabled()) { | 
| 254     use_crankshaft_ = false; | 251     use_crankshaft_ = false; | 
| 255   } | 252   } | 
| 256 | 253 | 
| 257   CPU::SetUp(); | 254   CPU::SetUp(); | 
| 258   if (!CPU::SupportsCrankshaft()) { | 255   if (!CPU::SupportsCrankshaft()) { | 
| 259     use_crankshaft_ = false; | 256     use_crankshaft_ = false; | 
| 260   } | 257   } | 
| 261 | 258 | 
| 262   RuntimeProfiler::GlobalSetup(); | 259   RuntimeProfiler::GlobalSetup(); | 
| 263 | 260 | 
| 264   ElementsAccessor::InitializeOncePerProcess(); | 261   ElementsAccessor::InitializeOncePerProcess(); | 
| 265 | 262 | 
| 266   if (FLAG_stress_compaction) { | 263   if (FLAG_stress_compaction) { | 
| 267     FLAG_force_marking_deque_overflows = true; | 264     FLAG_force_marking_deque_overflows = true; | 
| 268     FLAG_gc_global = true; | 265     FLAG_gc_global = true; | 
| 269     FLAG_max_new_space_size = (1 << (kPageSizeBits - 10)) * 2; | 266     FLAG_max_new_space_size = (1 << (kPageSizeBits - 10)) * 2; | 
| 270   } | 267   } | 
|  | 268 | 
|  | 269   LOperand::SetUpCaches(); | 
|  | 270 } | 
|  | 271 | 
|  | 272 void V8::InitializeOncePerProcess() { | 
|  | 273   CallOnce(&init_once, &InitializeOncePerProcessImpl); | 
| 271 } | 274 } | 
| 272 | 275 | 
| 273 } }  // namespace v8::internal | 276 } }  // namespace v8::internal | 
| OLD | NEW | 
|---|