#include "threads/atomic.hpp"
-#include "mm/memory.h"
+#include "mm/memory.hpp"
#include "native/jni.hpp"
#include "native/llni.h"
-#include "native/native.h"
+#include "native/native.hpp"
#if defined(ENABLE_JNI_HEADERS)
# include "native/include/sun_misc_Unsafe.h"
#endif
+#include "vm/array.hpp"
#include "vm/jit/builtin.hpp"
#include "vm/exceptions.hpp"
-#include "vm/initialize.h"
+#include "vm/initialize.hpp"
#include "vm/javaobjects.hpp"
#include "vm/os.hpp"
#include "vm/string.hpp"
*/
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);
}
}
+/*
+ * Class: sun/misc/Unsafe
+ * Method: getDouble
+ * Signature: (J)D
+ */
+JNIEXPORT jdouble JNICALL Java_sun_misc_Unsafe_getDouble__J(JNIEnv *env, jobject _this, jlong address)
+{
+ double *p;
+ double value;
+
+ p = (double*) (intptr_t) address;
+
+ value = *p;
+
+ return value;
+}
+
+
+/*
+ * Class: sun/misc/Unsafe
+ * Method: putDouble
+ * Signature: (JD)V
+ */
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putDouble__JD(JNIEnv *env, jobject _this, jlong address, jdouble value)
+{
+ double* p;
+
+ p = (double*) (intptr_t) address;
+
+ *p = value;
+}
+
+
/*
* Class: sun/misc/Unsafe
* Method: objectFieldOffset
/* check the indexes passed */
- if ((off < 0) || (len < 0) || ((off + len) > LLNI_array_size(b))) {
+ ByteArray ba(b);
+
+ if ((off < 0) || (len < 0) || ((off + len) > ba.get_length())) {
exceptions_throw_arrayindexoutofboundsexception();
return NULL;
}
/* define the class */
- c = class_define(utfname, cl, len, (uint8_t *) &(LLNI_array_direct((java_handle_bytearray_t*) b, off)),
+ uint8_t* ptr = ((uint8_t*) ba.get_raw_data_ptr()) + off;
+ c = class_define(utfname, cl, len, ptr,
(java_handle_t *) protectionDomain);
if (c == NULL)
*/
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;
+ FieldAccess::set_volatile(o, offset, x);
+}
- 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;
+/*
+ * Class: sun/misc/Unsafe
+ * Method: getBooleanVolatile
+ * Signature: (Ljava/lang/Object;J)Z
+ */
+JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_getBooleanVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
+{
+ return FieldAccess::get_volatile<int32_t>(o, offset);
+}
+
+
+/*
+ * Class: sun/misc/Unsafe
+ * Method: getByteVolatile
+ * Signature: (Ljava/lang/Object;J)B
+ */
+JNIEXPORT jbyte JNICALL Java_sun_misc_Unsafe_getByteVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
+{
+ return FieldAccess::get_volatile<int32_t>(o, offset);
+}
+
+
+/*
+ * Class: sun/misc/Unsafe
+ * Method: getShortVolatile
+ * Signature: (Ljava/lang/Object;J)S
+ */
+JNIEXPORT jshort JNICALL Java_sun_misc_Unsafe_getShortVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
+{
+ return FieldAccess::get_volatile<int32_t>(o, offset);
+}
+
+
+/*
+ * Class: sun/misc/Unsafe
+ * Method: getCharVolatile
+ * Signature: (Ljava/lang/Object;J)C
+ */
+JNIEXPORT jchar JNICALL Java_sun_misc_Unsafe_getCharVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
+{
+ return FieldAccess::get_volatile<int32_t>(o, offset);
+}
/*
*/
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);
+}
+
+
+/*
+ * Class: sun/misc/Unsafe
+ * Method: getFloatVolatile
+ * Signature: (Ljava/lang/Object;J)F
+ */
+JNIEXPORT jfloat JNICALL Java_sun_misc_Unsafe_getFloatVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
+{
+ return FieldAccess::get_volatile<float>(o, offset);
}
* Method: getDoubleVolatile
* Signature: (Ljava/lang/Object;J)D
*/
-JNIEXPORT jdouble JNICALL Java_sun_misc_Unsafe_getDoubleVolatile(JNIEnv *env, jobject __this, jobject o, jlong 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);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_unpark(JNIEnv *env, jobject _this, jobject thread)
{
- /* XXX IMPLEMENT ME */
+ java_handle_t *h = (java_handle_t *) thread;
+ threadobject *t;
+
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+ h = java_lang_Thread(h).get_vmThread();
+#endif
+ t = thread_get_thread(h);
+
+ threads_unpark(t);
}
*/
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_park(JNIEnv *env, jobject _this, jboolean isAbsolute, jlong time)
{
- /* XXX IMPLEMENT ME */
+ threads_park(isAbsolute, time);
}
} // extern "C"
{ (char*) "putLong", (char*) "(JJ)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putLong__JJ },
{ (char*) "getFloat", (char*) "(J)F", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getFloat__J },
{ (char*) "putFloat", (char*) "(JF)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putFloat__JF },
+ { (char*) "getDouble", (char*) "(J)D", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getDouble__J },
+ { (char*) "putDouble", (char*) "(JD)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putDouble__JD },
{ (char*) "objectFieldOffset", (char*) "(Ljava/lang/reflect/Field;)J", (void*) (uintptr_t) &Java_sun_misc_Unsafe_objectFieldOffset },
{ (char*) "allocateMemory", (char*) "(J)J", (void*) (uintptr_t) &Java_sun_misc_Unsafe_allocateMemory },
#if 0
{ (char*) "compareAndSwapLong", (char*) "(Ljava/lang/Object;JJJ)Z", (void*) (uintptr_t) &Java_sun_misc_Unsafe_compareAndSwapLong },
{ (char*) "getObjectVolatile", (char*) "(Ljava/lang/Object;J)Ljava/lang/Object;", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getObjectVolatile },
{ (char*) "putObjectVolatile", (char*) "(Ljava/lang/Object;JLjava/lang/Object;)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putObjectVolatile },
+ { (char*) "getBooleanVolatile", (char*) "(Ljava/lang/Object;J)Z", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getBooleanVolatile },
+ { (char*) "getByteVolatile", (char*) "(Ljava/lang/Object;J)B", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getByteVolatile },
+ { (char*) "getShortVolatile", (char*) "(Ljava/lang/Object;J)S", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getShortVolatile },
+ { (char*) "getCharVolatile", (char*) "(Ljava/lang/Object;J)C", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getCharVolatile },
{ (char*) "getIntVolatile", (char*) "(Ljava/lang/Object;J)I", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getIntVolatile },
{ (char*) "putIntVolatile", (char*) "(Ljava/lang/Object;JI)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putIntVolatile },
{ (char*) "getLongVolatile", (char*) "(Ljava/lang/Object;J)J", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getLongVolatile },
{ (char*) "putLongVolatile", (char*) "(Ljava/lang/Object;JJ)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putLongVolatile },
+ { (char*) "getFloatVolatile", (char*) "(Ljava/lang/Object;J)F", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getFloatVolatile },
{ (char*) "getDoubleVolatile", (char*) "(Ljava/lang/Object;J)D", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getDoubleVolatile },
{ (char*) "putOrderedObject", (char*) "(Ljava/lang/Object;JLjava/lang/Object;)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putOrderedObject },
{ (char*) "putOrderedInt", (char*) "(Ljava/lang/Object;JI)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putOrderedInt },
*******************************************************************************/
-// FIXME
-extern "C" {
void _Jv_sun_misc_Unsafe_init(void)
{
- utf *u;
-
- u = utf_new_char("sun/misc/Unsafe");
+ utf* u = utf_new_char("sun/misc/Unsafe");
- native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
+ NativeMethods& nm = VM::get_current()->get_nativemethods();
+ nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
}
+
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/