Merge from subtype.
[cacao.git] / src / native / vm / sun_misc_Unsafe.cpp
index 1117cd851d768e91fc65642742e203345ba035c8..950df13523d3fd106ff57418e2ce239cf1082fe6 100644 (file)
@@ -42,7 +42,7 @@
 
 #include "vm/jit/builtin.hpp"
 #include "vm/exceptions.hpp"
-#include "vm/initialize.h"
+#include "vm/initialize.hpp"
 #include "vm/javaobjects.hpp"
 #include "vm/os.hpp"
 #include "vm/string.hpp"
@@ -950,6 +950,17 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObjectVolatile(JNIEnv *env, jobje
 }
 
 
+/*
+ * Class:     sun/misc/Unsafe
+ * Method:    getByteVolatile
+ * Signature: (Ljava/lang/Object;J)B
+ */
+JNIEXPORT jbyte JNICALL Java_sun_misc_Unsafe_getByteVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
+{
+       return FieldAccess::get_volatile<int32_t>(o, offset);
+}
+
+
 /*
  * Class:     sun/misc/Unsafe
  * Method:    getIntVolatile
@@ -1056,7 +1067,15 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedLong(JNIEnv *env, jobject
  */
 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);
 }
 
 
@@ -1067,7 +1086,7 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_unpark(JNIEnv *env, jobject _this, j
  */
 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"
@@ -1133,6 +1152,7 @@ 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*) "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                  },
@@ -1153,18 +1173,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
@@ -1176,4 +1193,5 @@ void _Jv_sun_misc_Unsafe_init(void)
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */