v8.cc 3.3 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/debug/debug.h"
12
#include "src/deoptimizer.h"
13
#include "src/elements.h"
14 15
#include "src/frames.h"
#include "src/hydrogen.h"
16
#include "src/isolate.h"
17 18
#include "src/lithium-allocator.h"
#include "src/objects.h"
19 20
#include "src/profiler/heap-profiler.h"
#include "src/profiler/sampler.h"
21
#include "src/runtime-profiler.h"
22 23 24
#include "src/snapshot/natives.h"
#include "src/snapshot/serialize.h"
#include "src/snapshot/snapshot.h"
25

26

27 28
namespace v8 {
namespace internal {
29

30
V8_DECLARE_ONCE(init_once);
31

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

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

39

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


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

57

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

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

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

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

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

79 80
  Isolate::InitializeOncePerProcess();

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

97

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

102 103

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


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


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

121

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


125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
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
}
141 142
}  // namespace internal
}  // namespace v8