Merged with michi branch at rev 1684fe51cf3d.
[cacao.git] / src / native / vm / sun_misc_Unsafe.cpp
index a6c86a6daa8550c3e799ef774a7556a7123c4a73..bcbfe0feceb955cc6b29e16bf83e8e49f34a5f0d 100644 (file)
@@ -40,6 +40,7 @@
 # include "native/include/sun_misc_Unsafe.h"
 #endif
 
+#include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/exceptions.hpp"
 #include "vm/initialize.hpp"
@@ -825,7 +826,9 @@ JNIEXPORT jclass JNICALL Java_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3
 
        /* 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;
        }
@@ -841,7 +844,8 @@ JNIEXPORT jclass JNICALL Java_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3
 
        /* define the class */
 
-       c = class_define(utfname, cl, len, (uint8_t *) &(LLNI_array_direct((java_handle_bytearray_t*) b, off)),
+       uint8_t* ptr = ((uint8_t*) ba.get_raw_data_ptr()) + off;
+       c = class_define(utfname, cl, len, ptr,
                                         (java_handle_t *) protectionDomain);
 
        if (c == NULL)
@@ -899,14 +903,14 @@ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_throwException(JNIEnv *env, jobject
  */
 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 (result == expected)
                return true;
@@ -929,7 +933,7 @@ JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapInt(JNIEnv *env, j
 
        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 (result == (uint32_t) expected)
                return true;
@@ -952,7 +956,7 @@ JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapLong(JNIEnv *env,
 
        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 (result == (uint64_t) expected)
                return true;