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.
This commit is contained in:
Joel Dice 2012-01-15 10:02:36 -07:00
parent 49d19456d0
commit d29513c653
3 changed files with 17 additions and 2 deletions

View File

@ -246,7 +246,8 @@ ifeq ($(arch),arm)
ifeq ($(build-platform),darwin) ifeq ($(build-platform),darwin)
ios = true ios = true
else else
cflags += -marm -Wno-psabi no-psabi = -Wno-psabi
cflags += -marm $(no-psabi)
endif endif
ifneq ($(arch),$(build-arch)) ifneq ($(arch),$(build-arch))
@ -586,6 +587,8 @@ endif
cflags += $(extra-cflags) cflags += $(extra-cflags)
lflags += $(extra-lflags) lflags += $(extra-lflags)
openjdk-cflags += $(extra-cflags)
driver-source = $(src)/main.cpp driver-source = $(src)/main.cpp
driver-object = $(build)/main.o driver-object = $(build)/main.o
driver-dynamic-objects = \ driver-dynamic-objects = \

View File

@ -2594,15 +2594,25 @@ Avian_sun_misc_Unsafe_compareAndSwapObject
extern "C" JNIEXPORT int64_t JNICALL extern "C" JNIEXPORT int64_t JNICALL
Avian_sun_misc_Unsafe_compareAndSwapLong Avian_sun_misc_Unsafe_compareAndSwapLong
(Thread*, object, uintptr_t* arguments) (Thread* t UNUSED, object, uintptr_t* arguments)
{ {
object target = reinterpret_cast<object>(arguments[1]); object target = reinterpret_cast<object>(arguments[1]);
int64_t offset; memcpy(&offset, arguments + 2, 8); int64_t offset; memcpy(&offset, arguments + 2, 8);
uint64_t expect; memcpy(&expect, arguments + 4, 8); uint64_t expect; memcpy(&expect, arguments + 4, 8);
uint64_t update; memcpy(&update, arguments + 6, 8); uint64_t update; memcpy(&update, arguments + 6, 8);
#ifdef AVIAN_HAS_CAS64
return atomicCompareAndSwap64 return atomicCompareAndSwap64
(&cast<uint64_t>(target, offset), expect, update); (&cast<uint64_t>(target, offset), expect, update);
#else
ACQUIRE_FIELD_FOR_WRITE(t, local::fieldForOffset(t, target, offset));
if (cast<uint64_t>(target, offset) == expect) {
cast<uint64_t>(target, offset) = update;
return true;
} else {
return false;
}
#endif
} }
extern "C" JNIEXPORT int64_t JNICALL extern "C" JNIEXPORT int64_t JNICALL

View File

@ -255,6 +255,8 @@ atomicCompareAndSwap32(uint32_t* p, uint32_t old, uint32_t new_)
#endif #endif
} }
#define AVIAN_HAS_CAS64
inline bool inline bool
atomicCompareAndSwap64(uint64_t* p, uint64_t old, uint64_t new_) atomicCompareAndSwap64(uint64_t* p, uint64_t old, uint64_t new_)
{ {