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
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.h"
|
|
|
|
|
|
|
|
#include "src/assembler.h"
|
2014-06-05 12:14:47 +00:00
|
|
|
#include "src/base/once.h"
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/base/platform/platform.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/bootstrapper.h"
|
2014-08-05 13:20:26 +00:00
|
|
|
#include "src/compiler/pipeline.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/debug.h"
|
|
|
|
#include "src/deoptimizer.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/elements.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/frames.h"
|
2014-08-11 14:22:24 +00:00
|
|
|
#include "src/heap/store-buffer.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/heap-profiler.h"
|
|
|
|
#include "src/hydrogen.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/isolate.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/lithium-allocator.h"
|
|
|
|
#include "src/objects.h"
|
|
|
|
#include "src/runtime-profiler.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/sampler.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/serialize.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-07-30 13:54:45 +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
|
|
|
|
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();
|
2014-08-05 13:20:26 +00:00
|
|
|
compiler::Pipeline::TearDown();
|
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();
|
2013-04-15 13:57:41 +00:00
|
|
|
Sampler::TearDown();
|
2014-08-26 11:00:57 +00:00
|
|
|
FlagList::ResetAllFlags(); // Frees memory held by string arguments.
|
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
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
base::OS::Initialize(FLAG_random_seed, FLAG_hard_abort, FLAG_gc_fake_mmap);
|
2014-06-25 08:20:42 +00:00
|
|
|
|
2013-04-15 13:57:41 +00:00
|
|
|
Sampler::SetUp();
|
2014-05-16 15:18:24 +00:00
|
|
|
CpuFeatures::Probe(false);
|
2014-05-27 07:57:22 +00:00
|
|
|
init_memcopy_functions();
|
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();
|
2014-08-05 13:20:26 +00:00
|
|
|
compiler::Pipeline::SetUp();
|
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() {
|
2014-06-05 12:14:47 +00:00
|
|
|
base::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) {
|
2014-07-31 08:06:24 +00:00
|
|
|
CHECK(!platform_);
|
|
|
|
CHECK(platform);
|
2013-11-21 14:07:06 +00:00
|
|
|
platform_ = platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8::ShutdownPlatform() {
|
2014-07-31 08:06:24 +00:00
|
|
|
CHECK(platform_);
|
2013-11-21 14:07:06 +00:00
|
|
|
platform_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Platform* V8::GetCurrentPlatform() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(platform_);
|
2013-11-21 14:07:06 +00:00
|
|
|
return platform_;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|