Index: Source/platform/heap/ThreadState.cpp |
diff --git a/Source/platform/heap/ThreadState.cpp b/Source/platform/heap/ThreadState.cpp |
index e4c8669990f7e6c3652fdec1903c184ca9ddc586..9498a2dabdbdc2a2183294d7cf2d97b327c4c86f 100644 |
--- a/Source/platform/heap/ThreadState.cpp |
+++ b/Source/platform/heap/ThreadState.cpp |
@@ -572,6 +572,20 @@ bool ThreadState::shouldSchedulePreciseGC() |
#endif |
} |
+namespace { |
haraken
2015/06/11 04:10:30
Or static. No strong opinion.
|
+ |
+inline bool shouldForceMemoryPressureGC(size_t currentSize, size_t estimatedSize) |
haraken
2015/06/11 04:10:30
currentObjectSize, estimatedLiveObjectSize
|
+{ |
+ if (currentSize < 300 * 1024 * 1024) |
+ return false; |
+ |
+ // If we're consuming too much memory, trigger a conservative GC |
+ // aggressively. This is a safe guard to avoid OOM. |
+ return (currentSize >> 10) > (estimatedSize >> 10) * 3 / 2; |
haraken
2015/06/11 04:10:30
Add a comment about why we want to shift the size.
sof
2015/06/11 08:45:02
Done.
|
+} |
+ |
+} // namespace |
+ |
// TODO(haraken): We should improve the GC heuristics. |
// These heuristics affect performance significantly. |
bool ThreadState::shouldForceConservativeGC() |
@@ -587,11 +601,8 @@ bool ThreadState::shouldForceConservativeGC() |
// Heap::markedObjectSize() may be underestimated if any thread has not |
// finished completeSweep(). |
size_t currentObjectSize = allocatedObjectSize + Heap::markedObjectSize() + WTF::Partitions::totalSizeOfCommittedPages(); |
- if (currentObjectSize >= 300 * 1024 * 1024) { |
- // If we're consuming too much memory, trigger a conservative GC |
- // aggressively. This is a safe guard to avoid OOM. |
- return currentObjectSize > estimatedLiveObjectSize * 3 / 2; |
- } |
+ if (shouldForceMemoryPressureGC(currentObjectSize, estimatedLiveObjectSize)) |
+ return true; |
// Schedule a conservative GC if Oilpan has allocated more than 32 MB since |
// the last GC and the current memory usage is >400% larger than |
// the estimated live memory usage. |
@@ -792,6 +803,13 @@ void ThreadState::didV8GC() |
{ |
checkThread(); |
if (isMainThread()) { |
+ size_t currentObjectSize = Heap::allocatedObjectSize() + Heap::markedObjectSize() + WTF::Partitions::totalSizeOfCommittedPages(); |
haraken
2015/06/11 04:10:31
Or you can do:
if (shouldForceMemoryPressureGC(
|
+ size_t estimatedLiveObjectSize = Heap::estimatedLiveObjectSize(); |
+ if (shouldForceMemoryPressureGC(currentObjectSize, estimatedLiveObjectSize)) { |
+ // Under memory pressure, force a conservative GC. |
+ Heap::collectGarbage(HeapPointersOnStack, GCWithoutSweep, Heap::ConservativeGC); |
+ return; |
+ } |
// Lower the estimated live object size because the V8 major GC is |
// expected to have collected a lot of DOM wrappers and dropped |
// references to their DOM objects. |