Index: Source/platform/heap/Heap.cpp |
diff --git a/Source/platform/heap/Heap.cpp b/Source/platform/heap/Heap.cpp |
index dfe3e0e773fac5a0817483677da6f0fd45d8706c..18c464672864edfa7374e87db63aeac5a26d4be3 100644 |
--- a/Source/platform/heap/Heap.cpp |
+++ b/Source/platform/heap/Heap.cpp |
@@ -2439,8 +2439,7 @@ void Heap::collectGarbage(ThreadState::StackState stackState, ThreadState::GCTyp |
s_markingVisitor->configureEagerTraceLimit(); |
ASSERT(s_markingVisitor->canTraceEagerly()); |
- Heap::resetMarkedObjectSize(); |
- Heap::resetAllocatedObjectSize(); |
+ Heap::resetHeapCounters(); |
// 1. Trace persistent roots. |
ThreadState::visitPersistentRoots(s_markingVisitor); |
@@ -2815,6 +2814,52 @@ void Heap::RegionTree::remove(PageMemoryRegion* region, RegionTree** context) |
delete current; |
} |
+void Heap::resetHeapCounters() |
+{ |
+ ASSERT(ThreadState::current()->isInGC()); |
+ |
+ s_allocatedObjectSize = 0; |
+ s_markedObjectSize = 0; |
+ |
+ // Similarly, reset the amount of externally allocated memory. |
+ s_externallyAllocatedBytes = 0; |
+ s_externallyAllocatedBytesAlive = 0; |
+ |
+ s_requestedUrgentGC = false; |
+} |
+ |
+void Heap::increaseExternallyAllocatedBytes(size_t delta) |
+{ |
+ atomicAdd(&s_externallyAllocatedBytes, static_cast<long>(delta)); |
haraken
2015/02/19 23:47:43
You can use the return value of atomicAdd, instead
sof
2015/02/20 09:33:49
Inlined and tidied.
|
+ |
+ if (isGCUrgentlyRequested()) |
+ return; |
+ |
+ // Flag GC urgency on a 50% increase in external allocation |
+ // since the last GC, but not for less than 100M. |
+ // |
+ // FIXME: consider other, 'better' policies (e.g., have the count of |
+ // heap objects with external allocations be taken into |
+ // account, ...) The overall goal here is to trigger a |
+ // GC such that it considerably lessens memory pressure |
+ // for a renderer process. |
+ size_t externalBytesSinceGC = externallyAllocatedBytes(); |
haraken
2015/02/19 23:47:43
externalBytesSinceLastGC
|
+ if (externalBytesSinceGC < 100 * 1024 * 1024) |
+ return; |
+ |
+ size_t externalBytesAlive = externallyAllocatedBytesAlive(); |
+ |
+ // The urgent-gc flag will be considered the next time an out-of-line |
+ // allocation is made. Bump allocations from the current block will |
+ // go ahead until it can no longer service an allocation request. |
+ // |
+ // FIXME: if that delays urgently needed GCs for too long, consider |
+ // flushing out per-heap "allocation points" to trigger the GC |
+ // right away. |
+ if (externalBytesSinceGC > externalBytesAlive / 2) |
+ Heap::requestUrgentGC(); |
+} |
+ |
Visitor* Heap::s_markingVisitor; |
CallbackStack* Heap::s_markingStack; |
CallbackStack* Heap::s_postMarkingCallbackStack; |
@@ -2830,4 +2875,8 @@ size_t Heap::s_allocatedObjectSize = 0; |
size_t Heap::s_allocatedSpace = 0; |
size_t Heap::s_markedObjectSize = 0; |
+size_t Heap::s_externallyAllocatedBytes = 0; |
+size_t Heap::s_externallyAllocatedBytesAlive = 0; |
+unsigned Heap::s_requestedUrgentGC = false; |
+ |
} // namespace blink |