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

Unified Diff: src/snapshot-common.cc

Issue 789213002: Extract non-IO part of mksnapshot into an API method. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix external snapshot Created 6 years 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 80463542665ff7e2ed23947731fed7684da17d7a..dc7f655abc24ffafc2d9b5a6f718ba8939519f9c 100644
--- a/src/snapshot-common.cc
+++ b/src/snapshot-common.cc
@@ -19,37 +19,13 @@ bool Snapshot::HaveASnapshotToStartFrom() {
}
-const Vector<const byte> Snapshot::StartupSnapshot() {
- DCHECK(HaveASnapshotToStartFrom());
- const v8::StartupData blob = SnapshotBlob();
- SnapshotByteSource source(blob.data, blob.raw_size);
- const byte* data;
- int length;
- bool success = source.GetBlob(&data, &length);
- CHECK(success);
- return Vector<const byte>(data, length);
-}
-
-
-const Vector<const byte> Snapshot::ContextSnapshot() {
- DCHECK(HaveASnapshotToStartFrom());
- const v8::StartupData blob = SnapshotBlob();
- SnapshotByteSource source(blob.data, blob.raw_size);
- const byte* data;
- int length;
- bool success = source.GetBlob(&data, &length);
- success &= source.GetBlob(&data, &length);
- CHECK(success);
- return Vector<const byte>(data, length);
-}
-
-
bool Snapshot::Initialize(Isolate* isolate) {
if (!HaveASnapshotToStartFrom()) return false;
base::ElapsedTimer timer;
if (FLAG_profile_deserialization) timer.Start();
- SnapshotData snapshot_data(StartupSnapshot());
+ const v8::StartupData blob = SnapshotBlob();
+ SnapshotData snapshot_data(ExtractStartupData(&blob));
Deserializer deserializer(&snapshot_data);
bool success = isolate->Init(&deserializer);
if (FLAG_profile_deserialization) {
@@ -63,7 +39,8 @@ bool Snapshot::Initialize(Isolate* isolate) {
Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) {
if (!HaveASnapshotToStartFrom()) return Handle<Context>();
- SnapshotData snapshot_data(ContextSnapshot());
+ const v8::StartupData blob = SnapshotBlob();
+ SnapshotData snapshot_data(ExtractContextData(&blob));
Deserializer deserializer(&snapshot_data);
Object* root;
deserializer.DeserializePartial(isolate, &root);
@@ -71,4 +48,44 @@ Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) {
return Handle<Context>(Context::cast(root));
}
+
+v8::StartupData Snapshot::CreateSnapshotBlob(
+ const Vector<const byte> startup_data,
+ const Vector<const byte> context_data) {
+ int startup_length = startup_data.length();
+ int context_length = context_data.length();
+ int context_offset = kIntSize + 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 + context_offset, context_data.begin(), context_length);
+ v8::StartupData result = {data, length};
+ return result;
+}
+
+
+Vector<const byte> Snapshot::ExtractStartupData(const v8::StartupData* data) {
+ DCHECK_LT(kIntSize, data->raw_size);
+ int startup_length;
+ memcpy(&startup_length, data->data, kIntSize);
+ DCHECK_LT(startup_length, data->raw_size);
+ const byte* startup_data =
+ reinterpret_cast<const byte*>(data->data + kIntSize);
+ return Vector<const byte>(startup_data, startup_length);
+}
+
+
+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;
+ const byte* context_data =
+ reinterpret_cast<const byte*>(data->data + context_offset);
+ DCHECK_LT(context_offset, data->raw_size);
+ int context_length = data->raw_size - context_offset;
+ return Vector<const byte>(context_data, context_length);
+}
} } // namespace v8::internal
« 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