8155965: Unsafe.weakCompareAndSetVolatile entry points and intrinsics

Reviewed-by: psandoz, vlivanov
This commit is contained in:
Aleksey Shipilev 2016-05-06 17:59:35 +03:00
parent 9773289026
commit ffc21de072
9 changed files with 60 additions and 0 deletions

View File

@ -1298,12 +1298,15 @@
do_name(weakCompareAndSwapObject_name, "weakCompareAndSwapObject") \
do_name(weakCompareAndSwapObjectAcquire_name, "weakCompareAndSwapObjectAcquire") \
do_name(weakCompareAndSwapObjectRelease_name, "weakCompareAndSwapObjectRelease") \
do_name(weakCompareAndSwapObjectVolatile_name, "weakCompareAndSwapObjectVolatile") \
do_name(weakCompareAndSwapLong_name, "weakCompareAndSwapLong") \
do_name(weakCompareAndSwapLongAcquire_name, "weakCompareAndSwapLongAcquire") \
do_name(weakCompareAndSwapLongRelease_name, "weakCompareAndSwapLongRelease") \
do_name(weakCompareAndSwapLongVolatile_name, "weakCompareAndSwapLongVolatile") \
do_name(weakCompareAndSwapInt_name, "weakCompareAndSwapInt") \
do_name(weakCompareAndSwapIntAcquire_name, "weakCompareAndSwapIntAcquire") \
do_name(weakCompareAndSwapIntRelease_name, "weakCompareAndSwapIntRelease") \
do_name(weakCompareAndSwapIntVolatile_name, "weakCompareAndSwapIntVolatile") \
\
do_intrinsic(_compareAndSwapObject, jdk_internal_misc_Unsafe, compareAndSwapObject_name, compareAndSwapObject_signature, F_RN) \
do_intrinsic(_compareAndExchangeObjectVolatile, jdk_internal_misc_Unsafe, compareAndExchangeObjectVolatile_name, compareAndExchangeObject_signature, F_RN) \
@ -1321,12 +1324,15 @@
do_intrinsic(_weakCompareAndSwapObject, jdk_internal_misc_Unsafe, weakCompareAndSwapObject_name, compareAndSwapObject_signature, F_R) \
do_intrinsic(_weakCompareAndSwapObjectAcquire, jdk_internal_misc_Unsafe, weakCompareAndSwapObjectAcquire_name, compareAndSwapObject_signature, F_R) \
do_intrinsic(_weakCompareAndSwapObjectRelease, jdk_internal_misc_Unsafe, weakCompareAndSwapObjectRelease_name, compareAndSwapObject_signature, F_R) \
do_intrinsic(_weakCompareAndSwapObjectVolatile, jdk_internal_misc_Unsafe, weakCompareAndSwapObjectVolatile_name, compareAndSwapObject_signature, F_R) \
do_intrinsic(_weakCompareAndSwapLong, jdk_internal_misc_Unsafe, weakCompareAndSwapLong_name, compareAndSwapLong_signature, F_R) \
do_intrinsic(_weakCompareAndSwapLongAcquire, jdk_internal_misc_Unsafe, weakCompareAndSwapLongAcquire_name, compareAndSwapLong_signature, F_R) \
do_intrinsic(_weakCompareAndSwapLongRelease, jdk_internal_misc_Unsafe, weakCompareAndSwapLongRelease_name, compareAndSwapLong_signature, F_R) \
do_intrinsic(_weakCompareAndSwapLongVolatile, jdk_internal_misc_Unsafe, weakCompareAndSwapLongVolatile_name, compareAndSwapLong_signature, F_R) \
do_intrinsic(_weakCompareAndSwapInt, jdk_internal_misc_Unsafe, weakCompareAndSwapInt_name, compareAndSwapInt_signature, F_R) \
do_intrinsic(_weakCompareAndSwapIntAcquire, jdk_internal_misc_Unsafe, weakCompareAndSwapIntAcquire_name, compareAndSwapInt_signature, F_R) \
do_intrinsic(_weakCompareAndSwapIntRelease, jdk_internal_misc_Unsafe, weakCompareAndSwapIntRelease_name, compareAndSwapInt_signature, F_R) \
do_intrinsic(_weakCompareAndSwapIntVolatile, jdk_internal_misc_Unsafe, weakCompareAndSwapIntVolatile_name, compareAndSwapInt_signature, F_R) \
\
do_intrinsic(_getAndAddInt, jdk_internal_misc_Unsafe, getAndAddInt_name, getAndAddInt_signature, F_R) \
do_name( getAndAddInt_name, "getAndAddInt") \

View File

@ -670,12 +670,15 @@ bool LibraryCallKit::try_to_inline(int predicate) {
case vmIntrinsics::_weakCompareAndSwapObject: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Relaxed);
case vmIntrinsics::_weakCompareAndSwapObjectAcquire: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Acquire);
case vmIntrinsics::_weakCompareAndSwapObjectRelease: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Release);
case vmIntrinsics::_weakCompareAndSwapObjectVolatile: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Volatile);
case vmIntrinsics::_weakCompareAndSwapInt: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Relaxed);
case vmIntrinsics::_weakCompareAndSwapIntAcquire: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Acquire);
case vmIntrinsics::_weakCompareAndSwapIntRelease: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Release);
case vmIntrinsics::_weakCompareAndSwapIntVolatile: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Volatile);
case vmIntrinsics::_weakCompareAndSwapLong: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Relaxed);
case vmIntrinsics::_weakCompareAndSwapLongAcquire: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Acquire);
case vmIntrinsics::_weakCompareAndSwapLongRelease: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Release);
case vmIntrinsics::_weakCompareAndSwapLongVolatile: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Volatile);
case vmIntrinsics::_compareAndExchangeObjectVolatile: return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange, Volatile);
case vmIntrinsics::_compareAndExchangeObjectAcquire: return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange, Acquire);

View File

@ -281,6 +281,18 @@ public class JdkInternalMiscUnsafeAccessTestInt {
assertEquals(x, 2, "weakCompareAndSwapRelease int");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSwapIntVolatile(base, offset, 2, 1);
}
assertEquals(success, true, "weakCompareAndSwapVolatile int");
int x = UNSAFE.getInt(base, offset);
assertEquals(x, 1, "weakCompareAndSwapVolatile int");
}
UNSAFE.putInt(base, offset, 2);
// Compare set and get
{
int o = UNSAFE.getAndSetInt(base, offset, 1);

View File

@ -281,6 +281,18 @@ public class JdkInternalMiscUnsafeAccessTestLong {
assertEquals(x, 2L, "weakCompareAndSwapRelease long");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSwapLongVolatile(base, offset, 2L, 1L);
}
assertEquals(success, true, "weakCompareAndSwapVolatile long");
long x = UNSAFE.getLong(base, offset);
assertEquals(x, 1L, "weakCompareAndSwapVolatile long");
}
UNSAFE.putLong(base, offset, 2L);
// Compare set and get
{
long o = UNSAFE.getAndSetLong(base, offset, 1L);

View File

@ -234,6 +234,18 @@ public class JdkInternalMiscUnsafeAccessTestObject {
assertEquals(x, "bar", "weakCompareAndSwapRelease Object");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSwapObjectVolatile(base, offset, "bar", "foo");
}
assertEquals(success, true, "weakCompareAndSwapVolatile Object");
Object x = UNSAFE.getObject(base, offset);
assertEquals(x, "foo", "weakCompareAndSwapVolatile Object");
}
UNSAFE.putObject(base, offset, "bar");
// Compare set and get
{
Object o = UNSAFE.getAndSetObject(base, offset, "foo");

View File

@ -183,6 +183,7 @@ public class SunMiscUnsafeAccessTestInt {
assertEquals(x, 2, "failing compareAndSwap int value");
}
UNSAFE.putInt(base, offset, 2);
// Compare set and get
{

View File

@ -183,6 +183,7 @@ public class SunMiscUnsafeAccessTestLong {
assertEquals(x, 2L, "failing compareAndSwap long value");
}
UNSAFE.putLong(base, offset, 2L);
// Compare set and get
{

View File

@ -154,6 +154,7 @@ public class SunMiscUnsafeAccessTestObject {
assertEquals(x, "bar", "failing compareAndSwap Object value");
}
UNSAFE.putObject(base, offset, "bar");
// Compare set and get
{

View File

@ -302,7 +302,19 @@ public class $Qualifier$UnsafeAccessTest$Type$ {
$type$ x = UNSAFE.get$Type$(base, offset);
assertEquals(x, $value2$, "weakCompareAndSwapRelease $type$");
}
{
boolean success = false;
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
success = UNSAFE.weakCompareAndSwap$Type$Volatile(base, offset, $value2$, $value1$);
}
assertEquals(success, true, "weakCompareAndSwapVolatile $type$");
$type$ x = UNSAFE.get$Type$(base, offset);
assertEquals(x, $value1$, "weakCompareAndSwapVolatile $type$");
}
#end[JdkInternalMisc]
UNSAFE.put$Type$(base, offset, $value2$);
// Compare set and get
{