diff --git a/classpath/sun/misc/Unsafe.java b/classpath/sun/misc/Unsafe.java index ed00ee24ca..e5fd094c45 100644 --- a/classpath/sun/misc/Unsafe.java +++ b/classpath/sun/misc/Unsafe.java @@ -73,6 +73,9 @@ public final class Unsafe { public native boolean compareAndSwapInt(Object o, long offset, int old, int new_); + public native boolean compareAndSwapLong(Object o, long offset, + long old, long new_); + public native boolean compareAndSwapObject(Object o, long offset, Object old, Object new_); diff --git a/src/builtin.cpp b/src/builtin.cpp index 63b8a42591..ff29d6e3ce 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -681,6 +681,29 @@ Avian_sun_misc_Unsafe_compareAndSwapInt (&fieldAtOffset(target, offset), expect, update); } +extern "C" AVIAN_EXPORT int64_t JNICALL +Avian_sun_misc_Unsafe_compareAndSwapLong +(Thread* t UNUSED, object, uintptr_t* arguments) +{ + object target = reinterpret_cast(arguments[1]); + int64_t offset; memcpy(&offset, arguments + 2, 8); + uint64_t expect; memcpy(&expect, arguments + 4, 8); + uint64_t update; memcpy(&update, arguments + 6, 8); + +#ifdef AVIAN_HAS_CAS64 + return atomicCompareAndSwap64 + (&fieldAtOffset(target, offset), expect, update); +#else + ACQUIRE_FIELD_FOR_WRITE(t, local::fieldForOffset(t, target, offset)); + if (fieldAtOffset(target, offset) == expect) { + fieldAtOffset(target, offset) = update; + return true; + } else { + return false; + } +#endif +} + extern "C" AVIAN_EXPORT void JNICALL Avian_sun_misc_Unsafe_unpark (Thread* t, object, uintptr_t* arguments) diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index 0dfdae73c5..a49bd43db2 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -2898,29 +2898,6 @@ Avian_sun_misc_Unsafe_putOrderedObject Avian_sun_misc_Unsafe_putObjectVolatile(t, method, arguments); } -extern "C" AVIAN_EXPORT int64_t JNICALL -Avian_sun_misc_Unsafe_compareAndSwapLong -(Thread* t UNUSED, object, uintptr_t* arguments) -{ - object target = reinterpret_cast(arguments[1]); - int64_t offset; memcpy(&offset, arguments + 2, 8); - uint64_t expect; memcpy(&expect, arguments + 4, 8); - uint64_t update; memcpy(&update, arguments + 6, 8); - -#ifdef AVIAN_HAS_CAS64 - return atomicCompareAndSwap64 - (&fieldAtOffset(target, offset), expect, update); -#else - ACQUIRE_FIELD_FOR_WRITE(t, local::fieldForOffset(t, target, offset)); - if (fieldAtOffset(target, offset) == expect) { - fieldAtOffset(target, offset) = update; - return true; - } else { - return false; - } -#endif -} - extern "C" AVIAN_EXPORT int64_t JNICALL Avian_sun_misc_Unsafe_pageSize (Thread*, object, uintptr_t*)