Chromium Code Reviews| Index: src/heap/spaces.cc |
| diff --git a/src/heap/spaces.cc b/src/heap/spaces.cc |
| index b31aaf3998fd98a370b3a329dcfb992c12f9e112..18d8e228fbbee6659e950ecd8048a479f575b55e 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) { |
|
Hannes Payer (out of office)
2016/08/08 16:25:02
I think this if case should be a DCHECK and the el
Michael Lippautz
2016/08/09 11:30:25
Obsolete.
|
| + // Count how much we have served already. |
| + size_t memory_served = 0; |
| + for (Page* page : *this) { |
| + memory_served += page->area_size(); |
|
Hannes Payer (out of office)
2016/08/08 16:25:02
size of actual objects would be more precise here.
Michael Lippautz
2016/08/09 11:30:25
Obsolete.
|
| + } |
| + size_t needed = static_cast<size_t>(snapshot_requires) - memory_served; |
| + const int area_size = MemoryAllocator::PageAreaSize(identity()); |
|
Hannes Payer (out of office)
2016/08/08 16:25:02
Just call AreaSize() here.
Michael Lippautz
2016/08/09 11:30:25
Obsolete.
|
| + if (needed >= static_cast<size_t>(area_size)) return area_size; |
| + // 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); |
|
Hannes Payer (out of office)
2016/08/08 16:25:02
Maybe we should do a different approach here:
How
Michael Lippautz
2016/08/09 11:30:25
Done.
|
| } |
| + 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. |