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);
};
* 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
}
* 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
}
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);
// Memory barrier for the Java Memory Model.
Atomic::memory_barrier();
-
- GC::critical_leave();
}
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
#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
}