2012-02-08 09:55:25 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
2012-04-05 14:10:39 +00:00
|
|
|
#include "assembler.h"
|
2011-03-18 20:35:07 +00:00
|
|
|
#include "isolate.h"
|
2011-08-03 11:12:46 +00:00
|
|
|
#include "elements.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "bootstrapper.h"
|
|
|
|
#include "debug.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "deoptimizer.h"
|
2012-04-05 14:10:39 +00:00
|
|
|
#include "frames.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "heap-profiler.h"
|
|
|
|
#include "hydrogen.h"
|
2013-12-20 07:52:58 +00:00
|
|
|
#ifdef V8_USE_DEFAULT_PLATFORM
|
|
|
|
#include "libplatform/default-platform.h"
|
|
|
|
#endif
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "lithium-allocator.h"
|
2012-11-08 13:44:59 +00:00
|
|
|
#include "objects.h"
|
2012-03-12 13:56:56 +00:00
|
|
|
#include "once.h"
|
|
|
|
#include "platform.h"
|
2013-04-15 13:57:41 +00:00
|
|
|
#include "sampler.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "runtime-profiler.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "serialize.h"
|
2011-09-19 18:36:47 +00:00
|
|
|
#include "store-buffer.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-03-12 13:56:56 +00:00
|
|
|
V8_DECLARE_ONCE(init_once);
|
2011-03-31 16:17:37 +00:00
|
|
|
|
2013-06-11 10:41:14 +00:00
|
|
|
v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL;
|
2013-11-21 14:07:06 +00:00
|
|
|
v8::Platform* V8::platform_ = NULL;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-11-16 08:01:45 +00:00
|
|
|
|
2010-03-17 14:53:16 +00:00
|
|
|
bool V8::Initialize(Deserializer* des) {
|
2011-03-31 16:17:37 +00:00
|
|
|
InitializeOncePerProcess();
|
2014-04-16 12:01:38 +00:00
|
|
|
Isolate* isolate = Isolate::UncheckedCurrent();
|
|
|
|
if (isolate == NULL) return true;
|
2013-09-03 09:35:26 +00:00
|
|
|
if (isolate->IsDead()) return false;
|
2011-03-18 20:35:07 +00:00
|
|
|
if (isolate->IsInitialized()) return true;
|
2009-05-25 19:39:52 +00:00
|
|
|
|
2013-12-20 07:52:58 +00:00
|
|
|
#ifdef V8_USE_DEFAULT_PLATFORM
|
|
|
|
DefaultPlatform* platform = static_cast<DefaultPlatform*>(platform_);
|
|
|
|
platform->SetThreadPoolSize(isolate->max_available_threads());
|
2014-02-20 19:32:27 +00:00
|
|
|
// We currently only start the threads early, if we know that we'll use them.
|
|
|
|
if (FLAG_job_based_sweeping) platform->EnsureInitialized();
|
2013-12-20 07:52:58 +00:00
|
|
|
#endif
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
return isolate->Init(des);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 09:01:40 +00:00
|
|
|
void V8::TearDown() {
|
2014-01-17 10:52:00 +00:00
|
|
|
Bootstrapper::TearDownExtensions();
|
2012-03-27 10:51:13 +00:00
|
|
|
ElementsAccessor::TearDown();
|
2012-03-28 13:12:00 +00:00
|
|
|
LOperand::TearDownCaches();
|
2012-11-26 13:12:35 +00:00
|
|
|
ExternalReference::TearDownMathExpData();
|
2012-03-29 09:45:46 +00:00
|
|
|
RegisteredExtension::UnregisterAll();
|
2013-02-12 11:57:51 +00:00
|
|
|
Isolate::GlobalTearDown();
|
2012-03-27 10:51:13 +00:00
|
|
|
|
2013-04-15 13:57:41 +00:00
|
|
|
Sampler::TearDown();
|
2013-11-21 14:07:06 +00:00
|
|
|
|
|
|
|
#ifdef V8_USE_DEFAULT_PLATFORM
|
|
|
|
DefaultPlatform* platform = static_cast<DefaultPlatform*>(platform_);
|
|
|
|
platform_ = NULL;
|
|
|
|
delete platform;
|
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2009-05-25 19:39:52 +00:00
|
|
|
|
2012-02-27 15:15:53 +00:00
|
|
|
void V8::SetReturnAddressLocationResolver(
|
|
|
|
ReturnAddressLocationResolver resolver) {
|
|
|
|
StackFrame::SetReturnAddressLocationResolver(resolver);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-12 13:56:56 +00:00
|
|
|
void V8::InitializeOncePerProcessImpl() {
|
2013-01-21 12:04:40 +00:00
|
|
|
FlagList::EnforceFlagImplications();
|
2013-12-18 17:31:12 +00:00
|
|
|
|
2014-03-04 12:42:43 +00:00
|
|
|
if (FLAG_predictable && FLAG_random_seed == 0) {
|
|
|
|
// Avoid random seeds in predictable mode.
|
|
|
|
FLAG_random_seed = 12347;
|
2013-12-18 17:31:12 +00:00
|
|
|
}
|
|
|
|
|
2011-10-11 15:52:15 +00:00
|
|
|
if (FLAG_stress_compaction) {
|
|
|
|
FLAG_force_marking_deque_overflows = true;
|
|
|
|
FLAG_gc_global = true;
|
2014-05-09 08:38:27 +00:00
|
|
|
FLAG_max_semi_space_size = 1;
|
2011-10-11 15:52:15 +00:00
|
|
|
}
|
2013-08-05 09:02:47 +00:00
|
|
|
|
2013-11-21 14:07:06 +00:00
|
|
|
#ifdef V8_USE_DEFAULT_PLATFORM
|
|
|
|
platform_ = new DefaultPlatform;
|
|
|
|
#endif
|
2013-04-15 13:57:41 +00:00
|
|
|
Sampler::SetUp();
|
2014-05-16 15:18:24 +00:00
|
|
|
CpuFeatures::Probe(false);
|
2014-05-26 19:56:27 +00:00
|
|
|
OS::PostSetUp();
|
2014-05-06 11:14:37 +00:00
|
|
|
// The custom exp implementation needs 16KB of lookup data; initialize it
|
|
|
|
// on demand.
|
|
|
|
init_fast_sqrt_function();
|
|
|
|
#ifdef _WIN64
|
|
|
|
init_modulo_function();
|
|
|
|
#endif
|
2013-01-21 12:04:40 +00:00
|
|
|
ElementsAccessor::InitializeOncePerProcess();
|
2012-03-12 13:56:56 +00:00
|
|
|
LOperand::SetUpCaches();
|
2012-04-05 14:10:39 +00:00
|
|
|
SetUpJSCallerSavedCodeData();
|
|
|
|
ExternalReference::SetUp();
|
2013-05-21 12:03:49 +00:00
|
|
|
Bootstrapper::InitializeOncePerProcess();
|
2012-03-12 13:56:56 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2012-03-12 13:56:56 +00:00
|
|
|
void V8::InitializeOncePerProcess() {
|
|
|
|
CallOnce(&init_once, &InitializeOncePerProcessImpl);
|
2011-03-31 16:17:37 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 14:07:06 +00:00
|
|
|
|
|
|
|
void V8::InitializePlatform(v8::Platform* platform) {
|
|
|
|
ASSERT(!platform_);
|
|
|
|
ASSERT(platform);
|
|
|
|
platform_ = platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8::ShutdownPlatform() {
|
|
|
|
ASSERT(platform_);
|
|
|
|
platform_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Platform* V8::GetCurrentPlatform() {
|
|
|
|
ASSERT(platform_);
|
|
|
|
return platform_;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|