[llvm-commits] [vmkit] r49554 - in /vmkit/trunk/lib/Mvm: BoehmGC/ BoehmGC/MvmGC.h GCMmap2/MvmGC.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Fri Apr 11 13:05:56 PDT 2008


Author: geoffray
Date: Fri Apr 11 15:05:56 2008
New Revision: 49554

URL: http://llvm.org/viewvc/llvm-project?rev=49554&view=rev
Log:
Include the Boehm interface

Added:
    vmkit/trunk/lib/Mvm/BoehmGC/
    vmkit/trunk/lib/Mvm/BoehmGC/MvmGC.h
    vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h

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

==============================================================================
--- vmkit/trunk/lib/Mvm/BoehmGC/MvmGC.h (added)
+++ vmkit/trunk/lib/Mvm/BoehmGC/MvmGC.h Fri Apr 11 15:05:56 2008
@@ -0,0 +1,148 @@
+//===----------- MvmGC.h - Garbage Collection Interface -------------------===//
+//
+//                     The Micro Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#ifndef MVM_BOEHM_GC_H
+#define MVM_BOEHM_GC_H
+
+//#define GC_REDIRECT_TO_LOCAL
+#include <stdlib.h>
+#include <gc/gc_allocator.h>
+//#include "gc/gc_local_alloc.h"
+#include "gc/gc.h"
+
+extern "C" void * GC_dlopen(const char *path, int mode) throw ();
+
+#include "mvm/GC/GC.h"
+
+#define  gc_new(Class)  __gc_new(Class::VT) Class
+#define __gc_new new
+
+class gc : public gcRoot {
+public:
+
+  void markAndTrace() const {}
+
+  size_t  objectSize() const {
+    gc_header * res = (gc_header*)(GC_base((void*)this));
+    return (GC_size(res) - sizeof(gc_header));
+  }
+
+  static void my_destroyer(void * obj, void * unused){
+    gc_header* res = (gc_header*)GC_base(obj);
+    if(res){
+      res->_2gc()->destroyer(GC_size(res));
+   }
+  }
+  
+  void *  operator new(size_t sz, VirtualTable *VT) {
+    gc_header * res = (gc_header*) GC_MALLOC(sz + sizeof(gc_header));
+    res -> _XXX_vt= VT;
+  
+    GC_register_finalizer_no_order(res, my_destroyer, NULL, NULL, NULL); 
+    return res->_2gc();
+  }
+
+  void *  operator new(size_t sz) {
+    return malloc(sz);
+  }
+
+  void    operator delete(void * p) {
+    //GC_FREE(p);
+  }
+
+  void *  realloc(size_t n) {
+    void * old = GC_base(this);
+    gc_header * res = (gc_header*) GC_REALLOC(old, n + sizeof(gc_header));
+    GC_register_finalizer(old, NULL, NULL, NULL, NULL); 
+    return res->_2gc();
+  }
+
+};
+  
+static int maxMem = 0;
+
+class Collector {
+public:
+
+  typedef void (*markerFn)(void);
+  
+  static void initialise(markerFn mark, void *base_sp) {
+    GC_INIT();
+  }
+  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,
+                                 int, int, int, int) { 
+    return 1;
+  }
+  static unsigned int enable(unsigned int n) {
+    int old = GC_dont_gc;
+    if(n)
+      GC_enable();
+    else
+      GC_disable();
+    return !old;
+  }
+
+  static void gcStats(size_t &no, size_t &nbb) {
+    no = 0;
+    nbb = GC_get_heap_size(); 
+  }
+  
+  static void maybeCollect() {
+    GC_collect_a_little();
+  }
+
+  static void collect(void) {
+    GC_gcollect();
+  }
+  
+  static void inject_my_thread(void *sp) {
+    GC_init();
+  }
+  
+  static void remove_my_thread() {}
+  static Collector* allocate() { return 0; }
+
+  static gc* begOf(const void *obj) {
+    gc_header * a = (gc_header*)GC_base((void*)obj);
+    if(a == NULL) return NULL;
+    else return (gc*)a->_2gc();
+  }
+
+  inline static bool isObject(const void *o) {
+    return begOf((void*)o);
+  }
+  
+
+  static int getMaxMemory(void) { return maxMem; }
+  
+  static int getFreeMemory(void) {
+    return GC_get_free_bytes(); 
+  }
+
+  static int getTotalMemory(void) {
+    return GC_get_heap_size();
+  }
+  
+  static void setMaxMemory(size_t size) {
+    GC_set_max_heap_size(size);
+    maxMem = size;
+  }
+  
+  static void     setMinMemory(size_t size) {
+    if(GC_get_heap_size() < size)
+    GC_expand_hp(size - GC_get_heap_size());
+  }
+};
+
+
+#endif

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

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h (added)
+++ vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h Fri Apr 11 15:05:56 2008
@@ -0,0 +1,65 @@
+//===----------- GC.h - Garbage Collection Interface -----------------------===//
+//
+//                     The Micro Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#ifndef MVM_MMAP_GC_H
+#define MVM_MMAP_GC_H
+
+#include <sys/types.h>
+#include "mvm/GC/GC.h"
+
+#define gc_allocator std::allocator
+#define gc_new(Class)  __gc_new(Class::VT) Class
+#define __gc_new new
+
+class gc : public gcRoot {
+public:
+  
+  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 Collector {
+public:
+
+  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,
+                                 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 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);
+};
+
+
+#endif





More information about the llvm-commits mailing list