blink/gin: changes blink to load snapshot based on runtime information
In order to do an experiment (finch) that measures the impact of switching from v8-snapshot to blink context-snapshot I need to support both at the same time. This patch changes gin to store the type of snapshot that was loaded, and blink to use that information rather than ifdefs. BUG=764576,1257321 TEST=none Change-Id: I56db96937ef22ddf1c91975a9a4dc355c1c7559c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3212165 Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Richard Coles <torne@chromium.org> Reviewed-by: Kentaro Hara <haraken@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Andrey Kosyakov <caseq@chromium.org> Reviewed-by: John Abd-El-Malek <jam@chromium.org> Reviewed-by: Jeremy Roman <jbroman@chromium.org> Reviewed-by: Yuki Shiino <yukishiino@chromium.org> Commit-Queue: Scott Violet <sky@chromium.org> Cr-Commit-Position: refs/heads/main@{#930573}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
b108526086
commit
592f4f76a9
android_webview/lib
content
app
public
test
gin
headless/test
pdf/test
services
third_party/blink/renderer
@ -167,11 +167,10 @@ bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
|
||||
cl->AppendSwitch(switches::kWebViewDrawFunctorUsesVulkan);
|
||||
|
||||
#if defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
gin::V8Initializer::V8SnapshotFileType file_type =
|
||||
gin::V8Initializer::V8SnapshotFileType::kWithAdditionalContext;
|
||||
gin::V8SnapshotFileType file_type =
|
||||
gin::V8SnapshotFileType::kWithAdditionalContext;
|
||||
#else
|
||||
gin::V8Initializer::V8SnapshotFileType file_type =
|
||||
gin::V8Initializer::V8SnapshotFileType::kDefault;
|
||||
gin::V8SnapshotFileType file_type = gin::V8SnapshotFileType::kDefault;
|
||||
#endif
|
||||
base::android::RegisterApkAssetWithFileDescriptorStore(
|
||||
content::kV8Snapshot32DataDescriptor,
|
||||
|
@ -202,13 +202,13 @@ namespace {
|
||||
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
void LoadV8SnapshotFile() {
|
||||
#if defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
static constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8Initializer::V8SnapshotFileType::kWithAdditionalContext;
|
||||
static constexpr gin::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8SnapshotFileType::kWithAdditionalContext;
|
||||
static const char* snapshot_data_descriptor =
|
||||
kV8ContextSnapshotDataDescriptor;
|
||||
#else
|
||||
static constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8Initializer::V8SnapshotFileType::kDefault;
|
||||
static constexpr gin::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8SnapshotFileType::kDefault;
|
||||
static const char* snapshot_data_descriptor = kV8SnapshotDataDescriptor;
|
||||
#endif // USE_V8_CONTEXT_SNAPSHOT
|
||||
ALLOW_UNUSED_LOCAL(kSnapshotType);
|
||||
|
@ -30,11 +30,11 @@ namespace content {
|
||||
namespace {
|
||||
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
#if defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8Initializer::V8SnapshotFileType::kWithAdditionalContext;
|
||||
constexpr gin::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8SnapshotFileType::kWithAdditionalContext;
|
||||
#else
|
||||
constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8Initializer::V8SnapshotFileType::kDefault;
|
||||
constexpr gin::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8SnapshotFileType::kDefault;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -18,11 +18,11 @@ namespace content {
|
||||
namespace {
|
||||
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
#if defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8Initializer::V8SnapshotFileType::kWithAdditionalContext;
|
||||
constexpr gin::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8SnapshotFileType::kWithAdditionalContext;
|
||||
#else
|
||||
constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8Initializer::V8SnapshotFileType::kDefault;
|
||||
constexpr gin::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8SnapshotFileType::kDefault;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
@ -91,11 +91,11 @@ class DummyTaskRunner : public base::SingleThreadTaskRunner {
|
||||
|
||||
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
#if defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8Initializer::V8SnapshotFileType::kWithAdditionalContext;
|
||||
constexpr gin::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8SnapshotFileType::kWithAdditionalContext;
|
||||
#else
|
||||
constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8Initializer::V8SnapshotFileType::kDefault;
|
||||
constexpr gin::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8SnapshotFileType::kDefault;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -81,6 +81,7 @@ component("gin") {
|
||||
|
||||
if (v8_use_external_startup_data) {
|
||||
data = [ "$root_out_dir/snapshot_blob.bin" ]
|
||||
sources += [ "public/v8_snapshot_file_type.h" ]
|
||||
}
|
||||
|
||||
defines = [ "GIN_IMPLEMENTATION" ]
|
||||
@ -90,7 +91,10 @@ component("gin") {
|
||||
"//base/allocator:buildflags",
|
||||
"//v8",
|
||||
]
|
||||
deps = [ "//base/third_party/dynamic_annotations" ]
|
||||
deps = [
|
||||
"//base/third_party/dynamic_annotations",
|
||||
"//third_party/abseil-cpp:absl",
|
||||
]
|
||||
|
||||
if (is_mac) {
|
||||
frameworks = [ "CoreFoundation.framework" ]
|
||||
|
32
gin/public/v8_snapshot_file_type.h
Normal file
32
gin/public/v8_snapshot_file_type.h
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef GIN_PUBLIC_V8_SNAPSHOT_FILE_TYPE_H_
|
||||
#define GIN_PUBLIC_V8_SNAPSHOT_FILE_TYPE_H_
|
||||
|
||||
#if !defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
#error Don't include this header unless v8_external_startup_data is true.
|
||||
#endif
|
||||
|
||||
#include "gin/gin_export.h"
|
||||
|
||||
namespace gin {
|
||||
|
||||
// Indicates which file to load as a snapshot blob image.
|
||||
enum class V8SnapshotFileType {
|
||||
kDefault,
|
||||
|
||||
// Snapshot augmented with customized contexts, which can be deserialized
|
||||
// using v8::Context::FromSnapshot.
|
||||
kWithAdditionalContext,
|
||||
};
|
||||
|
||||
// Returns the V8SnapshotFileType used when loading the snapshot. This must
|
||||
// be called after loading the snapshot.
|
||||
// NOTE: this is implemented in v8_initializer.cc
|
||||
GIN_EXPORT V8SnapshotFileType GetLoadedSnapshotFileType();
|
||||
|
||||
} // namespace gin
|
||||
|
||||
#endif // GIN_PUBLIC_V8_SNAPSHOT_FILE_TYPE_H_
|
@ -31,6 +31,7 @@
|
||||
#include "base/time/time.h"
|
||||
#include "build/build_config.h"
|
||||
#include "gin/gin_features.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "v8/include/v8-initialization.h"
|
||||
#include "v8/include/v8-snapshot.h"
|
||||
|
||||
@ -49,6 +50,10 @@ namespace {
|
||||
// This global is never freed nor closed.
|
||||
base::MemoryMappedFile* g_mapped_snapshot = nullptr;
|
||||
|
||||
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
absl::optional<gin::V8SnapshotFileType> g_snapshot_file_type;
|
||||
#endif
|
||||
|
||||
bool GenerateEntropy(unsigned char* buffer, size_t amount) {
|
||||
base::RandBytes(buffer, amount);
|
||||
return true;
|
||||
@ -88,12 +93,11 @@ const char kV8ContextSnapshotFileName[] = V8_CONTEXT_SNAPSHOT_FILENAME;
|
||||
const char kSnapshotFileName[] = "snapshot_blob.bin";
|
||||
#endif // defined(OS_ANDROID)
|
||||
|
||||
const char* GetSnapshotFileName(
|
||||
const V8Initializer::V8SnapshotFileType file_type) {
|
||||
const char* GetSnapshotFileName(const V8SnapshotFileType file_type) {
|
||||
switch (file_type) {
|
||||
case V8Initializer::V8SnapshotFileType::kDefault:
|
||||
case V8SnapshotFileType::kDefault:
|
||||
return kSnapshotFileName;
|
||||
case V8Initializer::V8SnapshotFileType::kWithAdditionalContext:
|
||||
case V8SnapshotFileType::kWithAdditionalContext:
|
||||
#if defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
return kV8ContextSnapshotFileName;
|
||||
#else
|
||||
@ -413,6 +417,7 @@ void V8Initializer::LoadV8SnapshotFromFile(
|
||||
return;
|
||||
}
|
||||
|
||||
g_snapshot_file_type = snapshot_file_type;
|
||||
base::MemoryMappedFile::Region region =
|
||||
base::MemoryMappedFile::Region::kWholeFile;
|
||||
if (snapshot_file_region) {
|
||||
@ -433,10 +438,10 @@ base::FilePath V8Initializer::GetSnapshotFilePath(
|
||||
base::FilePath path;
|
||||
const char* filename = nullptr;
|
||||
switch (snapshot_file_type) {
|
||||
case V8Initializer::V8SnapshotFileType::kDefault:
|
||||
case V8SnapshotFileType::kDefault:
|
||||
filename = abi_32_bit ? kSnapshotFileName32 : kSnapshotFileName64;
|
||||
break;
|
||||
case V8Initializer::V8SnapshotFileType::kWithAdditionalContext:
|
||||
case V8SnapshotFileType::kWithAdditionalContext:
|
||||
filename = abi_32_bit ? kV8ContextSnapshotFileName32
|
||||
: kV8ContextSnapshotFileName64;
|
||||
break;
|
||||
@ -447,6 +452,12 @@ base::FilePath V8Initializer::GetSnapshotFilePath(
|
||||
return path;
|
||||
}
|
||||
#endif // defined(OS_ANDROID)
|
||||
|
||||
V8SnapshotFileType GetLoadedSnapshotFileType() {
|
||||
DCHECK(g_snapshot_file_type.has_value());
|
||||
return *g_snapshot_file_type;
|
||||
}
|
||||
|
||||
#endif // defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
|
||||
} // namespace gin
|
||||
|
@ -15,6 +15,10 @@
|
||||
#include "gin/public/isolate_holder.h"
|
||||
#include "gin/public/v8_platform.h"
|
||||
|
||||
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
#include "gin/public/v8_snapshot_file_type.h"
|
||||
#endif
|
||||
|
||||
namespace v8 {
|
||||
class StartupData;
|
||||
}
|
||||
@ -34,15 +38,6 @@ class GIN_EXPORT V8Initializer {
|
||||
int* snapshot_size_out);
|
||||
|
||||
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
// Indicates which file to load as a snapshot blob image.
|
||||
enum class V8SnapshotFileType {
|
||||
kDefault,
|
||||
|
||||
// Snapshot augmented with customized contexts, which can be deserialized
|
||||
// using v8::Context::FromSnapshot.
|
||||
kWithAdditionalContext,
|
||||
};
|
||||
|
||||
// Load V8 snapshot from default resources, if they are available.
|
||||
static void LoadV8Snapshot(
|
||||
V8SnapshotFileType snapshot_file_type = V8SnapshotFileType::kDefault);
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "base/tracing_buildflags.h"
|
||||
#include "build/build_config.h"
|
||||
|
||||
#include "gin/per_isolate_data.h"
|
||||
#include "v8_platform_page_allocator.h"
|
||||
|
||||
|
@ -169,11 +169,11 @@ HeadlessBrowserTest::~HeadlessBrowserTest() = default;
|
||||
void HeadlessBrowserTest::PreRunTestOnMainThread() {
|
||||
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
#if defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8Initializer::V8SnapshotFileType::kWithAdditionalContext;
|
||||
constexpr gin::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8SnapshotFileType::kWithAdditionalContext;
|
||||
#else
|
||||
constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8Initializer::V8SnapshotFileType::kDefault;
|
||||
constexpr gin::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8SnapshotFileType::kDefault;
|
||||
#endif // USE_V8_CONTEXT_SNAPSHOT
|
||||
gin::V8Initializer::LoadV8Snapshot(kSnapshotType);
|
||||
#endif
|
||||
|
@ -30,11 +30,11 @@
|
||||
namespace {
|
||||
|
||||
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
|
||||
constexpr gin::V8SnapshotFileType kSnapshotType =
|
||||
#if defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
gin::V8Initializer::V8SnapshotFileType::kWithAdditionalContext;
|
||||
gin::V8SnapshotFileType::kWithAdditionalContext;
|
||||
#else
|
||||
gin::V8Initializer::V8SnapshotFileType::kDefault;
|
||||
gin::V8SnapshotFileType::kDefault;
|
||||
#endif // defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
#endif // defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
|
||||
|
@ -32,11 +32,11 @@ const int64_t kTestMaxImageSize = 128 * 1024;
|
||||
|
||||
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
#if defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8Initializer::V8SnapshotFileType::kWithAdditionalContext;
|
||||
constexpr gin::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8SnapshotFileType::kWithAdditionalContext;
|
||||
#else
|
||||
constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8Initializer::V8SnapshotFileType::kDefault;
|
||||
constexpr gin::V8SnapshotFileType kSnapshotType =
|
||||
gin::V8SnapshotFileType::kDefault;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -375,7 +375,7 @@ class SharedIsolateFactory {
|
||||
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
#if defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
gin::V8Initializer::LoadV8Snapshot(
|
||||
gin::V8Initializer::V8SnapshotFileType::kWithAdditionalContext);
|
||||
gin::V8SnapshotFileType::kWithAdditionalContext);
|
||||
#else
|
||||
gin::V8Initializer::LoadV8Snapshot();
|
||||
#endif
|
||||
|
@ -88,6 +88,10 @@
|
||||
#include "v8/include/v8-profiler.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
#include "gin/public/v8_snapshot_file_type.h"
|
||||
#endif
|
||||
|
||||
namespace blink {
|
||||
|
||||
static void ReportFatalErrorInMainThread(const char* location,
|
||||
@ -732,6 +736,18 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
|
||||
size_t max_allocation_;
|
||||
};
|
||||
|
||||
V8PerIsolateData::V8ContextSnapshotMode GetV8ContextSnapshotMode() {
|
||||
#if defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
if (Platform::Current()->IsTakingV8ContextSnapshot())
|
||||
return V8PerIsolateData::V8ContextSnapshotMode::kTakeSnapshot;
|
||||
if (gin::GetLoadedSnapshotFileType() ==
|
||||
gin::V8SnapshotFileType::kWithAdditionalContext) {
|
||||
return V8PerIsolateData::V8ContextSnapshotMode::kUseSnapshot;
|
||||
}
|
||||
#endif // USE_V8_CONTEXT_SNAPSHOT
|
||||
return V8PerIsolateData::V8ContextSnapshotMode::kDontUseSnapshot;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void V8Initializer::InitializeMainThread(const intptr_t* reference_table) {
|
||||
@ -743,18 +759,8 @@ void V8Initializer::InitializeMainThread(const intptr_t* reference_table) {
|
||||
|
||||
ThreadScheduler* scheduler = ThreadScheduler::Current();
|
||||
|
||||
#if defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
V8PerIsolateData::V8ContextSnapshotMode v8_context_snapshot_mode =
|
||||
Platform::Current()->IsTakingV8ContextSnapshot()
|
||||
? V8PerIsolateData::V8ContextSnapshotMode::kTakeSnapshot
|
||||
: V8PerIsolateData::V8ContextSnapshotMode::kUseSnapshot;
|
||||
#else
|
||||
V8PerIsolateData::V8ContextSnapshotMode v8_context_snapshot_mode =
|
||||
V8PerIsolateData::V8ContextSnapshotMode::kDontUseSnapshot;
|
||||
#endif // USE_V8_CONTEXT_SNAPSHOT
|
||||
|
||||
v8::Isolate* isolate = V8PerIsolateData::Initialize(scheduler->V8TaskRunner(),
|
||||
v8_context_snapshot_mode);
|
||||
v8::Isolate* isolate = V8PerIsolateData::Initialize(
|
||||
scheduler->V8TaskRunner(), GetV8ContextSnapshotMode());
|
||||
scheduler->SetV8Isolate(isolate);
|
||||
|
||||
// ThreadState::isolate_ needs to be set before setting the EmbedderHeapTracer
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "third_party/blink/renderer/bindings/modules/v8/v8_context_snapshot_impl.h"
|
||||
|
||||
#include "third_party/blink/public/platform/platform.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_context_snapshot.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_event_target.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_html_document.h"
|
||||
@ -20,7 +21,25 @@
|
||||
#include "third_party/blink/renderer/platform/bindings/v8_private_property.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
|
||||
|
||||
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
|
||||
#include "gin/public/v8_snapshot_file_type.h"
|
||||
#endif
|
||||
|
||||
namespace blink {
|
||||
namespace {
|
||||
|
||||
bool IsUsingContextSnapshot() {
|
||||
#if defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
if (Platform::Current()->IsTakingV8ContextSnapshot() ||
|
||||
gin::GetLoadedSnapshotFileType() ==
|
||||
gin::V8SnapshotFileType::kWithAdditionalContext) {
|
||||
return true;
|
||||
}
|
||||
#endif // USE_V8_CONTEXT_SNAPSHOT
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void V8ContextSnapshotImpl::Init() {
|
||||
V8ContextSnapshot::SetCreateContextFromSnapshotFunc(CreateContext);
|
||||
@ -31,42 +50,6 @@ void V8ContextSnapshotImpl::Init() {
|
||||
V8ContextSnapshot::SetGetReferenceTableFunc(GetReferenceTable);
|
||||
}
|
||||
|
||||
#if !defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
|
||||
v8::Local<v8::Context> V8ContextSnapshotImpl::CreateContext(
|
||||
v8::Isolate* isolate,
|
||||
const DOMWrapperWorld& world,
|
||||
v8::ExtensionConfiguration* extension_config,
|
||||
v8::Local<v8::Object> global_proxy,
|
||||
Document* document) {
|
||||
DCHECK(document);
|
||||
|
||||
return v8::Local<v8::Context>();
|
||||
}
|
||||
|
||||
void V8ContextSnapshotImpl::InstallContextIndependentProps(
|
||||
ScriptState* script_state) {}
|
||||
|
||||
void V8ContextSnapshotImpl::InstallInterfaceTemplates(v8::Isolate* isolate) {}
|
||||
|
||||
v8::StartupData V8ContextSnapshotImpl::TakeSnapshot() {
|
||||
v8::Isolate* isolate = V8PerIsolateData::MainThreadIsolate();
|
||||
CHECK_EQ(isolate, v8::Isolate::GetCurrent());
|
||||
V8PerIsolateData* per_isolate_data = V8PerIsolateData::From(isolate);
|
||||
CHECK_EQ(per_isolate_data->GetV8ContextSnapshotMode(),
|
||||
V8PerIsolateData::V8ContextSnapshotMode::kTakeSnapshot);
|
||||
|
||||
return {nullptr, 0};
|
||||
}
|
||||
|
||||
const intptr_t* V8ContextSnapshotImpl::GetReferenceTable() {
|
||||
DCHECK(IsMainThread());
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#else // !defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
|
||||
namespace {
|
||||
|
||||
// Layout of the snapshot
|
||||
@ -340,6 +323,8 @@ v8::Local<v8::Context> V8ContextSnapshotImpl::CreateContext(
|
||||
v8::Local<v8::Object> global_proxy,
|
||||
Document* document) {
|
||||
DCHECK(document);
|
||||
if (!IsUsingContextSnapshot())
|
||||
return v8::Local<v8::Context>();
|
||||
|
||||
V8PerIsolateData* per_isolate_data = V8PerIsolateData::From(isolate);
|
||||
if (per_isolate_data->GetV8ContextSnapshotMode() !=
|
||||
@ -370,6 +355,9 @@ v8::Local<v8::Context> V8ContextSnapshotImpl::CreateContext(
|
||||
|
||||
void V8ContextSnapshotImpl::InstallContextIndependentProps(
|
||||
ScriptState* script_state) {
|
||||
if (!IsUsingContextSnapshot())
|
||||
return;
|
||||
|
||||
v8::Isolate* isolate = script_state->GetIsolate();
|
||||
v8::Local<v8::Context> context = script_state->GetContext();
|
||||
const DOMWrapperWorld& world = script_state->World();
|
||||
@ -398,6 +386,9 @@ void V8ContextSnapshotImpl::InstallContextIndependentProps(
|
||||
}
|
||||
|
||||
void V8ContextSnapshotImpl::InstallInterfaceTemplates(v8::Isolate* isolate) {
|
||||
if (!IsUsingContextSnapshot())
|
||||
return;
|
||||
|
||||
V8PerIsolateData* per_isolate_data = V8PerIsolateData::From(isolate);
|
||||
if (per_isolate_data->GetV8ContextSnapshotMode() !=
|
||||
V8PerIsolateData::V8ContextSnapshotMode::kUseSnapshot) {
|
||||
@ -430,6 +421,7 @@ v8::StartupData V8ContextSnapshotImpl::TakeSnapshot() {
|
||||
V8PerIsolateData* per_isolate_data = V8PerIsolateData::From(isolate);
|
||||
CHECK_EQ(per_isolate_data->GetV8ContextSnapshotMode(),
|
||||
V8PerIsolateData::V8ContextSnapshotMode::kTakeSnapshot);
|
||||
DCHECK(IsUsingContextSnapshot());
|
||||
|
||||
// Take a snapshot with minimum set-up. It's easier to add properties than
|
||||
// removing ones, so make it no need to remove any property.
|
||||
@ -461,6 +453,10 @@ v8::StartupData V8ContextSnapshotImpl::TakeSnapshot() {
|
||||
|
||||
const intptr_t* V8ContextSnapshotImpl::GetReferenceTable() {
|
||||
DCHECK(IsMainThread());
|
||||
|
||||
if (!IsUsingContextSnapshot())
|
||||
return nullptr;
|
||||
|
||||
DEFINE_STATIC_LOCAL(const intptr_t*, reference_table, (nullptr));
|
||||
if (reference_table)
|
||||
return reference_table;
|
||||
@ -495,6 +491,4 @@ const intptr_t* V8ContextSnapshotImpl::GetReferenceTable() {
|
||||
return reference_table;
|
||||
}
|
||||
|
||||
#endif // !defined(USE_V8_CONTEXT_SNAPSHOT)
|
||||
|
||||
} // namespace blink
|
||||
|
6
third_party/blink/renderer/core/BUILD.gn
vendored
6
third_party/blink/renderer/core/BUILD.gn
vendored
@ -250,7 +250,10 @@ component("core") {
|
||||
|
||||
configs -= core_config_remove
|
||||
configs += core_config_add
|
||||
configs += [ "//tools/v8_context_snapshot:use_v8_context_snapshot" ]
|
||||
configs += [
|
||||
"//tools/v8_context_snapshot:use_v8_context_snapshot",
|
||||
"//v8:external_startup_data",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
":core_generated",
|
||||
@ -282,6 +285,7 @@ component("core") {
|
||||
"//components/performance_manager/public/mojom:mojom_blink",
|
||||
"//components/power_scheduler",
|
||||
"//components/shared_highlighting/core/common",
|
||||
"//gin",
|
||||
"//gpu/config",
|
||||
"//mojo/public/cpp/bindings:bindings",
|
||||
"//mojo/public/cpp/system",
|
||||
|
2
third_party/blink/renderer/modules/BUILD.gn
vendored
2
third_party/blink/renderer/modules/BUILD.gn
vendored
@ -45,6 +45,7 @@ component("modules") {
|
||||
"//third_party/blink/renderer:inside_blink",
|
||||
"//third_party/blink/renderer/core:blink_core_pch",
|
||||
"//tools/v8_context_snapshot:use_v8_context_snapshot",
|
||||
"//v8:external_startup_data",
|
||||
]
|
||||
|
||||
sub_modules = [
|
||||
@ -177,6 +178,7 @@ component("modules") {
|
||||
|
||||
deps = [
|
||||
":make_modules_generated",
|
||||
"//gin",
|
||||
"//jingle:webrtc_glue",
|
||||
"//net:net",
|
||||
"//third_party/blink/renderer/bindings/modules/v8:generated",
|
||||
|
Reference in New Issue
Block a user