Heap::reportAbandonedObjectGraph should not hasten an allocation-triggered collection
https://bugs.webkit.org/show_bug.cgi?id=85543
Reviewed by Filip Pizlo.
Currently reportAbandonedObjectGraph causes the Heap to think it is closer to its
allocation limit for the current cycle, thus hastening an allocation-triggered collection.
In reality, it should just affect the opportunistic GC timer. We should track the bytes
we think have been abandoned and the bytes that have been allocated separately.
* heap/Heap.cpp: Added a new field m_abandonedBytes to Heap to keep track of how much
we think we've abandoned.
(JSC::Heap::Heap):
(JSC::Heap::reportAbandonedObjectGraph):
(JSC):
(JSC::Heap::didAbandon): Added this function for reportAbandonedObjectGraph to call
rather than didAllocate. Works the same as didAllocate, but modifies bytes abandoned rather
than bytes allocated. Also notifies the timer, summing the two values together.
(JSC::Heap::collect):
(JSC::Heap::didAllocate): Now adds the bytes allocated and bytes abandoned when reporting
to GCActivityCallback.
* heap/Heap.h:
(Heap):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@116025 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/heap/Heap.cpp b/Source/JavaScriptCore/heap/Heap.cpp
index 0e378ef..e7fc525 100644
--- a/Source/JavaScriptCore/heap/Heap.cpp
+++ b/Source/JavaScriptCore/heap/Heap.cpp
@@ -316,6 +316,7 @@
, m_sizeAfterLastCollect(0)
, m_bytesAllocatedLimit(m_minBytesPerCycle)
, m_bytesAllocated(0)
+ , m_bytesAbandoned(0)
, m_operationInProgress(NoOperation)
, m_objectSpace(this)
, m_storageSpace(this)
@@ -401,7 +402,13 @@
// been abandoned, the next collection has the potential to
// be more profitable. Since allocation is the trigger for collection,
// we hasten the next collection by pretending that we've allocated more memory.
- didAllocate(abandonedBytes);
+ didAbandon(abandonedBytes);
+}
+
+void Heap::didAbandon(size_t bytes)
+{
+ m_activityCallback->didAllocate(m_bytesAllocated + m_bytesAbandoned);
+ m_bytesAbandoned += bytes;
}
void Heap::protect(JSValue k)
@@ -728,6 +735,7 @@
void Heap::collect(SweepToggle sweepToggle)
{
SamplingRegion samplingRegion("Garbage Collection");
+ fprintf(stdout, "running collection\n");
GCPHASE(Collect);
ASSERT(globalData()->identifierTable == wtfThreadData().currentIdentifierTable());
@@ -785,6 +793,7 @@
sweep();
m_objectSpace.shrink();
m_weakSet.shrink();
+ m_bytesAbandoned = 0;
}
// To avoid pathological GC churn in large heaps, we set the new allocation
@@ -826,7 +835,7 @@
void Heap::didAllocate(size_t bytes)
{
- m_activityCallback->didAllocate(m_bytesAllocated);
+ m_activityCallback->didAllocate(m_bytesAllocated + m_bytesAbandoned);
m_bytesAllocated += bytes;
}