implement Unsafe.putOrderedLong and putVolatileLong

The former just defers to the latter for now, since it provides
strictly weaker guarantees.  Thus it's correct to use full
volatile-style barriers, though not as efficient as it could be on
some architectures.
This commit is contained in:
Joel Dice 2014-01-02 17:49:56 -07:00
parent ab4adef373
commit cc5b58725a
2 changed files with 40 additions and 0 deletions

View File

@ -50,6 +50,10 @@ public final class Unsafe {
public native long getLongVolatile(Object o, long offset);
public native long putLongVolatile(Object o, long offset, long x);
public native long putOrderedLong(Object o, long offset, long x);
public native void putOrderedInt(Object o, long offset, int x);
public native Object getObject(Object o, long offset);

View File

@ -784,6 +784,42 @@ Avian_sun_misc_Unsafe_getLongVolatile
return result;
}
extern "C" AVIAN_EXPORT void JNICALL
Avian_sun_misc_Unsafe_putLongVolatile
(Thread* t, object, uintptr_t* arguments)
{
object o = reinterpret_cast<object>(arguments[1]);
int64_t offset; memcpy(&offset, arguments + 2, 8);
int64_t value; memcpy(&value, arguments + 4, 8);
object field;
if (BytesPerWord < 8) {
field = fieldForOffset(t, o, offset);
PROTECT(t, field);
acquire(t, field);
} else {
storeStoreMemoryBarrier();
}
fieldAtOffset<int64_t>(o, offset) = value;
if (BytesPerWord < 8) {
release(t, field);
} else {
storeLoadMemoryBarrier();
}
}
extern "C" AVIAN_EXPORT void JNICALL
Avian_sun_misc_Unsafe_putOrderedLong
(Thread* t, object method, uintptr_t* arguments)
{
// todo: we might be able to use weaker barriers here than
// putLongVolatile does
Avian_sun_misc_Unsafe_putLongVolatile(t, method, arguments);
}
extern "C" AVIAN_EXPORT void JNICALL
Avian_sun_misc_Unsafe_unpark
(Thread* t, object, uintptr_t* arguments)