LCOV - code coverage report
Current view: top level - src - v8.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 58 61 95.1 %
Date: 2019-04-17 Functions: 11 12 91.7 %

          Line data    Source code
       1             : // Copyright 2012 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/v8.h"
       6             : 
       7             : #include <fstream>
       8             : 
       9             : #include "src/api.h"
      10             : #include "src/base/atomicops.h"
      11             : #include "src/base/once.h"
      12             : #include "src/base/platform/platform.h"
      13             : #include "src/bootstrapper.h"
      14             : #include "src/cpu-features.h"
      15             : #include "src/debug/debug.h"
      16             : #include "src/deoptimizer.h"
      17             : #include "src/elements.h"
      18             : #include "src/frames.h"
      19             : #include "src/interface-descriptors.h"
      20             : #include "src/isolate.h"
      21             : #include "src/libsampler/sampler.h"
      22             : #include "src/objects-inl.h"
      23             : #include "src/profiler/heap-profiler.h"
      24             : #include "src/runtime-profiler.h"
      25             : #include "src/simulator.h"
      26             : #include "src/snapshot/natives.h"
      27             : #include "src/snapshot/snapshot.h"
      28             : #include "src/tracing/tracing-category-observer.h"
      29             : #include "src/wasm/wasm-engine.h"
      30             : 
      31             : namespace v8 {
      32             : namespace internal {
      33             : 
      34             : V8_DECLARE_ONCE(init_once);
      35             : 
      36             : #ifdef V8_USE_EXTERNAL_STARTUP_DATA
      37             : V8_DECLARE_ONCE(init_natives_once);
      38             : V8_DECLARE_ONCE(init_snapshot_once);
      39             : #endif
      40             : 
      41             : v8::Platform* V8::platform_ = nullptr;
      42             : 
      43       61312 : bool V8::Initialize() {
      44       61312 :   InitializeOncePerProcess();
      45       61312 :   return true;
      46             : }
      47             : 
      48             : 
      49       59883 : void V8::TearDown() {
      50       59883 :   wasm::WasmEngine::GlobalTearDown();
      51             : #if defined(USE_SIMULATOR)
      52             :   Simulator::GlobalTearDown();
      53             : #endif
      54       59883 :   CallDescriptors::TearDown();
      55       59883 :   ElementsAccessor::TearDown();
      56       59883 :   RegisteredExtension::UnregisterAll();
      57       59883 :   FlagList::ResetAllFlags();  // Frees memory held by string arguments.
      58       59883 : }
      59             : 
      60             : 
      61       60988 : void V8::InitializeOncePerProcessImpl() {
      62       60988 :   FlagList::EnforceFlagImplications();
      63             : 
      64       60988 :   if (FLAG_predictable && FLAG_random_seed == 0) {
      65             :     // Avoid random seeds in predictable mode.
      66           0 :     FLAG_random_seed = 12347;
      67             :   }
      68             : 
      69       60988 :   if (FLAG_stress_compaction) {
      70          86 :     FLAG_force_marking_deque_overflows = true;
      71          86 :     FLAG_gc_global = true;
      72          86 :     FLAG_max_semi_space_size = 1;
      73             :   }
      74             : 
      75       60988 :   if (FLAG_trace_turbo) {
      76             :     // Create an empty file shared by the process (e.g. the wasm engine).
      77          10 :     std::ofstream(Isolate::GetTurboCfgFileName(nullptr).c_str(),
      78           5 :                   std::ios_base::trunc);
      79             :   }
      80             : 
      81             :   // Do not expose wasm in jitless mode.
      82             :   //
      83             :   // Even in interpreter-only mode, wasm currently still creates executable
      84             :   // memory at runtime. Unexpose wasm until this changes.
      85             :   // The correctness fuzzers are a special case: many of their test cases are
      86             :   // built by fetching a random property from the the global object, and thus
      87             :   // the global object layout must not change between configs. That is why we
      88             :   // continue exposing wasm on correctness fuzzers even in jitless mode.
      89             :   // TODO(jgruber): Remove this once / if wasm can run without executable
      90             :   // memory.
      91       60988 :   if (FLAG_jitless && !FLAG_abort_on_stack_or_string_length_overflow) {
      92        8146 :     FLAG_expose_wasm = false;
      93             :   }
      94             : 
      95       60988 :   base::OS::Initialize(FLAG_hard_abort, FLAG_gc_fake_mmap);
      96             : 
      97       60988 :   if (FLAG_random_seed) SetRandomMmapSeed(FLAG_random_seed);
      98             : 
      99       60988 :   Isolate::InitializeOncePerProcess();
     100             : 
     101             : #if defined(USE_SIMULATOR)
     102             :   Simulator::InitializeOncePerProcess();
     103             : #endif
     104             :   CpuFeatures::Probe(false);
     105       60988 :   ElementsAccessor::InitializeOncePerProcess();
     106       60988 :   Bootstrapper::InitializeOncePerProcess();
     107       60988 :   CallDescriptors::InitializeOncePerProcess();
     108       60988 :   wasm::WasmEngine::InitializeOncePerProcess();
     109       60988 : }
     110             : 
     111             : 
     112       61312 : void V8::InitializeOncePerProcess() {
     113      122624 :   base::CallOnce(&init_once, &InitializeOncePerProcessImpl);
     114       61312 : }
     115             : 
     116             : 
     117       60988 : void V8::InitializePlatform(v8::Platform* platform) {
     118       60988 :   CHECK(!platform_);
     119       60988 :   CHECK(platform);
     120       60988 :   platform_ = platform;
     121       60988 :   v8::base::SetPrintStackTrace(platform_->GetStackTracePrinter());
     122       60988 :   v8::tracing::TracingCategoryObserver::SetUp();
     123       60988 : }
     124             : 
     125             : 
     126       59839 : void V8::ShutdownPlatform() {
     127       59839 :   CHECK(platform_);
     128       59839 :   v8::tracing::TracingCategoryObserver::TearDown();
     129       59839 :   v8::base::SetPrintStackTrace(nullptr);
     130       59839 :   platform_ = nullptr;
     131       59839 : }
     132             : 
     133             : 
     134    38550276 : v8::Platform* V8::GetCurrentPlatform() {
     135             :   v8::Platform* platform = reinterpret_cast<v8::Platform*>(
     136    38550276 :       base::Relaxed_Load(reinterpret_cast<base::AtomicWord*>(&platform_)));
     137             :   DCHECK(platform);
     138    38550276 :   return platform;
     139             : }
     140             : 
     141         548 : void V8::SetPlatformForTesting(v8::Platform* platform) {
     142             :   base::Relaxed_Store(reinterpret_cast<base::AtomicWord*>(&platform_),
     143             :                       reinterpret_cast<base::AtomicWord>(platform));
     144         548 : }
     145             : 
     146       60997 : void V8::SetNativesBlob(StartupData* natives_blob) {
     147             : #ifdef V8_USE_EXTERNAL_STARTUP_DATA
     148       60997 :   base::CallOnce(&init_natives_once, &SetNativesFromFile, natives_blob);
     149             : #else
     150             :   UNREACHABLE();
     151             : #endif
     152       60997 : }
     153             : 
     154             : 
     155       60997 : void V8::SetSnapshotBlob(StartupData* snapshot_blob) {
     156             : #ifdef V8_USE_EXTERNAL_STARTUP_DATA
     157       60997 :   base::CallOnce(&init_snapshot_once, &SetSnapshotFromFile, snapshot_blob);
     158             : #else
     159             :   UNREACHABLE();
     160             : #endif
     161       60997 : }
     162             : }  // namespace internal
     163             : 
     164             : // static
     165           0 : double Platform::SystemClockTimeMillis() {
     166           0 :   return base::OS::TimeCurrentMillis();
     167             : }
     168      121996 : }  // namespace v8

Generated by: LCOV version 1.10