[llvm-commits] [vmkit] r49719 - in /vmkit/trunk: include/mvm/JIT.h include/mvm/MvmMemoryManager.h lib/Mvm/CommandLine.cpp lib/Mvm/GCMmap2/MvmGC.h lib/Mvm/GCMmap2/gc.cpp lib/Mvm/GCMmap2/gccollector.cpp lib/Mvm/GCMmap2/gccollector.h lib/Mvm/GCMmap2/gcthread.h lib/Mvm/GCMmap2/main.cpp lib/Mvm/JIT.cpp lib/Mvm/MvmMemoryManager.cpp lib/Mvm/MvmMemoryManager.h lib/Mvm/Object.cpp lib/Mvm/Sigsegv.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Tue Apr 15 03:00:55 PDT 2008


Author: geoffray
Date: Tue Apr 15 05:00:41 2008
New Revision: 49719

URL: http://llvm.org/viewvc/llvm-project?rev=49719&view=rev
Log:
Allow multiple GC to execute.
MvmMemoryManager has a map of llvm::Module->GC to allocate functions.
Make MvmMemoryManager.h accessible to virtual machines.


Added:
    vmkit/trunk/include/mvm/MvmMemoryManager.h
Removed:
    vmkit/trunk/lib/Mvm/MvmMemoryManager.h
Modified:
    vmkit/trunk/include/mvm/JIT.h
    vmkit/trunk/lib/Mvm/CommandLine.cpp
    vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h
    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/gcthread.h
    vmkit/trunk/lib/Mvm/GCMmap2/main.cpp
    vmkit/trunk/lib/Mvm/JIT.cpp
    vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp
    vmkit/trunk/lib/Mvm/Object.cpp
    vmkit/trunk/lib/Mvm/Sigsegv.cpp

Modified: vmkit/trunk/include/mvm/JIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=49719&r1=49718&r2=49719&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/JIT.h (original)
+++ vmkit/trunk/include/mvm/JIT.h Tue Apr 15 05:00:41 2008
@@ -26,6 +26,7 @@
 #include "types.h"
 
 #include "mvm/Threads/Locks.h"
+#include "mvm/MvmMemoryManager.h"
 
 namespace mvm {
 
@@ -148,7 +149,7 @@
 
 extern llvm::Module *globalModule;
 extern llvm::ExistingModuleProvider *globalModuleProvider;
-extern llvm::JITMemoryManager *memoryManager;
+extern mvm::MvmMemoryManager *memoryManager;
 
 extern void protectTypes();
 extern void unprotectTypes();

Added: vmkit/trunk/include/mvm/MvmMemoryManager.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/MvmMemoryManager.h?rev=49719&view=auto

==============================================================================
--- vmkit/trunk/include/mvm/MvmMemoryManager.h (added)
+++ vmkit/trunk/include/mvm/MvmMemoryManager.h Tue Apr 15 05:00:41 2008
@@ -0,0 +1,114 @@
+//===------- MvmMemoryManager.h - LLVM Memory manager for Mvm -------------===//
+//
+//                              Mvm
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#ifndef MVM_MEMORY_MANAGER_H
+#define MVM_MEMORY_MANAGER_H
+
+#include <map>
+
+#include "MvmGC.h"
+#include "mvm/Threads/Locks.h"
+#include "llvm/Module.h"
+#include <llvm/ExecutionEngine/JITMemoryManager.h>
+
+using namespace llvm;
+
+namespace mvm {
+
+class Method;
+class Object;
+
+class MvmMemoryManager : public JITMemoryManager {
+  Method* currentMethod;       // Current method being compiled
+  unsigned char *GOTBase;      // Target Specific reserved memory
+#ifdef MULTIPLE_GC
+  std::map<Module*, Collector*> GCMap;
+  mvm::Lock* lock;
+#endif
+public:
+  
+  MvmMemoryManager() : JITMemoryManager() { 
+      GOTBase = 0; 
+#ifdef MULTIPLE_GC
+      lock = mvm::Lock::allocNormal();
+#endif
+  }
+   ~MvmMemoryManager() { 
+      delete[] GOTBase;
+#ifdef MULTIPLE_GC
+      delete lock;
+#endif
+  }
+
+#ifdef MULTIPLE_GC 
+   void addGCForModule(Module* M, Collector* GC){
+      lock->lock();
+      GCMap[M] = GC;
+      lock->unlock();
+   }
+#endif
+
+   /// startFunctionBody - When we start JITing a function, the JIT calls this 
+  /// method to allocate a block of free RWX memory, which returns a pointer to
+  /// it.  The JIT doesn't know ahead of time how much space it will need to
+  /// emit the function, so it doesn't pass in the size.  Instead, this method
+  /// is required to pass back a "valid size".  The JIT will be careful to not
+  /// write more than the returned ActualSize bytes of memory. 
+  virtual unsigned char *startFunctionBody(const Function *F, 
+                                           uintptr_t &ActualSize);
+  
+  /// allocateStub - This method is called by the JIT to allocate space for a
+  /// function stub (used to handle limited branch displacements) while it is
+  /// JIT compiling a function.  For example, if foo calls bar, and if bar
+  /// either needs to be lazily compiled or is a native function that exists too
+  /// far away from the call site to work, this method will be used to make a
+  /// thunk for it.  The stub should be "close" to the current function body,
+  /// but should not be included in the 'actualsize' returned by
+  /// startFunctionBody.
+  virtual unsigned char *allocateStub(unsigned StubSize, unsigned Alignment);
+  
+  /// endFunctionBody - This method is called when the JIT is done codegen'ing
+  /// the specified function.  At this point we know the size of the JIT
+  /// compiled function.  This passes in FunctionStart (which was returned by
+  /// the startFunctionBody method) and FunctionEnd which is a pointer to the 
+  /// actual end of the function.  This method should mark the space allocated
+  /// and remember where it is in case the client wants to deallocate it.
+  virtual void endFunctionBody(const Function *F, unsigned char *FunctionStart,
+                               unsigned char *FunctionEnd);
+  
+  /// deallocateMemForFunction - Free JIT memory for the specified function.
+  /// This is never called when the JIT is currently emitting a function.
+  virtual void deallocateMemForFunction(const Function *F);
+  
+  /// AllocateGOT - If the current table requires a Global Offset Table, this
+  /// method is invoked to allocate it.  This method is required to set HasGOT
+  /// to true.
+  virtual void AllocateGOT();
+
+  /// getGOTBase - If this is managing a Global Offset Table, this method should
+  /// return a pointer to its base.
+  virtual unsigned char *getGOTBase() const;
+  
+
+  /// startExceptionTable - When we finished JITing the function, if exception
+  /// handling is set, we emit the exception table.
+  virtual unsigned char* startExceptionTable(const Function* F,
+                                             uintptr_t &ActualSize);
+  
+  /// endExceptionTable - This method is called when the JIT is done emitting
+  /// the exception table.
+  virtual void endExceptionTable(const Function *F, unsigned char *TableStart,
+                               unsigned char *TableEnd, 
+                               unsigned char* FrameRegister);
+};
+
+} // End mvm namespace
+
+#endif

Modified: vmkit/trunk/lib/Mvm/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommandLine.cpp?rev=49719&r1=49718&r2=49719&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/CommandLine.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommandLine.cpp Tue Apr 15 05:00:41 2008
@@ -105,10 +105,18 @@
   char** argv = arg->argv;
   vmlet_main_t func = arg->func;
   free(arg);
+#ifndef MULTIPLE_GC
   Collector::inject_my_thread(&argc);
   func(argc, argv);
   Collector::remove_my_thread();
   Collector::collect();
+#else
+  Collector* GC = Collector::allocate();
+  GC->inject_my_thread(&argc);
+  func(argc, argv);
+  GC->remove_my_thread();
+  GC->collect();
+#endif
   return 0;
 }
 
@@ -150,7 +158,6 @@
       Thread::start(&tid, (int (*)(void *))startApp, thread_arg);
 #else
       func(argc, argv);
-      Collector::collect();
 #endif
     }
   }

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

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h Tue Apr 15 05:00:41 2008
@@ -18,6 +18,8 @@
 #define gc_new(Class)  __gc_new(Class::VT) Class
 #define __gc_new new
 
+class Collector;
+
 class gc : public gcRoot {
 public:
   
@@ -28,37 +30,53 @@
   void    operator delete(void *);
   void *  realloc(size_t n);
 
+#ifdef MULTIPLE_GC
+#define collector_new(Class, Collector) __gc_new(Class::VT, Collector) Class
+  void    markAndTrace(Collector* GC) const;
+  size_t  objectSize(Collector* GC) const;
+  void *  operator new(size_t sz, VirtualTable *VT, Collector* GC);
+  void *  operator new(size_t sz, Collector* GC);
+  void    operator delete(void *, Collector* GC);
+  void *  realloc(size_t n, Collector* GC);
+#endif
+
 };
 
+#ifdef MULTIPLE_GC
+#define STATIC
+#else
+#define STATIC static
+#endif
+
 class Collector {
 public:
 
   typedef void (*markerFn)(void);
   
   static void  initialise(markerFn mark, void *base_sp);
-  static void  destroy();
+  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 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)(gcRoot *o, void *data), void *data);
-        static void     registerMemoryError(void (*func)(unsigned int));
-        static int      getMaxMemory(void);
-        static int      getFreeMemory(void);
-        static int      getTotalMemory(void);
-        static void     setMaxMemory(size_t);
-        static void     setMinMemory(size_t);
+  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)(gcRoot *o, void *data), void *data);
+        STATIC void     registerMemoryError(void (*func)(unsigned int));
+        STATIC int      getMaxMemory(void);
+        STATIC int      getFreeMemory(void);
+        STATIC int      getTotalMemory(void);
+        STATIC void     setMaxMemory(size_t);
+        STATIC void     setMinMemory(size_t);
 };
 
 

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

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp Tue Apr 15 05:00:41 2008
@@ -15,24 +15,31 @@
 
 using namespace mvm;
 
+#ifdef MULTIPLE_GC
+#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 {
-   GCCollector::markAndTrace((void*)this);
+  COLLECTOR markAndTrace((void*)this);
 }
 
 size_t gc::objectSize() const {
-   return GCCollector::objectSize((gc*)this);
+  return COLLECTOR objectSize((gc*)this);
 }
 
 void *gc::operator new(size_t sz, VirtualTable *vt) {
-   return GCCollector::gcmalloc(vt, sz);
+  return COLLECTOR gcmalloc(vt, sz);
 }
 
 void *gc::operator new(size_t sz) {
-   return malloc(sz);
+  return malloc(sz);
 }
 
 void gc::operator delete(void *) { 
@@ -40,62 +47,103 @@
 }
 
 void *gc::realloc(size_t n) {
-   return GCCollector::gcrealloc(this, n);
+  return COLLECTOR gcrealloc(this, n);
+}
+
+
+#ifdef MULTIPLE_GC
+void gc::markAndTrace(Collector* GC) const {
+  ((GCCollector*)GC)->markAndTrace((void*)this);
 }
 
+size_t gc::objectSize(Collector* GC) const {
+  return ((GCCollector*)GC)->objectSize((gc*)this);
+}
+
+void *gc::operator new(size_t sz, VirtualTable *VT, Collector* GC) {
+  return ((GCCollector*)GC)->gcmalloc(VT, sz);
+}
+
+void *gc::operator new(size_t sz, Collector* GC) {
+  return malloc(sz);
+}
+
+void gc::operator delete(void *, Collector* GC) {
+  gcfatal(0, "never call directly a destructor....."); 
+}
+
+void *gc::realloc(size_t n, Collector* GC) {
+  return ((GCCollector*)GC)->gcrealloc(this, n);
+}
+#endif
+
+#undef COLLECTOR
+#ifdef MULTIPLE_GC
+#define COLLECTOR ((GCCollector*)this)->
+#else
+#define COLLECTOR GCCollector::
+#endif
+
 unsigned int Collector::enable(unsigned int n) {
-   return GCCollector::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 GCCollector::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) {
-  GCCollector::die_if_sigsegv_occured_during_collection(addr);
+  COLLECTOR die_if_sigsegv_occured_during_collection(addr);
 }
 
 void Collector::gcStats(size_t &no, size_t &nbb) {
-  GCCollector::gcStats(&no, &nbb);
+  COLLECTOR gcStats(&no, &nbb);
 }
 
 void Collector::initialise(markerFn marker, void *base_sp) {
+#ifdef MULTIPLE_GC
+  GCCollector* GC = new GCCollector();
+  mvm::Thread::get()->GC = GC;
+  GC->initialise(marker);
+  GC->inject_my_thread(base_sp);
+#else
   GCCollector::initialise(marker);
   GCCollector::inject_my_thread(base_sp);
+#endif
 }
 
 void Collector::destroy() {
-  GCCollector::destroy();
+  COLLECTOR destroy();
 }
 
 void Collector::inject_my_thread(void *base_sp) {
 #ifdef HAVE_PTHREAD
-  GCCollector::inject_my_thread(base_sp);
+  COLLECTOR inject_my_thread(base_sp);
 #endif
 }
 
 void Collector::maybeCollect() {
-   GCCollector::maybeCollect();
+   COLLECTOR maybeCollect();
 }
 
 void Collector::collect(void) {
-   GCCollector::collect();
+   COLLECTOR collect();
 }
 
 gc *Collector::begOf(const void *obj) {
-  return (gc*)GCCollector::begOf((void*)obj);
+  return (gc*)COLLECTOR begOf((void*)obj);
 }
 
 int Collector::byteOffset(void *obj) {
-  int beg = (intptr_t)GCCollector::begOf(obj);
+  int beg = (intptr_t)COLLECTOR begOf(obj);
   intptr_t off = (intptr_t)obj;
   return (off-beg);
 }
 
 
 void Collector::applyFunc(void (*func)(gcRoot *o, void *data), void *data) {
-  return GCCollector::applyFunc(func, data);
+  return COLLECTOR applyFunc(func, data);
 }
 
 int Collector::getMaxMemory(void){
@@ -117,63 +165,74 @@
 }
 
 void Collector::registerMemoryError(void (*func)(unsigned int)){
-  GCCollector::internMemoryError = func;
-  //onMemoryError = &GCCollector::defaultMemoryError;
+  COLLECTOR internMemoryError = func;
+  //onMemoryError = &COLLECTOR defaultMemoryError;
 }
 
 void Collector::remove_my_thread() {
 #ifdef HAVE_PTHREAD
-  GCCollector::remove_thread(GCCollector::threads->myloc());
+  COLLECTOR remove_thread(COLLECTOR threads->myloc());
 #endif
 }
 
+void GCThread::waitCollection() {
+  unsigned int cm = COLLECTOR current_mark;
+
+  if(Thread::self() != collector_tid) {
+    collectorGo();
+    while((COLLECTOR current_mark == cm) && 
+          (COLLECTOR status == COLLECTOR stat_collect))
+      _collectionCond.wait(&_stackLock);
+  }
+}
+
 #ifdef HAVE_PTHREAD
+
+#undef COLLECTOR
 void GCCollector::siggc_handler(int) {
-   GCThreadCollector     *loc = GCCollector::threads->myloc();
-   register unsigned int cm = GCCollector::current_mark;
+#ifdef MULTIPLE_GC
+  GCCollector* GC = ((GCCollector*)mvm::Thread::get()->GC);
+#define COLLECTOR GC->
+#else
+#define COLLECTOR GCCollector::
+#endif
+   GCThreadCollector     *loc = COLLECTOR threads->myloc();
+   register unsigned int cm = COLLECTOR current_mark;
   //  jmp_buf buf;
 
   //  setjmp(buf);
-
-  GCCollector::threads->stackLock();
   
-   if(!loc) /* a key is being destroyed */  
-     GCCollector::threads->another_mark();
-   else if(loc->current_mark() != cm) {
+  COLLECTOR threads->stackLock();
+  
+  if(!loc) /* a key is being destroyed */  
+    COLLECTOR 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)) && (!GCCollector::isMarked(node))) {
+       if((node = o2node(*cur)) && (!COLLECTOR isMarked(node))) {
          node->remove();
-         node->append(GCCollector::used_nodes);
-         GCCollector::mark(node);
+         node->append(COLLECTOR used_nodes);
+         COLLECTOR mark(node);
        }
      }
     
      loc->current_mark(cm);
-     GCCollector::threads->another_mark();
-    
-    GCCollector::threads->waitCollection();
+     COLLECTOR threads->another_mark();
+    COLLECTOR threads->waitCollection();
   }
-  GCCollector::threads->stackUnlock();
+  COLLECTOR threads->stackUnlock();
+#undef COLLECTOR
 }
 #endif
 
-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);
-  }
-}
 
 Collector* Collector::allocate() {
-  return new GCCollector();
+  GCCollector* GC = new GCCollector();
+  GC->initialise(0);
+  return GC;
 }
 

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

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp Tue Apr 15 05:00:41 2008
@@ -12,7 +12,7 @@
 
 using namespace mvm;
 
-#ifndef MULTIPLE_VM
+#ifndef MULTIPLE_GC
 GCAllocator   *GCCollector::allocator = 0;
 #ifdef HAVE_PTHREAD
 GCThread      *GCCollector::threads;

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

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h Tue Apr 15 05:00:41 2008
@@ -17,7 +17,7 @@
 #endif
 #include "mvm/GC/GC.h"
 
-#ifdef MULTIPLE_VM
+#ifdef MULTIPLE_GC
 #define STATIC
 #else
 #define STATIC static

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

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h Tue Apr 15 05:00:41 2008
@@ -75,17 +75,23 @@
 };
 
 class GCThread {
-   Key<GCThreadCollector>  _loc;
-   GCThreadCollector        base;
+  GCThreadCollector        base;
   GCLockRecovery         _globalLock;     /* global lock for gcmalloc */
   LockNormal              _stackLock;     /* stack lock for synchronization */
   Cond                    _stackCond;     /* condition for unlocking other tasks (write protect) */
   Cond                    _collectionCond;/* condition for unblocking the collecter */
-   unsigned int            _nb_threads;    /* number of active threads */
-   unsigned int            _nb_collected;  /* number of threads collected */
+  unsigned int            _nb_threads;    /* number of active threads */
+  unsigned int            _nb_collected;  /* number of threads collected */
   int                     collector_tid;  /* don't synchonize this one */
 
+  
 public:
+  Key<GCThreadCollector>  _loc;
+  GCThread() {
+    _nb_threads = 0;
+    _nb_collected = 0;
+    collector_tid = 0;
+  }
 
   inline void lock()   { _globalLock.lock(); }
   inline void unlock() { _globalLock.unlock(); }
@@ -108,9 +114,9 @@
     collectionFinished();         /* unblock mutators */
   }
 
-   inline GCThreadCollector *myloc() { return _loc.get(); }
+  inline GCThreadCollector *myloc() { return _loc.get(); }
 
-   inline void another_mark() { _nb_collected++; }
+  inline void another_mark() { _nb_collected++; }
 
   void synchronize();
 

Modified: vmkit/trunk/lib/Mvm/GCMmap2/main.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/main.cpp?rev=49719&r1=49718&r2=49719&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/main.cpp (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/main.cpp Tue Apr 15 05:00:41 2008
@@ -26,8 +26,13 @@
 }
 
 int main(int argc, char **argv) {
+  mvm::Thread::initialise();
   Collector::initialise(marker, 0);
+#ifdef MULTIPLE_GC
+  mvm::Thread::get()->GC->destroy();
+#else
   Collector::destroy();
+#endif
   return 0;
 }
 

Modified: vmkit/trunk/lib/Mvm/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/JIT.cpp?rev=49719&r1=49718&r2=49719&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/JIT.cpp Tue Apr 15 05:00:41 2008
@@ -17,8 +17,7 @@
 
 #include "mvm/JIT.h"
 #include "mvm/Method.h"
-
-#include "MvmMemoryManager.h"
+#include "mvm/MvmMemoryManager.h"
 
 using namespace mvm;
 using namespace mvm::jit;
@@ -658,7 +657,7 @@
 
 llvm::Module *mvm::jit::globalModule;
 llvm::ExistingModuleProvider *mvm::jit::globalModuleProvider;
-llvm::JITMemoryManager *mvm::jit::memoryManager;
+mvm::MvmMemoryManager *mvm::jit::memoryManager;
 
 
 uint64 mvm::jit::getTypeSize(const llvm::Type* type) {

Modified: vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp?rev=49719&r1=49718&r2=49719&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp (original)
+++ vmkit/trunk/lib/Mvm/MvmMemoryManager.cpp Tue Apr 15 05:00:41 2008
@@ -12,7 +12,7 @@
 #include "mvm/Method.h"
 #include "mvm/Object.h"
 
-#include "MvmMemoryManager.h"
+#include "mvm/MvmMemoryManager.h"
 
 using namespace mvm;
 using namespace llvm;
@@ -20,9 +20,15 @@
 unsigned char* MvmMemoryManager::startFunctionBody(const Function* F, 
                                                    uintptr_t &ActualSize) {
   size_t nbb = ((ActualSize - 1) & -4) + 4 + sizeof(Method *);
+#ifdef MUTLIPLE_GC
+  Collector* GC = GCMap[F->getModule()];
+  assert(GC && "GC not available in a multi-GC environment");
+  Code *res = (Code *)gc::operator new(nbb, Code::VT, GC);
+  Method* meth = collector_new(Method, GC)(res, ActualSize);
+#else
   Code *res = (Code *)gc::operator new(nbb, Code::VT);
-  
   Method* meth = gc_new(Method)(res, ActualSize);
+#endif
   res->method(meth);
   currentMethod = meth;
   return (unsigned char*)((unsigned int*)res + 2);
@@ -59,8 +65,16 @@
 
 unsigned char *MvmMemoryManager::startExceptionTable(const Function* F, 
                                                      uintptr_t &ActualSize) {
+#ifdef MUTLIPLE_GC
+  Collector* GC = GCMap[F->getModule()];
+  assert(GC && "GC not available in a multi-GC environment");
+  ExceptionTable *res = (ExceptionTable*)gc::operator new(ActualSize + 4, 
+                                                          ExceptionTable::VT,
+                                                          GC);
+#else
   ExceptionTable *res = (ExceptionTable*)gc::operator new(ActualSize + 4, 
                                                           ExceptionTable::VT);
+#endif
   currentMethod->exceptionTable(res);
   return (unsigned char*)((unsigned int*)res + 2);
 }                                                     

Removed: vmkit/trunk/lib/Mvm/MvmMemoryManager.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MvmMemoryManager.h?rev=49718&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/MvmMemoryManager.h (original)
+++ vmkit/trunk/lib/Mvm/MvmMemoryManager.h (removed)
@@ -1,86 +0,0 @@
-//===------- MvmMemoryManager.h - LLVM Memory manager for Mvm -------------===//
-//
-//                              Mvm
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-
-#ifndef MVM_MEMORY_MANAGER_H
-#define MVM_MEMORY_MANAGER_H
-
-#include <llvm/ExecutionEngine/JITMemoryManager.h>
-
-using namespace llvm;
-
-namespace mvm {
-
-class Method;
-class Object;
-
-class MvmMemoryManager : public JITMemoryManager {
-  Method* currentMethod;       // Current method being compiled
-  unsigned char *GOTBase;      // Target Specific reserved memory
-public:
-  
-  MvmMemoryManager() : JITMemoryManager() { GOTBase = 0; }
-   ~MvmMemoryManager() { delete[] GOTBase; }     
-  /// startFunctionBody - When we start JITing a function, the JIT calls this 
-  /// method to allocate a block of free RWX memory, which returns a pointer to
-  /// it.  The JIT doesn't know ahead of time how much space it will need to
-  /// emit the function, so it doesn't pass in the size.  Instead, this method
-  /// is required to pass back a "valid size".  The JIT will be careful to not
-  /// write more than the returned ActualSize bytes of memory. 
-  virtual unsigned char *startFunctionBody(const Function *F, 
-                                           uintptr_t &ActualSize);
-  
-  /// allocateStub - This method is called by the JIT to allocate space for a
-  /// function stub (used to handle limited branch displacements) while it is
-  /// JIT compiling a function.  For example, if foo calls bar, and if bar
-  /// either needs to be lazily compiled or is a native function that exists too
-  /// far away from the call site to work, this method will be used to make a
-  /// thunk for it.  The stub should be "close" to the current function body,
-  /// but should not be included in the 'actualsize' returned by
-  /// startFunctionBody.
-  virtual unsigned char *allocateStub(unsigned StubSize, unsigned Alignment);
-  
-  /// endFunctionBody - This method is called when the JIT is done codegen'ing
-  /// the specified function.  At this point we know the size of the JIT
-  /// compiled function.  This passes in FunctionStart (which was returned by
-  /// the startFunctionBody method) and FunctionEnd which is a pointer to the 
-  /// actual end of the function.  This method should mark the space allocated
-  /// and remember where it is in case the client wants to deallocate it.
-  virtual void endFunctionBody(const Function *F, unsigned char *FunctionStart,
-                               unsigned char *FunctionEnd);
-  
-  /// deallocateMemForFunction - Free JIT memory for the specified function.
-  /// This is never called when the JIT is currently emitting a function.
-  virtual void deallocateMemForFunction(const Function *F);
-  
-  /// AllocateGOT - If the current table requires a Global Offset Table, this
-  /// method is invoked to allocate it.  This method is required to set HasGOT
-  /// to true.
-  virtual void AllocateGOT();
-
-  /// getGOTBase - If this is managing a Global Offset Table, this method should
-  /// return a pointer to its base.
-  virtual unsigned char *getGOTBase() const;
-  
-
-  /// startExceptionTable - When we finished JITing the function, if exception
-  /// handling is set, we emit the exception table.
-  virtual unsigned char* startExceptionTable(const Function* F,
-                                             uintptr_t &ActualSize);
-  
-  /// endExceptionTable - This method is called when the JIT is done emitting
-  /// the exception table.
-  virtual void endExceptionTable(const Function *F, unsigned char *TableStart,
-                               unsigned char *TableEnd, 
-                               unsigned char* FrameRegister);
-};
-
-} // End mvm namespace
-
-#endif

Modified: vmkit/trunk/lib/Mvm/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Object.cpp?rev=49719&r1=49718&r2=49719&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/Object.cpp (original)
+++ vmkit/trunk/lib/Mvm/Object.cpp Tue Apr 15 05:00:41 2008
@@ -88,7 +88,7 @@
 
 
 PrintBuffer *PrintBuffer::writeObj(const Object *obj) {
-  Object *beg = (Object*)Collector::begOf(obj);
+  Object *beg = (Object*)mvm::Thread::get()->GC->begOf(obj);
   
   if(beg) {
     if(beg == obj) {

Modified: vmkit/trunk/lib/Mvm/Sigsegv.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Sigsegv.cpp?rev=49719&r1=49718&r2=49719&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/Sigsegv.cpp (original)
+++ vmkit/trunk/lib/Mvm/Sigsegv.cpp Tue Apr 15 05:00:41 2008
@@ -10,6 +10,7 @@
 
 #include "MvmGC.h"
 #include "mvm/Sigsegv.h"
+#include "mvm/Threads/Thread.h"
 
 #include <signal.h>
 #include <stdio.h>
@@ -49,7 +50,11 @@
 #endif
 	
   /* Free the GC if it sisgegv'd. No other collection is possible */
+#ifndef MULTIPLE_GC
   Collector::die_if_sigsegv_occured_during_collection(addr);
+#else
+  mvm::Thread::get()->GC->die_if_sigsegv_occured_during_collection(addr);
+#endif
 	
   //	sys_exit(0);
   if(client_sigsegv_handler)





More information about the llvm-commits mailing list