IcedTea/PR585
[cacao.git] / src / native / vm / sun_misc_Unsafe.cpp
index 0ff3c8f7a0baf5a88666f355c784bc66bf87f4bb..e17e68fbc29ab5e5640266eb73928103c00b94f6 100644 (file)
@@ -1,6 +1,6 @@
 /* src/native/vm/sun_misc_Unsafe.cpp - sun/misc/Unsafe
 
-   Copyright (C) 2006, 2007, 2008
+   Copyright (C) 2006, 2007, 2008, 2009, 2010
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
 #include "threads/atomic.hpp"
 
-#include "mm/memory.h"
+#include "mm/memory.hpp"
 
-#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/array.hpp"
+#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.
@@ -90,16 +71,9 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_registerNatives(JNIEnv *env, jclass
  * 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);
 }
 
 
@@ -108,13 +82,9 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getInt__Ljava_lang_Object_2J(JNIE
  * 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);
 }
 
 
@@ -123,16 +93,9 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__Ljava_lang_Object_2JI(JNIEnv
  * 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);
 }
 
 
@@ -141,13 +104,9 @@ JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_getObject(JNIEnv *env,
  * 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);
 }
 
 
@@ -156,16 +115,9 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObject(JNIEnv *env, sun_misc_Unsa
  * 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);
 }
 
 
@@ -174,13 +126,9 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getBoolean(JNIEnv *env, sun_misc_
  * 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);
 }
 
 
@@ -189,16 +137,9 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putBoolean(JNIEnv *env, sun_misc_Uns
  * 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);
 }
 
 
@@ -207,13 +148,9 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getByte__Ljava_lang_Object_2J(JNI
  * 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);
 }
 
 
@@ -222,16 +159,9 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__Ljava_lang_Object_2JB(JNIEn
  * 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);
 }
 
 
@@ -240,13 +170,9 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getShort__Ljava_lang_Object_2J(JN
  * 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);
 }
 
 
@@ -255,16 +181,9 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__Ljava_lang_Object_2JS(JNIE
  * 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);
 }
 
 
@@ -273,13 +192,9 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getChar__Ljava_lang_Object_2J(JNI
  * 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);
 }
 
 
@@ -288,16 +203,9 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__Ljava_lang_Object_2JC(JNIEn
  * 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);
 }
 
 
@@ -306,13 +214,9 @@ JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLong__Ljava_lang_Object_2J(JNI
  * 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);
 }
 
 
@@ -321,16 +225,9 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ(JNIEn
  * 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);
 }
 
 
@@ -339,13 +236,9 @@ JNIEXPORT float JNICALL Java_sun_misc_Unsafe_getFloat__Ljava_lang_Object_2J(JNIE
  * 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);
 }
 
 
@@ -354,16 +247,9 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__Ljava_lang_Object_2JF(JNIE
  * 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);
 }
 
 
@@ -372,13 +258,9 @@ JNIEXPORT double JNICALL Java_sun_misc_Unsafe_getDouble__Ljava_lang_Object_2J(JN
  * 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);
 }
 
 
@@ -387,7 +269,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putDouble__Ljava_lang_Object_2JD(JNI
  * 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;
@@ -405,7 +287,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getByte__J(JNIEnv *env, sun_misc_
  * 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;
 
@@ -420,7 +302,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__JB(JNIEnv *env, sun_misc_Un
  * 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;
@@ -438,7 +320,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getShort__J(JNIEnv *env, sun_misc
  * 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;
 
@@ -453,7 +335,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__JS(JNIEnv *env, sun_misc_U
  * 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;
@@ -471,7 +353,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getChar__J(JNIEnv *env, sun_misc_
  * 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;
 
@@ -486,7 +368,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__JC(JNIEnv *env, sun_misc_Un
  * 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;
@@ -504,7 +386,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getInt__J(JNIEnv *env, sun_misc_U
  * 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;
 
@@ -519,7 +401,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__JI(JNIEnv *env, struct sun_m
  * 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;
@@ -537,7 +419,7 @@ JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLong__J(JNIEnv *env, sun_misc_
  * 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;
 
@@ -552,7 +434,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__JJ(JNIEnv *env, sun_misc_Un
  * 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;
@@ -570,7 +452,7 @@ JNIEXPORT float JNICALL Java_sun_misc_Unsafe_getFloat__J(JNIEnv *env, sun_misc_U
  * 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;
 
@@ -582,37 +464,60 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__JF(JNIEnv *env, struct sun
 
 /*
  * Class:     sun/misc/Unsafe
- * Method:    objectFieldOffset
- * Signature: (Ljava/lang/reflect/Field;)J
+ * Method:    getDouble
+ * Signature: (J)D
  */
-JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_objectFieldOffset(JNIEnv *env, sun_misc_Unsafe *_this, java_lang_reflect_Field *field)
+JNIEXPORT jdouble JNICALL Java_sun_misc_Unsafe_getDouble__J(JNIEnv *env, jobject _this, jlong address)
 {
-       classinfo *c;
-       fieldinfo *f;
-       int32_t    slot;
+       double *p;
+       double  value;
 
-#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
-       java_lang_reflect_VMField *rvmf;
-#endif
+       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
+ * Signature: (Ljava/lang/reflect/Field;)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_objectFieldOffset(JNIEnv *env, jobject _this, jobject field)
+{
 #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;
 }
 
 
@@ -621,7 +526,7 @@ JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_objectFieldOffset(JNIEnv *env, su
  * 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;
@@ -639,7 +544,6 @@ JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_allocateMemory(JNIEnv *env, sun_m
 }
 
 
-#if 0
 /* OpenJDK 7 */
 
 /*
@@ -647,7 +551,7 @@ JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_allocateMemory(JNIEnv *env, sun_m
  * 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_jdk7(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong bytes, jbyte value)
 {
        size_t  length;
        void   *p;
@@ -665,7 +569,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, sun_misc_Unsa
 
        /* XXX Not sure this is correct. */
 
-       system_memset(p, value, length);
+       os::memset(p, value, length);
 }
 
 
@@ -674,7 +578,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, sun_misc_Unsa
  * 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_jdk7(JNIEnv *env, jobject _this, jobject srcBase, jlong srcOffset, jobject destBase, jlong destOffset, jlong bytes)
 {
        size_t  length;
        void   *src;
@@ -695,15 +599,15 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, sun_misc_Uns
        src  = (void *) (((uint8_t *) srcBase) + srcOffset);
        dest = (void *) (((uint8_t *) destBase) + destOffset);
 
-       system_memcpy(dest, src, length);
+       os::memcpy(dest, src, length);
 }
-#else
+
 /*
  * Class:     sun/misc/Unsafe
  * 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_jdk6(JNIEnv *env, jobject _this, jlong address, jlong bytes, jbyte value)
 {
        size_t  length;
        void   *p;
@@ -719,7 +623,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, sun_misc_Unsa
 
        /* XXX Not sure this is correct. */
 
-       system_memset(p, value, length);
+       os::memset(p, value, length);
 }
 
 
@@ -728,7 +632,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, sun_misc_Unsa
  * 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_jdk6(JNIEnv *env, jobject _this, jlong srcAddress, jlong destAddress, jlong bytes)
 {
        size_t  length;
        void   *src;
@@ -747,9 +651,8 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, sun_misc_Uns
        src  = (void *) (intptr_t) srcAddress;
        dest = (void *) (intptr_t) destAddress;
 
-       system_memcpy(dest, src, length);
+       os::memcpy(dest, src, length);
 }
-#endif
 
 
 /*
@@ -757,7 +660,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, sun_misc_Uns
  * 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;
 
@@ -777,7 +680,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_freeMemory(JNIEnv *env, sun_misc_Uns
  * 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. */
 
@@ -790,34 +693,24 @@ JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_staticFieldOffset(JNIEnv *env, su
  * 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);
 }
 
 
@@ -826,7 +719,7 @@ JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_staticFieldBase(JNIEnv
  * 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;
 
@@ -842,7 +735,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_ensureClassInitialized(JNIEnv *env,
  * 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;
@@ -865,7 +758,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_arrayBaseOffset(JNIEnv *env, sun_
  * 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;
@@ -888,7 +781,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv *env, sun_
  * 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;
 }
@@ -899,7 +792,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_addressSize(JNIEnv *env, sun_misc
  * 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;
 
@@ -914,12 +807,11 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_pageSize(JNIEnv *env, sun_misc_Un
  * 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);
 
@@ -932,7 +824,9 @@ JNIEXPORT java_lang_Class* JNICALL Java_sun_misc_Unsafe_defineClass__Ljava_lang_
 
        /* 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;
        }
@@ -948,23 +842,22 @@ JNIEXPORT java_lang_Class* JNICALL Java_sun_misc_Unsafe_defineClass__Ljava_lang_
 
        /* define the class */
 
-       c = class_define(utfname, cl, len, (uint8_t *) &(LLNI_array_direct(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)
                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;
 }
 
 
@@ -973,7 +866,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_sun_misc_Unsafe_defineClass__Ljava_lang_
  * 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;
@@ -982,7 +875,7 @@ JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_allocateInstance(JNIEnv
 
        o = builtin_new(c);
 
-       return (java_lang_Object *) o;
+       return (jobject ) o;
 }
 
 
@@ -991,7 +884,7 @@ JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_allocateInstance(JNIEnv
  * 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;
 
@@ -1006,16 +899,21 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_throwException(JNIEnv *env, sun_misc
  * 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 **p;
        void           *result;
 
        /* XXX Use LLNI */
 
-       p = (volatile void **) (((uint8_t *) o) + offset);
+       p = (void **) (((uint8_t *) o) + offset);
 
-       result = Atomic::compare_and_swap(p, expected, x);
+       result = Atomic::compare_and_swap(p, (void *) expected, (void *) x);
+#if defined(CAS_PROVIDES_FULL_BARRIER) && CAS_PROVIDES_FULL_BARRIER
+       Atomic::instruction_barrier();
+#else
+       Atomic::memory_barrier();
+#endif
 
        if (result == expected)
                return true;
@@ -1029,7 +927,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapObject(JNIEnv *env,
  * 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;
@@ -1038,7 +936,12 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapInt(JNIEnv *env, su
 
        p = (uint32_t *) (((uint8_t *) o) + offset);
 
-       result = Atomic::compare_and_swap(p, expected, x);
+       result = Atomic::compare_and_swap(p, (uint32_t) expected, (uint32_t) x);
+#if defined(CAS_PROVIDES_FULL_BARRIER) && CAS_PROVIDES_FULL_BARRIER
+       Atomic::instruction_barrier();
+#else
+       Atomic::memory_barrier();
+#endif
 
        if (result == (uint32_t) expected)
                return true;
@@ -1052,7 +955,7 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapInt(JNIEnv *env, su
  * 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;
@@ -1061,7 +964,12 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapLong(JNIEnv *env, s
 
        p = (uint64_t *) (((uint8_t *) o) + offset);
 
-       result = Atomic::compare_and_swap(p, expected, x);
+       result = Atomic::compare_and_swap(p, (uint64_t) expected, (uint64_t) x);
+#if defined(CAS_PROVIDES_FULL_BARRIER) && CAS_PROVIDES_FULL_BARRIER
+       Atomic::instruction_barrier();
+#else
+       Atomic::memory_barrier();
+#endif
 
        if (result == (uint64_t) expected)
                return true;
@@ -1075,71 +983,109 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapLong(JNIEnv *env, s
  * 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;
+       return FieldAccess::get_volatile<jobject>(o, offset);
+}
 
-       p = (volatile void **) (((uint8_t *) o) + offset);
 
-       value = *p;
+/*
+ * Class:     sun/misc/Unsafe
+ * Method:    putObjectVolatile
+ * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObjectVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject x)
+{
+       FieldAccess::set_volatile(o, offset, x);
+}
 
-       return (java_lang_Object *) value;
+
+/*
+ * 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:    putObjectVolatile
- * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
+ * Method:    putBooleanVolatile
+ * Signature: (Ljava/lang/Object;JZ)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_putBooleanVolatile (JNIEnv *env, jobject _this, jobject o, jlong offset, jboolean x)
 {
-       volatile void **p;
+       FieldAccess::set_volatile(o, offset, x);
+}
 
-       p = (volatile void **) (((uint8_t *) o) + offset);
 
-       *p = x;
+/*
+ * 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);
 }
 
 
-#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;
+/*
+ * Class:     sun/misc/Unsafe
+ * Method:    putByteVolatile
+ * Signature: (Ljava/lang/Object;JB)V
+ */
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByteVolatile (JNIEnv *env, jobject _this, jobject o, jlong offset, jbyte x)
+{
+       FieldAccess::set_volatile(o, offset, 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:    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:    putShortVolatile
+ * Signature: (Ljava/lang/Object;JS)V
+ */
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShortVolatile (JNIEnv *env, jobject _this, jobject o, jlong offset, jshort x)
+{
+       FieldAccess::set_volatile(o, offset, x);
+}
+
+
+/*
+ * 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);
+}
+
+
+/*
+ * Class:     sun/misc/Unsafe
+ * Method:    putCharVolatile
+ * Signature: (Ljava/lang/Object;JC)V
+ */
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putCharVolatile (JNIEnv *env, jobject _this, jobject o, jlong offset, jchar x)
+{
+       FieldAccess::set_volatile(o, offset, x);
+}
 
 
 /*
@@ -1147,9 +1093,9 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObjectVolatile(JNIEnv *env, sun_m
  * 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);
 }
 
 
@@ -1158,9 +1104,9 @@ JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getIntVolatile(JNIEnv *env, sun_m
  * 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);
 }
 
 
@@ -1169,9 +1115,9 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putIntVolatile(JNIEnv *env, sun_misc
  * 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);
 }
 
 
@@ -1180,50 +1126,64 @@ JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLongVolatile(JNIEnv *env, sun_
  * 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)
 {
-       UNSAFE_PUT_VOLATILE(int64_t);
+       FieldAccess::set_volatile(o, offset, x);
 }
 
 
 /*
  * Class:     sun/misc/Unsafe
- * Method:    getDoubleVolatile
- * Signature: (Ljava/lang/Object;J)D
+ * Method:    getFloatVolatile
+ * Signature: (Ljava/lang/Object;J)F
  */
-JNIEXPORT double JNICALL Java_sun_misc_Unsafe_getDoubleVolatile(JNIEnv *env, sun_misc_Unsafe* __this, java_lang_Object* o, int64_t offset)
+JNIEXPORT jfloat JNICALL Java_sun_misc_Unsafe_getFloatVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
 {
-       UNSAFE_GET_VOLATILE(double);
+       return FieldAccess::get_volatile<float>(o, offset);
 }
 
 
 /*
  * Class:     sun/misc/Unsafe
- * Method:    putOrderedObject
- * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
+ * Method:    putFloatVolatile
+ * Signature: (Ljava/lang/Object;JF)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_putFloatVolatile (JNIEnv *env, jobject _this, jobject o, jlong offset, jfloat x)
 {
-       java_handle_t  *_h;
-       java_handle_t  *_hx;
-       java_object_t  *_o;
-       java_object_t  *_x;
-       volatile void **_p;
+       FieldAccess::set_volatile(o, offset, x);
+}
 
-       _h  = (java_handle_t *) o;
-       _hx = (java_handle_t *) x;
 
-       LLNI_CRITICAL_START;
+/*
+ * Class:     sun/misc/Unsafe
+ * Method:    getDoubleVolatile
+ * Signature: (Ljava/lang/Object;J)D
+ */
+JNIEXPORT jdouble JNICALL Java_sun_misc_Unsafe_getDoubleVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset)
+{
+       return FieldAccess::get_volatile<double>(o, offset);
+}
 
-       _o = LLNI_UNWRAP(_h);
-       _x = LLNI_UNWRAP(_hx);
-       _p = (volatile void **) (((uint8_t *) _o) + offset);
 
-       *_p = _x;
+/*
+ * Class:     sun/misc/Unsafe
+ * Method:    putDoubleVolatile
+ * Signature: (Ljava/lang/Object;JD)V
+ */
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putDoubleVolatile (JNIEnv *env, jobject _this, jobject o, jlong offset, jdouble x)
+{
+       FieldAccess::set_volatile(o, offset, x);
+}
 
-       Atomic::memory_barrier();
 
-       LLNI_CRITICAL_END;
+/*
+ * Class:     sun/misc/Unsafe
+ * Method:    putOrderedObject
+ * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedObject(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject x)
+{
+       FieldAccess::set_volatile(o, offset, x);
 }
 
 
@@ -1232,9 +1192,9 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedObject(JNIEnv *env, sun_mi
  * 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);
 }
 
 
@@ -1243,9 +1203,9 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedInt(JNIEnv *env, sun_misc_
  * 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);
 }
 
 
@@ -1254,9 +1214,17 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedLong(JNIEnv *env, sun_misc
  * 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);
 }
 
 
@@ -1265,9 +1233,39 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_unpark(JNIEnv *env, sun_misc_Unsafe
  * 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);
+}
+
+
+/*
+ * Class:     sun/misc/Unsafe
+ * Method:    getLoadAverage
+ * Signature: ([DI)I
+ */
+JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_getLoadAverage(JNIEnv *env, jobject _this, jdoubleArray loadavg, jint nelem)
+{
+       DoubleArray da(loadavg);
+
+#define MAX_SAMPLES 3
+
+       // Check the passed number of samples.
+       if ((nelem < 0) || (nelem > da.get_length()) || nelem > MAX_SAMPLES) {
+               exceptions_throw_arrayindexoutofboundsexception();
+               return -1;
+       }
+
+       // Actually retrieve samples.
+       double values[MAX_SAMPLES];
+       int result = os::getloadavg(values, nelem);
+
+       // Save samples into the given array.
+       for (int i = 0; i < result; i++) {
+               da.set_element(i, values[i]);
+       }
+
+       return result;
 }
 
 } // extern "C"
@@ -1307,16 +1305,16 @@ static JNINativeMethod methods[] = {
        { (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
-       // OpenJDK 7
-       { (char*) "setMemory",              (char*) "(Ljava/lang/Object;JJB)V",                                   (void*) (uintptr_t) &Java_sun_misc_Unsafe_setMemory                        },
-       { (char*) "copyMemory",             (char*) "(Ljava/lang/Object;JLjava/lang/Object;JJ)V",                 (void*) (uintptr_t) &Java_sun_misc_Unsafe_copyMemory                       },
-#else
-       { (char*) "setMemory",              (char*) "(JJB)V",                                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_setMemory                        },
-       { (char*) "copyMemory",             (char*) "(JJJ)V",                                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_copyMemory                       },
-#endif
+       // next two methods: OpenJDK 7
+       { (char*) "setMemory",              (char*) "(Ljava/lang/Object;JJB)V",                                   (void*) (uintptr_t) &Java_sun_misc_Unsafe_setMemory_jdk7                   },
+       { (char*) "copyMemory",             (char*) "(Ljava/lang/Object;JLjava/lang/Object;JJ)V",                 (void*) (uintptr_t) &Java_sun_misc_Unsafe_copyMemory_jdk7                  },
+       // next two methods: OpenJDK 6
+       { (char*) "setMemory",              (char*) "(JJB)V",                                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_setMemory_jdk6                   },
+       { (char*) "copyMemory",             (char*) "(JJJ)V",                                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_copyMemory_jdk6                  },
        { (char*) "freeMemory",             (char*) "(J)V",                                                       (void*) (uintptr_t) &Java_sun_misc_Unsafe_freeMemory                       },
        { (char*) "staticFieldOffset",      (char*) "(Ljava/lang/reflect/Field;)J",                               (void*) (uintptr_t) &Java_sun_misc_Unsafe_staticFieldOffset                },
        { (char*) "staticFieldBase",        (char*) "(Ljava/lang/reflect/Field;)Ljava/lang/Object;",              (void*) (uintptr_t) &Java_sun_misc_Unsafe_staticFieldBase                  },
@@ -1325,7 +1323,7 @@ static JNINativeMethod methods[] = {
        { (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/ProtectionDomain;)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             },
@@ -1333,16 +1331,28 @@ static JNINativeMethod methods[] = {
        { (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*) "putBooleanVolatile",     (char*) "(Ljava/lang/Object;JZ)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putBooleanVolatile               },
+       { (char*) "getByteVolatile",        (char*) "(Ljava/lang/Object;J)B",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getByteVolatile                  },
+       { (char*) "putByteVolatile",        (char*) "(Ljava/lang/Object;JB)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putByteVolatile                  },
+       { (char*) "getShortVolatile",       (char*) "(Ljava/lang/Object;J)S",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getShortVolatile                 },
+       { (char*) "putShortVolatile",       (char*) "(Ljava/lang/Object;JS)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putShortVolatile                 },
+       { (char*) "getCharVolatile",        (char*) "(Ljava/lang/Object;J)C",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getCharVolatile                  },
+       { (char*) "putCharVolatile",        (char*) "(Ljava/lang/Object;JC)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putCharVolatile                  },
        { (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*) "putFloatVolatile",       (char*) "(Ljava/lang/Object;JF)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putFloatVolatile                 },
        { (char*) "getDoubleVolatile",      (char*) "(Ljava/lang/Object;J)D",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getDoubleVolatile                },
+       { (char*) "putDoubleVolatile",      (char*) "(Ljava/lang/Object;JD)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putDoubleVolatile                },
        { (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                    },
        { (char*) "putOrderedLong",         (char*) "(Ljava/lang/Object;JJ)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putOrderedLong                   },
        { (char*) "unpark",                 (char*) "(Ljava/lang/Object;)V",                                      (void*) (uintptr_t) &Java_sun_misc_Unsafe_unpark                           },
        { (char*) "park",                   (char*) "(ZJ)V",                                                      (void*) (uintptr_t) &Java_sun_misc_Unsafe_park                             },
+       { (char*) "getLoadAverage",         (char*) "([DI)I",                                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getLoadAverage                   },
 };
 
 
@@ -1352,18 +1362,15 @@ static JNINativeMethod methods[] = {
 
 *******************************************************************************/
 
-// 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
@@ -1375,4 +1382,5 @@ void _Jv_sun_misc_Unsafe_init(void)
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */