OLD | NEW |
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 Loading... |
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 | 34 uint32_t Snapshot::SizeOfSnapshot(Isolate* isolate, AllocationSpace space) { |
35 uint32_t Snapshot::SizeOfFirstPage(Isolate* isolate, AllocationSpace space) { | |
36 DCHECK(space >= FIRST_PAGED_SPACE && space <= LAST_PAGED_SPACE); | 35 DCHECK(space >= FIRST_PAGED_SPACE && space <= LAST_PAGED_SPACE); |
37 if (!isolate->snapshot_available()) { | 36 if (!isolate->snapshot_available()) { |
38 return static_cast<uint32_t>(MemoryAllocator::PageAreaSize(space)); | 37 return 0; |
39 } | 38 } |
40 uint32_t size; | 39 uint32_t size; |
41 int offset = kFirstPageSizesOffset + (space - FIRST_PAGED_SPACE) * kInt32Size; | 40 int offset = kFirstPageSizesOffset + (space - FIRST_PAGED_SPACE) * kInt32Size; |
42 memcpy(&size, isolate->snapshot_blob()->data + offset, kInt32Size); | 41 memcpy(&size, isolate->snapshot_blob()->data + offset, kInt32Size); |
43 return size; | 42 return size; |
44 } | 43 } |
45 | 44 |
46 | 45 |
47 bool Snapshot::Initialize(Isolate* isolate) { | 46 bool Snapshot::Initialize(Isolate* isolate) { |
48 if (!isolate->snapshot_available()) return false; | 47 if (!isolate->snapshot_available()) return false; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 for (int space = 0; space < i::Serializer::kNumberOfSpaces; space++) { | 140 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 | 141 // 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. | 142 // limiting the size of the first page in order to save memory on startup. |
144 uint32_t required = startup_requirements[space] + | 143 uint32_t required = startup_requirements[space] + |
145 2 * context_requirements[space] + | 144 2 * context_requirements[space] + |
146 Page::kObjectStartOffset; | 145 Page::kObjectStartOffset; |
147 // Add a small allowance to the code space for small scripts. | 146 // Add a small allowance to the code space for small scripts. |
148 if (space == CODE_SPACE) required += 32 * KB; | 147 if (space == CODE_SPACE) required += 32 * KB; |
149 | 148 |
150 if (space >= FIRST_PAGED_SPACE && space <= LAST_PAGED_SPACE) { | 149 if (space >= FIRST_PAGED_SPACE && space <= LAST_PAGED_SPACE) { |
151 uint32_t max_size = | 150 sizes_out[space - FIRST_PAGED_SPACE] = required; |
152 MemoryAllocator::PageAreaSize(static_cast<AllocationSpace>(space)); | |
153 sizes_out[space - FIRST_PAGED_SPACE] = std::min(required, max_size); | |
154 } | 151 } |
155 } | 152 } |
156 } | 153 } |
157 | 154 |
158 v8::StartupData Snapshot::CreateSnapshotBlob( | 155 v8::StartupData Snapshot::CreateSnapshotBlob( |
159 const SnapshotData* startup_snapshot, | 156 const SnapshotData* startup_snapshot, |
160 const List<SnapshotData*>* context_snapshots) { | 157 const List<SnapshotData*>* context_snapshots) { |
161 int num_contexts = context_snapshots->length(); | 158 int num_contexts = context_snapshots->length(); |
162 int startup_snapshot_offset = StartupSnapshotOffset(num_contexts); | 159 int startup_snapshot_offset = StartupSnapshotOffset(num_contexts); |
163 int total_length = startup_snapshot_offset; | 160 int total_length = startup_snapshot_offset; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 Vector<const byte> SnapshotData::Payload() const { | 281 Vector<const byte> SnapshotData::Payload() const { |
285 int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size; | 282 int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size; |
286 const byte* payload = data_ + kHeaderSize + reservations_size; | 283 const byte* payload = data_ + kHeaderSize + reservations_size; |
287 int length = GetHeaderValue(kPayloadLengthOffset); | 284 int length = GetHeaderValue(kPayloadLengthOffset); |
288 DCHECK_EQ(data_ + size_, payload + length); | 285 DCHECK_EQ(data_ + size_, payload + length); |
289 return Vector<const byte>(payload, length); | 286 return Vector<const byte>(payload, length); |
290 } | 287 } |
291 | 288 |
292 } // namespace internal | 289 } // namespace internal |
293 } // namespace v8 | 290 } // namespace v8 |
OLD | NEW |