Skip to content

Commit

Permalink
Allow non-JNI unsafes for p codegen
Browse files Browse the repository at this point in the history
In Java9 sun.misc.Unsafe JNI methods are moved to jdk.internal and
replaced with simple wrappers. This leads to a few places in the
code where we do the wrong thing by assuming that the recognized
Unsafe method is a JNI method.
This commit adds explicit tests to prevent p codegen from attempting
to transform the non-JNI versions of the unsafe CAS instructions.

Signed-off-by: James Kingdon <jkingdon@ca.ibm.com>
  • Loading branch information
JamesKingdon committed Oct 26, 2017
1 parent 2f316cc commit 111f0b0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions runtime/tr.source/trj9/p/codegen/J9TreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12874,6 +12874,12 @@ J9::Power::CodeGenerator::inlineDirectCall(TR::Node *node, TR::Register *&result
break;

case TR::sun_misc_Unsafe_compareAndSwapInt_jlObjectJII_Z:
// In Java9 this can be either the jdk.internal JNI method or the sun.misc Java wrapper.
// In Java8 it will be sun.misc which will contain the JNI directly.
// We only want to inline the JNI methods, so add an explicit test for isNative().
if (!methodSymbol->isNative())
break;

if ((node->isUnsafeGetPutCASCallOnNonArray() || !TR::Compiler->om.canGenerateArraylets()) && node->isSafeForCGToFastPathUnsafeCall())
{
resultReg = VMinlineCompareAndSwap(node, cg, false);
Expand All @@ -12883,6 +12889,10 @@ J9::Power::CodeGenerator::inlineDirectCall(TR::Node *node, TR::Register *&result

case TR::sun_misc_Unsafe_compareAndSwapLong_jlObjectJJJ_Z:
traceMsg(comp, "In evaluator for compareAndSwapLong. node = %p node->isSafeForCGToFastPathUnsafeCall = %p\n", node, node->isSafeForCGToFastPathUnsafeCall());
// As above, we only want to inline the JNI methods, so add an explicit test for isNative()
if (!methodSymbol->isNative())
break;

if (TR::Compiler->target.is64Bit() && (node->isUnsafeGetPutCASCallOnNonArray() || !TR::Compiler->om.canGenerateArraylets()) && node->isSafeForCGToFastPathUnsafeCall())
{
resultReg = VMinlineCompareAndSwap(node, cg, true);
Expand All @@ -12896,6 +12906,10 @@ J9::Power::CodeGenerator::inlineDirectCall(TR::Node *node, TR::Register *&result
break;

case TR::sun_misc_Unsafe_compareAndSwapObject_jlObjectJjlObjectjlObject_Z:
// As above, we only want to inline the JNI methods, so add an explicit test for isNative()
if (!methodSymbol->isNative())
break;

if ((node->isUnsafeGetPutCASCallOnNonArray() || !TR::Compiler->om.canGenerateArraylets()) && node->isSafeForCGToFastPathUnsafeCall())
{
resultReg = VMinlineCompareAndSwapObject(node, cg);
Expand Down

0 comments on commit 111f0b0

Please sign in to comment.