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

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

Issue 2311963002: [heap,snapshot] Replace first page size from snapshots with page trimming (Closed)
Patch Set: Remove debugging print Created 4 years, 3 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/snapshot.h ('k') | test/cctest/heap/heap-utils.h » ('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/snapshot/snapshot.h" 7 #include "src/snapshot/snapshot.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"
(...skipping 13 matching lines...) Expand all
24 24
25 bool Snapshot::HasContextSnapshot(Isolate* isolate, size_t index) { 25 bool Snapshot::HasContextSnapshot(Isolate* isolate, size_t index) {
26 // Do not use snapshots if the isolate is used to create snapshots. 26 // Do not use snapshots if the isolate is used to create snapshots.
27 const v8::StartupData* blob = isolate->snapshot_blob(); 27 const v8::StartupData* blob = isolate->snapshot_blob();
28 if (blob == nullptr) return false; 28 if (blob == nullptr) return false;
29 if (blob->data == nullptr) return false; 29 if (blob->data == nullptr) return false;
30 size_t num_contexts = static_cast<size_t>(ExtractNumContexts(blob)); 30 size_t num_contexts = static_cast<size_t>(ExtractNumContexts(blob));
31 return index < num_contexts; 31 return index < num_contexts;
32 } 32 }
33 33
34
35 uint32_t Snapshot::SizeOfFirstPage(Isolate* isolate, AllocationSpace space) {
36 DCHECK(space >= FIRST_PAGED_SPACE && space <= LAST_PAGED_SPACE);
37 if (!isolate->snapshot_available()) {
38 return static_cast<uint32_t>(MemoryAllocator::PageAreaSize(space));
39 }
40 uint32_t size;
41 int offset = kFirstPageSizesOffset + (space - FIRST_PAGED_SPACE) * kInt32Size;
42 memcpy(&size, isolate->snapshot_blob()->data + offset, kInt32Size);
43 return size;
44 }
45
46
47 bool Snapshot::Initialize(Isolate* isolate) { 34 bool Snapshot::Initialize(Isolate* isolate) {
48 if (!isolate->snapshot_available()) return false; 35 if (!isolate->snapshot_available()) return false;
49 base::ElapsedTimer timer; 36 base::ElapsedTimer timer;
50 if (FLAG_profile_deserialization) timer.Start(); 37 if (FLAG_profile_deserialization) timer.Start();
51 38
52 const v8::StartupData* blob = isolate->snapshot_blob(); 39 const v8::StartupData* blob = isolate->snapshot_blob();
53 Vector<const byte> startup_data = ExtractStartupData(blob); 40 Vector<const byte> startup_data = ExtractStartupData(blob);
54 SnapshotData snapshot_data(startup_data); 41 SnapshotData snapshot_data(startup_data);
55 Deserializer deserializer(&snapshot_data); 42 Deserializer deserializer(&snapshot_data);
56 bool success = isolate->Init(&deserializer); 43 bool success = isolate->Init(&deserializer);
(...skipping 25 matching lines...) Expand all
82 CHECK(result->IsContext()); 69 CHECK(result->IsContext());
83 if (FLAG_profile_deserialization) { 70 if (FLAG_profile_deserialization) {
84 double ms = timer.Elapsed().InMillisecondsF(); 71 double ms = timer.Elapsed().InMillisecondsF();
85 int bytes = context_data.length(); 72 int bytes = context_data.length();
86 PrintF("[Deserializing context #%zu (%d bytes) took %0.3f ms]\n", 73 PrintF("[Deserializing context #%zu (%d bytes) took %0.3f ms]\n",
87 context_index, bytes, ms); 74 context_index, bytes, ms);
88 } 75 }
89 return Handle<Context>::cast(result); 76 return Handle<Context>::cast(result);
90 } 77 }
91 78
92 void UpdateMaxRequirementPerPage( 79 void ProfileDeserialization(const SnapshotData* startup_snapshot,
93 uint32_t* requirements, 80 const List<SnapshotData*>* context_snapshots) {
94 Vector<const SerializedData::Reservation> reservations) {
95 int space = 0;
96 uint32_t current_requirement = 0;
97 for (const auto& reservation : reservations) {
98 current_requirement += reservation.chunk_size();
99 if (reservation.is_last()) {
100 requirements[space] = std::max(requirements[space], current_requirement);
101 current_requirement = 0;
102 space++;
103 }
104 }
105 DCHECK_EQ(i::Serializer::kNumberOfSpaces, space);
106 }
107
108 void CalculateFirstPageSizes(const SnapshotData* startup_snapshot,
109 const List<SnapshotData*>* context_snapshots,
110 uint32_t* sizes_out) {
111 if (FLAG_profile_deserialization) { 81 if (FLAG_profile_deserialization) {
112 int startup_total = 0; 82 int startup_total = 0;
113 PrintF("Deserialization will reserve:\n"); 83 PrintF("Deserialization will reserve:\n");
114 for (const auto& reservation : startup_snapshot->Reservations()) { 84 for (const auto& reservation : startup_snapshot->Reservations()) {
115 startup_total += reservation.chunk_size(); 85 startup_total += reservation.chunk_size();
116 } 86 }
117 PrintF("%10d bytes per isolate\n", startup_total); 87 PrintF("%10d bytes per isolate\n", startup_total);
118 for (int i = 0; i < context_snapshots->length(); i++) { 88 for (int i = 0; i < context_snapshots->length(); i++) {
119 int context_total = 0; 89 int context_total = 0;
120 for (const auto& reservation : context_snapshots->at(i)->Reservations()) { 90 for (const auto& reservation : context_snapshots->at(i)->Reservations()) {
121 context_total += reservation.chunk_size(); 91 context_total += reservation.chunk_size();
122 } 92 }
123 PrintF("%10d bytes per context #%d\n", context_total, i); 93 PrintF("%10d bytes per context #%d\n", context_total, i);
124 } 94 }
125 } 95 }
126
127 uint32_t startup_requirements[i::Serializer::kNumberOfSpaces];
128 uint32_t context_requirements[i::Serializer::kNumberOfSpaces];
129 for (int space = 0; space < i::Serializer::kNumberOfSpaces; space++) {
130 startup_requirements[space] = 0;
131 context_requirements[space] = 0;
132 }
133
134 UpdateMaxRequirementPerPage(startup_requirements,
135 startup_snapshot->Reservations());
136 for (const auto& context_snapshot : *context_snapshots) {
137 UpdateMaxRequirementPerPage(context_requirements,
138 context_snapshot->Reservations());
139 }
140
141 for (int space = 0; space < i::Serializer::kNumberOfSpaces; space++) {
142 // If the space requirement for a page is less than a page size, we consider
143 // limiting the size of the first page in order to save memory on startup.
144 uint32_t required = startup_requirements[space] +
145 2 * context_requirements[space] +
146 Page::kObjectStartOffset;
147 // Add a small allowance to the code space for small scripts.
148 if (space == CODE_SPACE) required += 32 * KB;
149
150 if (space >= FIRST_PAGED_SPACE && space <= LAST_PAGED_SPACE) {
151 uint32_t max_size =
152 MemoryAllocator::PageAreaSize(static_cast<AllocationSpace>(space));
153 sizes_out[space - FIRST_PAGED_SPACE] = std::min(required, max_size);
154 }
155 }
156 } 96 }
157 97
158 v8::StartupData Snapshot::CreateSnapshotBlob( 98 v8::StartupData Snapshot::CreateSnapshotBlob(
159 const SnapshotData* startup_snapshot, 99 const SnapshotData* startup_snapshot,
160 const List<SnapshotData*>* context_snapshots) { 100 const List<SnapshotData*>* context_snapshots) {
161 int num_contexts = context_snapshots->length(); 101 int num_contexts = context_snapshots->length();
162 int startup_snapshot_offset = StartupSnapshotOffset(num_contexts); 102 int startup_snapshot_offset = StartupSnapshotOffset(num_contexts);
163 int total_length = startup_snapshot_offset; 103 int total_length = startup_snapshot_offset;
164 total_length += startup_snapshot->RawData().length(); 104 total_length += startup_snapshot->RawData().length();
165 for (const auto& context_snapshot : *context_snapshots) { 105 for (const auto& context_snapshot : *context_snapshots) {
166 total_length += context_snapshot->RawData().length(); 106 total_length += context_snapshot->RawData().length();
167 } 107 }
168 108
169 uint32_t first_page_sizes[kNumPagedSpaces]; 109 ProfileDeserialization(startup_snapshot, context_snapshots);
170 CalculateFirstPageSizes(startup_snapshot, context_snapshots,
171 first_page_sizes);
172 110
173 char* data = new char[total_length]; 111 char* data = new char[total_length];
174 memcpy(data + kFirstPageSizesOffset, first_page_sizes,
175 kNumPagedSpaces * kInt32Size);
176 memcpy(data + kNumberOfContextsOffset, &num_contexts, kInt32Size); 112 memcpy(data + kNumberOfContextsOffset, &num_contexts, kInt32Size);
177 int payload_offset = StartupSnapshotOffset(num_contexts); 113 int payload_offset = StartupSnapshotOffset(num_contexts);
178 int payload_length = startup_snapshot->RawData().length(); 114 int payload_length = startup_snapshot->RawData().length();
179 memcpy(data + payload_offset, startup_snapshot->RawData().start(), 115 memcpy(data + payload_offset, startup_snapshot->RawData().start(),
180 payload_length); 116 payload_length);
181 if (FLAG_profile_deserialization) { 117 if (FLAG_profile_deserialization) {
182 PrintF("Snapshot blob consists of:\n%10d bytes for startup\n", 118 PrintF("Snapshot blob consists of:\n%10d bytes for startup\n",
183 payload_length); 119 payload_length);
184 } 120 }
185 payload_offset += payload_length; 121 payload_offset += payload_length;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 Vector<const byte> SnapshotData::Payload() const { 220 Vector<const byte> SnapshotData::Payload() const {
285 int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size; 221 int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size;
286 const byte* payload = data_ + kHeaderSize + reservations_size; 222 const byte* payload = data_ + kHeaderSize + reservations_size;
287 int length = GetHeaderValue(kPayloadLengthOffset); 223 int length = GetHeaderValue(kPayloadLengthOffset);
288 DCHECK_EQ(data_ + size_, payload + length); 224 DCHECK_EQ(data_ + size_, payload + length);
289 return Vector<const byte>(payload, length); 225 return Vector<const byte>(payload, length);
290 } 226 }
291 227
292 } // namespace internal 228 } // namespace internal
293 } // namespace v8 229 } // namespace v8
OLDNEW
« no previous file with comments | « src/snapshot/snapshot.h ('k') | test/cctest/heap/heap-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698