[llvm-commits] [vmkit] r49476 - in /vmkit/trunk: include/mvm/GC/GC.h include/mvm/Threads/Thread.h lib/Mvm/CommonThread/ctthread.cpp lib/Mvm/GCMmap2/gc.cpp lib/Mvm/GCMmap2/gccollector.cpp lib/Mvm/GCMmap2/gccollector.h lib/Mvm/GCMmap2/main.cpp lib/Mvm/Object.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Thu Apr 10 04:23:37 PDT 2008
Author: geoffray
Date: Thu Apr 10 06:23:26 2008
New Revision: 49476
URL: http://llvm.org/viewvc/llvm-project?rev=49476&view=rev
Log:
A thread now owns a collector for builds with MULTIPLE_VM
Modified:
vmkit/trunk/include/mvm/GC/GC.h
vmkit/trunk/include/mvm/Threads/Thread.h
vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp
vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp
vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp
vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h
vmkit/trunk/lib/Mvm/GCMmap2/main.cpp
vmkit/trunk/lib/Mvm/Object.cpp
Modified: vmkit/trunk/include/mvm/GC/GC.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/GC/GC.h?rev=49476&r1=49475&r2=49476&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/GC/GC.h (original)
+++ vmkit/trunk/include/mvm/GC/GC.h Thu Apr 10 06:23:26 2008
@@ -26,41 +26,43 @@
virtual void destroyer(size_t) {}
virtual void tracer(size_t) {}
- void markAndTrace() const;
- size_t objectSize() const;
- void * operator new(size_t sz, VirtualTable *VT);
- void operator delete(void *);
- void * realloc(size_t n);
+ void markAndTrace() const;
+ size_t objectSize() const;
+ void * operator new(size_t sz, VirtualTable *VT);
+ void * operator new(size_t sz);
+ void operator delete(void *);
+ void * realloc(size_t n);
};
class gc_header {
public:
VirtualTable *_XXX_vt;
- inline gc *_2gc() { return (gc *)this; }
+ inline gc *_2gc() { return (gc *)this; }
};
class Collector {
public:
- typedef void (*markerFn)(void);
-
- static void initialise(markerFn mark, void *base_sp);
- static void destroy();
+ typedef void (*markerFn)(void);
+
+ static void initialise(markerFn mark, void *base_sp);
+ static void destroy();
- static void die_if_sigsegv_occured_during_collection(void *addr);
- static int isStable(gc_lock_recovery_fct_t, int, int, int, int,
+ static void die_if_sigsegv_occured_during_collection(void *addr);
+ static int isStable(gc_lock_recovery_fct_t, int, int, int, int,
int, int, int, int);
- static unsigned int enable(unsigned int n);
- static void gcStats(size_t &no, size_t &nbb);
- static void maybeCollect();
- static void collect(void);
- static void inject_my_thread(void *sp);
- static void remove_my_thread();
-
- static gc *begOf(const void *o);
- static int byteOffset(void *o);
- inline static bool isObject(const void *o) { return begOf((void*)o); }
+ static unsigned int enable(unsigned int n);
+ static void gcStats(size_t &no, size_t &nbb);
+ static void maybeCollect();
+ static void collect(void);
+ static void inject_my_thread(void *sp);
+ static void remove_my_thread();
+ static Collector* allocate();
+
+ static gc *begOf(const void *o);
+ static int byteOffset(void *o);
+ inline static bool isObject(const void *o) { return begOf((void*)o); }
static void applyFunc(void (*func)(gc *o, void *data), void *data);
static void registerMemoryError(void (*func)(unsigned int));
static int getMaxMemory(void);
Modified: vmkit/trunk/include/mvm/Threads/Thread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=49476&r1=49475&r2=49476&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/Threads/Thread.h (original)
+++ vmkit/trunk/include/mvm/Threads/Thread.h Thu Apr 10 06:23:26 2008
@@ -10,14 +10,13 @@
#ifndef MVM_THREAD_H
#define MVM_THREAD_H
-#include "mvm/Object.h"
#include "mvm/Threads/Key.h"
class Collector;
namespace mvm {
-class Thread : public Object{
+class Thread : public gc {
public:
static void yield(void);
static void yield(unsigned int *);
@@ -28,10 +27,10 @@
static int start(int *tid, int (*fct)(void *), void *arg);
static mvm::Key<Thread>* threadKey;
-#ifdef MULTIPLE_VM
Collector* GC;
-#endif
- static Thread* get();
+ static Thread* get() {
+ return (Thread*)Thread::threadKey->get();
+ }
};
Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=49476&r1=49475&r2=49476&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Thu Apr 10 06:23:26 2008
@@ -66,6 +66,9 @@
}
void Thread::initialise() {
+ Thread::threadKey = new mvm::Key<Thread>();
+ Thread* th = new Thread();
+ mvm::Thread::threadKey->set(th);
}
int Thread::start(int *tid, int (*fct)(void *), void *arg) {
Modified: vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp?rev=49476&r1=49475&r2=49476&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp Thu Apr 10 06:23:26 2008
@@ -7,20 +7,26 @@
//
//===----------------------------------------------------------------------===//
+#include <stdlib.h>
+
#include "mvm/GC/GC.h"
#include "gccollector.h"
#include "gcerror.h"
using namespace mvm;
-static GCCollector TheCollector;
+#ifdef MULTIPLE_VM
+#define COLLECTOR ((GCCollector*)(mvm::Thread::get()->GC))->
+#else
+#define COLLECTOR GCCollector::
+#endif
typedef void (*memoryError_t)(unsigned int);
memoryError_t GCCollector::internMemoryError;
void gc::markAndTrace() const {
- TheCollector.markAndTrace((void*)this);
+ COLLECTOR markAndTrace((void*)this);
}
size_t gc::objectSize() const {
@@ -28,7 +34,11 @@
}
void *gc::operator new(size_t sz, VirtualTable *vt) {
- return TheCollector.gcmalloc(vt, sz);
+ return COLLECTOR gcmalloc(vt, sz);
+}
+
+void *gc::operator new(size_t sz) {
+ return malloc(sz);
}
void gc::operator delete(void *) {
@@ -36,52 +46,57 @@
}
void *gc::realloc(size_t n) {
- return TheCollector.gcrealloc(this, n);
+ return COLLECTOR gcrealloc(this, n);
}
unsigned int Collector::enable(unsigned int n) {
- return TheCollector.enable(n);
+ return COLLECTOR 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 TheCollector.isStable(fct, a0, a1, a2, a3, a4, a5, a6, a7);
+ return COLLECTOR isStable(fct, a0, a1, a2, a3, a4, a5, a6, a7);
}
void Collector::die_if_sigsegv_occured_during_collection(void *addr) {
- TheCollector.die_if_sigsegv_occured_during_collection(addr);
+ COLLECTOR die_if_sigsegv_occured_during_collection(addr);
}
void Collector::gcStats(size_t &no, size_t &nbb) {
- TheCollector.gcStats(&no, &nbb);
+ COLLECTOR gcStats(&no, &nbb);
}
void Collector::initialise(markerFn marker, void *base_sp) {
#ifdef HAVE_PTHREAD
- Thread::initialise();
+ Thread::initialise();
#endif
- TheCollector.initialise(marker);
-#ifdef HAVE_PTHREAD
- TheCollector.inject_my_thread(base_sp);
+#ifdef MULTIPLE_VM
+ GCCollector* GC = new GCCollector();
+ GC->initialise(marker);
+ GC->inject_my_thread(base_sp);
+ mvm::Thread::get()->GC = GC;
+#else
+ GCCollector::initialise(marker);
+ GCCollector::inject_my_thread(base_sp);
#endif
}
void Collector::destroy() {
- TheCollector.destroy();
+ COLLECTOR destroy();
}
void Collector::inject_my_thread(void *base_sp) {
#ifdef HAVE_PTHREAD
- TheCollector.inject_my_thread(base_sp);
+ COLLECTOR inject_my_thread(base_sp);
#endif
}
void Collector::maybeCollect() {
- TheCollector.maybeCollect();
+ COLLECTOR maybeCollect();
}
void Collector::collect(void) {
- TheCollector.collect();
+ COLLECTOR collect();
}
gc *Collector::begOf(const void *obj) {
@@ -96,7 +111,7 @@
void Collector::applyFunc(void (*func)(gc *o, void *data), void *data) {
- return TheCollector.applyFunc(func, data);
+ return COLLECTOR applyFunc(func, data);
}
int Collector::getMaxMemory(void){
@@ -124,22 +139,22 @@
void Collector::remove_my_thread() {
#ifdef HAVE_PTHREAD
- TheCollector.remove_thread(TheCollector.threads->myloc());
+ COLLECTOR remove_thread(COLLECTOR threads->myloc());
#endif
}
#ifdef HAVE_PTHREAD
void GCCollector::siggc_handler(int) {
- GCThreadCollector *loc = TheCollector.threads->myloc();
- register unsigned int cm = TheCollector.current_mark;
+ GCThreadCollector *loc = COLLECTOR threads->myloc();
+ register unsigned int cm = COLLECTOR current_mark;
// jmp_buf buf;
// setjmp(buf);
- TheCollector.threads->stackLock();
+ COLLECTOR threads->stackLock();
if(!loc) /* a key is being destroyed */
- TheCollector.threads->another_mark();
+ COLLECTOR threads->another_mark();
else if(loc->current_mark() != cm) {
register unsigned int **cur = (unsigned int **)&cur;
register unsigned int **max = loc->base_sp();
@@ -147,29 +162,33 @@
GCChunkNode *node;
for(; cur<max; cur++) {
- if((node = o2node(*cur)) && (!TheCollector.isMarked(node))) {
+ if((node = o2node(*cur)) && (!COLLECTOR isMarked(node))) {
node->remove();
- node->append(TheCollector.used_nodes);
- TheCollector.mark(node);
+ node->append(COLLECTOR used_nodes);
+ COLLECTOR mark(node);
}
}
loc->current_mark(cm);
- TheCollector.threads->another_mark();
+ COLLECTOR threads->another_mark();
- TheCollector.threads->waitCollection();
+ COLLECTOR threads->waitCollection();
}
- TheCollector.threads->stackUnlock();
+ COLLECTOR threads->stackUnlock();
}
#endif
void GCThread::waitCollection() {
- unsigned int cm = TheCollector.current_mark;
+ unsigned int cm = COLLECTOR current_mark;
if(Thread::self() != collector_tid) {
collectorGo();
- while((TheCollector.current_mark == cm) &&
- (TheCollector.status == GCCollector::stat_collect))
+ while((COLLECTOR current_mark == cm) &&
+ (COLLECTOR status == GCCollector::stat_collect))
_collectionCond.wait(&_stackLock);
}
}
+
+Collector* Collector::allocate() {
+ return new GCCollector();
+}
Modified: vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp?rev=49476&r1=49475&r2=49476&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp Thu Apr 10 06:23:26 2008
@@ -12,6 +12,31 @@
using namespace mvm;
+#ifndef MULTIPLE_VM
+GCAllocator *GCCollector::allocator = 0;
+#ifdef HAVE_PTHREAD
+GCThread *GCCollector::threads;
+#endif
+
+GCCollector::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;
+#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=49476&r1=49475&r2=49476&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h Thu Apr 10 06:23:26 2008
@@ -17,45 +17,51 @@
#endif
#include "mvm/GC/GC.h"
+#ifdef MULTIPLE_VM
+#define STATIC
+#else
+#define STATIC static
+#endif
+
namespace mvm {
class GCCollector : public Collector {
#ifdef HAVE_PTHREAD
friend class GCThread;
#endif
- GCAllocator *allocator; /* The allocator */
+ STATIC GCAllocator *allocator; /* The allocator */
- Collector::markerFn _marker; /* The function which traces roots */
+ STATIC Collector::markerFn _marker; /* The function which traces roots */
- GCChunkNode *used_nodes; /* Used memory nodes */
- GCChunkNode *unused_nodes; /* Unused memory nodes */
+ STATIC GCChunkNode *used_nodes; /* Used memory nodes */
+ STATIC GCChunkNode *unused_nodes; /* Unused memory nodes */
- unsigned int current_mark;
+ STATIC unsigned int current_mark;
- int _collect_freq_auto; /* Collection frequency in gcmalloc/gcrealloc */
- int _collect_freq_maybe; /* Collection frequency in maybeCollect */
- int _since_last_collection; /* Bytes left since last collection */
- bool _enable_auto; /* Automatic collection? */
- bool _enable_maybe; /* Collection in maybeCollect()? */
- bool _enable_collection; /* collection authorized? */
- int status;
+ STATIC int _collect_freq_auto; /* Collection frequency in gcmalloc/gcrealloc */
+ STATIC int _collect_freq_maybe; /* Collection frequency in maybeCollect */
+ STATIC int _since_last_collection; /* Bytes left since last collection */
+ STATIC bool _enable_auto; /* Automatic collection? */
+ STATIC bool _enable_maybe; /* Collection in maybeCollect()? */
+ STATIC bool _enable_collection; /* collection authorized? */
+ STATIC int status;
enum { stat_collect, stat_finalize, stat_alloc, stat_broken };
#ifdef HAVE_PTHREAD
static void siggc_handler(int);
- inline void lock() { threads->lock(); }
- inline void unlock() { threads->unlock(); }
+ STATIC inline void lock() { threads->lock(); }
+ STATIC inline void unlock() { threads->unlock(); }
#else
static void siggc_handler(int) { }
- inline void lock() { }
- inline void unlock() { }
+ STATIC inline void lock() { }
+ STATIC inline void unlock() { }
#endif
/* Interface for collection, verifies enable_collect */
- void collect_unprotect();
+ STATIC void collect_unprotect();
/* The collection */
- void do_collect();
+ STATIC void do_collect();
static inline GCChunkNode *o2node(void *p) {
return GCHash::get(p)->o2node(p, GCChunkNode::maskCollectable);
@@ -66,48 +72,48 @@
}
public:
- GCThread *threads; /* le gestionnaire de thread et de synchro */
+ STATIC GCThread *threads; /* le gestionnaire de thread et de synchro */
static void (*internMemoryError)(unsigned int);
#ifdef HAVE_PTHREAD
- inline void unlock_dont_recovery() { threads->unlock_dont_recovery(); }
- void die_if_sigsegv_occured_during_collection(void *addr);
+ STATIC inline void unlock_dont_recovery() { threads->unlock_dont_recovery(); }
+ STATIC void die_if_sigsegv_occured_during_collection(void *addr);
#else
- void die_if_sigsegv_occured_during_collection(void *addr) { }
+ STATIC void die_if_sigsegv_occured_during_collection(void *addr) { }
#endif
- void defaultMemoryError(unsigned int sz){
+ STATIC void defaultMemoryError(unsigned int sz){
unlock();
internMemoryError(sz);
lock();
}
- void initialise(Collector::markerFn marker);
- void destroy();
+ STATIC void initialise(Collector::markerFn marker);
+ STATIC void destroy();
static int siggc();
#ifdef HAVE_PTHREAD
- void inject_my_thread(void *base_sp);
- inline void remove_thread(GCThreadCollector *loc) {
+ STATIC void inject_my_thread(void *base_sp);
+ STATIC 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) {
+ 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) {
return threads->isStable(fct, a0, a1, a2, a3, a4, a5, a6, a7);
}
#else
- 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) {
+ 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) {
return 0;
}
#endif
- inline void *allocate_unprotected(size_t sz) {
+ STATIC inline void *allocate_unprotected(size_t sz) {
return allocator->alloc(sz);
}
- inline void free_unprotected(void *ptr) {
+ STATIC inline void free_unprotected(void *ptr) {
allocator->free(ptr);
}
@@ -119,26 +125,26 @@
return 0;
}
- void gcStats(size_t *no, size_t *nbb);
+ STATIC 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;
}
- inline void collect() {
+ STATIC inline void collect() {
lock();
collect_unprotect();
unlock();
}
- inline void maybeCollect() {
+ STATIC inline void maybeCollect() {
if(_enable_auto &&
(_since_last_collection <= (_collect_freq_auto - _collect_freq_maybe)))
collect();
}
- inline gc *gcmalloc(VirtualTable *vt, size_t n) {
+ STATIC inline gc *gcmalloc(VirtualTable *vt, size_t n) {
lock();
register GCChunkNode *header = allocator->alloc_chunk(n + sizeof(gc_header), 1, current_mark & 1);
@@ -157,7 +163,7 @@
return p->_2gc();
}
- inline gc *gcrealloc(void *ptr, size_t n) {
+ STATIC inline gc *gcrealloc(void *ptr, size_t n) {
lock();
GCPage *desc = GCHash::get(ptr);
@@ -184,27 +190,27 @@
return obj->_2gc();
}
- inline unsigned int enable(unsigned int n) {
+ STATIC inline unsigned int enable(unsigned int n) {
register unsigned int old = _enable_collection;
_enable_collection = n;
return old;
}
- inline bool isMarked(GCChunkNode *node) {
+ STATIC inline bool isMarked(GCChunkNode *node) {
return node->mark() == (current_mark & 1);
}
- inline void mark(GCChunkNode *node) {
+ STATIC inline void mark(GCChunkNode *node) {
node->_mark(current_mark & 1);
}
- inline void trace(GCChunkNode *node) {
+ STATIC inline void trace(GCChunkNode *node) {
gc_header *o = node->chunk();
o->_2gc()->tracer(real_nbb(node));
markAndTrace(o);
}
- inline void markAndTrace(void *ptr) {
+ STATIC inline void markAndTrace(void *ptr) {
GCChunkNode *node = o2node(ptr);
if(node && !isMarked(node)) {
@@ -215,7 +221,7 @@
}
}
- inline void applyFunc(void (*func)(gc *o, void *data), void *data){
+ STATIC inline void applyFunc(void (*func)(gc *o, void *data), void *data){
lock(); /* Make sure no one collects or allocates */
status = stat_collect; /* Forbids collections */
GCChunkNode *cur=used_nodes->next(); /* Get starter */
Modified: vmkit/trunk/lib/Mvm/GCMmap2/main.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/main.cpp?rev=49476&r1=49475&r2=49476&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/main.cpp (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/main.cpp Thu Apr 10 06:23:26 2008
@@ -8,8 +8,11 @@
//===----------------------------------------------------------------------===//
#include "mvm/GC/GC.h"
+#include "mvm/Threads/Thread.h"
#include <stdio.h>
+mvm::Key<mvm::Thread>* mvm::Thread::threadKey = 0;
+
void destr(gc *me, size_t sz) {
printf("Destroy %p\n", me);
}
@@ -24,9 +27,8 @@
int main(int argc, char **argv) {
Collector::initialise(marker, 0);
-
- Collector::destroy();
- return 0;
+ Collector::destroy();
+ return 0;
}
Modified: vmkit/trunk/lib/Mvm/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Object.cpp?rev=49476&r1=49475&r2=49476&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Object.cpp (original)
+++ vmkit/trunk/lib/Mvm/Object.cpp Thu Apr 10 06:23:26 2008
@@ -63,7 +63,6 @@
INIT(ExceptionTable);
#undef INIT
- Thread::threadKey = new mvm::Key<Thread>();
}
void Code::tracer(size_t sz) {
@@ -175,7 +174,3 @@
}
NativeString *PrintBuffer::getContents() { return contents(); }
-
-Thread* Thread::get() {
- return (Thread*)Thread::threadKey->get();
-}
More information about the llvm-commits
mailing list