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

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

Issue 932823002: Limit size of first page based on serialized data. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove printf debugging 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') | test/cctest/test-heap.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/serialize.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() { 17 bool Snapshot::HaveASnapshotToStartFrom() {
18 return SnapshotBlob().data != NULL; 18 return SnapshotBlob().data != NULL;
19 } 19 }
20 20
21 21
22 #ifdef DEBUG 22 #ifdef DEBUG
23 bool Snapshot::SnapshotIsValid(v8::StartupData* snapshot_blob) { 23 bool Snapshot::SnapshotIsValid(v8::StartupData* snapshot_blob) {
24 return !Snapshot::ExtractStartupData(snapshot_blob).is_empty() && 24 return !Snapshot::ExtractStartupData(snapshot_blob).is_empty() &&
25 !Snapshot::ExtractContextData(snapshot_blob).is_empty(); 25 !Snapshot::ExtractContextData(snapshot_blob).is_empty();
26 } 26 }
27 #endif // DEBUG 27 #endif // DEBUG
28 28
29 29
30 bool Snapshot::EmbedsScript() { 30 bool Snapshot::EmbedsScript() {
31 if (!HaveASnapshotToStartFrom()) return false; 31 if (!HaveASnapshotToStartFrom()) return false;
32 const v8::StartupData blob = SnapshotBlob(); 32 const v8::StartupData blob = SnapshotBlob();
33 return ExtractMetadata(&blob).embeds_script(); 33 return ExtractMetadata(&blob).embeds_script();
34 } 34 }
35 35
36 36
37 uint32_t Snapshot::SizeOfFirstPage(AllocationSpace space) {
38 DCHECK(space >= FIRST_PAGED_SPACE && space <= LAST_PAGED_SPACE);
39 if (!HaveASnapshotToStartFrom()) {
40 return static_cast<uint32_t>(MemoryAllocator::PageAreaSize(space));
41 }
42 uint32_t size;
43 int offset = kFirstPageSizesOffset + (space - FIRST_PAGED_SPACE) * kInt32Size;
44 memcpy(&size, SnapshotBlob().data + offset, kInt32Size);
45 return size;
46 }
47
48
37 bool Snapshot::Initialize(Isolate* isolate) { 49 bool Snapshot::Initialize(Isolate* isolate) {
38 if (!HaveASnapshotToStartFrom()) return false; 50 if (!HaveASnapshotToStartFrom()) return false;
39 base::ElapsedTimer timer; 51 base::ElapsedTimer timer;
40 if (FLAG_profile_deserialization) timer.Start(); 52 if (FLAG_profile_deserialization) timer.Start();
41 53
42 const v8::StartupData blob = SnapshotBlob(); 54 const v8::StartupData blob = SnapshotBlob();
43 Vector<const byte> startup_data = ExtractStartupData(&blob); 55 Vector<const byte> startup_data = ExtractStartupData(&blob);
44 SnapshotData snapshot_data(startup_data); 56 SnapshotData snapshot_data(startup_data);
45 Deserializer deserializer(&snapshot_data); 57 Deserializer deserializer(&snapshot_data);
46 bool success = isolate->Init(&deserializer); 58 bool success = isolate->Init(&deserializer);
(...skipping 28 matching lines...) Expand all
75 CHECK(EmbedsScript() || (*outdated_contexts_out)->length() == 1); 87 CHECK(EmbedsScript() || (*outdated_contexts_out)->length() == 1);
76 if (FLAG_profile_deserialization) { 88 if (FLAG_profile_deserialization) {
77 double ms = timer.Elapsed().InMillisecondsF(); 89 double ms = timer.Elapsed().InMillisecondsF();
78 int bytes = context_data.length(); 90 int bytes = context_data.length();
79 PrintF("[Deserializing context (%d bytes) took %0.3f ms]\n", bytes, ms); 91 PrintF("[Deserializing context (%d bytes) took %0.3f ms]\n", bytes, ms);
80 } 92 }
81 return Handle<Context>::cast(result); 93 return Handle<Context>::cast(result);
82 } 94 }
83 95
84 96
97 void CalculateFirstPageSizes(bool is_default_snapshot,
98 const SnapshotData& startup_snapshot,
99 const SnapshotData& context_snapshot,
100 uint32_t* sizes_out) {
101 Vector<const SerializedData::Reservation> startup_reservations =
102 startup_snapshot.Reservations();
103 Vector<const SerializedData::Reservation> context_reservations =
104 context_snapshot.Reservations();
105 int startup_index = 0;
106 int context_index = 0;
107 for (int space = 0; space < i::Serializer::kNumberOfSpaces; space++) {
108 bool single_chunk = true;
109 while (!startup_reservations[startup_index].is_last()) {
110 single_chunk = false;
111 startup_index++;
112 }
113 while (!context_reservations[context_index].is_last()) {
114 single_chunk = false;
115 context_index++;
116 }
117
118 uint32_t required = kMaxUInt32;
119 if (single_chunk) {
120 // If both the startup snapshot data and the context snapshot data on
121 // this space fit in a single page, then we consider limiting the size
122 // of the first page. For this, we add the chunk sizes and some extra
123 // allowance. This way we achieve a smaller startup memory footprint.
124 required = (startup_reservations[startup_index].chunk_size() +
125 2 * context_reservations[context_index].chunk_size()) +
126 Page::kObjectStartOffset;
127 } else {
128 // We expect the vanilla snapshot to only require on page per space.
129 DCHECK(!is_default_snapshot);
130 }
131
132 if (space >= FIRST_PAGED_SPACE && space <= LAST_PAGED_SPACE) {
133 uint32_t max_size =
134 MemoryAllocator::PageAreaSize(static_cast<AllocationSpace>(space));
135 sizes_out[space - FIRST_PAGED_SPACE] = Min(required, max_size);
136 } else {
137 DCHECK(single_chunk);
138 }
139 startup_index++;
140 context_index++;
141 }
142
143 DCHECK_EQ(startup_reservations.length(), startup_index);
144 DCHECK_EQ(context_reservations.length(), context_index);
145 }
146
147
85 v8::StartupData Snapshot::CreateSnapshotBlob( 148 v8::StartupData Snapshot::CreateSnapshotBlob(
86 const Vector<const byte> startup_data, 149 const i::StartupSerializer& startup_ser,
87 const Vector<const byte> context_data, Snapshot::Metadata metadata) { 150 const i::PartialSerializer& context_ser, Snapshot::Metadata metadata) {
151 SnapshotData startup_snapshot(startup_ser);
152 SnapshotData context_snapshot(context_ser);
153 Vector<const byte> startup_data = startup_snapshot.RawData();
154 Vector<const byte> context_data = context_snapshot.RawData();
155
156 uint32_t first_page_sizes[kNumPagedSpaces];
157
158 CalculateFirstPageSizes(metadata.embeds_script(), startup_snapshot,
159 context_snapshot, first_page_sizes);
160
88 int startup_length = startup_data.length(); 161 int startup_length = startup_data.length();
89 int context_length = context_data.length(); 162 int context_length = context_data.length();
90 int context_offset = ContextOffset(startup_length); 163 int context_offset = ContextOffset(startup_length);
91 164
92 int length = context_offset + context_length; 165 int length = context_offset + context_length;
93 char* data = new char[length]; 166 char* data = new char[length];
94 167
95 memcpy(data + kMetadataOffset, &metadata.RawValue(), kInt32Size); 168 memcpy(data + kMetadataOffset, &metadata.RawValue(), kInt32Size);
169 memcpy(data + kFirstPageSizesOffset, first_page_sizes,
170 kNumPagedSpaces * kInt32Size);
96 memcpy(data + kStartupLengthOffset, &startup_length, kInt32Size); 171 memcpy(data + kStartupLengthOffset, &startup_length, kInt32Size);
97 memcpy(data + kStartupDataOffset, startup_data.begin(), startup_length); 172 memcpy(data + kStartupDataOffset, startup_data.begin(), startup_length);
98 memcpy(data + context_offset, context_data.begin(), context_length); 173 memcpy(data + context_offset, context_data.begin(), context_length);
99 v8::StartupData result = {data, length}; 174 v8::StartupData result = {data, length};
100 return result; 175 return result;
101 } 176 }
102 177
103 178
104 Snapshot::Metadata Snapshot::ExtractMetadata(const v8::StartupData* data) { 179 Snapshot::Metadata Snapshot::ExtractMetadata(const v8::StartupData* data) {
105 uint32_t raw; 180 uint32_t raw;
(...skipping 18 matching lines...) Expand all
124 int startup_length; 199 int startup_length;
125 memcpy(&startup_length, data->data + kStartupLengthOffset, kIntSize); 200 memcpy(&startup_length, data->data + kStartupLengthOffset, kIntSize);
126 int context_offset = ContextOffset(startup_length); 201 int context_offset = ContextOffset(startup_length);
127 const byte* context_data = 202 const byte* context_data =
128 reinterpret_cast<const byte*>(data->data + context_offset); 203 reinterpret_cast<const byte*>(data->data + context_offset);
129 DCHECK_LT(context_offset, data->raw_size); 204 DCHECK_LT(context_offset, data->raw_size);
130 int context_length = data->raw_size - context_offset; 205 int context_length = data->raw_size - context_offset;
131 return Vector<const byte>(context_data, context_length); 206 return Vector<const byte>(context_data, context_length);
132 } 207 }
133 } } // namespace v8::internal 208 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/snapshot.h ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698