*/
JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_getInt__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset)
{
- int32_t *p;
- int32_t value;
-
- p = (int32_t *) (((uint8_t *) o) + offset);
-
- value = *p;
-
- return value;
+ return FieldAccess::get<int32_t>(o, offset);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__Ljava_lang_Object_2JI(JNIEnv *env, jobject _this, jobject o, jlong offset, jint x)
{
- int32_t *p;
-
- p = (int32_t *) (((uint8_t *) o) + offset);
-
- *p = x;
+ FieldAccess::set(o, offset, x);
}
*/
JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_getObject(JNIEnv *env, jobject _this, jobject o, jlong offset)
{
- void **p;
- void *value;
-
- p = (void **) (((uint8_t *) o) + offset);
-
- value = *p;
-
- return (jobject) value;
+ return FieldAccess::get<jobject>(o, offset);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObject(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject x)
{
- void **p;
-
- p = (void **) (((uint8_t *) o) + offset);
-
- *p = (void *) x;
+ FieldAccess::set(o, offset, x);
}
*/
JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_getBoolean(JNIEnv *env, jobject _this, jobject o, jlong offset)
{
- int32_t *p;
- int32_t value;
-
- p = (int32_t *) (((uint8_t *) o) + offset);
-
- value = *p;
-
- return value;
+ return FieldAccess::get<int32_t>(o, offset);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putBoolean(JNIEnv *env, jobject _this, jobject o, jlong offset, jboolean x)
{
- int32_t *p;
-
- p = (int32_t *) (((uint8_t *) o) + offset);
-
- *p = x;
+ FieldAccess::set(o, offset, (int32_t) x);
}
*/
JNIEXPORT jbyte JNICALL Java_sun_misc_Unsafe_getByte__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset)
{
- int32_t *p;
- int32_t value;
-
- p = (int32_t *) (((uint8_t *) o) + offset);
-
- value = *p;
-
- return value;
+ return FieldAccess::get<int32_t>(o, offset);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__Ljava_lang_Object_2JB(JNIEnv *env, jobject _this, jobject o, jlong offset, jbyte x)
{
- int32_t *p;
-
- p = (int32_t *) (((uint8_t *) o) + offset);
-
- *p = x;
+ FieldAccess::set(o, offset, (int32_t) x);
}
*/
JNIEXPORT jshort JNICALL Java_sun_misc_Unsafe_getShort__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset)
{
- int32_t *p;
- int32_t value;
-
- p = (int32_t *) (((uint8_t *) o) + offset);
-
- value = *p;
-
- return value;
+ return FieldAccess::get<int32_t>(o, offset);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__Ljava_lang_Object_2JS(JNIEnv *env, jobject _this, jobject o, jlong offset, jshort x)
{
- int32_t *p;
-
- p = (int32_t *) (((uint8_t *) o) + offset);
-
- *p = x;
+ FieldAccess::set(o, offset, (int32_t) x);
}
*/
JNIEXPORT jchar JNICALL Java_sun_misc_Unsafe_getChar__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset)
{
- int32_t *p;
- int32_t value;
-
- p = (int32_t *) (((uint8_t *) o) + offset);
-
- value = *p;
-
- return value;
+ return FieldAccess::get<int32_t>(o, offset);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__Ljava_lang_Object_2JC(JNIEnv *env, jobject _this, jobject o, jlong offset, jchar x)
{
- int32_t *p;
-
- p = (int32_t *) (((uint8_t *) o) + offset);
-
- *p = x;
+ FieldAccess::set(o, offset, (int32_t) x);
}
*/
JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_getLong__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset)
{
- int64_t *p;
- int64_t value;
-
- p = (int64_t *) (((uint8_t *) o) + offset);
-
- value = *p;
-
- return value;
+ return FieldAccess::get<int64_t>(o, offset);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong x)
{
- int64_t *p;
-
- p = (int64_t *) (((uint8_t *) o) + offset);
-
- *p = x;
+ FieldAccess::set(o, offset, x);
}
*/
JNIEXPORT jfloat JNICALL Java_sun_misc_Unsafe_getFloat__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset)
{
- float *p;
- float value;
-
- p = (float *) (((uint8_t *) o) + offset);
-
- value = *p;
-
- return value;
+ return FieldAccess::get<float>(o, offset);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__Ljava_lang_Object_2JF(JNIEnv *env, jobject _this, jobject o, jlong offset, jfloat x)
{
- float *p;
-
- p = (float *) (((uint8_t *) o) + offset);
-
- *p = x;
+ FieldAccess::set(o, offset, x);
}
*/
JNIEXPORT jdouble JNICALL Java_sun_misc_Unsafe_getDouble__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset)
{
- double *p;
- double value;
-
- p = (double *) (((uint8_t *) o) + offset);
-
- value = *p;
-
- return value;
+ return FieldAccess::get<double>(o, offset);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putDouble__Ljava_lang_Object_2JD(JNIEnv *env, jobject _this, jobject o, jlong offset, jdouble x)
{
- double *p;
-
- p = (double *) (((uint8_t *) o) + offset);
-
- *p = x;
+ FieldAccess::set(o, offset, x);
}
*/
JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_getObjectVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset)
{
- volatile void **p;
- volatile void *value;
-
- p = (volatile void **) (((uint8_t *) o) + offset);
-
- value = *p;
-
- return (jobject ) value;
+ return FieldAccess::get_volatile<jobject>(o, offset);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObjectVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject x)
{
- volatile void **p;
-
- p = (volatile void **) (((uint8_t *) o) + offset);
-
- *p = x;
-}
-
-
-#define UNSAFE_GET_VOLATILE(type) \
- java_handle_t *_h; \
- java_object_t *_o; \
- volatile type *_p; \
- volatile type _x; \
- \
- _h = (java_handle_t *) o; \
- \
- LLNI_CRITICAL_START; \
- \
- _o = LLNI_UNWRAP(_h); \
- _p = (volatile type *) (((uint8_t *) _o) + offset); \
- \
- _x = *_p; \
- \
- LLNI_CRITICAL_END; \
- \
- return _x;
-
-
-#define UNSAFE_PUT_VOLATILE(type) \
- java_handle_t *_h; \
- java_object_t *_o; \
- volatile type *_p; \
- \
- _h = (java_handle_t *) o; \
- \
- LLNI_CRITICAL_START; \
- \
- _o = LLNI_UNWRAP(_h); \
- _p = (volatile type *) (((uint8_t *) _o) + offset); \
- \
- *_p = x; \
- \
- Atomic::memory_barrier(); \
- \
- LLNI_CRITICAL_END;
+ FieldAccess::set_volatile(o, offset, x);
+}
/*
*/
JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_getIntVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset)
{
- UNSAFE_GET_VOLATILE(int32_t);
+ return FieldAccess::get_volatile<int32_t>(o, offset);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putIntVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset, jint x)
{
- UNSAFE_PUT_VOLATILE(int32_t);
+ FieldAccess::set_volatile(o, offset, x);
}
*/
JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_getLongVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset)
{
- UNSAFE_GET_VOLATILE(int64_t);
+ return FieldAccess::get_volatile<int64_t>(o, offset);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLongVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong x)
{
- UNSAFE_PUT_VOLATILE(int64_t);
+ FieldAccess::set_volatile(o, offset, x);
}
*/
JNIEXPORT jfloat JNICALL Java_sun_misc_Unsafe_getFloatVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
{
- UNSAFE_GET_VOLATILE(float);
+ return FieldAccess::get_volatile<float>(o, offset);
}
*/
JNIEXPORT jdouble JNICALL Java_sun_misc_Unsafe_getDoubleVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset)
{
- UNSAFE_GET_VOLATILE(double);
+ return FieldAccess::get_volatile<double>(o, offset);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedObject(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject x)
{
- java_handle_t *_h;
- java_handle_t *_hx;
- java_object_t *_o;
- java_object_t *_x;
- volatile void **_p;
-
- _h = (java_handle_t *) o;
- _hx = (java_handle_t *) x;
-
- LLNI_CRITICAL_START;
-
- _o = LLNI_UNWRAP(_h);
- _x = LLNI_UNWRAP(_hx);
- _p = (volatile void **) (((uint8_t *) _o) + offset);
-
- *_p = _x;
-
- Atomic::memory_barrier();
-
- LLNI_CRITICAL_END;
+ FieldAccess::set_volatile(o, offset, x);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedInt(JNIEnv *env, jobject _this, jobject o, jlong offset, jint x)
{
- UNSAFE_PUT_VOLATILE(int32_t);
+ FieldAccess::set_volatile(o, offset, x);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedLong(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong x)
{
- UNSAFE_PUT_VOLATILE(int64_t);
+ FieldAccess::set_volatile(o, offset, x);
}
#include "native/llni.h"
+#include "threads/atomic.hpp"
+
#include "vm/class.h"
#include "vm/field.hpp"
#include "vm/global.h"
* 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;
-
GC::critical_enter();
// XXX This should be _handle->get_object();
- o = LLNI_UNWRAP(h);
-
- result = raw_get<T>(o, offset);
+ java_object_t* ho = LLNI_UNWRAP(h);
+ T result = raw_get<T>(ho, offset);
GC::critical_leave();
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;
-
GC::critical_enter();
// XXX This should be _handle->get_object();
- o = LLNI_UNWRAP(h);
-
- result = raw_get<java_object_t*>(o, offset);
-
- hresult = LLNI_WRAP(result);
+ 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();
template<class T> inline void FieldAccess::set(java_handle_t* h, const off_t offset, T value)
{
- java_object_t* o;
+ GC::critical_enter();
+ 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();
// XXX This should be h->get_object();
- o = LLNI_UNWRAP(h);
+ java_object_t* o = LLNI_UNWRAP(h);
+ java_object_t* ovalue = LLNI_UNWRAP(value);
- raw_set(o, offset, value);
+ raw_set(o, offset, ovalue);
GC::critical_leave();
}
-template<> inline void FieldAccess::set<java_handle_t*>(java_handle_t* h, const off_t offset, java_handle_t* value)
+
+template<class T> inline T FieldAccess::get_volatile(java_handle_t* h, const off_t offset)
{
- java_object_t* o;
- java_object_t* ovalue;
+ GC::critical_enter();
+
+ // 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;
+}
+
+template<> inline java_handle_t* FieldAccess::get_volatile(java_handle_t* h, const off_t offset)
+{
+ GC::critical_enter();
+
+ // 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;
+}
+
+
+template<class T> inline void FieldAccess::set_volatile(java_handle_t* h, const off_t offset, T value)
+{
+ GC::critical_enter();
+
+ 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();
// 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);
+ // Memory barrier for the Java Memory Model.
+ Atomic::memory_barrier();
GC::critical_leave();
}