From d29513c65325b3af4bbbf6d558884a15195c9264 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sun, 15 Jan 2012 10:02:36 -0700 Subject: [PATCH] fix Avian_sun_misc_Unsafe_compareAndSwapLong for platforms without atomicCompareAndSwap64 We never define atomicCompareAndSwap64 for ARM or PowerPC, and apparently only very recent ARM chips support it, so we must fall back to synchronization-based emulation. --- makefile | 5 ++++- src/classpath-openjdk.cpp | 12 +++++++++++- src/x86.h | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/makefile b/makefile index 89990514f0..218216f537 100755 --- a/makefile +++ b/makefile @@ -246,7 +246,8 @@ ifeq ($(arch),arm) ifeq ($(build-platform),darwin) ios = true else - cflags += -marm -Wno-psabi + no-psabi = -Wno-psabi + cflags += -marm $(no-psabi) endif ifneq ($(arch),$(build-arch)) @@ -586,6 +587,8 @@ endif cflags += $(extra-cflags) lflags += $(extra-lflags) +openjdk-cflags += $(extra-cflags) + driver-source = $(src)/main.cpp driver-object = $(build)/main.o driver-dynamic-objects = \ diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index ecbb86a0a0..2b12362a6c 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -2594,15 +2594,25 @@ Avian_sun_misc_Unsafe_compareAndSwapObject extern "C" JNIEXPORT int64_t JNICALL Avian_sun_misc_Unsafe_compareAndSwapLong -(Thread*, object, uintptr_t* arguments) +(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 (&cast(target, offset), expect, update); +#else + ACQUIRE_FIELD_FOR_WRITE(t, local::fieldForOffset(t, target, offset)); + if (cast(target, offset) == expect) { + cast(target, offset) = update; + return true; + } else { + return false; + } +#endif } extern "C" JNIEXPORT int64_t JNICALL diff --git a/src/x86.h b/src/x86.h index 72570e03a8..72cc891ac1 100644 --- a/src/x86.h +++ b/src/x86.h @@ -255,6 +255,8 @@ atomicCompareAndSwap32(uint32_t* p, uint32_t old, uint32_t new_) #endif } +#define AVIAN_HAS_CAS64 + inline bool atomicCompareAndSwap64(uint64_t* p, uint64_t old, uint64_t new_) {