* src/mm/gc.hpp (GC): Removed critical_enter, critical_leave.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Fri, 5 Sep 2008 13:22:09 +0000 (15:22 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Fri, 5 Sep 2008 13:22:09 +0000 (15:22 +0200)
(GCCriticalSection): New class.
* src/vm/javaobjects.hpp: Use new GCCriticalSection.

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

index 4443c93c324562ad0b27db72dd4da0b5137e9229..e41352e1720c96824008ae4ee200d04333ec237a 100644 (file)
 
 class GC {
 public:
-       // Critical section functions.
-       static void critical_enter(void);
-       static void critical_leave(void);
+};
+
+
+/**
+ * Critical section for the GC.
+ */
+class GCCriticalSection {
+public:
+       GCCriticalSection()  { enter(); }
+       ~GCCriticalSection() { leave(); }
+
+       static void enter(void);
+       static void leave(void);
 };
 
 
@@ -56,13 +66,15 @@ public:
  * 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()
+#include <stdio.h>
+inline void GCCriticalSection::enter()
 {
 #if defined(ENABLE_GC_CACAO)
-       threadobject *t;
+       threadobject* t = thread_get_current();
+
+       // Sanity check.
+       assert(t->gc_critical == false);
 
-       t = THREADOBJECT;
-       assert(!t->gc_critical);
        t->gc_critical = true;
 #endif
 }
@@ -71,13 +83,14 @@ inline void GC::critical_enter()
  * Leaves a LLNI critical section and allows the GC to move objects
  * around on the collected heap again.
  */
-inline void GC::critical_leave()
+inline void GCCriticalSection::leave()
 {
 #if defined(ENABLE_GC_CACAO)
-       threadobject *t;
+       threadobject* t = thread_get_current();
+
+       // Sanity check.
+       assert(t->gc_critical == true);
 
-       t = THREADOBJECT;
-       assert(t->gc_critical);
        t->gc_critical = false;
 #endif
 }
index 068ac583190cd976d3fdbbd89bd56b5155623831..5eb1025e26d93aa4c68bf5bc73366ee9a4c293b0 100644 (file)
@@ -92,100 +92,85 @@ public:
 
 template<class T> inline T FieldAccess::get(java_handle_t* h, const off_t offset)
 {
-       GC::critical_enter();
+       // This function is inside a critical section.
+       GCCriticalSection cs;
 
        // XXX This should be _handle->get_object();
        java_object_t* ho = LLNI_UNWRAP(h);
-       T result = raw_get<T>(ho, offset);
-
-       GC::critical_leave();
-
-       return result;
+       return raw_get<T>(ho, offset);
 }
 
 template<> inline java_handle_t* FieldAccess::get(java_handle_t* h, const off_t offset)
 {
-       GC::critical_enter();
+       // This function is inside a critical section.
+       GCCriticalSection cs;
 
        // XXX This should be _handle->get_object();
        java_object_t* o = LLNI_UNWRAP(h);
        java_object_t* result = raw_get<java_object_t*>(o, offset);
-       java_handle_t* hresult = LLNI_WRAP(result);
-
-       GC::critical_leave();
-
-       return hresult;
+       return LLNI_WRAP(result);
 }      
 
 
 template<class T> inline void FieldAccess::set(java_handle_t* h, const off_t offset, T value)
 {
-       GC::critical_enter();
+       // This function is inside a critical section.
+       GCCriticalSection cs;
 
        java_object_t* ho = LLNI_UNWRAP(h);
        raw_set(ho, offset, value);
-
-       GC::critical_leave();
 }
 
 template<> inline void FieldAccess::set<java_handle_t*>(java_handle_t* h, const off_t offset, java_handle_t* value)
 {
-       GC::critical_enter();
+       // This function is inside a critical section.
+       GCCriticalSection cs;
 
        // XXX This should be h->get_object();
        java_object_t* o      = LLNI_UNWRAP(h);
        java_object_t* ovalue = LLNI_UNWRAP(value);
-
        raw_set(o, offset, ovalue);
-
-       GC::critical_leave();
 }
 
 
 template<class T> inline T FieldAccess::get_volatile(java_handle_t* h, const off_t offset)
 {
-       GC::critical_enter();
+       // This function is inside a critical section.
+       GCCriticalSection cs;
 
        // XXX This should be _handle->get_object();
        java_object_t* ho = LLNI_UNWRAP(h);
-       T result = raw_get<volatile T>(ho, offset);
-
-       GC::critical_leave();
-
-       return result;
+       return raw_get<volatile T>(ho, offset);
 }
 
 template<> inline java_handle_t* FieldAccess::get_volatile(java_handle_t* h, const off_t offset)
 {
-       GC::critical_enter();
+       // This function is inside a critical section.
+       GCCriticalSection cs;
 
        // XXX This should be _handle->get_object();
        java_object_t* o = LLNI_UNWRAP(h);
        java_object_t* result = (java_object_t*) raw_get<volatile java_object_t*>(o, offset);
-       java_handle_t* hresult = LLNI_WRAP(result);
-
-       GC::critical_leave();
-
-       return hresult;
+       return LLNI_WRAP(result);
 }      
 
 
 template<class T> inline void FieldAccess::set_volatile(java_handle_t* h, const off_t offset, T value)
 {
-       GC::critical_enter();
+       // This function is inside a critical section.
+       GCCriticalSection cs;
 
        java_object_t* ho = LLNI_UNWRAP(h);
        raw_set(ho, offset, (volatile T) value);
 
        // Memory barrier for the Java Memory Model.
        Atomic::memory_barrier();
-
-       GC::critical_leave();
 }
 
 template<> inline void FieldAccess::set_volatile<java_handle_t*>(java_handle_t* h, const off_t offset, java_handle_t* value)
 {
-       GC::critical_enter();
+       // This function is inside a critical section.
+       GCCriticalSection cs;
 
        // XXX This should be h->get_object();
        java_object_t* o      = LLNI_UNWRAP(h);
@@ -194,8 +179,6 @@ template<> inline void FieldAccess::set_volatile<java_handle_t*>(java_handle_t*
 
        // Memory barrier for the Java Memory Model.
        Atomic::memory_barrier();
-
-       GC::critical_leave();
 }
 
 
@@ -229,15 +212,12 @@ public:
 
 inline vftbl_t* java_lang_Object::get_vftbl() const
 {
-       GC::critical_enter();
+       // This function is inside a critical section.
+       GCCriticalSection cs;
 
        // XXX This should be h->get_object();
        java_object_t* o = LLNI_UNWRAP(_handle);
-       vftbl_t* vftbl = o->vftbl;
-
-       GC::critical_leave();
-
-       return vftbl;
+       return o->vftbl;
 }
 
 inline classinfo* java_lang_Object::get_Class() const
@@ -250,19 +230,12 @@ inline int32_t java_lang_Object::get_hashcode() const
 #if defined(ENABLE_GC_CACAO)
        return heap_get_hashcode(_handle);
 #else
-       java_object_t* o;
-       int32_t hashcode;
-
-       GC::critical_enter();
+       // This function is inside a critical section.
+       GCCriticalSection cs;
 
        // XXX This should be h->get_object();
-       o = LLNI_UNWRAP(_handle);
-
-       hashcode = (int32_t)(intptr_t) o;
-
-       GC::critical_leave();
-       
-       return hashcode;
+       java_object_t* o = LLNI_UNWRAP(_handle);
+       return (int32_t) (intptr_t) o;
 #endif
 }