diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2011-07-05 14:40:13 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-07-05 14:51:29 -0700 |
commit | 149562555c9bf56457dee9a1ad70c53ed670a776 (patch) | |
tree | f6217cf3c54ddbee03f37247a3c7c75203f868fd /deps/v8/src/v8.cc | |
parent | f08720606757577d95bd09b48697c7decbf17f00 (diff) | |
download | node-149562555c9bf56457dee9a1ad70c53ed670a776.tar.gz |
Downgrade V8 to 3.1.8.25
There are serious performance regressions both in V8 and our own legacy
networking stack. Until we correct our own problems we are going back to the
old V8.
Diffstat (limited to 'deps/v8/src/v8.cc')
-rw-r--r-- | deps/v8/src/v8.cc | 225 |
1 files changed, 146 insertions, 79 deletions
diff --git a/deps/v8/src/v8.cc b/deps/v8/src/v8.cc index 11af057b1..945043da9 100644 --- a/deps/v8/src/v8.cc +++ b/deps/v8/src/v8.cc @@ -1,4 +1,4 @@ -// Copyright 2011 the V8 project authors. All rights reserved. +// Copyright 2006-2009 the V8 project authors. All rights reserved. // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: @@ -27,7 +27,6 @@ #include "v8.h" -#include "isolate.h" #include "bootstrapper.h" #include "debug.h" #include "deoptimizer.h" @@ -37,13 +36,12 @@ #include "log.h" #include "runtime-profiler.h" #include "serialize.h" +#include "simulator.h" +#include "stub-cache.h" namespace v8 { namespace internal { -static Mutex* init_once_mutex = OS::CreateMutex(); -static bool init_once_called = false; - bool V8::is_running_ = false; bool V8::has_been_setup_ = false; bool V8::has_been_disposed_ = false; @@ -52,33 +50,102 @@ bool V8::use_crankshaft_ = true; bool V8::Initialize(Deserializer* des) { - InitializeOncePerProcess(); - - // The current thread may not yet had entered an isolate to run. - // Note the Isolate::Current() may be non-null because for various - // initialization purposes an initializing thread may be assigned an isolate - // but not actually enter it. - if (i::Isolate::CurrentPerIsolateThreadData() == NULL) { - i::Isolate::EnterDefaultIsolate(); - } - - ASSERT(i::Isolate::CurrentPerIsolateThreadData() != NULL); - ASSERT(i::Isolate::CurrentPerIsolateThreadData()->thread_id().Equals( - i::ThreadId::Current())); - ASSERT(i::Isolate::CurrentPerIsolateThreadData()->isolate() == - i::Isolate::Current()); - - if (IsDead()) return false; + bool create_heap_objects = des == NULL; + if (has_been_disposed_ || has_fatal_error_) return false; + if (IsRunning()) return true; - Isolate* isolate = Isolate::Current(); - if (isolate->IsInitialized()) return true; +#if defined(V8_TARGET_ARCH_ARM) && !defined(USE_ARM_EABI) + use_crankshaft_ = false; +#else + use_crankshaft_ = FLAG_crankshaft; +#endif + // Peephole optimization might interfere with deoptimization. + FLAG_peephole_optimization = !use_crankshaft_; is_running_ = true; has_been_setup_ = true; has_fatal_error_ = false; has_been_disposed_ = false; +#ifdef DEBUG + // The initialization process does not handle memory exhaustion. + DisallowAllocationFailure disallow_allocation_failure; +#endif + + // Enable logging before setting up the heap + Logger::Setup(); - return isolate->Init(des); + CpuProfiler::Setup(); + HeapProfiler::Setup(); + + // Setup the platform OS support. + OS::Setup(); + + // Initialize other runtime facilities +#if defined(USE_SIMULATOR) +#if defined(V8_TARGET_ARCH_ARM) + Simulator::Initialize(); +#elif defined(V8_TARGET_ARCH_MIPS) + ::assembler::mips::Simulator::Initialize(); +#endif +#endif + + { // NOLINT + // Ensure that the thread has a valid stack guard. The v8::Locker object + // will ensure this too, but we don't have to use lockers if we are only + // using one thread. + ExecutionAccess lock; + StackGuard::InitThread(lock); + } + + // Setup the object heap + ASSERT(!Heap::HasBeenSetup()); + if (!Heap::Setup(create_heap_objects)) { + SetFatalError(); + return false; + } + + Bootstrapper::Initialize(create_heap_objects); + Builtins::Setup(create_heap_objects); + Top::Initialize(); + + if (FLAG_preemption) { + v8::Locker locker; + v8::Locker::StartPreemption(100); + } + +#ifdef ENABLE_DEBUGGER_SUPPORT + Debug::Setup(create_heap_objects); +#endif + StubCache::Initialize(create_heap_objects); + + // If we are deserializing, read the state into the now-empty heap. + if (des != NULL) { + des->Deserialize(); + StubCache::Clear(); + } + + // Deserializing may put strange things in the root array's copy of the + // stack guard. + Heap::SetStackLimits(); + + // Setup the CPU support. Must be done after heap setup and after + // any deserialization because we have to have the initial heap + // objects in place for creating the code object used for probing. + CPU::Setup(); + + Deoptimizer::Setup(); + LAllocator::Setup(); + RuntimeProfiler::Setup(); + + // If we are deserializing, log non-function code objects and compiled + // functions found in the snapshot. + if (des != NULL && FLAG_log_code) { + HandleScope scope; + LOG(LogCodeObjects()); + LOG(LogCompiledFunctions()); + } + + return true; } @@ -89,54 +156,80 @@ void V8::SetFatalError() { void V8::TearDown() { - Isolate* isolate = Isolate::Current(); - ASSERT(isolate->IsDefaultIsolate()); - if (!has_been_setup_ || has_been_disposed_) return; - isolate->TearDown(); + + if (FLAG_time_hydrogen) HStatistics::Instance()->Print(); + + // We must stop the logger before we tear down other components. + Logger::EnsureTickerStopped(); + + Deoptimizer::TearDown(); + + if (FLAG_preemption) { + v8::Locker locker; + v8::Locker::StopPreemption(); + } + + Builtins::TearDown(); + Bootstrapper::TearDown(); + + Top::TearDown(); + + HeapProfiler::TearDown(); + CpuProfiler::TearDown(); + RuntimeProfiler::TearDown(); + + Logger::TearDown(); + Heap::TearDown(); is_running_ = false; has_been_disposed_ = true; } -static void seed_random(uint32_t* state) { - for (int i = 0; i < 2; ++i) { - state[i] = FLAG_random_seed; - while (state[i] == 0) { - state[i] = random(); - } +static uint32_t random_seed() { + if (FLAG_random_seed == 0) { + return random(); } + return FLAG_random_seed; } -// Random number generator using George Marsaglia's MWC algorithm. -static uint32_t random_base(uint32_t* state) { - // Initialize seed using the system random(). - // No non-zero seed will ever become zero again. - if (state[0] == 0) seed_random(state); +typedef struct { + uint32_t hi; + uint32_t lo; +} random_state; - // Mix the bits. Never replaces state[i] with 0 if it is nonzero. - state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16); - state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16); - return (state[0] << 14) + (state[1] & 0x3FFFF); +// Random number generator using George Marsaglia's MWC algorithm. +static uint32_t random_base(random_state *state) { + // Initialize seed using the system random(). If one of the seeds + // should ever become zero again, or if random() returns zero, we + // avoid getting stuck with zero bits in hi or lo by re-initializing + // them on demand. + if (state->hi == 0) state->hi = random_seed(); + if (state->lo == 0) state->lo = random_seed(); + + // Mix the bits. + state->hi = 36969 * (state->hi & 0xFFFF) + (state->hi >> 16); + state->lo = 18273 * (state->lo & 0xFFFF) + (state->lo >> 16); + return (state->hi << 16) + (state->lo & 0xFFFF); } // Used by JavaScript APIs -uint32_t V8::Random(Isolate* isolate) { - ASSERT(isolate == Isolate::Current()); - return random_base(isolate->random_seed()); +uint32_t V8::Random() { + static random_state state = {0, 0}; + return random_base(&state); } // Used internally by the JIT and memory allocator for security // purposes. So, we keep a different state to prevent informations // leaks that could be used in an exploit. -uint32_t V8::RandomPrivate(Isolate* isolate) { - ASSERT(isolate == Isolate::Current()); - return random_base(isolate->private_random_seed()); +uint32_t V8::RandomPrivate() { + static random_state state = {0, 0}; + return random_base(&state); } @@ -146,7 +239,7 @@ bool V8::IdleNotification() { if (!FLAG_use_idle_notification) return true; // Tell the heap that it may want to adjust. - return HEAP->IdleNotification(); + return Heap::IdleNotification(); } @@ -157,8 +250,8 @@ typedef union { } double_int_union; -Object* V8::FillHeapNumberWithRandom(Object* heap_number, Isolate* isolate) { - uint64_t random_bits = Random(isolate); +Object* V8::FillHeapNumberWithRandom(Object* heap_number) { + uint64_t random_bits = Random(); // Make a double* from address (heap_number + sizeof(double)). double_int_union* r = reinterpret_cast<double_int_union*>( reinterpret_cast<char*>(heap_number) + @@ -174,30 +267,4 @@ Object* V8::FillHeapNumberWithRandom(Object* heap_number, Isolate* isolate) { return heap_number; } - -void V8::InitializeOncePerProcess() { - ScopedLock lock(init_once_mutex); - if (init_once_called) return; - init_once_called = true; - - // Setup the platform OS support. - OS::Setup(); - - use_crankshaft_ = FLAG_crankshaft; - - if (Serializer::enabled()) { - use_crankshaft_ = false; - } - - CPU::Setup(); - if (!CPU::SupportsCrankshaft()) { - use_crankshaft_ = false; - } - - RuntimeProfiler::GlobalSetup(); - - // Peephole optimization might interfere with deoptimization. - FLAG_peephole_optimization = !use_crankshaft_; -} - } } // namespace v8::internal |