Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dicej committed Jan 3, 2014
1 parent ab4adef commit cc5b587
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions classpath/sun/misc/Unsafe.java
Expand Up @@ -50,6 +50,10 @@ public static Unsafe getUnsafe() {

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);
Expand Down
36 changes: 36 additions & 0 deletions src/builtin.cpp
Expand Up @@ -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)
Expand Down

0 comments on commit cc5b587

Please sign in to comment.