mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8004318: JEP-171: Support Unsafe fences intrinsics
Add three memory-ordering intrinsics to the sun.misc.Unsafe class. Reviewed-by: twisti, kvn
This commit is contained in:
parent
52da261983
commit
4c293ebcd6
5 changed files with 70 additions and 0 deletions
|
@ -3442,6 +3442,11 @@ bool GraphBuilder::try_inline_intrinsics(ciMethod* callee) {
|
||||||
preserves_state = true;
|
preserves_state = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case vmIntrinsics::_loadFence :
|
||||||
|
case vmIntrinsics::_storeFence:
|
||||||
|
case vmIntrinsics::_fullFence :
|
||||||
|
break;
|
||||||
|
|
||||||
default : return false; // do not inline
|
default : return false; // do not inline
|
||||||
}
|
}
|
||||||
// create intrinsic node
|
// create intrinsic node
|
||||||
|
|
|
@ -2977,6 +2977,16 @@ void LIRGenerator::do_Intrinsic(Intrinsic* x) {
|
||||||
do_CompareAndSwap(x, longType);
|
do_CompareAndSwap(x, longType);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case vmIntrinsics::_loadFence :
|
||||||
|
if (os::is_MP()) __ membar_acquire();
|
||||||
|
break;
|
||||||
|
case vmIntrinsics::_storeFence:
|
||||||
|
if (os::is_MP()) __ membar_release();
|
||||||
|
break;
|
||||||
|
case vmIntrinsics::_fullFence :
|
||||||
|
if (os::is_MP()) __ membar();
|
||||||
|
break;
|
||||||
|
|
||||||
case vmIntrinsics::_Reference_get:
|
case vmIntrinsics::_Reference_get:
|
||||||
do_Reference_get(x);
|
do_Reference_get(x);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -756,6 +756,15 @@
|
||||||
do_intrinsic(_unpark, sun_misc_Unsafe, unpark_name, unpark_signature, F_RN) \
|
do_intrinsic(_unpark, sun_misc_Unsafe, unpark_name, unpark_signature, F_RN) \
|
||||||
do_name( unpark_name, "unpark") \
|
do_name( unpark_name, "unpark") \
|
||||||
do_alias( unpark_signature, /*(LObject;)V*/ object_void_signature) \
|
do_alias( unpark_signature, /*(LObject;)V*/ object_void_signature) \
|
||||||
|
do_intrinsic(_loadFence, sun_misc_Unsafe, loadFence_name, loadFence_signature, F_RN) \
|
||||||
|
do_name( loadFence_name, "loadFence") \
|
||||||
|
do_alias( loadFence_signature, void_method_signature) \
|
||||||
|
do_intrinsic(_storeFence, sun_misc_Unsafe, storeFence_name, storeFence_signature, F_RN) \
|
||||||
|
do_name( storeFence_name, "storeFence") \
|
||||||
|
do_alias( storeFence_signature, void_method_signature) \
|
||||||
|
do_intrinsic(_fullFence, sun_misc_Unsafe, fullFence_name, fullFence_signature, F_RN) \
|
||||||
|
do_name( fullFence_name, "fullFence") \
|
||||||
|
do_alias( fullFence_signature, void_method_signature) \
|
||||||
\
|
\
|
||||||
/* unsafe memory references (there are a lot of them...) */ \
|
/* unsafe memory references (there are a lot of them...) */ \
|
||||||
do_signature(getObject_signature, "(Ljava/lang/Object;J)Ljava/lang/Object;") \
|
do_signature(getObject_signature, "(Ljava/lang/Object;J)Ljava/lang/Object;") \
|
||||||
|
|
|
@ -282,6 +282,7 @@ class LibraryCallKit : public GraphKit {
|
||||||
typedef enum { LS_xadd, LS_xchg, LS_cmpxchg } LoadStoreKind;
|
typedef enum { LS_xadd, LS_xchg, LS_cmpxchg } LoadStoreKind;
|
||||||
bool inline_unsafe_load_store(BasicType type, LoadStoreKind kind);
|
bool inline_unsafe_load_store(BasicType type, LoadStoreKind kind);
|
||||||
bool inline_unsafe_ordered_store(BasicType type);
|
bool inline_unsafe_ordered_store(BasicType type);
|
||||||
|
bool inline_unsafe_fence(vmIntrinsics::ID id);
|
||||||
bool inline_fp_conversions(vmIntrinsics::ID id);
|
bool inline_fp_conversions(vmIntrinsics::ID id);
|
||||||
bool inline_number_methods(vmIntrinsics::ID id);
|
bool inline_number_methods(vmIntrinsics::ID id);
|
||||||
bool inline_reference_get();
|
bool inline_reference_get();
|
||||||
|
@ -334,6 +335,9 @@ CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) {
|
||||||
case vmIntrinsics::_getAndSetInt:
|
case vmIntrinsics::_getAndSetInt:
|
||||||
case vmIntrinsics::_getAndSetLong:
|
case vmIntrinsics::_getAndSetLong:
|
||||||
case vmIntrinsics::_getAndSetObject:
|
case vmIntrinsics::_getAndSetObject:
|
||||||
|
case vmIntrinsics::_loadFence:
|
||||||
|
case vmIntrinsics::_storeFence:
|
||||||
|
case vmIntrinsics::_fullFence:
|
||||||
break; // InlineNatives does not control String.compareTo
|
break; // InlineNatives does not control String.compareTo
|
||||||
case vmIntrinsics::_Reference_get:
|
case vmIntrinsics::_Reference_get:
|
||||||
break; // InlineNatives does not control Reference.get
|
break; // InlineNatives does not control Reference.get
|
||||||
|
@ -732,6 +736,10 @@ bool LibraryCallKit::try_to_inline() {
|
||||||
case vmIntrinsics::_getAndSetLong: return inline_unsafe_load_store(T_LONG, LS_xchg);
|
case vmIntrinsics::_getAndSetLong: return inline_unsafe_load_store(T_LONG, LS_xchg);
|
||||||
case vmIntrinsics::_getAndSetObject: return inline_unsafe_load_store(T_OBJECT, LS_xchg);
|
case vmIntrinsics::_getAndSetObject: return inline_unsafe_load_store(T_OBJECT, LS_xchg);
|
||||||
|
|
||||||
|
case vmIntrinsics::_loadFence:
|
||||||
|
case vmIntrinsics::_storeFence:
|
||||||
|
case vmIntrinsics::_fullFence: return inline_unsafe_fence(intrinsic_id());
|
||||||
|
|
||||||
case vmIntrinsics::_currentThread: return inline_native_currentThread();
|
case vmIntrinsics::_currentThread: return inline_native_currentThread();
|
||||||
case vmIntrinsics::_isInterrupted: return inline_native_isInterrupted();
|
case vmIntrinsics::_isInterrupted: return inline_native_isInterrupted();
|
||||||
|
|
||||||
|
@ -2840,6 +2848,26 @@ bool LibraryCallKit::inline_unsafe_ordered_store(BasicType type) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LibraryCallKit::inline_unsafe_fence(vmIntrinsics::ID id) {
|
||||||
|
// Regardless of form, don't allow previous ld/st to move down,
|
||||||
|
// then issue acquire, release, or volatile mem_bar.
|
||||||
|
insert_mem_bar(Op_MemBarCPUOrder);
|
||||||
|
switch(id) {
|
||||||
|
case vmIntrinsics::_loadFence:
|
||||||
|
insert_mem_bar(Op_MemBarAcquire);
|
||||||
|
return true;
|
||||||
|
case vmIntrinsics::_storeFence:
|
||||||
|
insert_mem_bar(Op_MemBarRelease);
|
||||||
|
return true;
|
||||||
|
case vmIntrinsics::_fullFence:
|
||||||
|
insert_mem_bar(Op_MemBarVolatile);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
fatal_unexpected_iid(id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------inline_unsafe_allocate---------------------------
|
//----------------------------inline_unsafe_allocate---------------------------
|
||||||
// public native Object sun.mics.Unsafe.allocateInstance(Class<?> cls);
|
// public native Object sun.mics.Unsafe.allocateInstance(Class<?> cls);
|
||||||
bool LibraryCallKit::inline_unsafe_allocate() {
|
bool LibraryCallKit::inline_unsafe_allocate() {
|
||||||
|
|
|
@ -468,6 +468,21 @@ UNSAFE_ENTRY(void, Unsafe_SetOrderedLong(JNIEnv *env, jobject unsafe, jobject ob
|
||||||
#endif
|
#endif
|
||||||
UNSAFE_END
|
UNSAFE_END
|
||||||
|
|
||||||
|
UNSAFE_ENTRY(void, Unsafe_LoadFence(JNIEnv *env, jobject unsafe))
|
||||||
|
UnsafeWrapper("Unsafe_LoadFence");
|
||||||
|
OrderAccess::acquire();
|
||||||
|
UNSAFE_END
|
||||||
|
|
||||||
|
UNSAFE_ENTRY(void, Unsafe_StoreFence(JNIEnv *env, jobject unsafe))
|
||||||
|
UnsafeWrapper("Unsafe_StoreFence");
|
||||||
|
OrderAccess::release();
|
||||||
|
UNSAFE_END
|
||||||
|
|
||||||
|
UNSAFE_ENTRY(void, Unsafe_FullFence(JNIEnv *env, jobject unsafe))
|
||||||
|
UnsafeWrapper("Unsafe_FullFence");
|
||||||
|
OrderAccess::fence();
|
||||||
|
UNSAFE_END
|
||||||
|
|
||||||
////// Data in the C heap.
|
////// Data in the C heap.
|
||||||
|
|
||||||
// Note: These do not throw NullPointerException for bad pointers.
|
// Note: These do not throw NullPointerException for bad pointers.
|
||||||
|
@ -1550,6 +1565,9 @@ static JNINativeMethod methods[] = {
|
||||||
{CC"putOrderedObject", CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetOrderedObject)},
|
{CC"putOrderedObject", CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetOrderedObject)},
|
||||||
{CC"putOrderedInt", CC"("OBJ"JI)V", FN_PTR(Unsafe_SetOrderedInt)},
|
{CC"putOrderedInt", CC"("OBJ"JI)V", FN_PTR(Unsafe_SetOrderedInt)},
|
||||||
{CC"putOrderedLong", CC"("OBJ"JJ)V", FN_PTR(Unsafe_SetOrderedLong)},
|
{CC"putOrderedLong", CC"("OBJ"JJ)V", FN_PTR(Unsafe_SetOrderedLong)},
|
||||||
|
{CC"loadFence", CC"()V", FN_PTR(Unsafe_LoadFence)},
|
||||||
|
{CC"storeFence", CC"()V", FN_PTR(Unsafe_StoreFence)},
|
||||||
|
{CC"fullFence", CC"()V", FN_PTR(Unsafe_FullFence)},
|
||||||
{CC"park", CC"(ZJ)V", FN_PTR(Unsafe_Park)},
|
{CC"park", CC"(ZJ)V", FN_PTR(Unsafe_Park)},
|
||||||
{CC"unpark", CC"("OBJ")V", FN_PTR(Unsafe_Unpark)}
|
{CC"unpark", CC"("OBJ")V", FN_PTR(Unsafe_Unpark)}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue