Index: src/heap/spaces.cc |
diff --git a/src/heap/spaces.cc b/src/heap/spaces.cc |
index 238fc9b39318b583f1580642a0484dec2be7db66..3fb21691959ad383ec17b10481204112dd62884d 100644 |
--- a/src/heap/spaces.cc |
+++ b/src/heap/spaces.cc |
@@ -1213,17 +1213,39 @@ Object* PagedSpace::FindObject(Address addr) { |
return Smi::FromInt(0); |
} |
-bool PagedSpace::Expand() { |
- int size = AreaSize(); |
- if (snapshotable() && !HasPages()) { |
- size = Snapshot::SizeOfFirstPage(heap()->isolate(), identity()); |
+int PagedSpace::AreaSizeDuringDeserialization() { |
+ // Try to keep the memory as compact as possible for a snapshot. This way the |
+ // heap stays small for small/empty scripts. |
+ DCHECK(snapshotable()); |
+ DCHECK(!heap()->deserialization_complete()); |
+ uint32_t snapshot_requires = |
+ Snapshot::SizeOfSnapshot(heap()->isolate(), identity()); |
+ if (snapshot_requires > 0) { |
+ // Count how much we have served already. |
+ size_t memory_served = 0; |
+ for (Page* page : *this) { |
+ memory_served += page->area_size(); |
+ } |
+ size_t needed = static_cast<size_t>(snapshot_requires) - memory_served; |
+ const int area_size = MemoryAllocator::PageAreaSize(identity()); |
+ if (needed / area_size > 0) return area_size; |
ulan
2016/08/03 10:31:51
if (need >= area_size) return area_size
Michael Lippautz
2016/08/04 08:43:57
Done.
|
+ // Less than a page of memory needed. We need to allocate at least |
+ // kMaxRegularHeapObjectSize of space. |
+ if (needed < Page::kMaxRegularHeapObjectSize) |
+ return Page::kMaxRegularHeapObjectSize; |
+ return static_cast<int>(needed); |
} |
+ return AreaSize(); |
+} |
- if (!heap()->CanExpandOldGeneration(size)) return false; |
+bool PagedSpace::Expand() { |
+ int size = heap()->deserialization_complete() |
+ ? AreaSize() |
+ : AreaSizeDuringDeserialization(); |
+ if (!heap()->CanExpandOldGeneration(size)) return false; |
Page* p = heap()->memory_allocator()->AllocatePage(size, this, executable()); |
if (p == nullptr) return false; |
- |
AccountCommitted(static_cast<intptr_t>(p->size())); |
// Pages created during bootstrapping may contain immortal immovable objects. |