Merge pull request #138 from soc/topic/unsafe-compareAndSwap

Move Unsafe.compareAndSwapLong from classpath-openjdk.cpp to builtin.cpp
This commit is contained in:
Joel Dice 2013-12-18 08:35:01 -08:00
commit dae1f81d27
3 changed files with 26 additions and 23 deletions

View File

@ -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_);

View File

@ -681,6 +681,29 @@ Avian_sun_misc_Unsafe_compareAndSwapInt
(&fieldAtOffset<uint32_t>(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<object>(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<uint64_t>(target, offset), expect, update);
#else
ACQUIRE_FIELD_FOR_WRITE(t, local::fieldForOffset(t, target, offset));
if (fieldAtOffset<uint64_t>(target, offset) == expect) {
fieldAtOffset<uint64_t>(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)

View File

@ -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<object>(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<uint64_t>(target, offset), expect, update);
#else
ACQUIRE_FIELD_FOR_WRITE(t, local::fieldForOffset(t, target, offset));
if (fieldAtOffset<uint64_t>(target, offset) == expect) {
fieldAtOffset<uint64_t>(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*)