[vmkit-commits] [vmkit] r84087 - in /vmkit/trunk: include/mvm/Threads/Thread.h lib/Mvm/MMTk/MutatorThread.cpp lib/Mvm/MMTk/MutatorThread.h lib/Mvm/MMTk/MvmGC.cpp lib/Mvm/MMTk/MvmGC.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Wed Oct 14 04:44:23 PDT 2009


Author: geoffray
Date: Wed Oct 14 06:44:23 2009
New Revision: 84087

URL: http://llvm.org/viewvc/llvm-project?rev=84087&view=rev
Log:
More implementation of MMTk interface.


Added:
    vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp
    vmkit/trunk/lib/Mvm/MMTk/MvmGC.h
Modified:
    vmkit/trunk/include/mvm/Threads/Thread.h
    vmkit/trunk/lib/Mvm/MMTk/MutatorThread.cpp
    vmkit/trunk/lib/Mvm/MMTk/MutatorThread.h

Modified: vmkit/trunk/include/mvm/Threads/Thread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=84087&r1=84086&r2=84087&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/Threads/Thread.h (original)
+++ vmkit/trunk/include/mvm/Threads/Thread.h Wed Oct 14 06:44:23 2009
@@ -121,7 +121,7 @@
   
   /// start - Start the execution of a thread.
   ///
-  int start(void (*fct)(mvm::Thread*));
+  virtual int start(void (*fct)(mvm::Thread*));
   
   uint64_t getThreadID() {
     return (uint64_t)this;

Modified: vmkit/trunk/lib/Mvm/MMTk/MutatorThread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MMTk/MutatorThread.cpp?rev=84087&r1=84086&r2=84087&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/MMTk/MutatorThread.cpp (original)
+++ vmkit/trunk/lib/Mvm/MMTk/MutatorThread.cpp Wed Oct 14 06:44:23 2009
@@ -16,12 +16,8 @@
 uint32_t MutatorThread::MMTkMutatorSize = 0;
 uint32_t MutatorThread::MMTkCollectorSize = 0;
 
-void (*MutatorThread::MutatorInit)(uintptr_t) = 0;
-void (*MutatorThread::CollectorInit)(uintptr_t) = 0;
-
-gc* (*gc::MMTkGCAllocator)(uintptr_t Mutator, uint32_t sz, uint32_t align,
-                           uint32_t offset, uint32_t allocator,
-                           uint32_t site);
+MutatorThread::MMTkInitType MutatorThread::MutatorInit = 0;
+MutatorThread::MMTkInitType MutatorThread::CollectorInit = 0;
 
 extern "C" void* MMTkMutatorAllocate(uint32_t size, VirtualTable* VT) {
   void* val = MutatorThread::get()->Allocator.Allocate(size, "MMTk");

Modified: vmkit/trunk/lib/Mvm/MMTk/MutatorThread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MMTk/MutatorThread.h?rev=84087&r1=84086&r2=84087&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/MMTk/MutatorThread.h (original)
+++ vmkit/trunk/lib/Mvm/MMTk/MutatorThread.h Wed Oct 14 06:44:23 2009
@@ -21,26 +21,40 @@
   mvm::BumpPtrAllocator Allocator;
   uintptr_t MutatorContext;
   uintptr_t CollectorContext;
+  
+  /// realRoutine - The function to invoke when the thread starts.
+  ///
+  void (*realRoutine)(mvm::Thread*);
+ 
 
   static uint32_t MMTkMutatorSize;
   static uint32_t MMTkCollectorSize;
 
-  static void (*MutatorInit)(uintptr_t);
-  static void (*CollectorInit)(uintptr_t);
+  typedef void (*MMTkInitType)(uintptr_t);
+  static MMTkInitType MutatorInit;
+  static MMTkInitType CollectorInit;
 
 
-  MutatorThread() {
-    MutatorContext = (uintptr_t)Allocator.Allocate(MMTkMutatorSize, "Mutator");
-    MutatorInit(MutatorContext);
-    CollectorContext = 
-      (uintptr_t)Allocator.Allocate(MMTkCollectorSize, "Collector");
-    CollectorInit(CollectorContext);
+  static void init(Thread* _th) {
+    MutatorThread* th = (MutatorThread*)_th;
+    th->MutatorContext =
+      (uintptr_t)th->Allocator.Allocate(MMTkMutatorSize, "Mutator");
+    MutatorInit(th->MutatorContext);
+    th->CollectorContext = 
+      (uintptr_t)th->Allocator.Allocate(MMTkCollectorSize, "Collector");
+    CollectorInit(th->CollectorContext);
+    th->realRoutine(_th);
   }
 
   static MutatorThread* get() {
     return (MutatorThread*)mvm::Thread::get();
   }
 
+  virtual int start(void (*fct)(mvm::Thread*)) {
+    realRoutine = fct;
+    routine = init;
+    return Thread::start(init);
+  }
 };
 
 }

Added: vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp?rev=84087&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp (added)
+++ vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp Wed Oct 14 06:44:23 2009
@@ -0,0 +1,79 @@
+//===----------- MvmGC.cpp - Garbage Collection Interface -----------------===//
+//
+//                     The VMKit project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#include "MvmGC.h"
+#include "MutatorThread.h"
+
+#include <set>
+
+using namespace mvm;
+
+gc::MMTkAllocType gc::MMTkGCAllocator = 0;
+gc::MMTkPostAllocType gc::MMTkGCPostAllocator = 0;
+
+  
+static std::set<gc*> Set;
+static mvm::SpinLock lock;
+
+extern "C" gc* internalMalloc(uintptr_t Mutator, uint32_t sz, uint32_t align,
+                              uint32_t offset, uint32_t allocator,
+                              uint32_t site) {
+  
+  
+  gc* res = (gc*)malloc(sz);
+  memset(res, 0, sz);
+  
+  lock.acquire();
+  Set.insert(res);
+  lock.release();
+  
+  return res;
+}
+
+void* Collector::begOf(gc* obj) {
+  if (gc::MMTkGCAllocator == internalMalloc) {
+    lock.acquire();
+    std::set<gc*>::iterator I = Set.find(obj);
+    std::set<gc*>::iterator E = Set.end();
+    lock.release();
+    
+    if (I != E) return obj;
+    return 0;
+  } else {
+    abort();
+  }
+}
+
+extern "C" void fakeInit(uintptr_t) {
+}
+
+void Collector::initialise() {
+  if (!gc::MMTkGCAllocator) {
+    gc::MMTkGCAllocator = internalMalloc;
+    MutatorThread::MMTkMutatorSize = 0;
+    MutatorThread::MMTkCollectorSize = 0;
+    MutatorThread::MutatorInit = fakeInit;
+    MutatorThread::CollectorInit = fakeInit;
+  }
+}
+
+extern "C" void conditionalSafePoint() {
+  mvm::Thread::get()->startNative(1);
+  abort();
+  mvm::Thread::get()->endNative();
+}
+
+extern "C" void* gcmalloc(size_t sz, VirtualTable* VT) {
+  mvm::Thread::get()->startNative(1);
+  void* res = gc::operator new(sz, VT);
+  mvm::Thread::get()->endNative();
+  return res;
+}
+

Added: vmkit/trunk/lib/Mvm/MMTk/MvmGC.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MMTk/MvmGC.h?rev=84087&view=auto

==============================================================================
--- vmkit/trunk/lib/Mvm/MMTk/MvmGC.h (added)
+++ vmkit/trunk/lib/Mvm/MMTk/MvmGC.h Wed Oct 14 06:44:23 2009
@@ -0,0 +1,114 @@
+//===----------- MvmGC.h - Garbage Collection Interface -------------------===//
+//
+//                     The VMKit project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#ifndef MVM_MMTK_GC_H
+#define MVM_MMTK_GC_H
+
+#include "MutatorThread.h"
+#include "mvm/VirtualMachine.h"
+#include "mvm/GC/GC.h"
+
+#define gc_allocator std::allocator
+#define gc_new(Class)  __gc_new(Class::VT) Class
+#define __gc_new new
+
+
+#define TRACER tracer()
+#define MARK_AND_TRACE markAndTrace()
+#define CALL_TRACER tracer()
+
+
+
+class gc : public gcRoot {
+public:
+
+  void markAndTrace() const {
+    fprintf(stderr, "Implement mark and trace\n");
+    abort();
+  }
+
+  size_t objectSize() const {
+    fprintf(stderr, "Implement object size\n");
+    abort();
+    return 0;
+  }
+
+  typedef gc* (*MMTkAllocType)(uintptr_t Mutator, uint32_t sz, uint32_t align,
+                               uint32_t offset, uint32_t allocator,
+                               uint32_t site);
+  
+  typedef gc* (*MMTkPostAllocType)(uintptr_t Mutator, uintptr_t ref,
+                                   uintptr_t typeref, uint32_t bytes,
+                                   uint32_t allocator);
+
+  static MMTkAllocType MMTkGCAllocator;
+  
+  static MMTkPostAllocType MMTkGCPostAllocator;
+
+
+  void* operator new(size_t sz, VirtualTable *VT) {
+    gc* res = (gc*)MMTkGCAllocator(mvm::MutatorThread::get()->MutatorContext,
+                                   sz, 0, 0, 0, 0);
+    res->setVirtualTable(VT);
+    
+    if (VT->destructor) {
+      mvm::Thread::get()->MyVM->addFinalizationCandidate(res);
+    }
+    return res;
+  }
+
+};
+
+namespace mvm {
+  
+class Collector {
+public:
+
+  static bool isLive(gc*) {
+    abort();
+  }
+  
+  static void traceStackThread() {
+    abort();
+  }
+  
+  static void scanObject(void*) {
+    abort();
+  }
+  
+  static void collect() {
+    abort();
+  }
+  
+  static void initialise();
+  
+  static int getMaxMemory() {
+    return 0;
+  }
+  
+  static int getFreeMemory() {
+    return 0;
+  }
+  
+  static int getTotalMemory() {
+    return 0;
+  }
+
+  void setMaxMemory(size_t sz){
+  }
+
+  void setMinMemory(size_t sz){
+  }
+
+  static void* begOf(gc*);
+};
+
+}
+#endif





More information about the vmkit-commits mailing list