From 111f0b0bcc55e3ae7d88900d0dbcca460e7ed875 Mon Sep 17 00:00:00 2001 From: James Kingdon Date: Thu, 26 Oct 2017 11:47:33 -0400 Subject: [PATCH] Allow non-JNI unsafes for p codegen 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 --- .../tr.source/trj9/p/codegen/J9TreeEvaluator.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/runtime/tr.source/trj9/p/codegen/J9TreeEvaluator.cpp b/runtime/tr.source/trj9/p/codegen/J9TreeEvaluator.cpp index 57c0c949d9f..43de8357bed 100644 --- a/runtime/tr.source/trj9/p/codegen/J9TreeEvaluator.cpp +++ b/runtime/tr.source/trj9/p/codegen/J9TreeEvaluator.cpp @@ -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); @@ -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); @@ -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);