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

Side by Side Diff: src/snapshot-common.cc

Issue 949623006: Attach snapshot data blob to the isolate. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « src/snapshot.h ('k') | src/snapshot-empty.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // The common functionality when building with or without snapshots. 5 // The common functionality when building with or without snapshots.
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
11 #include "src/full-codegen.h" 11 #include "src/full-codegen.h"
12 #include "src/snapshot.h" 12 #include "src/snapshot.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 16
17 bool Snapshot::HaveASnapshotToStartFrom() {
18 return SnapshotBlob().data != NULL;
19 }
20
21
22 #ifdef DEBUG 17 #ifdef DEBUG
23 bool Snapshot::SnapshotIsValid(v8::StartupData* snapshot_blob) { 18 bool Snapshot::SnapshotIsValid(v8::StartupData* snapshot_blob) {
24 return !Snapshot::ExtractStartupData(snapshot_blob).is_empty() && 19 return !Snapshot::ExtractStartupData(snapshot_blob).is_empty() &&
25 !Snapshot::ExtractContextData(snapshot_blob).is_empty(); 20 !Snapshot::ExtractContextData(snapshot_blob).is_empty();
26 } 21 }
27 #endif // DEBUG 22 #endif // DEBUG
28 23
29 24
30 bool Snapshot::EmbedsScript() { 25 bool Snapshot::EmbedsScript(Isolate* isolate) {
31 if (!HaveASnapshotToStartFrom()) return false; 26 if (!isolate->snapshot_available()) return false;
32 const v8::StartupData blob = SnapshotBlob(); 27 return ExtractMetadata(isolate->snapshot_blob()).embeds_script();
33 return ExtractMetadata(&blob).embeds_script();
34 } 28 }
35 29
36 30
37 uint32_t Snapshot::SizeOfFirstPage(AllocationSpace space) { 31 uint32_t Snapshot::SizeOfFirstPage(Isolate* isolate, AllocationSpace space) {
38 DCHECK(space >= FIRST_PAGED_SPACE && space <= LAST_PAGED_SPACE); 32 DCHECK(space >= FIRST_PAGED_SPACE && space <= LAST_PAGED_SPACE);
39 if (!HaveASnapshotToStartFrom()) { 33 if (!isolate->snapshot_available()) {
40 return static_cast<uint32_t>(MemoryAllocator::PageAreaSize(space)); 34 return static_cast<uint32_t>(MemoryAllocator::PageAreaSize(space));
41 } 35 }
42 uint32_t size; 36 uint32_t size;
43 int offset = kFirstPageSizesOffset + (space - FIRST_PAGED_SPACE) * kInt32Size; 37 int offset = kFirstPageSizesOffset + (space - FIRST_PAGED_SPACE) * kInt32Size;
44 memcpy(&size, SnapshotBlob().data + offset, kInt32Size); 38 memcpy(&size, isolate->snapshot_blob()->data + offset, kInt32Size);
45 return size; 39 return size;
46 } 40 }
47 41
48 42
49 bool Snapshot::Initialize(Isolate* isolate) { 43 bool Snapshot::Initialize(Isolate* isolate) {
50 if (!HaveASnapshotToStartFrom()) return false; 44 if (!isolate->snapshot_available()) return false;
51 base::ElapsedTimer timer; 45 base::ElapsedTimer timer;
52 if (FLAG_profile_deserialization) timer.Start(); 46 if (FLAG_profile_deserialization) timer.Start();
53 47
54 const v8::StartupData blob = SnapshotBlob(); 48 const v8::StartupData* blob = isolate->snapshot_blob();
55 Vector<const byte> startup_data = ExtractStartupData(&blob); 49 Vector<const byte> startup_data = ExtractStartupData(blob);
56 SnapshotData snapshot_data(startup_data); 50 SnapshotData snapshot_data(startup_data);
57 Deserializer deserializer(&snapshot_data); 51 Deserializer deserializer(&snapshot_data);
58 bool success = isolate->Init(&deserializer); 52 bool success = isolate->Init(&deserializer);
59 if (FLAG_profile_deserialization) { 53 if (FLAG_profile_deserialization) {
60 double ms = timer.Elapsed().InMillisecondsF(); 54 double ms = timer.Elapsed().InMillisecondsF();
61 int bytes = startup_data.length(); 55 int bytes = startup_data.length();
62 PrintF("[Deserializing isolate (%d bytes) took %0.3f ms]\n", bytes, ms); 56 PrintF("[Deserializing isolate (%d bytes) took %0.3f ms]\n", bytes, ms);
63 } 57 }
64 return success; 58 return success;
65 } 59 }
66 60
67 61
68 MaybeHandle<Context> Snapshot::NewContextFromSnapshot( 62 MaybeHandle<Context> Snapshot::NewContextFromSnapshot(
69 Isolate* isolate, Handle<JSGlobalProxy> global_proxy, 63 Isolate* isolate, Handle<JSGlobalProxy> global_proxy,
70 Handle<FixedArray>* outdated_contexts_out) { 64 Handle<FixedArray>* outdated_contexts_out) {
71 if (!HaveASnapshotToStartFrom()) return Handle<Context>(); 65 if (!isolate->snapshot_available()) return Handle<Context>();
72 base::ElapsedTimer timer; 66 base::ElapsedTimer timer;
73 if (FLAG_profile_deserialization) timer.Start(); 67 if (FLAG_profile_deserialization) timer.Start();
74 68
75 const v8::StartupData blob = SnapshotBlob(); 69 const v8::StartupData* blob = isolate->snapshot_blob();
76 Vector<const byte> context_data = ExtractContextData(&blob); 70 Vector<const byte> context_data = ExtractContextData(blob);
77 SnapshotData snapshot_data(context_data); 71 SnapshotData snapshot_data(context_data);
78 Deserializer deserializer(&snapshot_data); 72 Deserializer deserializer(&snapshot_data);
79 73
80 MaybeHandle<Object> maybe_context = deserializer.DeserializePartial( 74 MaybeHandle<Object> maybe_context = deserializer.DeserializePartial(
81 isolate, global_proxy, outdated_contexts_out); 75 isolate, global_proxy, outdated_contexts_out);
82 Handle<Object> result; 76 Handle<Object> result;
83 if (!maybe_context.ToHandle(&result)) return MaybeHandle<Context>(); 77 if (!maybe_context.ToHandle(&result)) return MaybeHandle<Context>();
84 CHECK(result->IsContext()); 78 CHECK(result->IsContext());
85 // If the snapshot does not contain a custom script, we need to update 79 // If the snapshot does not contain a custom script, we need to update
86 // the global object for exactly one context. 80 // the global object for exactly one context.
87 CHECK(EmbedsScript() || (*outdated_contexts_out)->length() == 1); 81 CHECK(EmbedsScript(isolate) || (*outdated_contexts_out)->length() == 1);
88 if (FLAG_profile_deserialization) { 82 if (FLAG_profile_deserialization) {
89 double ms = timer.Elapsed().InMillisecondsF(); 83 double ms = timer.Elapsed().InMillisecondsF();
90 int bytes = context_data.length(); 84 int bytes = context_data.length();
91 PrintF("[Deserializing context (%d bytes) took %0.3f ms]\n", bytes, ms); 85 PrintF("[Deserializing context (%d bytes) took %0.3f ms]\n", bytes, ms);
92 } 86 }
93 return Handle<Context>::cast(result); 87 return Handle<Context>::cast(result);
94 } 88 }
95 89
96 90
97 void CalculateFirstPageSizes(bool is_default_snapshot, 91 void CalculateFirstPageSizes(bool is_default_snapshot,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 int startup_length; 193 int startup_length;
200 memcpy(&startup_length, data->data + kStartupLengthOffset, kIntSize); 194 memcpy(&startup_length, data->data + kStartupLengthOffset, kIntSize);
201 int context_offset = ContextOffset(startup_length); 195 int context_offset = ContextOffset(startup_length);
202 const byte* context_data = 196 const byte* context_data =
203 reinterpret_cast<const byte*>(data->data + context_offset); 197 reinterpret_cast<const byte*>(data->data + context_offset);
204 DCHECK_LT(context_offset, data->raw_size); 198 DCHECK_LT(context_offset, data->raw_size);
205 int context_length = data->raw_size - context_offset; 199 int context_length = data->raw_size - context_offset;
206 return Vector<const byte>(context_data, context_length); 200 return Vector<const byte>(context_data, context_length);
207 } 201 }
208 } } // namespace v8::internal 202 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/snapshot.h ('k') | src/snapshot-empty.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698