Skip to content

Commit

Permalink
Merge pull request #3116 from liqunl/jsr292
Browse files Browse the repository at this point in the history
Inlining changes for MethodHandle
  • Loading branch information
andrewcraik authored Oct 4, 2018
2 parents a17230d + f7e9fa1 commit 0eaa6d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,6 @@ MethodHandle cloneWithNewType(MethodType newType) {
// Until the JIT can synthesize calls to virtual methods, we must synthesize calls to these static ones instead
/*[ENDIF]*/
private static MethodHandle asType(MethodHandle mh, MethodType newType) {
/*
* JIT can easily propagate type information and fold the if when it can prove early return always happen.
* The early return also saves the JIT from having to inline full asType call
*/
if (mh.type == newType) {
return mh;
}
return mh.asType(newType);
}
/*[IF Sidecar19-SE]*/
Expand Down
4 changes: 1 addition & 3 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3197,7 +3197,6 @@ int TR_J9VMBase::checkInlineableTarget (TR_CallTarget* target, TR_CallSite* call
// This first if statement controls inlining of a large class of JSR292 methods, which we want to consider ONLY in certain cases in early rounds of inlining...
if ( resolvedMethod->convertToMethod()->isArchetypeSpecimen() ||
resolvedMethod->getRecognizedMethod() == TR::java_lang_invoke_MethodHandle_invokeExact ||
resolvedMethod->getRecognizedMethod() == TR::java_lang_invoke_MethodHandle_asType ||
resolvedMethod->getRecognizedMethod() == TR::java_lang_invoke_MethodHandle_invokeExactTargetAddress ||
resolvedMethod->getRecognizedMethod() == TR::java_lang_invoke_MutableCallSite_getTarget ||
resolvedMethod->getRecognizedMethod() == TR::java_lang_invoke_DirectHandle_invokeExact ||
Expand All @@ -3208,7 +3207,6 @@ int TR_J9VMBase::checkInlineableTarget (TR_CallTarget* target, TR_CallSite* call
{
if ( resolvedMethod->getRecognizedMethod() == TR::java_lang_invoke_MethodHandle_invokeExactTargetAddress ||
resolvedMethod->getRecognizedMethod() == TR::java_lang_invoke_MutableCallSite_getTarget ||
resolvedMethod->getRecognizedMethod() == TR::java_lang_invoke_MethodHandle_asType ||
TR_J9MethodBase::isVarHandleOperationMethod(resolvedMethod->getRecognizedMethod()) ||
resolvedMethod->getRecognizedMethod() == TR::java_lang_invoke_DirectHandle_invokeExact ||
resolvedMethod->getRecognizedMethod() == TR::java_lang_invoke_InterfaceHandle_invokeExact ||
Expand Down Expand Up @@ -3324,7 +3322,7 @@ int TR_J9VMBase::checkInlineableTarget (TR_CallTarget* target, TR_CallSite* call
case TR::com_ibm_jit_JITHelpers_getClassInitializeStatus:
case TR::java_lang_StringUTF16_getChar:
case TR::java_lang_StringUTF16_toBytes:
case TR::java_lang_invoke_MethodHandle_asType_instance:
case TR::java_lang_invoke_MethodHandle_asType:
return DontInline_Callee;
default:
break;
Expand Down
22 changes: 14 additions & 8 deletions runtime/compiler/optimizer/InlinerTempForJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,6 @@ TR_J9InlinerPolicy::mustBeInlinedEvenInDebug(TR_ResolvedMethod * calleeMethod, T
// call to invokeExactTargetAddress are generated out of thin air by our JSR292
// implementation, but we never want the VM or anyone else to know this so we must
// always inlne the implementation
case TR::java_lang_invoke_MethodHandle_asType:
return true;
case TR::java_lang_invoke_MethodHandle_invokeExactTargetAddress:
{
TR::TreeTop *scanTT = callNodeTreeTop->getNextTreeTop();
Expand Down Expand Up @@ -356,9 +354,11 @@ TR_J9InlinerPolicy::alwaysWorthInlining(TR_ResolvedMethod * calleeMethod, TR::No
if (calleeMethod->isDAAWrapperMethod())
return true;

if (TR_J9MethodBase::isVarHandleOperationMethod(calleeMethod->convertToMethod()->getMandatoryRecognizedMethod()))
return true;

switch (calleeMethod->convertToMethod()->getMandatoryRecognizedMethod())
{
case TR::java_lang_invoke_MethodHandle_asType:
case TR::java_lang_invoke_MethodHandle_invokeExactTargetAddress:
return true;
default:
Expand Down Expand Up @@ -421,6 +421,14 @@ TR_J9InlinerPolicy::alwaysWorthInlining(TR_ResolvedMethod * calleeMethod, TR::No
return true;
}

int32_t length = calleeMethod->classNameLength();
char* className = calleeMethod->classNameChars();

if (length == 24 && !strncmp(className, "jdk/internal/misc/Unsafe", 24))
return true;
else if (length == 15 && !strncmp(className, "sun/misc/Unsafe", 15))
return true;

return false;
}

Expand Down Expand Up @@ -2004,6 +2012,8 @@ TR_J9InlinerPolicy::inlineUnsafeCall(TR::ResolvedMethodSymbol *calleeSymbol, TR:
case TR::sun_misc_Unsafe_compareAndSwapInt_jlObjectJII_Z:
case TR::sun_misc_Unsafe_compareAndSwapLong_jlObjectJJJ_Z:
case TR::sun_misc_Unsafe_compareAndSwapObject_jlObjectJjlObjectjlObject_Z:
if (callNode->isSafeForCGToFastPathUnsafeCall())
return false;
switch (callerSymbol->castToMethodSymbol()->getRecognizedMethod())
{
case TR::java_util_concurrent_ConcurrentHashMap_addCount:
Expand Down Expand Up @@ -4926,15 +4936,11 @@ bool TR_J9InlinerUtil::needTargetedInlining(TR::ResolvedMethodSymbol *callee)
// Trees from archetype specimens may not match the archetype method's bytecodes,
// so there may be some calls things that inliner missed.
//
// We also inline again if MethodHandle.asType has been inlined because VP might be able to
// prove invokeHandleGeneric is invoke exact
//
// Tactically, we also inline again based on hasMethodHandleInvokes because EstimateCodeSize
// doesn't yet cope with invokeHandle, invokeHandleGeneric, and invokeDynamic (but it should).
//
if (callee->getMethod()->isArchetypeSpecimen() ||
callee->hasMethodHandleInvokes() ||
callee->getRecognizedMethod() == TR::java_lang_invoke_MethodHandle_asType)
callee->hasMethodHandleInvokes())
return true;
return false;
}
Expand Down

0 comments on commit 0eaa6d2

Please sign in to comment.