v8.cc 3.28 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6 7
#include "src/v8.h"

#include "src/assembler.h"
8
#include "src/base/once.h"
9
#include "src/base/platform/platform.h"
10
#include "src/bootstrapper.h"
11
#include "src/crankshaft/lithium-allocator.h"
12
#include "src/debug/debug.h"
13
#include "src/deoptimizer.h"
14
#include "src/elements.h"
15
#include "src/frames.h"
16
#include "src/isolate.h"
17
#include "src/objects.h"
18 19
#include "src/profiler/heap-profiler.h"
#include "src/profiler/sampler.h"
20
#include "src/runtime-profiler.h"
21 22 23
#include "src/snapshot/natives.h"
#include "src/snapshot/serialize.h"
#include "src/snapshot/snapshot.h"
24

25

26 27
namespace v8 {
namespace internal {
28

29
V8_DECLARE_ONCE(init_once);
30

31 32 33 34 35
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
V8_DECLARE_ONCE(init_natives_once);
V8_DECLARE_ONCE(init_snapshot_once);
#endif

36
v8::Platform* V8::platform_ = NULL;
37

38

39
bool V8::Initialize() {
40
  InitializeOncePerProcess();
41
  return true;
42 43 44
}


45
void V8::TearDown() {
46
  Bootstrapper::TearDownExtensions();
47
  ElementsAccessor::TearDown();
48
  LOperand::TearDownCaches();
49
  ExternalReference::TearDownMathExpData();
50
  RegisteredExtension::UnregisterAll();
51
  Isolate::GlobalTearDown();
52
  Sampler::TearDown();
53
  FlagList::ResetAllFlags();  // Frees memory held by string arguments.
54 55
}

56

57
void V8::InitializeOncePerProcessImpl() {
58
  FlagList::EnforceFlagImplications();
59

60 61 62
  if (FLAG_predictable && FLAG_random_seed == 0) {
    // Avoid random seeds in predictable mode.
    FLAG_random_seed = 12347;
63 64
  }

65 66 67
  if (FLAG_stress_compaction) {
    FLAG_force_marking_deque_overflows = true;
    FLAG_gc_global = true;
68
    FLAG_max_semi_space_size = 1;
69
  }
70

71 72 73 74 75
  if (FLAG_turbo && strcmp(FLAG_turbo_filter, "~~") == 0) {
    const char* filter_flag = "--turbo-filter=*";
    FlagList::SetFlagsFromString(filter_flag, StrLength(filter_flag));
  }

76
  base::OS::Initialize(FLAG_random_seed, FLAG_hard_abort, FLAG_gc_fake_mmap);
77

78 79
  Isolate::InitializeOncePerProcess();

80
  Sampler::SetUp();
81
  CpuFeatures::Probe(false);
82
  init_memcopy_functions();
83 84 85 86 87 88
  // The custom exp implementation needs 16KB of lookup data; initialize it
  // on demand.
  init_fast_sqrt_function();
#ifdef _WIN64
  init_modulo_function();
#endif
89
  ElementsAccessor::InitializeOncePerProcess();
90
  LOperand::SetUpCaches();
91 92
  SetUpJSCallerSavedCodeData();
  ExternalReference::SetUp();
93
  Bootstrapper::InitializeOncePerProcess();
94 95
}

96

97
void V8::InitializeOncePerProcess() {
98
  base::CallOnce(&init_once, &InitializeOncePerProcessImpl);
99 100
}

101 102

void V8::InitializePlatform(v8::Platform* platform) {
103 104
  CHECK(!platform_);
  CHECK(platform);
105 106 107 108 109
  platform_ = platform;
}


void V8::ShutdownPlatform() {
110
  CHECK(platform_);
111 112 113 114 115
  platform_ = NULL;
}


v8::Platform* V8::GetCurrentPlatform() {
116
  DCHECK(platform_);
117 118 119
  return platform_;
}

120

121 122 123
void V8::SetPlatformForTesting(v8::Platform* platform) { platform_ = platform; }


124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
void V8::SetNativesBlob(StartupData* natives_blob) {
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
  base::CallOnce(&init_natives_once, &SetNativesFromFile, natives_blob);
#else
  CHECK(false);
#endif
}


void V8::SetSnapshotBlob(StartupData* snapshot_blob) {
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
  base::CallOnce(&init_snapshot_once, &SetSnapshotFromFile, snapshot_blob);
#else
  CHECK(false);
#endif
}
140 141
}  // namespace internal
}  // namespace v8