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"
|
|
|
|
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/api.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/assembler.h"
|
2017-06-13 16:48:23 +00:00
|
|
|
#include "src/base/atomicops.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"
|
2015-07-31 11:07:50 +00:00
|
|
|
#include "src/debug/debug.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#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-06-20 08:40:11 +00:00
|
|
|
#include "src/isolate.h"
|
2016-07-08 06:44:46 +00:00
|
|
|
#include "src/libsampler/sampler.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/objects-inl.h"
|
2015-09-28 19:34:08 +00:00
|
|
|
#include "src/profiler/heap-profiler.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/runtime-profiler.h"
|
2017-12-13 12:48:01 +00:00
|
|
|
#include "src/simulator.h"
|
2015-03-27 15:28:55 +00:00
|
|
|
#include "src/snapshot/natives.h"
|
|
|
|
#include "src/snapshot/snapshot.h"
|
2016-11-03 18:03:25 +00:00
|
|
|
#include "src/tracing/tracing-category-observer.h"
|
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
|
|
|
|
2014-11-24 12:44:34 +00:00
|
|
|
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
|
|
|
|
V8_DECLARE_ONCE(init_natives_once);
|
|
|
|
V8_DECLARE_ONCE(init_snapshot_once);
|
|
|
|
#endif
|
|
|
|
|
2017-10-13 16:33:03 +00:00
|
|
|
v8::Platform* V8::platform_ = nullptr;
|
2010-11-16 08:01:45 +00:00
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
bool V8::Initialize() {
|
2011-03-31 16:17:37 +00:00
|
|
|
InitializeOncePerProcess();
|
2014-09-19 08:01:35 +00:00
|
|
|
return true;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-02 09:01:40 +00:00
|
|
|
void V8::TearDown() {
|
2017-12-13 12:48:01 +00:00
|
|
|
#if defined(USE_SIMULATOR)
|
|
|
|
Simulator::GlobalTearDown();
|
|
|
|
#endif
|
2014-01-17 10:52:00 +00:00
|
|
|
Bootstrapper::TearDownExtensions();
|
2012-03-27 10:51:13 +00:00
|
|
|
ElementsAccessor::TearDown();
|
2012-03-29 09:45:46 +00:00
|
|
|
RegisteredExtension::UnregisterAll();
|
2013-02-12 11:57:51 +00:00
|
|
|
Isolate::GlobalTearDown();
|
2016-05-26 02:13:58 +00:00
|
|
|
sampler::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-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
|
|
|
|
2017-12-20 14:50:09 +00:00
|
|
|
base::OS::Initialize(FLAG_hard_abort, FLAG_gc_fake_mmap);
|
|
|
|
|
|
|
|
if (FLAG_random_seed) SetRandomMmapSeed(FLAG_random_seed);
|
2014-06-25 08:20:42 +00:00
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
Isolate::InitializeOncePerProcess();
|
|
|
|
|
2017-12-13 12:48:01 +00:00
|
|
|
#if defined(USE_SIMULATOR)
|
|
|
|
Simulator::InitializeOncePerProcess();
|
|
|
|
#endif
|
2016-05-26 02:13:58 +00:00
|
|
|
sampler::Sampler::SetUp();
|
2014-05-16 15:18:24 +00:00
|
|
|
CpuFeatures::Probe(false);
|
2013-01-21 12:04:40 +00:00
|
|
|
ElementsAccessor::InitializeOncePerProcess();
|
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;
|
2017-03-17 11:41:30 +00:00
|
|
|
v8::base::SetPrintStackTrace(platform_->GetStackTracePrinter());
|
2016-11-03 18:03:25 +00:00
|
|
|
v8::tracing::TracingCategoryObserver::SetUp();
|
2013-11-21 14:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8::ShutdownPlatform() {
|
2014-07-31 08:06:24 +00:00
|
|
|
CHECK(platform_);
|
2016-11-03 18:03:25 +00:00
|
|
|
v8::tracing::TracingCategoryObserver::TearDown();
|
2017-03-17 11:41:30 +00:00
|
|
|
v8::base::SetPrintStackTrace(nullptr);
|
2017-10-13 16:33:03 +00:00
|
|
|
platform_ = nullptr;
|
2013-11-21 14:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Platform* V8::GetCurrentPlatform() {
|
2017-06-13 16:48:23 +00:00
|
|
|
v8::Platform* platform = reinterpret_cast<v8::Platform*>(
|
|
|
|
base::Relaxed_Load(reinterpret_cast<base::AtomicWord*>(&platform_)));
|
|
|
|
DCHECK(platform);
|
|
|
|
return platform;
|
2013-11-21 14:07:06 +00:00
|
|
|
}
|
|
|
|
|
2017-06-13 16:48:23 +00:00
|
|
|
void V8::SetPlatformForTesting(v8::Platform* platform) {
|
|
|
|
base::Relaxed_Store(reinterpret_cast<base::AtomicWord*>(&platform_),
|
|
|
|
reinterpret_cast<base::AtomicWord>(platform));
|
|
|
|
}
|
2015-09-08 15:54:24 +00:00
|
|
|
|
2014-11-24 12:44:34 +00:00
|
|
|
void V8::SetNativesBlob(StartupData* natives_blob) {
|
|
|
|
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
|
|
|
|
base::CallOnce(&init_natives_once, &SetNativesFromFile, natives_blob);
|
|
|
|
#else
|
2017-12-19 11:39:50 +00:00
|
|
|
UNREACHABLE();
|
2014-11-24 12:44:34 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8::SetSnapshotBlob(StartupData* snapshot_blob) {
|
|
|
|
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
|
|
|
|
base::CallOnce(&init_snapshot_once, &SetSnapshotFromFile, snapshot_blob);
|
|
|
|
#else
|
2017-12-19 11:39:50 +00:00
|
|
|
UNREACHABLE();
|
2014-11-24 12:44:34 +00:00
|
|
|
#endif
|
|
|
|
}
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
2017-08-28 00:52:46 +00:00
|
|
|
|
|
|
|
// static
|
|
|
|
double Platform::SystemClockTimeMillis() {
|
|
|
|
return base::OS::TimeCurrentMillis();
|
|
|
|
}
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace v8
|