mmgc-threadsafe-gctests
author jorendorff@mozilla.com
Fri, 04 Jan 2008 16:11:56 -0600
changeset 32 5900e6424cbd989bcd7f8d3ff2c4bc2857f98ac1
parent 21 ed155007d2cd37876539f30bb6e2d35b34f80b94
child 34 ec1155ba48ec7f8f8b0c2e5f35f619d0ea4e95e3
permissions -rw-r--r--
Preliminarily split mmgc-threadsafe into two parts, mmgc-threadsafe-baseline containing only the changes that are in tamarin-central, and mmgc-threadsafe containing additional actionmonkey-specific stuff on top of that.

diff --git a/MMgc/GCTests.cpp b/MMgc/GCTests.cpp
--- a/MMgc/GCTests.cpp
+++ b/MMgc/GCTests.cpp
@@ -55,6 +55,15 @@ namespace MMgc
 {
 	GC *gc;
 
+	void collect()
+	{
+#ifdef MMGC_THREADSAFE
+		gc->CollectFromRequest();
+#else
+		gc->Collect();
+#endif
+	}
+
 	GCWeakRef* createWeakRef(int extra = 0)
 	{
 		// Bogusly use up some extra stack.
@@ -65,11 +74,11 @@ namespace MMgc
 		// pointer there causes the temporary to be marked, and not collected,
 		// which causes tests to fail with assertions.
 		///
-		// The extra 32 bytes here causes the temporary to end up higher on
+		// The extra 64 bytes here causes the temporary to end up higher on
 		// the stack (numerically lesser address, on Intel at least) where
 		// CleanStack will clobber it.
 		//
-		char buf[32];
+		char buf[64];
 		sprintf(buf, "%d", extra);  // don't optimize away buf
 
 		return (new (gc, extra) GCObject())->GetWeakRef();
@@ -78,9 +87,9 @@ namespace MMgc
 	void weakRefSweepSmall()
 	{
 		GCWeakRef *ref = createWeakRef();
-		gc->Collect();
+		collect();
 		gc->CleanStack(true);
-		gc->Collect();
+		collect();
 		(void)ref;
 		GCAssert(ref->get() == NULL);
 	}
@@ -88,9 +97,9 @@ namespace MMgc
 	void weakRefSweepLarge()
 	{
 		GCWeakRef *ref = createWeakRef(5000);
-		gc->Collect();
+		collect();
 		gc->CleanStack(true);
-		gc->Collect();
+		collect();
 		(void)ref;
 		GCAssert(ref->get() == NULL);
 	}
@@ -166,11 +175,17 @@ namespace MMgc
 	void RunGCTests(GC *g)
 	{
 		gc = g;
+#ifdef MMGC_THREADSAFE
+		g->OnEnterRequest();
+#endif
 		weakRefSweepSmall();
 		weakRefSweepLarge();
 		weakRefFreeSmall();
 		weakRefFreeLarge();
 		drcApolloTest();
+#ifdef MMGC_THREADSAFE
+		g->OnLeaveRequest();
+#endif
 	}
 }