snapshot-external.cc 1.32 KB
Newer Older
1 2 3 4 5 6
// Copyright 2006-2008 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Used for building with external snapshots.

7
#include "src/snapshot/snapshot.h"
8

9
#include "src/base/platform/mutex.h"
10 11
#include "src/snapshot/serialize.h"
#include "src/snapshot/snapshot-source-sink.h"
12
#include "src/v8.h"  // for V8::Initialize
13

14

15 16 17
#ifndef V8_USE_EXTERNAL_STARTUP_DATA
#error snapshot-external.cc is used only for the external snapshot build.
#endif  // V8_USE_EXTERNAL_STARTUP_DATA
18 19


20 21
namespace v8 {
namespace internal {
22

23
static base::LazyMutex external_startup_data_mutex = LAZY_MUTEX_INITIALIZER;
24
static v8::StartupData external_startup_blob = {NULL, 0};
25 26

void SetSnapshotFromFile(StartupData* snapshot_blob) {
27 28
  base::LockGuard<base::Mutex> lock_guard(
      external_startup_data_mutex.Pointer());
29 30 31
  DCHECK(snapshot_blob);
  DCHECK(snapshot_blob->data);
  DCHECK(snapshot_blob->raw_size > 0);
32
  DCHECK(!external_startup_blob.data);
33
  DCHECK(Snapshot::SnapshotIsValid(snapshot_blob));
34
  external_startup_blob = *snapshot_blob;
35 36
}

37

38
const v8::StartupData* Snapshot::DefaultSnapshotBlob() {
39 40
  base::LockGuard<base::Mutex> lock_guard(
      external_startup_data_mutex.Pointer());
41
  return &external_startup_blob;
42
}
43 44
}  // namespace internal
}  // namespace v8