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

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

Issue 2229403003: Revert of [heap] Switch to 500k pages (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 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/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/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
34 bool Snapshot::Initialize(Isolate* isolate) { 47 bool Snapshot::Initialize(Isolate* isolate) {
35 if (!isolate->snapshot_available()) return false; 48 if (!isolate->snapshot_available()) return false;
36 base::ElapsedTimer timer; 49 base::ElapsedTimer timer;
37 if (FLAG_profile_deserialization) timer.Start(); 50 if (FLAG_profile_deserialization) timer.Start();
38 51
39 const v8::StartupData* blob = isolate->snapshot_blob(); 52 const v8::StartupData* blob = isolate->snapshot_blob();
40 Vector<const byte> startup_data = ExtractStartupData(blob); 53 Vector<const byte> startup_data = ExtractStartupData(blob);
41 SnapshotData snapshot_data(startup_data); 54 SnapshotData snapshot_data(startup_data);
42 Deserializer deserializer(&snapshot_data); 55 Deserializer deserializer(&snapshot_data);
43 bool success = isolate->Init(&deserializer); 56 bool success = isolate->Init(&deserializer);
(...skipping 25 matching lines...) Expand all
69 CHECK(result->IsContext()); 82 CHECK(result->IsContext());
70 if (FLAG_profile_deserialization) { 83 if (FLAG_profile_deserialization) {
71 double ms = timer.Elapsed().InMillisecondsF(); 84 double ms = timer.Elapsed().InMillisecondsF();
72 int bytes = context_data.length(); 85 int bytes = context_data.length();
73 PrintF("[Deserializing context #%zu (%d bytes) took %0.3f ms]\n", 86 PrintF("[Deserializing context #%zu (%d bytes) took %0.3f ms]\n",
74 context_index, bytes, ms); 87 context_index, bytes, ms);
75 } 88 }
76 return Handle<Context>::cast(result); 89 return Handle<Context>::cast(result);
77 } 90 }
78 91
79 void ProfileDeserialization(const SnapshotData* startup_snapshot, 92 void UpdateMaxRequirementPerPage(
80 const List<SnapshotData*>* context_snapshots) { 93 uint32_t* requirements,
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) {
81 if (FLAG_profile_deserialization) { 111 if (FLAG_profile_deserialization) {
82 int startup_total = 0; 112 int startup_total = 0;
83 PrintF("Deserialization will reserve:\n"); 113 PrintF("Deserialization will reserve:\n");
84 for (const auto& reservation : startup_snapshot->Reservations()) { 114 for (const auto& reservation : startup_snapshot->Reservations()) {
85 startup_total += reservation.chunk_size(); 115 startup_total += reservation.chunk_size();
86 } 116 }
87 PrintF("%10d bytes per isolate\n", startup_total); 117 PrintF("%10d bytes per isolate\n", startup_total);
88 for (int i = 0; i < context_snapshots->length(); i++) { 118 for (int i = 0; i < context_snapshots->length(); i++) {
89 int context_total = 0; 119 int context_total = 0;
90 for (const auto& reservation : context_snapshots->at(i)->Reservations()) { 120 for (const auto& reservation : context_snapshots->at(i)->Reservations()) {
91 context_total += reservation.chunk_size(); 121 context_total += reservation.chunk_size();
92 } 122 }
93 PrintF("%10d bytes per context #%d\n", context_total, i); 123 PrintF("%10d bytes per context #%d\n", context_total, i);
94 } 124 }
95 } 125 }
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 }
96 } 156 }
97 157
98 v8::StartupData Snapshot::CreateSnapshotBlob( 158 v8::StartupData Snapshot::CreateSnapshotBlob(
99 const SnapshotData* startup_snapshot, 159 const SnapshotData* startup_snapshot,
100 const List<SnapshotData*>* context_snapshots) { 160 const List<SnapshotData*>* context_snapshots) {
101 int num_contexts = context_snapshots->length(); 161 int num_contexts = context_snapshots->length();
102 int startup_snapshot_offset = StartupSnapshotOffset(num_contexts); 162 int startup_snapshot_offset = StartupSnapshotOffset(num_contexts);
103 int total_length = startup_snapshot_offset; 163 int total_length = startup_snapshot_offset;
104 total_length += startup_snapshot->RawData().length(); 164 total_length += startup_snapshot->RawData().length();
105 for (const auto& context_snapshot : *context_snapshots) { 165 for (const auto& context_snapshot : *context_snapshots) {
106 total_length += context_snapshot->RawData().length(); 166 total_length += context_snapshot->RawData().length();
107 } 167 }
108 168
109 ProfileDeserialization(startup_snapshot, context_snapshots); 169 uint32_t first_page_sizes[kNumPagedSpaces];
170 CalculateFirstPageSizes(startup_snapshot, context_snapshots,
171 first_page_sizes);
110 172
111 char* data = new char[total_length]; 173 char* data = new char[total_length];
174 memcpy(data + kFirstPageSizesOffset, first_page_sizes,
175 kNumPagedSpaces * kInt32Size);
112 memcpy(data + kNumberOfContextsOffset, &num_contexts, kInt32Size); 176 memcpy(data + kNumberOfContextsOffset, &num_contexts, kInt32Size);
113 int payload_offset = StartupSnapshotOffset(num_contexts); 177 int payload_offset = StartupSnapshotOffset(num_contexts);
114 int payload_length = startup_snapshot->RawData().length(); 178 int payload_length = startup_snapshot->RawData().length();
115 memcpy(data + payload_offset, startup_snapshot->RawData().start(), 179 memcpy(data + payload_offset, startup_snapshot->RawData().start(),
116 payload_length); 180 payload_length);
117 if (FLAG_profile_deserialization) { 181 if (FLAG_profile_deserialization) {
118 PrintF("Snapshot blob consists of:\n%10d bytes for startup\n", 182 PrintF("Snapshot blob consists of:\n%10d bytes for startup\n",
119 payload_length); 183 payload_length);
120 } 184 }
121 payload_offset += payload_length; 185 payload_offset += payload_length;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 Vector<const byte> SnapshotData::Payload() const { 284 Vector<const byte> SnapshotData::Payload() const {
221 int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size; 285 int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size;
222 const byte* payload = data_ + kHeaderSize + reservations_size; 286 const byte* payload = data_ + kHeaderSize + reservations_size;
223 int length = GetHeaderValue(kPayloadLengthOffset); 287 int length = GetHeaderValue(kPayloadLengthOffset);
224 DCHECK_EQ(data_ + size_, payload + length); 288 DCHECK_EQ(data_ + size_, payload + length);
225 return Vector<const byte>(payload, length); 289 return Vector<const byte>(payload, length);
226 } 290 }
227 291
228 } // namespace internal 292 } // namespace internal
229 } // namespace v8 293 } // namespace v8
OLDNEW
« no previous file with comments | « src/snapshot/snapshot.h ('k') | test/cctest/heap/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698