-
Notifications
You must be signed in to change notification settings - Fork 30.3k
/
Copy pathsnapshot-external.cc
61 lines (52 loc) · 1.96 KB
/
snapshot-external.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 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.
#include "src/base/platform/mutex.h"
#include "src/flags/flags.h"
#include "src/init/v8.h" // for V8::Initialize
#include "src/snapshot/snapshot-source-sink.h"
#include "src/snapshot/snapshot.h"
#ifndef V8_USE_EXTERNAL_STARTUP_DATA
#error snapshot-external.cc is used only for the external snapshot build.
#endif // V8_USE_EXTERNAL_STARTUP_DATA
namespace v8 {
namespace internal {
static base::LazyMutex external_startup_data_mutex = LAZY_MUTEX_INITIALIZER;
static v8::StartupData external_startup_blob = {nullptr, 0};
#ifdef V8_TARGET_OS_ANDROID
static bool external_startup_checksum_verified = false;
#endif
void SetSnapshotFromFile(StartupData* snapshot_blob) {
base::MutexGuard lock_guard(external_startup_data_mutex.Pointer());
DCHECK(snapshot_blob);
DCHECK(snapshot_blob->data);
DCHECK_GT(snapshot_blob->raw_size, 0);
DCHECK(!external_startup_blob.data);
DCHECK(Snapshot::SnapshotIsValid(snapshot_blob));
external_startup_blob = *snapshot_blob;
#ifdef V8_TARGET_OS_ANDROID
external_startup_checksum_verified = false;
#endif
}
bool Snapshot::ShouldVerifyChecksum(const v8::StartupData* data) {
#ifdef V8_TARGET_OS_ANDROID
base::MutexGuard lock_guard(external_startup_data_mutex.Pointer());
if (data != &external_startup_blob) {
return v8_flags.verify_snapshot_checksum;
}
// Verify the external snapshot maximally once per process due to the
// additional overhead.
if (external_startup_checksum_verified) return false;
external_startup_checksum_verified = true;
return true;
#else
return v8_flags.verify_snapshot_checksum;
#endif
}
const v8::StartupData* Snapshot::DefaultSnapshotBlob() {
base::MutexGuard lock_guard(external_startup_data_mutex.Pointer());
return &external_startup_blob;
}
} // namespace internal
} // namespace v8