[llvm-commits] [vmkit] r48951 - in /vmkit/trunk/lib/Mvm/GCMmap2: gc.cc gccollector.cc gccollector.h gcinit.cc gcthread.cc gcthread.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sun Mar 30 09:04:32 PDT 2008


Author: geoffray
Date: Sun Mar 30 11:04:31 2008
New Revision: 48951

URL: http://llvm.org/viewvc/llvm-project?rev=48951&view=rev
Log:
Make the collector an object instead of static functions



Modified:
    vmkit/trunk/lib/Mvm/GCMmap2/gc.cc
    vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cc
    vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h
    vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cc
    vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cc
    vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h

Modified: vmkit/trunk/lib/Mvm/GCMmap2/gc.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gc.cc?rev=48951&r1=48950&r2=48951&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gc.cc (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gc.cc Sun Mar 30 11:04:31 2008
@@ -13,12 +13,14 @@
 
 using namespace mvm;
 
+static GCCollector TheCollector;
+
 typedef void (*memoryError_t)(unsigned int);
 
 memoryError_t GCCollector::internMemoryError;
 
 void gc::markAndTrace() const {
- 	GCCollector::markAndTrace((void*)this);
+ 	TheCollector.markAndTrace((void*)this);
 }
 
 size_t gc::objectSize() const {
@@ -26,60 +28,60 @@
 }
 
 void *gc::operator new(size_t sz, VirtualTable *vt) {
- 	return GCCollector::gcmalloc(vt, sz);
+ 	return TheCollector.gcmalloc(vt, sz);
 }
 
 void gc::operator delete(void *) { 
 	gcfatal(0, "never call directly a destructor....."); 
 }
 
-
 void *gc::realloc(size_t n) {
- 	return GCCollector::gcrealloc(this, n);
+ 	return TheCollector.gcrealloc(this, n);
 }
 
 unsigned int Collector::enable(unsigned int n) {
- 	return GCCollector::enable(n);
+ 	return TheCollector.enable(n);
 }
 
-int Collector::isStable(gc_lock_recovery_fct_t fct, int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7) {
-	return GCCollector::isStable(fct, a0, a1, a2, a3, a4, a5, a6, a7);
+int Collector::isStable(gc_lock_recovery_fct_t fct, int a0, int a1, int a2, 
+                        int a3, int a4, int a5, int a6, int a7) {
+  return TheCollector.isStable(fct, a0, a1, a2, a3, a4, a5, a6, a7);
 }
 
 void Collector::die_if_sigsegv_occured_during_collection(void *addr) {
-	GCCollector::die_if_sigsegv_occured_during_collection(addr);
+  TheCollector.die_if_sigsegv_occured_during_collection(addr);
 }
 
 void Collector::gcStats(size_t &no, size_t &nbb) {
-	GCCollector::gcStats(&no, &nbb);
+	TheCollector.gcStats(&no, &nbb);
 }
 
 void Collector::initialise(markerFn marker, void *base_sp) {
 #ifdef HAVE_PTHREAD
 	Thread::initialise();
 #endif
-	GCCollector::initialise(marker);
+	TheCollector.initialise(marker);
 #ifdef HAVE_PTHREAD
-	GCCollector::inject_my_thread(base_sp);
+	TheCollector.inject_my_thread(base_sp);
 #endif
 }
 
 void Collector::destroy() {
-	GCCollector::destroy();
+	TheCollector.destroy();
 }
 
 void Collector::inject_my_thread(void *base_sp) {
 #ifdef HAVE_PTHREAD
-	GCCollector::inject_my_thread(base_sp);
+	TheCollector.inject_my_thread(base_sp);
 #endif
 }
 
 void Collector::maybeCollect() {
- 	GCCollector::maybeCollect();
+ 	TheCollector.maybeCollect();
 }
 
 void Collector::collect(void) {
- 	GCCollector::collect();
+ 	TheCollector.collect();
 }
 
 gc *Collector::begOf(const void *obj) {
@@ -93,8 +95,8 @@
 }
 
 
-void Collector::applyFunc(void (*func)(gc *o, void *data), void *data){
-  return GCCollector::applyFunc(func, data);
+void Collector::applyFunc(void (*func)(gc *o, void *data), void *data) {
+  return TheCollector.applyFunc(func, data);
 }
 
 int Collector::getMaxMemory(void){
@@ -117,13 +119,57 @@
 
 void Collector::registerMemoryError(void (*func)(unsigned int)){
   GCCollector::internMemoryError = func;
-  onMemoryError = &GCCollector::defaultMemoryError;
-  
+  //onMemoryError = &GCCollector::defaultMemoryError;
 }
 
 void Collector::remove_my_thread() {
 #ifdef HAVE_PTHREAD
-  GCCollector::remove_thread(GCCollector::threads->myloc());
+  TheCollector.remove_thread(TheCollector.threads->myloc());
 #endif
 }
 
+#ifdef HAVE_PTHREAD
+void GCCollector::siggc_handler(int) {
+ 	GCThreadCollector     *loc = TheCollector.threads->myloc();
+ 	register unsigned int cm = TheCollector.current_mark;
+	//	jmp_buf buf;
+
+	//	setjmp(buf);
+
+	TheCollector.threads->stackLock();
+	
+ 	if(!loc) /* a key is being destroyed */	
+ 		TheCollector.threads->another_mark();
+ 	else if(loc->current_mark() != cm) {
+ 		register unsigned int	**cur = (unsigned int **)&cur;
+ 		register unsigned int	**max = loc->base_sp();
+		
+ 		GCChunkNode *node;
+		
+ 		for(; cur<max; cur++) {
+ 			if((node = o2node(*cur)) && (!TheCollector.isMarked(node))) {
+ 				node->remove();
+ 				node->append(TheCollector.used_nodes);
+ 				TheCollector.mark(node);
+ 			}
+ 		}
+		
+ 		loc->current_mark(cm);
+ 		TheCollector.threads->another_mark();
+		
+		TheCollector.threads->waitCollection();
+	}
+	TheCollector.threads->stackUnlock();
+}
+#endif
+
+void GCThread::waitCollection() {
+	unsigned int cm = TheCollector.current_mark;
+
+	if(Thread::self() != collector_tid) {
+		collectorGo();
+		while((TheCollector.current_mark == cm) && 
+          (TheCollector.status == GCCollector::stat_collect))
+			_collectionCond.wait(&_stackLock);
+	}
+}

Modified: vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cc?rev=48951&r1=48950&r2=48951&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cc (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cc Sun Mar 30 11:04:31 2008
@@ -12,63 +12,6 @@
 
 using namespace mvm;
 
-GCAllocator   *GCCollector::allocator = 0;
-#ifdef HAVE_PTHREAD
-GCThread      *GCCollector::threads;
-#endif
-
-Collector::markerFn   GCCollector::_marker;
-
-int  GCCollector::_collect_freq_auto;
-int  GCCollector::_collect_freq_maybe;
-int  GCCollector::_since_last_collection;
-
-bool GCCollector::_enable_auto;
-bool GCCollector::_enable_maybe;
-bool GCCollector::_enable_collection;
-
-int					  GCCollector::status;
-
-GCChunkNode    *GCCollector::used_nodes;
-GCChunkNode    *GCCollector::unused_nodes;
-
-unsigned int   GCCollector::current_mark;
-
-#ifdef HAVE_PTHREAD
-void GCCollector::siggc_handler(int) {
- 	GCThreadCollector     *loc = threads->myloc();
- 	register unsigned int cm = current_mark;
-	//	jmp_buf buf;
-
-	//	setjmp(buf);
-
-	threads->stackLock();
-	
- 	if(!loc) /* a key is being destroyed */	
- 		threads->another_mark();
- 	else if(loc->current_mark() != cm) {
- 		register unsigned int	**cur = (unsigned int **)&cur;
- 		register unsigned int	**max = loc->base_sp();
-		
- 		GCChunkNode *node;
-		
- 		for(; cur<max; cur++) {
- 			if((node = o2node(*cur)) && (!isMarked(node))) {
- 				node->remove();
- 				node->append(used_nodes);
- 				mark(node);
- 			}
- 		}
-		
- 		loc->current_mark(cm);
- 		threads->another_mark();
-		
-		threads->waitCollection();
-	}
-	threads->stackUnlock();
-}
-#endif
-
 void GCCollector::do_collect() {
 	//printf("----- do collect -----\n");
 	jmp_buf   buf;

Modified: vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h?rev=48951&r1=48950&r2=48951&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h Sun Mar 30 11:04:31 2008
@@ -24,80 +24,89 @@
 	friend class GCThread;
 
 #endif
-	static GCAllocator  *allocator;      /* la machine à allouer de la mémoire */
+	GCAllocator  *allocator;      /* la machine à allouer de la mémoire */
 
- 	static Collector::markerFn  _marker;        /* la fonction qui marque les racines */
+ 	Collector::markerFn  _marker;        /* la fonction qui marque les racines */
 
- 	static GCChunkNode  *used_nodes;     /* les noeuds mémoires utilisés */
-	static GCChunkNode  *unused_nodes;   /* les noeuds inutilisés */
+ 	GCChunkNode  *used_nodes;     /* les noeuds mémoires utilisés */
+	GCChunkNode  *unused_nodes;   /* les noeuds inutilisés */
 
- 	static unsigned int	 current_mark;
+ 	unsigned int	 current_mark;
 
- 	static int	_collect_freq_auto;     /* fréquence de collection automatique (lors des gcmalloc/gcrealloc) */
- 	static int	_collect_freq_maybe;    /* fréquence de collection lors de l'appel à maybeCollect() */
-	static int	_since_last_collection; /* nombre d'octets restants depuis la dernière collection */
- 	static bool	_enable_auto;           /* collection automatique? */
-	static bool	_enable_maybe;          /* collection lors des maybeCollect()? */
-	static bool	_enable_collection;     /* collection autorisée? */
-	static int	status;
+ 	int	_collect_freq_auto;     /* fréquence de collection automatique (lors des gcmalloc/gcrealloc) */
+ 	int	_collect_freq_maybe;    /* fréquence de collection lors de l'appel à maybeCollect() */
+	int	_since_last_collection; /* nombre d'octets restants depuis la dernière collection */
+ 	bool	_enable_auto;           /* collection automatique? */
+	bool	_enable_maybe;          /* collection lors des maybeCollect()? */
+	bool	_enable_collection;     /* collection autorisée? */
+	int	status;
 
  	enum { stat_collect, stat_finalize, stat_alloc, stat_broken };
 
 #ifdef HAVE_PTHREAD
 	static void	siggc_handler(int);
-	static inline void  lock()   { threads->lock(); }
-	static inline void  unlock() { threads->unlock(); }
+	inline void  lock()   { threads->lock(); }
+	inline void  unlock() { threads->unlock(); }
 #else
 	static void	siggc_handler(int) { }
-	static inline void  lock()   { }
-	static inline void  unlock() { }
+	inline void  lock()   { }
+	inline void  unlock() { }
 #endif
 
-	static void         collect_unprotect();    /* interface pour la collection, verifie le enable_collect */
-	static void         do_collect();           /* la collection proprement dite */
+	void collect_unprotect();    /* interface pour la collection, verifie le enable_collect */
+	void do_collect();           /* la collection proprement dite */
 
-	static inline GCChunkNode *o2node(void *p)
-        {
-                return GCHash::get(p)->o2node(p, GCChunkNode::maskCollectable);
-        }
+	static inline GCChunkNode *o2node(void *p) {
+    return GCHash::get(p)->o2node(p, GCChunkNode::maskCollectable);
+  }
+
+	static inline size_t real_nbb(GCChunkNode *n) { 
+    return n->nbb() - sizeof(gc_header);
+  }
 
-	static inline size_t real_nbb(GCChunkNode *n) { return n->nbb() - sizeof(gc_header); }
 public:
-	static GCThread     *threads;        /* le gestionnaire de thread et de synchro */
-         static void         (*internMemoryError)(unsigned int);
+	GCThread *threads;        /* le gestionnaire de thread et de synchro */
+  static void (*internMemoryError)(unsigned int);
 
 #ifdef HAVE_PTHREAD
-        static inline void  unlock_dont_recovery() { threads->unlock_dont_recovery(); }
-	static        void  die_if_sigsegv_occured_during_collection(void *addr);
+  inline void  unlock_dont_recovery() { threads->unlock_dont_recovery(); }
+	void die_if_sigsegv_occured_during_collection(void *addr);
 #else
-	static        void  die_if_sigsegv_occured_during_collection(void *addr) { }
+	void die_if_sigsegv_occured_during_collection(void *addr) { }
 #endif
 
-       static void defaultMemoryError(unsigned int sz){
-            unlock();
-               internMemoryError(sz);
+  void defaultMemoryError(unsigned int sz){
+    unlock();
+    internMemoryError(sz);
     lock();
   }
 
-	static void	initialise(Collector::markerFn marker);
-	static void	destroy();
+  void	initialise(Collector::markerFn marker);
+  void	destroy();
 
 	static int	siggc();
 
 #ifdef HAVE_PTHREAD
-	static void	        inject_my_thread(void *base_sp);
-	static inline void	remove_thread(GCThreadCollector *loc) { threads->remove(loc); }
-	static inline int       isStable(gc_lock_recovery_fct_t fct, int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7) {
+	void inject_my_thread(void *base_sp);
+	inline void	remove_thread(GCThreadCollector *loc) {
+    threads->remove(loc);
+  }
+	inline int isStable(gc_lock_recovery_fct_t fct, int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7) {
 		return threads->isStable(fct, a0, a1, a2, a3, a4, a5, a6, a7);
 	}
 #else
-	static inline int       isStable(gc_lock_recovery_fct_t fct, int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7) {
+	inline int isStable(gc_lock_recovery_fct_t fct, int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7) {
 		return 0;
 	}
 #endif
 
-	static inline void  *allocate_unprotected(size_t sz) { return allocator->alloc(sz); }
-	static inline void  free_unprotected(void *ptr) { allocator->free(ptr); }
+  inline void *allocate_unprotected(size_t sz) {
+    return allocator->alloc(sz);
+  }
+	
+  inline void  free_unprotected(void *ptr) {
+    allocator->free(ptr);
+  }
 
 	static inline gc *begOf(void *p) {
 		GCChunkNode *node = o2node(p);
@@ -107,25 +116,26 @@
 			return 0;
 	}
 
-	static void gcStats(size_t *no, size_t *nbb);
+	void gcStats(size_t *no, size_t *nbb);
 
 	static inline size_t objectSize(void *ptr) {
 		GCChunkNode *node = o2node(ptr);
 		return node ? real_nbb(node) : 0;
 	}
 
- 	static inline void collect() {
+ 	inline void collect() {
  		lock();
  		collect_unprotect();
  		unlock();
  	}
 
- 	static inline void maybeCollect() {
- 		if(_enable_auto && (_since_last_collection <= (_collect_freq_auto - _collect_freq_maybe)))
+ 	inline void maybeCollect() {
+    if(_enable_auto && 
+       (_since_last_collection <= (_collect_freq_auto - _collect_freq_maybe)))
  			collect(); 
  	}
 
- 	static inline gc *gcmalloc(VirtualTable *vt, size_t n) {
+ 	inline gc *gcmalloc(VirtualTable *vt, size_t n) {
  		lock();
  		register GCChunkNode *header = allocator->alloc_chunk(n + sizeof(gc_header), 1, current_mark & 1);
 		
@@ -143,7 +153,7 @@
  		return p->_2gc();
  	}
 
- 	static inline gc *gcrealloc(void *ptr, size_t n) {
+ 	inline gc *gcrealloc(void *ptr, size_t n) {
  		lock();
 
  		GCPage    	*desc = GCHash::get(ptr);
@@ -170,22 +180,27 @@
  		return obj->_2gc();
  	}
 
-	static inline unsigned int enable(unsigned int n)  {
+	inline unsigned int enable(unsigned int n)  {
  		register unsigned int old = _enable_collection;
  		_enable_collection = n; 
  		return old;
  	}
 
- 	static inline bool isMarked(GCChunkNode *node) { return node->mark() == (current_mark & 1); }
-	static inline void mark(GCChunkNode *node) { node->_mark(current_mark & 1); }
+ 	inline bool isMarked(GCChunkNode *node) { 
+    return node->mark() == (current_mark & 1);
+  }
+	
+  inline void mark(GCChunkNode *node) {
+    node->_mark(current_mark & 1);
+  }
 
- 	static inline void trace(GCChunkNode *node) {
+ 	inline void trace(GCChunkNode *node) {
  		gc_header *o = node->chunk();
     o->_2gc()->tracer(real_nbb(node));
     markAndTrace(o);
  	}
 
- 	static inline void markAndTrace(void *ptr) {
+ 	inline void markAndTrace(void *ptr) {
  		GCChunkNode *node = o2node(ptr);
 
  		if(node && !isMarked(node)) {
@@ -196,7 +211,7 @@
  		}
  	}
 
-  static inline void applyFunc(void (*func)(gc *o, void *data), void *data){
+  inline void applyFunc(void (*func)(gc *o, void *data), void *data){
     lock(); /* on s'assure que personne n'alloue ou ne collect */
     status = stat_collect; /* empeche les collections */
     GCChunkNode *cur=used_nodes->next(); /* reccupère l'amorce */

Modified: vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cc?rev=48951&r1=48950&r2=48951&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cc (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cc Sun Mar 30 11:04:31 2008
@@ -37,7 +37,7 @@
 	sigset_t mask;
 
 #ifdef HAVE_PTHREAD
-	on_fatal = unlock_dont_recovery;
+	//on_fatal = unlock_dont_recovery;
 #endif
 
 	sigaction(SIGGC, 0, &sa);

Modified: vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cc?rev=48951&r1=48950&r2=48951&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cc (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cc Sun Mar 30 11:04:31 2008
@@ -11,19 +11,6 @@
 
 using namespace mvm;
 
-void *GCThreadCollector::operator new(size_t sz)   { 
-	return GCCollector::allocate_unprotected(sz); 
-}
-
-void GCThreadCollector::operator delete(void *ptr) { 
-	//printf("DELETE %p\n", ptr);
-	GCCollector::free_unprotected(ptr); 
-}
-
-void GCThreadCollector::destroy_Key(void *ptr) {
-	GCCollector::remove_thread((GCThreadCollector *)ptr);
-}
-
 void GCThread::waitStacks() {
 	_stackLock.lock();
 	while(_nb_collected < _nb_threads)
@@ -31,16 +18,6 @@
 	_stackLock.unlock();
 }
 
-void GCThread::waitCollection() {
-	unsigned int cm = GCCollector::current_mark;
-
-	if(Thread::self() != collector_tid) {
-		collectorGo();
-		while((GCCollector::current_mark == cm) && (GCCollector::status == GCCollector::stat_collect))
-			_collectionCond.wait(&_stackLock);
-	}
-}
-
 void GCThread::synchronize() {
  	GCThreadCollector *cur;
 	int signo = GCCollector::siggc();

Modified: vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h?rev=48951&r1=48950&r2=48951&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h Sun Mar 30 11:04:31 2008
@@ -10,8 +10,6 @@
 #ifndef _GC_THREAD_H_
 #define _GC_THREAD_H_
 
-//#include "gcalloc.h"
-//#include "ctlock.h"
 #include "ctcircular.h"
 #include "mvm/GC/GC.h"
 #include "mvm/Threads/Cond.h"
@@ -29,10 +27,6 @@
  	int								_tid;
 	
 public:
- 	static void initialise_Key(void *) {}
- 	static void duplicate_for_thread(void *, void *) {}
- 	static void destroy_Key(void *ptr);
-
 	inline GCThreadCollector() {}
  	inline GCThreadCollector(GCThreadCollector *pred, int t, void *p, int m) : CircularBase(pred) {
 		_base_sp = p;
@@ -45,9 +39,6 @@
 	/* soit parce que le collecteur quitte et dans ce cas, toute la mémoire est bien libérée */
  	inline 	~GCThreadCollector() {}
 	
- 	void *operator new(size_t sz);
- 	void operator delete(void *ptr);
-
  	inline int					tid()						{ return _tid; }
  	inline unsigned int current_mark()	{ return _cur_mark; }
  	inline void					current_mark(unsigned int m)	{ _cur_mark = m; }





More information about the llvm-commits mailing list