From 2d74ae51ec3fc0e90ccfa12cc3930674d20370e8 Mon Sep 17 00:00:00 2001
From: jzhou <jzhou>
Date: Thu, 2 Sep 2010 18:57:58 +0000
Subject: [PATCH] Fix the 'markbit' bug of cache-adapt multicoregc version.  In
 the compact phase, some cores might need to move some local objects to some
 other remote cores.  There could be cache incoherent problem caused by the
 mark bit.  To fix it, in the mark phase, whenever the mark bit is changed,
 flush it to the main memory and after the mark phase is finished add a
 'barrier' before starting the compact phase

---
 Robust/src/Runtime/bamboo/multicoregarbage.c | 13 +++++++++++--
 Robust/src/Runtime/bamboo/multicoreruntime.h |  4 ++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/Robust/src/Runtime/bamboo/multicoregarbage.c b/Robust/src/Runtime/bamboo/multicoregarbage.c
index 8ecfb6ee..b3ef31f7 100644
--- a/Robust/src/Runtime/bamboo/multicoregarbage.c
+++ b/Robust/src/Runtime/bamboo/multicoregarbage.c
@@ -243,7 +243,7 @@ inline void * gc_lobjdequeue_I(int * length,
       gclobjspare=tmp;
       tmp->next = NULL;
       tmp->prev = NULL;
-    }             // if (gclobjspare!=NULL)
+    }  // if (gclobjspare!=NULL)
   } // if (gclobjtailindex==NUMLOBJPTRS)
   if(length != NULL) {
     *length = gclobjtail->lengths[gclobjtailindex];
@@ -1223,6 +1223,7 @@ inline void markObj(void * objptr) {
 		// this is the first time that this object is discovered,
 		// set the flag as DISCOVERED
 		((int *)objptr)[6] |= DISCOVERED;
+		BAMBOO_CACHE_FLUSH_RANGE_NO_FENCE(objptr, (7*sizeof(int)));
 		gc_enqueue_I(objptr);
 	  }
       BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
@@ -1436,6 +1437,7 @@ inline void mark(bool isfirst,
 			BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
 			// mark this obj
 			((int *)ptr)[6] = ((int *)ptr)[6] & (~DISCOVERED) | MARKED;
+			BAMBOO_CACHE_FLUSH_RANGE_NO_FENCE(ptr, (7*sizeof(int)));
 		  } else if(isnotmarked) {
 			// ptr is an unmarked active object on this core
 			ALIGNSIZE(size, &isize);
@@ -1448,6 +1450,7 @@ inline void mark(bool isfirst,
 #endif
 			// mark this obj
 			((int *)ptr)[6] = ((int *)ptr)[6] & (~DISCOVERED) | MARKED;
+			BAMBOO_CACHE_FLUSH_RANGE_NO_FENCE(ptr, (7*sizeof(int)));
 		  
 			if(ptr + size > gcmarkedptrbound) {
 			  gcmarkedptrbound = ptr + size;
@@ -1541,7 +1544,10 @@ inline void mark(bool isfirst,
 #endif
       return;
     }
-  }       // while(MARKPHASE == gcphase)
+  } // while(MARKPHASE == gcphase)
+
+  BAMBOO_CLEAN_DTLB();
+  BAMBOO_CACHE_MEM_FENCE_INCOHERENT();
 } // mark()
 
 inline void compact2Heaptophelper_I(int coren,
@@ -3164,6 +3170,9 @@ inline void gc_master(struct garbagelist * stackptr) {
 	gcrequiredmems[i] = 0;
   }
 
+  BAMBOO_CLEAN_DTLB();
+  BAMBOO_CACHE_MEM_FENCE_INCOHERENT();
+
 #ifdef GC_PROFILE
   gc_profileItem();
 #endif
diff --git a/Robust/src/Runtime/bamboo/multicoreruntime.h b/Robust/src/Runtime/bamboo/multicoreruntime.h
index c734d5cc..958f9f65 100644
--- a/Robust/src/Runtime/bamboo/multicoreruntime.h
+++ b/Robust/src/Runtime/bamboo/multicoreruntime.h
@@ -598,6 +598,10 @@ void outputProfileData();
 // BAMBOO_CLEAN_DTLB(): zero-out all the dtlb entries                      //
 // BAMBOO_CACHE_FLUSH_L2(): Flush the contents of this tile's L2 back to   //
 //                          main memory                                    //
+// BAMBOO_CACHE_FLUSH_RANGE_NO_FENCE(x, y): flush a range of mem without   //
+//                                          mem fence                      //
+// BAMBOO_CACHE_MEM_FENCE_INCOHERENT(): fence to guarantee visibility of   //
+//                                      stores to incoherent memory        //
 /////////////////////////////////////////////////////////////////////////////
 
 #endif  // #ifdef MULTICORE
-- 
2.34.1