#include "mm/memory.h"
-#include "native/jni.h"
+#include "native/jni.hpp"
#include "native/llni.h"
-#include "native/native.h"
+#include "native/native.hpp"
-#include "native/include/java_lang_Object.h" /* before c.l.C */
-#include "native/include/java_lang_String.h" /* required by j.l.CL */
-
-#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
-# include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
-#endif
-
-#include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
-#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_reflect_Field.h"
-#include "native/include/java_lang_Thread.h" /* required by s.m.U */
-#include "native/include/java_lang_Throwable.h"
-
-#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
-# include "native/include/java_lang_reflect_VMField.h"
+#if defined(ENABLE_JNI_HEADERS)
+# include "native/include/sun_misc_Unsafe.h"
#endif
-#include "native/include/java_security_ProtectionDomain.h" /* required by smU */
-
-// FIXME
-extern "C" {
-#include "native/include/sun_misc_Unsafe.h"
-}
-
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
-#include "vm/initialize.h"
-#include "vm/stringlocal.h"
-
-#include "vmcore/system.h"
-#include "vmcore/utf8.h"
+#include "vm/jit/builtin.hpp"
+#include "vm/exceptions.hpp"
+#include "vm/initialize.hpp"
+#include "vm/javaobjects.hpp"
+#include "vm/os.hpp"
+#include "vm/string.hpp"
+#include "vm/utf8.h"
// Native functions are exported as C functions.
* Method: getInt
* Signature: (Ljava/lang/Object;J)I
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getInt__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset)
+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);
}
* Method: putInt
* Signature: (Ljava/lang/Object;JI)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__Ljava_lang_Object_2JI(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int32_t x)
+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);
}
* Method: getObject
* Signature: (Ljava/lang/Object;J)Ljava/lang/Object;
*/
-JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_getObject(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset)
+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 (java_lang_Object*) value;
+ return FieldAccess::get<jobject>(o, offset);
}
* Method: putObject
* Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObject(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, java_lang_Object *x)
+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);
}
* Method: getBoolean
* Signature: (Ljava/lang/Object;J)Z
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getBoolean(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset)
+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);
}
* Method: putBoolean
* Signature: (Ljava/lang/Object;JZ)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putBoolean(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int32_t x)
+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);
}
* Method: getByte
* Signature: (Ljava/lang/Object;J)B
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getByte__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset)
+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);
}
* Method: putByte
* Signature: (Ljava/lang/Object;JB)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__Ljava_lang_Object_2JB(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int32_t x)
+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);
}
* Method: getShort
* Signature: (Ljava/lang/Object;J)S
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getShort__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset)
+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);
}
* Method: putShort
* Signature: (Ljava/lang/Object;JS)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__Ljava_lang_Object_2JS(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int32_t x)
+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);
}
* Method: getChar
* Signature: (Ljava/lang/Object;J)C
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getChar__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset)
+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);
}
* Method: putChar
* Signature: (Ljava/lang/Object;JC)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__Ljava_lang_Object_2JC(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int32_t x)
+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);
}
* Method: getLong
* Signature: (Ljava/lang/Object;J)J
*/
-JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLong__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset)
+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);
}
* Method: putLong
* Signature: (Ljava/lang/Object;JJ)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int64_t x)
+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);
}
* Method: getFloat
* Signature: (Ljava/lang/Object;J)F
*/
-JNIEXPORT float JNICALL Java_sun_misc_Unsafe_getFloat__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset)
+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);
}
* Method: putFloat
* Signature: (Ljava/lang/Object;JF)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__Ljava_lang_Object_2JF(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, float x)
+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);
}
* Method: getDouble
* Signature: (Ljava/lang/Object;J)D
*/
-JNIEXPORT double JNICALL Java_sun_misc_Unsafe_getDouble__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset)
+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);
}
* Method: putDouble
* Signature: (Ljava/lang/Object;JD)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putDouble__Ljava_lang_Object_2JD(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, double x)
+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);
}
* Method: getByte
* Signature: (J)B
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getByte__J(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address)
+JNIEXPORT jbyte JNICALL Java_sun_misc_Unsafe_getByte__J(JNIEnv *env, jobject _this, jlong address)
{
int8_t *p;
int8_t value;
* Method: putByte
* Signature: (JB)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__JB(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address, int32_t value)
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__JB(JNIEnv *env, jobject _this, jlong address, jbyte value)
{
int8_t *p;
* Method: getShort
* Signature: (J)S
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getShort__J(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address)
+JNIEXPORT jshort JNICALL Java_sun_misc_Unsafe_getShort__J(JNIEnv *env, jobject _this, jlong address)
{
int16_t *p;
int16_t value;
* Method: putShort
* Signature: (JS)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__JS(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address, int32_t value)
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__JS(JNIEnv *env, jobject _this, jlong address, jshort value)
{
int16_t *p;
* Method: getChar
* Signature: (J)C
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getChar__J(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address)
+JNIEXPORT jchar JNICALL Java_sun_misc_Unsafe_getChar__J(JNIEnv *env, jobject _this, jlong address)
{
uint16_t *p;
uint16_t value;
* Method: putChar
* Signature: (JC)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__JC(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address, int32_t value)
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__JC(JNIEnv *env, jobject _this, jlong address, jchar value)
{
uint16_t *p;
* Method: getInt
* Signature: (J)I
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getInt__J(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address)
+JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_getInt__J(JNIEnv *env, jobject _this, jlong address)
{
int32_t *p;
int32_t value;
* Method: putInt
* Signature: (JI)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__JI(JNIEnv *env, struct sun_misc_Unsafe* _this, int64_t address, int32_t value)
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__JI(JNIEnv *env, jobject _this, jlong address, jint value)
{
int32_t *p;
* Method: getLong
* Signature: (J)J
*/
-JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLong__J(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address)
+JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_getLong__J(JNIEnv *env, jobject _this, jlong address)
{
int64_t *p;
int64_t value;
* Method: putLong
* Signature: (JJ)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__JJ(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address, int64_t value)
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__JJ(JNIEnv *env, jobject _this, jlong address, jlong value)
{
int64_t *p;
* Method: getFloat
* Signature: (J)F
*/
-JNIEXPORT float JNICALL Java_sun_misc_Unsafe_getFloat__J(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address)
+JNIEXPORT jfloat JNICALL Java_sun_misc_Unsafe_getFloat__J(JNIEnv *env, jobject _this, jlong address)
{
float *p;
float value;
* Method: putFloat
* Signature: (JF)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__JF(JNIEnv *env, struct sun_misc_Unsafe* __this, int64_t address, float value)
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__JF(JNIEnv *env, jobject _this, jlong address, jfloat value)
{
float* p;
* Method: objectFieldOffset
* Signature: (Ljava/lang/reflect/Field;)J
*/
-JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_objectFieldOffset(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_reflect_Field *field)
+JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_objectFieldOffset(JNIEnv *env, jobject _this, jobject field)
{
- classinfo *c;
- fieldinfo *f;
- int32_t slot;
-
-#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
- java_lang_reflect_VMField *rvmf;
-#endif
-
#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
- LLNI_field_get_ref(field, f, rvmf);
- LLNI_field_get_cls(rvmf, clazz, c);
- LLNI_field_get_val(rvmf, slot , slot);
+ java_lang_reflect_Field rf(field);
+ java_lang_reflect_VMField rvmf(rf.get_f());
+ fieldinfo* f = rvmf.get_field();
#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
- LLNI_field_get_cls(field, clazz, c);
- LLNI_field_get_val(field, slot , slot);
+ java_lang_reflect_Field rf(field);
+ fieldinfo* f = rf.get_field();
#else
# error unknown configuration
#endif
- f = &(c->fields[slot]);
-
- return (int64_t) f->offset;
+ return (jlong) f->offset;
}
* Method: allocateMemory
* Signature: (J)J
*/
-JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_allocateMemory(JNIEnv *env, sun_misc_Unsafe *_this, int64_t bytes)
+JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_allocateMemory(JNIEnv *env, jobject _this, jlong bytes)
{
size_t length;
void *p;
* Method: setMemory
* Signature: (Ljava/lang/Object;JJB)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int64_t bytes, int32_t value)
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong bytes, jbyte value)
{
size_t length;
void *p;
/* XXX Not sure this is correct. */
- system_memset(p, value, length);
+ os::memset(p, value, length);
}
* Method: copyMemory
* Signature: (Ljava/lang/Object;JLjava/lang/Object;JJ)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *srcBase, int64_t srcOffset, java_lang_Object *destBase, int64_t destOffset, int64_t bytes)
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, jobject _this, jobject srcBase, jlong srcOffset, jobject destBase, jlong destOffset, jlong bytes)
{
size_t length;
void *src;
src = (void *) (((uint8_t *) srcBase) + srcOffset);
dest = (void *) (((uint8_t *) destBase) + destOffset);
- system_memcpy(dest, src, length);
+ os::memcpy(dest, src, length);
}
#else
/*
* Method: setMemory
* Signature: (JJB)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address, int64_t bytes, int32_t value)
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, jobject _this, jlong address, jlong bytes, jbyte value)
{
size_t length;
void *p;
/* XXX Not sure this is correct. */
- system_memset(p, value, length);
+ os::memset(p, value, length);
}
* Method: copyMemory
* Signature: (JJJ)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, sun_misc_Unsafe *_this, int64_t srcAddress, int64_t destAddress, int64_t bytes)
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, jobject _this, jlong srcAddress, jlong destAddress, jlong bytes)
{
size_t length;
void *src;
src = (void *) (intptr_t) srcAddress;
dest = (void *) (intptr_t) destAddress;
- system_memcpy(dest, src, length);
+ os::memcpy(dest, src, length);
}
#endif
* Method: freeMemory
* Signature: (J)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_freeMemory(JNIEnv *env, sun_misc_Unsafe *_this, int64_t address)
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_freeMemory(JNIEnv *env, jobject _this, jlong address)
{
void *p;
* Method: staticFieldOffset
* Signature: (Ljava/lang/reflect/Field;)J
*/
-JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_staticFieldOffset(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_reflect_Field *f)
+JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_staticFieldOffset(JNIEnv *env, jobject _this, jobject f)
{
/* The offset of static fields is 0. */
* Method: staticFieldBase
* Signature: (Ljava/lang/reflect/Field;)Ljava/lang/Object;
*/
-JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_staticFieldBase(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_reflect_Field *rf)
+JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_staticFieldBase(JNIEnv *env, jobject _this, jobject field)
{
- classinfo *c;
- fieldinfo *f;
- int32_t slot;
-
-#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
- java_lang_reflect_VMField *rvmf;
-#endif
-
#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
- LLNI_field_get_ref(rf, f, rvmf);
- LLNI_field_get_cls(rvmf, clazz, c);
- LLNI_field_get_val(rvmf, slot , slot);
+ java_lang_reflect_Field rf(field);
+ java_lang_reflect_VMField rvmf(rf.get_f());
+ fieldinfo* f = rvmf.get_field();
#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
- LLNI_field_get_cls(rf, clazz, c);
- LLNI_field_get_val(rf, slot , slot);
+ java_lang_reflect_Field rf(field);
+ fieldinfo* f = rf.get_field();
#else
# error unknown configuration
#endif
- f = &(c->fields[slot]);
-
- return (java_lang_Object *) (f->value);
+ return (jobject) (f->value);
}
* Method: ensureClassInitialized
* Signature: (Ljava/lang/Class;)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_ensureClassInitialized(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Class *clazz)
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_ensureClassInitialized(JNIEnv *env, jobject _this, jclass clazz)
{
classinfo *c;
* Method: arrayBaseOffset
* Signature: (Ljava/lang/Class;)I
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_arrayBaseOffset(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Class *arrayClass)
+JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_arrayBaseOffset(JNIEnv *env, jobject _this, jclass arrayClass)
{
classinfo *c;
arraydescriptor *ad;
* Method: arrayIndexScale
* Signature: (Ljava/lang/Class;)I
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Class *arrayClass)
+JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv *env, jobject _this, jclass arrayClass)
{
classinfo *c;
arraydescriptor *ad;
* Method: addressSize
* Signature: ()I
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_addressSize(JNIEnv *env, sun_misc_Unsafe *_this)
+JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_addressSize(JNIEnv *env, jobject _this)
{
return SIZEOF_VOID_P;
}
* Method: pageSize
* Signature: ()I
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_pageSize(JNIEnv *env, sun_misc_Unsafe *_this)
+JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_pageSize(JNIEnv *env, jobject _this)
{
int sz;
* Method: defineClass
* Signature: (Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;
*/
-JNIEXPORT java_lang_Class* JNICALL Java_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3BIILjava_lang_ClassLoader_2Ljava_security_ProtectionDomain_2(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_String *name, java_handle_bytearray_t *b, int32_t off, int32_t len, java_lang_ClassLoader *loader, java_security_ProtectionDomain *protectionDomain)
+JNIEXPORT jclass JNICALL Java_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3BIILjava_lang_ClassLoader_2Ljava_security_ProtectionDomain_2(JNIEnv *env, jobject _this, jstring name, jbyteArray b, jint off, jint len, jobject loader, jobject protectionDomain)
{
classloader_t *cl;
utf *utfname;
classinfo *c;
- java_lang_Class *o;
cl = loader_hashtable_classloader_add((java_handle_t *) loader);
/* define the class */
- c = class_define(utfname, cl, len, (uint8_t *) &(LLNI_array_direct(b, off)),
+ c = class_define(utfname, cl, len, (uint8_t *) &(LLNI_array_direct((java_handle_bytearray_t*) b, off)),
(java_handle_t *) protectionDomain);
if (c == NULL)
return NULL;
- /* for convenience */
-
- o = LLNI_classinfo_wrap(c);
+ java_handle_t* h = LLNI_classinfo_wrap(c);
#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
- /* set ProtectionDomain */
-
- LLNI_field_set_ref(o, pd, protectionDomain);
+ // Set ProtectionDomain.
+ java_lang_Class jlc(h);
+ jlc.set_pd(protectionDomain);
#endif
- return o;
+ return (jclass) h;
}
* Method: allocateInstance
* Signature: (Ljava/lang/Class;)Ljava/lang/Object;
*/
-JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_allocateInstance(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Class *cls)
+JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_allocateInstance(JNIEnv *env, jobject _this, jclass cls)
{
classinfo *c;
java_handle_t *o;
o = builtin_new(c);
- return (java_lang_Object *) o;
+ return (jobject ) o;
}
* Method: throwException
* Signature: (Ljava/lang/Throwable;)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_throwException(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Throwable *ee)
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_throwException(JNIEnv *env, jobject _this, jobject ee)
{
java_handle_t *o;
* Method: compareAndSwapObject
* Signature: (Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapObject(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, java_lang_Object *expected, java_lang_Object *x)
+JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapObject(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject expected, jobject x)
{
volatile void **p;
void *result;
* Method: compareAndSwapInt
* Signature: (Ljava/lang/Object;JII)Z
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapInt(JNIEnv *env, sun_misc_Unsafe* _this, java_lang_Object* o, int64_t offset, int32_t expected, int32_t x)
+JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapInt(JNIEnv *env, jobject _this, jobject o, jlong offset, jint expected, jint x)
{
uint32_t *p;
uint32_t result;
* Method: compareAndSwapLong
* Signature: (Ljava/lang/Object;JJJ)Z
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapLong(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int64_t expected, int64_t x)
+JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapLong(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong expected, jlong x)
{
uint64_t *p;
uint64_t result;
* Method: getObjectVolatile
* Signature: (Ljava/lang/Object;J)Ljava/lang/Object;
*/
-JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_getObjectVolatile(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset)
+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 (java_lang_Object *) value;
+ return FieldAccess::get_volatile<jobject>(o, offset);
}
* Method: putObjectVolatile
* Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObjectVolatile(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, java_lang_Object *x)
+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: 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);
+}
/*
* Method: getIntVolatile
* Signature: (Ljava/lang/Object;J)I
*/
-JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getIntVolatile(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t 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);
}
* Method: putIntVolatile
* Signature: (Ljava/lang/Object;JI)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putIntVolatile(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int32_t x)
+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);
}
* Method: getLongVolatile
* Signature: (Ljava/lang/Object;J)J
*/
-JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLongVolatile(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset)
+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);
}
* Method: putLongVolatile
* Signature: (Ljava/lang/Object;JJ)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLongVolatile(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int64_t x)
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLongVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong x)
+{
+ 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)
{
- UNSAFE_PUT_VOLATILE(int64_t);
+ return FieldAccess::get_volatile<float>(o, offset);
}
* Method: getDoubleVolatile
* Signature: (Ljava/lang/Object;J)D
*/
-JNIEXPORT double JNICALL Java_sun_misc_Unsafe_getDoubleVolatile(JNIEnv *env, sun_misc_Unsafe* __this, java_lang_Object* o, int64_t 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);
}
* Method: putOrderedObject
* Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedObject(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, java_lang_Object *x)
+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);
}
* Method: putOrderedInt
* Signature: (Ljava/lang/Object;JI)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedInt(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int32_t 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);
}
* Method: putOrderedLong
* Signature: (Ljava/lang/Object;JJ)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedLong(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *o, int64_t offset, int64_t 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);
}
* Method: unpark
* Signature: (Ljava/lang/Object;)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_unpark(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_Object *thread)
+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);
}
* Method: park
* Signature: (ZJ)V
*/
-JNIEXPORT void JNICALL Java_sun_misc_Unsafe_park(JNIEnv *env, sun_misc_Unsafe *_this, int32_t isAbsolute, int64_t time)
+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*) "arrayIndexScale", (char*) "(Ljava/lang/Class;)I", (void*) (uintptr_t) &Java_sun_misc_Unsafe_arrayIndexScale },
{ (char*) "addressSize", (char*) "()I", (void*) (uintptr_t) &Java_sun_misc_Unsafe_addressSize },
{ (char*) "pageSize", (char*) "()I", (void*) (uintptr_t) &Java_sun_misc_Unsafe_pageSize },
- { (char*) "defineClass", (char*) "(Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtetionDomain;)Ljava/lang/Class;", (void *) (intptr_t) &Java_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3BIILjava_lang_ClassLoader_2Ljava_security_ProtectionDomain_2 },
+ { (char*) "defineClass", (char*) "(Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3BIILjava_lang_ClassLoader_2Ljava_security_ProtectionDomain_2 },
{ (char*) "allocateInstance", (char*) "(Ljava/lang/Class;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_sun_misc_Unsafe_allocateInstance },
{ (char*) "throwException", (char*) "(Ljava/lang/Throwable;)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_throwException },
{ (char*) "compareAndSwapObject", (char*) "(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_sun_misc_Unsafe_compareAndSwapObject },
{ (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*) "getByteVolatile", (char*) "(Ljava/lang/Object;J)B", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getByteVolatile },
{ (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:
*/