Add patch for bug 392602
authorjorendorff@mozilla.com
Tue, 18 Dec 2007 10:40:58 -0600
changeset 24 7b177201b469
parent 23 debe472d7df5
child 25 bc21193f2b1c
push id1
push userbsmedberg@mozilla.com
push dateMon, 21 Apr 2008 01:54:18 +0000
bugs392602
Add patch for bug 392602
mmgc-maybegc
series
new file mode 100644
--- /dev/null
+++ b/mmgc-maybegc
@@ -0,0 +1,70 @@
+diff --git a/MMgc/GC.cpp b/MMgc/GC.cpp
+--- a/MMgc/GC.cpp
++++ b/MMgc/GC.cpp
+@@ -745,6 +745,42 @@ namespace MMgc
+ 		return item;
+ 	}
+ 
++	void GC::MaybeGC(bool callerHasActiveRequest)
++	{
++		if (greedy) {
++			CollectWithBookkeeping(false, callerHasActiveRequest);
++		} else if (marking) {
++			IncrementalMark();
++		} else {
++#ifdef MMGC_THREADSAFE
++			GCAutoLock _lock(m_lock);
++#endif
++
++			// Burst logic to prevent collections from happening back to back.
++			uint64 now = GetPerformanceCounter();
++			if (now - lastSweepTicks <= kMarkSweepBurstTicks)
++				return;
++
++			// Definitely start GC if the heap expanded due to FixedMalloc
++			// allocations.  The same heuristic applies to incremental and
++			// non-incremental.
++			bool force = (heapSizeAtLastAlloc > collectThreshold &&
++						  heapSizeAtLastAlloc < heap->GetTotalHeapSize());
++
++			if (incremental) {
++				if (force || (totalGCPages > collectThreshold &&
++							  allocsSinceCollect * kFreeSpaceDivisor >= totalGCPages)) {
++					StartIncrementalMark();
++				}
++			} else {
++				// Collect only if the heap is completely full (a conservative
++				// heuristic).
++				if (force || heap->GetFreeHeapSize() == 0)
++					CollectWithBookkeeping(true, callerHasActiveRequest);
++			}
++		}
++	}
++
+ 	void *GC::Calloc(size_t num, size_t elsize, int flags, int skip)
+ 	{
+ 		uint64 size = (uint64)num * (uint64)elsize;
+diff --git a/MMgc/GC.h b/MMgc/GC.h
+--- a/MMgc/GC.h
++++ b/MMgc/GC.h
+@@ -673,6 +673,20 @@ namespace MMgc
+ 		void Collect();
+ 
+ 		/**
++		 * Perform some GC-related work if needed.  Call this during
++		 * application down time.
++		 *
++		 * In incremental mode, this may result in a call to
++		 * StartIncrementalMark() or IncrementalMark(), which may in turn push
++		 * the current GC cycle to completion.  In non-incremental mode, this
++		 * heuristically decides whether to do a full Collect().
++		 *
++		 * @param callerHasActiveRequest
++		 *     Must be true iff the calling thread is already in a request.
++		 */
++		void MaybeGC(bool callerHasActiveRequest=false);
++
++		/**
+ 		* flags to be passed as second argument to alloc
+ 		*/
+ 		enum AllocFlags
--- a/series
+++ b/series
@@ -1,6 +1,7 @@
 tweak-esc-main.sh
 configure-with-threadsafe-mmgc
 mmgc-threadsafe
 mmgc-threadsafe-gctests
+mmgc-maybegc
 mmgc-graphviz
 mmgc-bit-checks