#include <stdint.h>
-#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
* afterwards.
*/
class FieldAccess : private RawFieldAccess {
-protected:
+public:
+ // Normal field accessors.
template<class T> static inline T get(java_handle_t* h, const off_t offset);
template<class T> static inline void set(java_handle_t* h, const off_t offset, T value);
+
+ // Volatile field accessors.
+ template<class T> static inline T get_volatile(java_handle_t* h, const off_t offset);
+ template<class T> static inline void set_volatile(java_handle_t* h, const off_t offset, T value);
};
+
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;
+ // This function is inside a critical section.
+ GCCriticalSection cs;
// XXX This should be _handle->get_object();
- o = LLNI_UNWRAP(h);
-
- result = raw_get<T>(o, offset);
+ java_object_t* ho = LLNI_UNWRAP(h);
+ return raw_get<T>(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<java_object_t*>(o, offset);
+ return LLNI_WRAP(result);
}
-template<> inline java_handle_t* FieldAccess::get(java_handle_t* h, const off_t offset)
+
+template<class T> 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<java_object_t*>(o, offset);
+template<> inline void FieldAccess::set<java_handle_t*>(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 hresult;
-}
+template<class T> 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<volatile T>(ho, offset);
+}
-template<class T> 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<volatile java_object_t*>(o, offset);
+ return LLNI_WRAP(result);
+}
- // XXX This should be h->get_object();
- o = LLNI_UNWRAP(h);
- raw_set(o, offset, value);
+template<class T> 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*>(java_handle_t* h, const off_t offset, java_handle_t* value)
+template<> inline void FieldAccess::set_volatile<java_handle_t*>(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();
}
// 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;
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
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
{
// 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)
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
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.
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);
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.
};
-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);
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
{
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.
};
-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);
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);
};
-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);
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.
};
-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);
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.
};
-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);
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.
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)
{
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);
};
-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);
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
{
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.
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);
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);
};
set(_handle, offset_group, value);
}
+inline void java_lang_Thread::set_threadStatus(int32_t value)
+{
+ set(_handle, offset_threadStatus, value);
+}
+
/**
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;
};
-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);
}
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);
};
-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);
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.
};
-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);
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);
};
-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);
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));
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;
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);
};
-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);
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.
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)
{
public:
java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
- java_lang_Thread(jobject h);
// java_lang_Thread(threadobject* t);
// Getters.
};
-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));
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;
};
-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<java_handle_t*>(_handle, offset_detailMessage);
#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