Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Unified Diff: src/snapshot-common.cc

Issue 848023002: Store embed-script flag as metadata into snapshot blob. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressed comment Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/snapshot.h ('k') | src/snapshot-external.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/snapshot-common.cc
diff --git a/src/snapshot-common.cc b/src/snapshot-common.cc
index 09cf7223ffc931f8e889c524e7aebd965ad1b11d..c2ce60d5fbdbe220eb21e7578636a1eb936a7ffc 100644
--- a/src/snapshot-common.cc
+++ b/src/snapshot-common.cc
@@ -19,6 +19,21 @@ bool Snapshot::HaveASnapshotToStartFrom() {
}
+#ifdef DEBUG
+bool Snapshot::SnapshotIsValid(v8::StartupData* snapshot_blob) {
+ return !Snapshot::ExtractStartupData(snapshot_blob).is_empty() &&
+ !Snapshot::ExtractContextData(snapshot_blob).is_empty();
+}
+#endif // DEBUG
+
+
+bool Snapshot::EmbedsScript() {
+ if (!HaveASnapshotToStartFrom()) return false;
+ const v8::StartupData blob = SnapshotBlob();
+ return ExtractMetadata(&blob).embeds_script();
+}
+
+
bool Snapshot::Initialize(Isolate* isolate) {
if (!HaveASnapshotToStartFrom()) return false;
base::ElapsedTimer timer;
@@ -54,6 +69,9 @@ MaybeHandle<Context> Snapshot::NewContextFromSnapshot(
Handle<Object> result;
if (!maybe_context.ToHandle(&result)) return MaybeHandle<Context>();
CHECK(result->IsContext());
+ // If the snapshot does not contain a custom script, we need to update
+ // the global object for exactly one context.
+ CHECK(EmbedsScript() || (*outdated_contexts_out)->length() == 1);
if (FLAG_profile_deserialization) {
double ms = timer.Elapsed().InMillisecondsF();
int bytes = context_data.length();
@@ -65,28 +83,37 @@ MaybeHandle<Context> Snapshot::NewContextFromSnapshot(
v8::StartupData Snapshot::CreateSnapshotBlob(
const Vector<const byte> startup_data,
- const Vector<const byte> context_data) {
+ const Vector<const byte> context_data, Snapshot::Metadata metadata) {
int startup_length = startup_data.length();
int context_length = context_data.length();
- int context_offset = kIntSize + startup_length;
+ int context_offset = ContextOffset(startup_length);
+
int length = context_offset + context_length;
char* data = new char[length];
- memcpy(data, &startup_length, kIntSize);
- memcpy(data + kIntSize, startup_data.begin(), startup_length);
+ memcpy(data + kMetadataOffset, &metadata.RawValue(), kInt32Size);
+ memcpy(data + kStartupLengthOffset, &startup_length, kInt32Size);
+ memcpy(data + kStartupDataOffset, startup_data.begin(), startup_length);
memcpy(data + context_offset, context_data.begin(), context_length);
v8::StartupData result = {data, length};
return result;
}
+Snapshot::Metadata Snapshot::ExtractMetadata(const v8::StartupData* data) {
+ uint32_t raw;
+ memcpy(&raw, data->data + kMetadataOffset, kInt32Size);
+ return Metadata(raw);
+}
+
+
Vector<const byte> Snapshot::ExtractStartupData(const v8::StartupData* data) {
DCHECK_LT(kIntSize, data->raw_size);
int startup_length;
- memcpy(&startup_length, data->data, kIntSize);
+ memcpy(&startup_length, data->data + kStartupLengthOffset, kInt32Size);
DCHECK_LT(startup_length, data->raw_size);
const byte* startup_data =
- reinterpret_cast<const byte*>(data->data + kIntSize);
+ reinterpret_cast<const byte*>(data->data + kStartupDataOffset);
return Vector<const byte>(startup_data, startup_length);
}
@@ -94,8 +121,8 @@ Vector<const byte> Snapshot::ExtractStartupData(const v8::StartupData* data) {
Vector<const byte> Snapshot::ExtractContextData(const v8::StartupData* data) {
DCHECK_LT(kIntSize, data->raw_size);
int startup_length;
- memcpy(&startup_length, data->data, kIntSize);
- int context_offset = kIntSize + startup_length;
+ memcpy(&startup_length, data->data + kStartupLengthOffset, kIntSize);
+ int context_offset = ContextOffset(startup_length);
const byte* context_data =
reinterpret_cast<const byte*>(data->data + context_offset);
DCHECK_LT(context_offset, data->raw_size);
« no previous file with comments | « src/snapshot.h ('k') | src/snapshot-external.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698