Skip to content

Commit d3869ce

Browse files
committed
hotspot: Support sun.misc.Unsafe intrinsics
1 parent 779538e commit d3869ce

File tree

7 files changed

+130
-50
lines changed

7 files changed

+130
-50
lines changed

src/hotspot/share/c1/c1_Compiler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ bool Compiler::is_intrinsic_supported(const methodHandle& method) {
110110

111111
bool Compiler::is_intrinsic_supported(vmIntrinsics::ID id) {
112112
switch (id) {
113+
#if HOTSPOT_TARGET_CLASSLIB == 8
114+
case vmIntrinsics::_putOrderedObject:
115+
case vmIntrinsics::_putOrderedInt:
116+
case vmIntrinsics::_putOrderedLong:
117+
#endif
113118
case vmIntrinsics::_compareAndSetLong:
114119
break;
115120
case vmIntrinsics::_getAndAddInt:

src/hotspot/share/c1/c1_GraphBuilder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3613,6 +3613,11 @@ void GraphBuilder::build_graph_for_intrinsic(ciMethod* callee, bool ignore_retur
36133613
case vmIntrinsics::_putLongVolatile : append_unsafe_put(callee, T_LONG, true); return;
36143614
case vmIntrinsics::_putFloatVolatile : append_unsafe_put(callee, T_FLOAT, true); return;
36153615
case vmIntrinsics::_putDoubleVolatile : append_unsafe_put(callee, T_DOUBLE, true); return;
3616+
#if HOTSPOT_TARGET_CLASSLIB == 8
3617+
case vmIntrinsics::_putOrderedObject : append_unsafe_put(callee, T_OBJECT, true); return;
3618+
case vmIntrinsics::_putOrderedInt : append_unsafe_put(callee, T_INT, true); return;
3619+
case vmIntrinsics::_putOrderedLong : append_unsafe_put(callee, T_LONG, true); return;
3620+
#endif
36163621
case vmIntrinsics::_compareAndSetLong:
36173622
case vmIntrinsics::_compareAndSetInt:
36183623
case vmIntrinsics::_compareAndSetReference : append_unsafe_CAS(callee); return;

src/hotspot/share/classfile/vmIntrinsics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,11 @@ bool vmIntrinsics::disabled_by_jvm_flags(vmIntrinsics::ID id) {
433433
case vmIntrinsics::_compareAndExchangeReferenceAcquire:
434434
case vmIntrinsics::_compareAndExchangeReferenceRelease:
435435
case vmIntrinsics::_allocateInstance:
436+
#if HOTSPOT_TARGET_CLASSLIB == 8
437+
case vmIntrinsics::_putOrderedObject:
438+
case vmIntrinsics::_putOrderedInt:
439+
case vmIntrinsics::_putOrderedLong:
440+
#endif
436441
if (!InlineUnsafeOps) return true;
437442
break;
438443
case vmIntrinsics::_getShortUnaligned:

src/hotspot/share/classfile/vmIntrinsics.hpp

Lines changed: 91 additions & 50 deletions
Large diffs are not rendered by default.

src/hotspot/share/opto/c2compiler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,11 @@ bool C2Compiler::is_intrinsic_supported(vmIntrinsics::ID id) {
687687
case vmIntrinsics::_putLongVolatile:
688688
case vmIntrinsics::_putFloatVolatile:
689689
case vmIntrinsics::_putDoubleVolatile:
690+
#if HOTSPOT_TARGET_CLASSLIB == 8
691+
case vmIntrinsics::_putOrderedObject:
692+
case vmIntrinsics::_putOrderedInt:
693+
case vmIntrinsics::_putOrderedLong:
694+
#endif
690695
case vmIntrinsics::_getReferenceAcquire:
691696
case vmIntrinsics::_getBooleanAcquire:
692697
case vmIntrinsics::_getByteAcquire:

src/hotspot/share/opto/library_call.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ bool LibraryCallKit::try_to_inline(int predicate) {
355355
case vmIntrinsics::_putLongVolatile: return inline_unsafe_access( is_store, T_LONG, Volatile, false);
356356
case vmIntrinsics::_putFloatVolatile: return inline_unsafe_access( is_store, T_FLOAT, Volatile, false);
357357
case vmIntrinsics::_putDoubleVolatile: return inline_unsafe_access( is_store, T_DOUBLE, Volatile, false);
358+
#if HOTSPOT_TARGET_CLASSLIB == 8
359+
case vmIntrinsics::_putOrderedObject: return inline_unsafe_access( is_store, T_OBJECT, Release, false);
360+
case vmIntrinsics::_putOrderedInt: return inline_unsafe_access( is_store, T_INT, Release, false);
361+
case vmIntrinsics::_putOrderedLong: return inline_unsafe_access( is_store, T_LONG, Release, false);
362+
#endif
358363

359364
case vmIntrinsics::_getShortUnaligned: return inline_unsafe_access(!is_store, T_SHORT, Relaxed, true);
360365
case vmIntrinsics::_getCharUnaligned: return inline_unsafe_access(!is_store, T_CHAR, Relaxed, true);

src/hotspot/share/prims/unsafe.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@ UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclas
379379
UNSAFE_LEAF(jlong, Unsafe_AllocateMemory0(JNIEnv *env, jobject unsafe, jlong size)) {
380380
size_t sz = (size_t)size;
381381

382+
#if HOTSPOT_TARGET_CLASSLIB == 8
383+
// classlib8 needs alignment here
384+
if (!is_aligned(sz, HeapWordSize)) {
385+
sz = align_up(sz, HeapWordSize);
386+
}
387+
#endif
388+
382389
assert(is_aligned(sz, HeapWordSize), "sz not aligned");
383390

384391
void* x = os::malloc(sz, mtOther);
@@ -390,6 +397,13 @@ UNSAFE_LEAF(jlong, Unsafe_ReallocateMemory0(JNIEnv *env, jobject unsafe, jlong a
390397
void* p = addr_from_java(addr);
391398
size_t sz = (size_t)size;
392399

400+
#if HOTSPOT_TARGET_CLASSLIB == 8
401+
// classlib8 needs alignment here
402+
if (!is_aligned(sz, HeapWordSize)) {
403+
sz = align_up(sz, HeapWordSize);
404+
}
405+
#endif
406+
393407
assert(is_aligned(sz, HeapWordSize), "sz not aligned");
394408

395409
void* x = os::realloc(p, sz, mtOther);

0 commit comments

Comments
 (0)