From 0f19905c621b6603a6381b43a7227b637786c972 Mon Sep 17 00:00:00 2001 From: Michael Starzinger Date: Tue, 19 Aug 2008 15:05:51 +0200 Subject: [PATCH] * src/mm/gc.hpp (GC): Added inline function critical_enter and critical_leave for LLNI critical sections. * src/vm/javaobjects.hpp: Use above new functions instead of LLNI macros. --- src/mm/gc.hpp | 56 ++++++++++++++++++++++++++++++++++++++++++ src/vm/javaobjects.hpp | 46 ++++++++++------------------------ 2 files changed, 69 insertions(+), 33 deletions(-) diff --git a/src/mm/gc.hpp b/src/mm/gc.hpp index 60d5c3ae5..d7f74e572 100644 --- a/src/mm/gc.hpp +++ b/src/mm/gc.hpp @@ -28,8 +28,13 @@ #include "config.h" +#include #include +#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 */ diff --git a/src/vm/javaobjects.hpp b/src/vm/javaobjects.hpp index c3b7a6d9a..53e9c9774 100644 --- a/src/vm/javaobjects.hpp +++ b/src/vm/javaobjects.hpp @@ -86,32 +86,26 @@ template 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(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 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* h, const off_t offset, java_handle_t* value) @@ -151,9 +139,7 @@ template<> inline void FieldAccess::set(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* 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; } -- 2.25.1