X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fvm%2Fjavaobjects.hpp;h=285e23572ab532443ef3e31e76a86b7c8480fe08;hb=1a841b897ae73436107ccf8ba070042d681b18e3;hp=7253e44b6bc46a8204132af2d81137b40e7e1ce7;hpb=032957bfb6cc84a4440fb6c3de972b15148b52b6;p=cacao.git diff --git a/src/vm/javaobjects.hpp b/src/vm/javaobjects.hpp index 7253e44b6..285e23572 100644 --- a/src/vm/javaobjects.hpp +++ b/src/vm/javaobjects.hpp @@ -29,15 +29,17 @@ #include -#include "mm/memory.h" +#include "mm/memory.hpp" #include "native/llni.h" -#include "vm/class.h" -#include "vm/field.h" +#include "threads/atomic.hpp" + +#include "vm/class.hpp" +#include "vm/field.hpp" #include "vm/global.h" #include "vm/globals.hpp" -#include "vm/method.h" +#include "vm/method.hpp" #ifdef __cplusplus @@ -77,93 +79,106 @@ template inline void RawFieldAccess::raw_set(void* address, const off_t * afterwards. */ class FieldAccess : private RawFieldAccess { -protected: +public: + // Normal field accessors. template static inline T get(java_handle_t* h, const off_t offset); template static inline void set(java_handle_t* h, const off_t offset, T value); + + // Volatile field accessors. + template static inline T get_volatile(java_handle_t* h, const off_t offset); + template static inline void set_volatile(java_handle_t* h, const off_t offset, T value); }; + 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; + // This function is inside a critical section. + GCCriticalSection cs; // XXX This should be _handle->get_object(); - o = LLNI_UNWRAP(h); - - result = raw_get(o, offset); + java_object_t* ho = LLNI_UNWRAP(h); + return raw_get(ho, offset); +} - // XXX Move this to a GC inline function. - // gc->leave_critical(); - LLNI_CRITICAL_END; +template<> inline java_handle_t* FieldAccess::get(java_handle_t* h, const off_t offset) +{ + // This function is inside a critical section. + GCCriticalSection cs; - return result; + // XXX This should be _handle->get_object(); + java_object_t* o = LLNI_UNWRAP(h); + java_object_t* result = raw_get(o, offset); + return LLNI_WRAP(result); } -template<> inline java_handle_t* FieldAccess::get(java_handle_t* h, const off_t offset) + +template inline void FieldAccess::set(java_handle_t* h, const off_t offset, T value) { - 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; + // This function is inside a critical section. + GCCriticalSection cs; - // XXX This should be _handle->get_object(); - o = LLNI_UNWRAP(h); + java_object_t* ho = LLNI_UNWRAP(h); + raw_set(ho, offset, value); +} - result = raw_get(o, offset); +template<> inline void FieldAccess::set(java_handle_t* h, const off_t offset, java_handle_t* value) +{ + // This function is inside a critical section. + GCCriticalSection cs; - hresult = LLNI_WRAP(result); + // 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); +} - // XXX Move this to a GC inline function. - // gc->leave_critical(); - LLNI_CRITICAL_END; - return result; -} +template inline T FieldAccess::get_volatile(java_handle_t* h, const off_t offset) +{ + // This function is inside a critical section. + GCCriticalSection cs; + // XXX This should be _handle->get_object(); + java_object_t* ho = LLNI_UNWRAP(h); + return raw_get(ho, offset); +} -template inline void FieldAccess::set(java_handle_t* h, const off_t offset, T value) +template<> inline java_handle_t* FieldAccess::get_volatile(java_handle_t* h, const off_t offset) { - java_object_t* o; + // This function is inside a critical section. + GCCriticalSection cs; - // XXX Move this to a GC inline function, e.g. - // gc->enter_critical(); - LLNI_CRITICAL_START; + // XXX This should be _handle->get_object(); + java_object_t* o = LLNI_UNWRAP(h); + java_object_t* result = (java_object_t*) raw_get(o, offset); + return LLNI_WRAP(result); +} - // XXX This should be h->get_object(); - o = LLNI_UNWRAP(h); - raw_set(o, offset, value); +template inline void FieldAccess::set_volatile(java_handle_t* h, const off_t offset, T value) +{ + // This function is inside a critical section. + GCCriticalSection cs; + + java_object_t* ho = LLNI_UNWRAP(h); + raw_set(ho, offset, (volatile T) value); - // XXX Move this to a GC inline function. - // gc->leave_critical(); - LLNI_CRITICAL_END; + // Memory barrier for the Java Memory Model. + Atomic::memory_barrier(); } -template<> inline void FieldAccess::set(java_handle_t* h, const off_t offset, java_handle_t* value) +template<> inline void FieldAccess::set_volatile(java_handle_t* h, const off_t offset, java_handle_t* value) { - java_object_t* o; - java_object_t* ovalue; - - // XXX Move this to a GC inline function, e.g. - // gc->enter_critical(); - LLNI_CRITICAL_START; + // This function is inside a critical section. + GCCriticalSection cs; // XXX This should be h->get_object(); - o = LLNI_UNWRAP(h); - ovalue = LLNI_UNWRAP(value); + java_object_t* o = LLNI_UNWRAP(h); + java_object_t* ovalue = LLNI_UNWRAP(value); + raw_set(o, offset, (volatile java_object_t*) ovalue); - raw_set(o, offset, ovalue); - - // XXX Move this to a GC inline function. - // gc->leave_critical(); - LLNI_CRITICAL_END; + // Memory barrier for the Java Memory Model. + Atomic::memory_barrier(); } @@ -179,17 +194,16 @@ protected: // Handle of Java object. java_handle_t* _handle; -protected: +public: java_lang_Object() : _handle(NULL) {} java_lang_Object(java_handle_t* h) : _handle(h) {} - java_lang_Object(jobject h) : _handle((java_handle_t*) h) {} virtual ~java_lang_Object() {} -public: // Getters. - virtual inline java_handle_t* get_handle() const { return _handle; } - inline vftbl_t* get_vftbl () const; - inline classinfo* get_Class () const; + virtual inline java_handle_t* get_handle () const { return _handle; } + inline vftbl_t* get_vftbl () const; + inline classinfo* get_Class () const; + inline int32_t get_hashcode() const; inline bool is_null () const; inline bool is_non_null() const; @@ -198,19 +212,12 @@ 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; + // 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; - - // XXX Move this to a GC inline function. - // gc->leave_critical(); - LLNI_CRITICAL_END; - - return vftbl; + return o->vftbl; } inline classinfo* java_lang_Object::get_Class() const @@ -218,6 +225,20 @@ inline classinfo* java_lang_Object::get_Class() const return get_vftbl()->clazz; } +inline int32_t java_lang_Object::get_hashcode() const +{ +#if defined(ENABLE_GC_CACAO) + return heap_get_hashcode(_handle); +#else + // This function is inside a critical section. + GCCriticalSection cs; + + // XXX This should be h->get_object(); + java_object_t* o = LLNI_UNWRAP(_handle); + return (int32_t) (intptr_t) o; +#endif +} + inline bool java_lang_Object::is_null() const { @@ -561,7 +582,6 @@ public: // Setters. inline void set_pd(java_handle_t* value); - inline void set_pd(jobject value); }; inline void java_lang_Class::set_pd(java_handle_t* value) @@ -569,11 +589,6 @@ inline void java_lang_Class::set_pd(java_handle_t* value) set(_handle, offset_pd, value); } -inline void java_lang_Class::set_pd(jobject value) -{ - set_pd((java_handle_t*) value); -} - /** * GNU Classpath java/lang/StackTraceElement @@ -636,7 +651,6 @@ private: public: java_lang_String(java_handle_t* h) : java_lang_Object(h) {} - java_lang_String(jstring h); java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0); // Getters. @@ -650,11 +664,6 @@ public: inline void set_offset(int32_t value); }; -inline java_lang_String::java_lang_String(jstring h) : java_lang_Object(h) -{ - java_lang_String((java_handle_t*) h); -} - inline java_lang_String::java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset) : java_lang_Object(h) { set_value(value); @@ -813,7 +822,6 @@ private: public: java_lang_VMThread(java_handle_t* h) : java_lang_Object(h) {} - java_lang_VMThread(jobject h); java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata); // Getters. @@ -826,11 +834,6 @@ public: }; -inline java_lang_VMThread::java_lang_VMThread(jobject h) : java_lang_Object(h) -{ - java_lang_VMThread((java_handle_t*) h); -} - inline java_lang_VMThread::java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata) : java_lang_Object(h) { set_thread(thread); @@ -922,16 +925,11 @@ private: public: java_lang_VMThrowable(java_handle_t* h) : java_lang_Object(h) {} - java_lang_VMThrowable(jobject h); inline java_handle_bytearray_t* get_vmdata() const; inline void set_vmdata(java_handle_bytearray_t* value); }; -inline java_lang_VMThrowable::java_lang_VMThrowable(jobject h) : java_lang_Object(h) -{ - java_lang_VMThrowable((java_handle_t*) h); -} inline java_handle_bytearray_t* java_lang_VMThrowable::get_vmdata() const { @@ -970,7 +968,6 @@ private: public: java_lang_reflect_VMConstructor(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_VMConstructor(jobject h); java_lang_reflect_VMConstructor(methodinfo* m); // Getters. @@ -994,11 +991,6 @@ public: }; -inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_VMConstructor((java_handle_t*) h); -} - inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(methodinfo* m) { _handle = builtin_new(class_java_lang_reflect_VMConstructor); @@ -1106,7 +1098,6 @@ private: public: java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_Constructor(jobject h); java_lang_reflect_Constructor(methodinfo* m); java_handle_t* new_instance(java_handle_objectarray_t* args); @@ -1124,11 +1115,6 @@ public: }; -inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_Constructor((java_handle_t*) h); -} - inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(methodinfo* m) { java_lang_reflect_VMConstructor jlrvmc(m); @@ -1202,7 +1188,6 @@ private: public: java_lang_reflect_VMField(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_VMField(jobject h); java_lang_reflect_VMField(fieldinfo* f); // Getters. @@ -1225,11 +1210,6 @@ public: }; -inline java_lang_reflect_VMField::java_lang_reflect_VMField(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_VMField((java_handle_t*) h); -} - inline java_lang_reflect_VMField::java_lang_reflect_VMField(fieldinfo* f) { _handle = builtin_new(class_java_lang_reflect_VMField); @@ -1333,7 +1313,6 @@ private: public: java_lang_reflect_Field(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_Field(jobject h); java_lang_reflect_Field(fieldinfo* f); // Getters. @@ -1348,11 +1327,6 @@ public: }; -inline java_lang_reflect_Field::java_lang_reflect_Field(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_Field((java_handle_t*) h); -} - inline java_lang_reflect_Field::java_lang_reflect_Field(fieldinfo* f) { java_lang_reflect_VMField jlrvmf(f); @@ -1425,7 +1399,6 @@ private: public: java_lang_reflect_VMMethod(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_VMMethod(jobject h); java_lang_reflect_VMMethod(methodinfo* m); // Getters. @@ -1451,10 +1424,6 @@ public: inline methodinfo* get_method() const; }; -inline java_lang_reflect_VMMethod::java_lang_reflect_VMMethod(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_VMMethod((java_handle_t*) h); -} inline java_lang_reflect_VMMethod::java_lang_reflect_VMMethod(methodinfo* m) { @@ -1581,7 +1550,6 @@ private: public: java_lang_reflect_Method(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_Method(jobject h); java_lang_reflect_Method(methodinfo* m); java_handle_t* invoke(java_handle_t* o, java_handle_objectarray_t* args); @@ -1599,11 +1567,6 @@ public: }; -inline java_lang_reflect_Method::java_lang_reflect_Method(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_Method((java_handle_t*) h); -} - inline java_lang_reflect_Method::java_lang_reflect_Method(methodinfo* m) { java_lang_reflect_VMMethod jlrvmm(m); @@ -1718,16 +1681,11 @@ private: public: java_nio_DirectByteBufferImpl(java_handle_t* h) : java_lang_Object(h) {} - java_nio_DirectByteBufferImpl(jobject h); // Getters. inline java_handle_t* get_address() const; }; -inline java_nio_DirectByteBufferImpl::java_nio_DirectByteBufferImpl(jobject h) : java_lang_Object(h) -{ - java_nio_DirectByteBufferImpl((java_handle_t*) h); -} inline java_handle_t* java_nio_DirectByteBufferImpl::get_address() const { @@ -1891,7 +1849,6 @@ private: public: java_lang_String(java_handle_t* h) : java_lang_Object(h) {} - java_lang_String(jstring h); java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0); // Getters. @@ -1905,11 +1862,6 @@ public: inline void set_count (int32_t value); }; -inline java_lang_String::java_lang_String(jstring h) : java_lang_Object(h) -{ - java_lang_String((java_handle_t*) h); -} - inline java_lang_String::java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset) : java_lang_Object(h) { set_value(value); @@ -2017,8 +1969,9 @@ public: inline java_handle_t* get_uncaughtExceptionHandler() const; // Setters. - inline void set_priority(int32_t value); - inline void set_group (java_handle_t* value); + inline void set_priority (int32_t value); + inline void set_group (java_handle_t* value); + inline void set_threadStatus(int32_t value); }; @@ -2053,6 +2006,11 @@ inline void java_lang_Thread::set_group(java_handle_t* value) set(_handle, offset_group, value); } +inline void java_lang_Thread::set_threadStatus(int32_t value) +{ + set(_handle, offset_threadStatus, value); +} + /** @@ -2077,8 +2035,7 @@ private: public: java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {} - java_lang_Throwable(jobject h); - java_lang_Throwable(jobject h, java_handle_bytearray_t* backtrace); + java_lang_Throwable(java_handle_t* h, java_handle_bytearray_t* backtrace); // Getters. inline java_handle_bytearray_t* get_backtrace () const; @@ -2090,14 +2047,8 @@ public: }; -inline java_lang_Throwable::java_lang_Throwable(jobject h) : java_lang_Object(h) +inline java_lang_Throwable::java_lang_Throwable(java_handle_t* h, java_handle_bytearray_t* backtrace) : java_lang_Object(h) { - java_lang_Throwable((java_handle_t*) h); -} - -inline java_lang_Throwable::java_lang_Throwable(jobject h, java_handle_bytearray_t* backtrace) : java_lang_Object(h) -{ - java_lang_Throwable((java_handle_t*) h); set_backtrace(backtrace); } @@ -2166,7 +2117,6 @@ private: public: java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_Constructor(jobject h); java_lang_reflect_Constructor(methodinfo* m); java_handle_t* new_instance(java_handle_objectarray_t* args); @@ -2192,11 +2142,6 @@ public: }; -inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_Constructor((java_handle_t*) h); -} - inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(methodinfo* m) { _handle = builtin_new(class_java_lang_reflect_Constructor); @@ -2336,7 +2281,6 @@ private: public: java_lang_reflect_Field(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_Field(jobject h); java_lang_reflect_Field(fieldinfo* f); // Getters. @@ -2359,11 +2303,6 @@ public: }; -inline java_lang_reflect_Field::java_lang_reflect_Field(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_Field((java_handle_t*) h); -} - inline java_lang_reflect_Field::java_lang_reflect_Field(fieldinfo* f) { _handle = builtin_new(class_java_lang_reflect_Field); @@ -2498,7 +2437,6 @@ private: public: java_lang_reflect_Method(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_Method(jobject h); java_lang_reflect_Method(methodinfo* m); java_handle_t* invoke(java_handle_t* o, java_handle_objectarray_t* args); @@ -2518,11 +2456,6 @@ public: }; -inline java_lang_reflect_Method::java_lang_reflect_Method(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_Method((java_handle_t*) h); -} - inline java_lang_reflect_Method::java_lang_reflect_Method(methodinfo* m) { _handle = builtin_new(class_java_lang_reflect_Method); @@ -2530,13 +2463,13 @@ inline java_lang_reflect_Method::java_lang_reflect_Method(methodinfo* m) if (is_null()) return; - set(_handle, offset_clazz, m->clazz); - set(_handle, offset_slot, m - m->clazz->methods); - set(_handle, offset_name, javastring_intern(javastring_new(m->name))); + set(_handle, offset_clazz, m->clazz); + set(_handle, offset_slot, (int32_t) (m - m->clazz->methods)); // This cast is important (see PR100). + set(_handle, offset_name, javastring_intern(javastring_new(m->name))); set(_handle, offset_returnType, method_returntype_get(m)); set(_handle, offset_parameterTypes, method_get_parametertypearray(m)); set(_handle, offset_exceptionTypes, method_get_exceptionarray(m)); - set(_handle, offset_modifiers, m->flags & ACC_CLASS_REFLECT_MASK); + set(_handle, offset_modifiers, (int32_t) (m->flags & ACC_CLASS_REFLECT_MASK)); set(_handle, offset_signature, m->signature ? javastring_new(m->signature) : NULL); set(_handle, offset_annotations, method_get_annotations(m)); set(_handle, offset_parameterAnnotations, method_get_parameterannotations(m)); @@ -2608,7 +2541,6 @@ private: public: java_nio_Buffer(java_handle_t* h) : java_lang_Object(h) {} - java_nio_Buffer(jobject h) : java_lang_Object(h) {} // Getters. inline void* get_address() const; @@ -2645,7 +2577,6 @@ private: public: com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h) : java_lang_Object(h) {} - com_sun_cldchi_jvm_FileDescriptor(jobject h); com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, int64_t pointer, int32_t position, int32_t length); com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, com_sun_cldchi_jvm_FileDescriptor& fd); @@ -2661,11 +2592,6 @@ public: }; -inline com_sun_cldchi_jvm_FileDescriptor::com_sun_cldchi_jvm_FileDescriptor(jobject h) : java_lang_Object(h) -{ - com_sun_cldchi_jvm_FileDescriptor((java_handle_t*) h); -} - inline com_sun_cldchi_jvm_FileDescriptor::com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, int64_t pointer, int32_t position, int32_t length) : java_lang_Object(h) { set_pointer(pointer); @@ -2731,7 +2657,6 @@ private: public: java_lang_String(java_handle_t* h) : java_lang_Object(h) {} - java_lang_String(jstring h); java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0); // Getters. @@ -2745,10 +2670,6 @@ public: inline void set_count (int32_t value); }; -inline java_lang_String::java_lang_String(jstring h) : java_lang_Object(h) -{ - java_lang_String((java_handle_t*) h); -} inline java_lang_String::java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset) : java_lang_Object(h) { @@ -2814,7 +2735,6 @@ private: public: java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {} - java_lang_Thread(jobject h); // java_lang_Thread(threadobject* t); // Getters. @@ -2827,11 +2747,6 @@ public: }; -inline java_lang_Thread::java_lang_Thread(jobject h) : java_lang_Object(h) -{ - java_lang_Thread((java_handle_t*) h); -} - // inline java_lang_Thread::java_lang_Thread(threadobject* t) : java_lang_Object(h) // { // java_lang_Thread(thread_get_object(t)); @@ -2878,7 +2793,6 @@ private: public: java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {} - java_lang_Throwable(jobject h); // Getters. inline java_handle_t* get_detailMessage() const; @@ -2889,12 +2803,6 @@ public: }; -inline java_lang_Throwable::java_lang_Throwable(jobject h) : java_lang_Object(h) -{ - java_lang_Throwable((java_handle_t*) h); -} - - inline java_handle_t* java_lang_Throwable::get_detailMessage() const { return get(_handle, offset_detailMessage); @@ -2913,13 +2821,6 @@ inline void java_lang_Throwable::set_backtrace(java_handle_bytearray_t* value) #endif // WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1 -#else - -// Legacy C interface. -java_handle_t* java_lang_reflect_Constructor_create(methodinfo* m); -java_handle_t* java_lang_reflect_Field_create(fieldinfo* f); -java_handle_t* java_lang_reflect_Method_create(methodinfo* m); - #endif #endif // _JAVAOBJECTS_HPP