* src/mm/gc.hpp (GC): Added inline function critical_enter and critical_leave
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Tue, 19 Aug 2008 13:05:51 +0000 (15:05 +0200)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Tue, 19 Aug 2008 13:05:51 +0000 (15:05 +0200)
for LLNI critical sections.
* src/vm/javaobjects.hpp: Use above new functions instead of LLNI macros.

src/mm/gc.hpp
src/vm/javaobjects.hpp

index 60d5c3ae58d75ac8d2577d9780abb34b2585a993..d7f74e572521a5504ac5dc0b37905eb1940d7af0 100644 (file)
 
 #include "config.h"
 
+#include <assert.h>
 #include <stdint.h>
 
+#if defined(ENABLE_GC_CACAO)
+# include "threads/thread.hpp"
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -37,6 +42,22 @@ extern "C" {
 #include "vm/global.h"
 #include "vm/method.h"
 
+#ifdef __cplusplus
+}
+#endif
+
+#ifdef __cplusplus
+
+class GC {
+public:
+       // Critical section functions.
+       static void critical_enter(void);
+       static void critical_leave(void);
+};
+
+extern "C" {
+#endif
+
 
 /* reference types ************************************************************/
 
@@ -94,6 +115,41 @@ static inline int32_t heap_hashcode(java_object_t *obj)
 
 #ifdef __cplusplus
 }
+
+/**
+ * Enters a LLNI critical section which prevents the GC from moving
+ * objects around on the collected heap.
+ *
+ * There are no race conditions possible while entering such a critical
+ * section, because each thread only modifies its own thread local flag
+ * and the GC reads the flags while the world is stopped.
+ */
+inline void GC::critical_enter()
+{
+#if defined(ENABLE_GC_CACAO)
+       threadobject *t;
+
+       t = THREADOBJECT;
+       assert(!t->gc_critical);
+       t->gc_critical = true;
+#endif
+}
+
+/**
+ * Leaves a LLNI critical section and allows the GC to move objects
+ * around on the collected heap again.
+ */
+inline void GC::critical_leave()
+{
+#if defined(ENABLE_GC_CACAO)
+       threadobject *t;
+
+       t = THREADOBJECT;
+       assert(t->gc_critical);
+       t->gc_critical = false;
+#endif
+}
+
 #endif
 
 #endif /* _GC_HPP */
index c3b7a6d9a7ee3dbeb22b114ee161ded7412d1a8c..53e9c9774cc158e0c6b629f799d9e214cc4dbc34 100644 (file)
@@ -86,32 +86,26 @@ template<class T> inline T FieldAccess::get(java_handle_t* h, const off_t offset
 {
        java_object_t* o;
        T result;
-               
-       // XXX Move this to a GC inline function, e.g.
-       // gc->enter_critical();
-       LLNI_CRITICAL_START;
+
+       GC::critical_enter();
 
        // XXX This should be _handle->get_object();
        o = LLNI_UNWRAP(h);
 
        result = raw_get<T>(o, offset);
 
-       // XXX Move this to a GC inline function.
-       // gc->leave_critical();
-       LLNI_CRITICAL_END;
+       GC::critical_leave();
 
        return result;
-}      
+}
 
 template<> inline java_handle_t* FieldAccess::get(java_handle_t* h, const off_t offset)
 {
        java_object_t* o;
        java_object_t* result;
        java_handle_t* hresult;
-               
-       // XXX Move this to a GC inline function, e.g.
-       // gc->enter_critical();
-       LLNI_CRITICAL_START;
+
+       GC::critical_enter();
 
        // XXX This should be _handle->get_object();
        o = LLNI_UNWRAP(h);
@@ -120,9 +114,7 @@ template<> inline java_handle_t* FieldAccess::get(java_handle_t* h, const off_t
 
        hresult = LLNI_WRAP(result);
 
-       // XXX Move this to a GC inline function.
-       // gc->leave_critical();
-       LLNI_CRITICAL_END;
+       GC::critical_leave();
 
        return hresult;
 }      
@@ -132,18 +124,14 @@ template<class T> inline void FieldAccess::set(java_handle_t* h, const off_t off
 {
        java_object_t* o;
 
-       // XXX Move this to a GC inline function, e.g.
-       // gc->enter_critical();
-       LLNI_CRITICAL_START;
+       GC::critical_enter();
 
        // XXX This should be h->get_object();
        o = LLNI_UNWRAP(h);
 
        raw_set(o, offset, value);
 
-       // XXX Move this to a GC inline function.
-       // gc->leave_critical();
-       LLNI_CRITICAL_END;
+       GC::critical_leave();
 }
 
 template<> inline void FieldAccess::set<java_handle_t*>(java_handle_t* h, const off_t offset, java_handle_t* value)
@@ -151,9 +139,7 @@ template<> inline void FieldAccess::set<java_handle_t*>(java_handle_t* h, const
        java_object_t* o;
        java_object_t* ovalue;
 
-       // XXX Move this to a GC inline function, e.g.
-       // gc->enter_critical();
-       LLNI_CRITICAL_START;
+       GC::critical_enter();
 
        // XXX This should be h->get_object();
        o      = LLNI_UNWRAP(h);
@@ -161,9 +147,7 @@ template<> inline void FieldAccess::set<java_handle_t*>(java_handle_t* h, const
 
        raw_set(o, offset, ovalue);
 
-       // XXX Move this to a GC inline function.
-       // gc->leave_critical();
-       LLNI_CRITICAL_END;
+       GC::critical_leave();
 }
 
 
@@ -197,17 +181,13 @@ public:
 
 inline vftbl_t* java_lang_Object::get_vftbl() const
 {
-       // XXX Move this to a GC inline function, e.g.
-       // gc->enter_critical();
-       LLNI_CRITICAL_START;
+       GC::critical_enter();
 
        // XXX This should be h->get_object();
        java_object_t* o = LLNI_UNWRAP(_handle);
        vftbl_t* vftbl = o->vftbl;
 
-       // XXX Move this to a GC inline function.
-       // gc->leave_critical();
-       LLNI_CRITICAL_END;
+       GC::critical_leave();
 
        return vftbl;
 }