@@ -1294,6 +1294,30 @@ TR_ResolvedRelocatableJ9Method::isUnresolvedMethodHandle(I_32 cpIndex)
12941294 return true ;
12951295 }
12961296
1297+ bool
1298+ TR_ResolvedRelocatableJ9Method::isUnresolvedCallSiteTableEntry (int32_t callSiteIndex)
1299+ {
1300+ bool unresolved = true ;
1301+ J9JavaVM * javaVM = fej9 ()->_jitConfig ->javaVM ;
1302+ if (J9_ARE_ALL_BITS_SET (javaVM->sharedClassConfig ->runtimeFlags2 , J9SHR_RUNTIMEFLAG2_SHARE_LAMBDAFORM))
1303+ {
1304+ unresolved = TR_ResolvedJ9Method::isUnresolvedCallSiteTableEntry (callSiteIndex);
1305+ }
1306+ return unresolved;
1307+ }
1308+
1309+ bool
1310+ TR_ResolvedRelocatableJ9Method::isUnresolvedMethodTypeTableEntry (int32_t cpIndex)
1311+ {
1312+ bool unresolved = true ;
1313+ J9JavaVM * javaVM = fej9 ()->_jitConfig ->javaVM ;
1314+ if (J9_ARE_ALL_BITS_SET (javaVM->sharedClassConfig ->runtimeFlags2 , J9SHR_RUNTIMEFLAG2_SHARE_LAMBDAFORM))
1315+ {
1316+ unresolved = TR_ResolvedJ9Method::isUnresolvedMethodTypeTableEntry (cpIndex);
1317+ }
1318+ return unresolved;
1319+ }
1320+
12971321TR_ResolvedMethod *
12981322TR_ResolvedRelocatableJ9Method::getResolvedPossiblyPrivateVirtualMethod (
12991323 TR::Compilation *comp,
@@ -6970,6 +6994,20 @@ TR_ResolvedJ9Method::handleUnresolvedVirtualMethodInCP(int32_t cpIndex, bool * u
69706994 {
69716995 }
69726996
6997+ TR_OpaqueMethodBlock *
6998+ TR_ResolvedJ9Method::getTargetMethodFromMemberName (uintptr_t * invokeCacheArray, bool * isInvokeCacheAppendixNull)
6999+ {
7000+ TR::VMAccessCriticalSection getTargetMethodCS (fej9 ());
7001+ TR_OpaqueMethodBlock *targetJ9MethodBlock = fej9 ()->targetMethodFromMemberName ((uintptr_t ) fej9 ()->getReferenceElement (*invokeCacheArray, JSR292_invokeCacheArrayMemberNameIndex));
7002+ // if the callSite table entry / method type table entry is resolved,
7003+ // we can check if the appendix object is null,
7004+ // in which case the appendix object must not be pushed to stack
7005+ auto appendixObject = fej9 ()->getReferenceElement (*invokeCacheArray, JSR292_invokeCacheArrayAppendixIndex);
7006+ if (isInvokeCacheAppendixNull && !appendixObject)
7007+ *isInvokeCacheAppendixNull = true ;
7008+ return targetJ9MethodBlock;
7009+ }
7010+
69737011TR_ResolvedMethod *
69747012TR_ResolvedJ9Method::getResolvedDynamicMethod (TR::Compilation * comp, I_32 callSiteIndex, bool * unresolvedInCP, bool * isInvokeCacheAppendixNull)
69757013 {
@@ -7006,13 +7044,12 @@ TR_ResolvedJ9Method::getResolvedDynamicMethod(TR::Compilation * comp, I_32 callS
70067044 J9UTF8 *signature = J9ROMNAMEANDSIGNATURE_SIGNATURE (nameAndSig);
70077045
70087046#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
7009- if (isInvokeCacheAppendixNull)
7010- *isInvokeCacheAppendixNull = false ;
7047+ bool invokeCacheAppendixNull = false ;
70117048
70127049 if (!isUnresolvedEntry)
70137050 {
7014- TR_OpaqueMethodBlock * targetJ9MethodBlock = NULL ;
70157051 uintptr_t * invokeCacheArray = (uintptr_t *) callSiteTableEntryAddress (callSiteIndex);
7052+
70167053 // invokedynamic resolution can either result in a valid entry in the corresponding CallSite table slot if successful,
70177054 // or an exception object otherwise. The CallSite table entry is a two-element array containing the MemberName
70187055 // and appendix objects necessary for constructing a resolved invokedynamic adapter method call.
@@ -7023,14 +7060,21 @@ TR_ResolvedJ9Method::getResolvedDynamicMethod(TR::Compilation * comp, I_32 callS
70237060 comp->failCompilation <TR::CompilationException>(" Invalid CallSite table entry for invokedynamic" );
70247061 }
70257062
7063+ TR_OpaqueMethodBlock * targetJ9MethodBlock = getTargetMethodFromMemberName (invokeCacheArray, &invokeCacheAppendixNull);
7064+
7065+ if (comp->compileRelocatableCode ())
70267066 {
7027- TR::VMAccessCriticalSection getResolvedDynamicMethod (fej9 ());
7028- targetJ9MethodBlock = fej9 ()->targetMethodFromMemberName ((uintptr_t ) fej9 ()->getReferenceElement (*invokeCacheArray, JSR292_invokeCacheArrayMemberNameIndex)); // this will not work in AOT or JITServer
7029- // if the callSite table entry is resolved, we can check if the appendix object is null,
7030- // in which case the appendix object must not be pushed to stack
7031- uintptr_t appendixObject = (uintptr_t ) fej9 ()->getReferenceElement (*invokeCacheArray, JSR292_invokeCacheArrayAppendixIndex);
7032- if (isInvokeCacheAppendixNull && !appendixObject) *isInvokeCacheAppendixNull = true ;
7067+ bool valid =
7068+ comp->getSymbolValidationManager ()->addDynamicMethodFromCallsiteIndex (
7069+ targetJ9MethodBlock,
7070+ getNonPersistentIdentifier (),
7071+ callSiteIndex,
7072+ invokeCacheAppendixNull);
7073+
7074+ if (!valid)
7075+ comp->failCompilation <J9::AOTHasInvokeHandle>(" Failed to add validation record for resolved dynamic method %p" , targetJ9MethodBlock);
70337076 }
7077+
70347078 result = fej9 ()->createResolvedMethod (comp->trMemory (), targetJ9MethodBlock, this );
70357079 }
70367080 else
@@ -7044,6 +7088,9 @@ TR_ResolvedJ9Method::getResolvedDynamicMethod(TR::Compilation * comp, I_32 callS
70447088 char * linkToStaticSignature = _fe->getSignatureForLinkToStaticForInvokeDynamic (comp, signature, signatureLength);
70457089 result = _fe->createResolvedMethodWithSignature (comp->trMemory (), dummyInvoke, NULL , linkToStaticSignature, signatureLength, this );
70467090 }
7091+
7092+ if (isInvokeCacheAppendixNull)
7093+ *isInvokeCacheAppendixNull = invokeCacheAppendixNull;
70477094#else
70487095 TR_OpaqueMethodBlock *dummyInvokeExact = _fe->getMethodFromName (" java/lang/invoke/MethodHandle" , " invokeExact" , JSR292_invokeExactSig);
70497096 result = _fe->createResolvedMethodWithSignature (comp->trMemory (), dummyInvokeExact, NULL , utf8Data (signature), J9UTF8_LENGTH (signature), this );
@@ -7081,19 +7128,27 @@ TR_ResolvedJ9Method::getResolvedHandleMethod(TR::Compilation * comp, I_32 cpInde
70817128#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
70827129 J9UTF8 *signature = J9ROMNAMEANDSIGNATURE_SIGNATURE (nameAndSig);
70837130
7084- if (isInvokeCacheAppendixNull)
7085- *isInvokeCacheAppendixNull = false ;
7131+ bool invokeCacheAppendixNull = false ;
70867132
70877133 if (!isUnresolvedEntry)
70887134 {
70897135 uintptr_t * invokeCacheArray = (uintptr_t *) methodTypeTableEntryAddress (cpIndex);
7090- TR_OpaqueMethodBlock * targetJ9MethodBlock = NULL ;
7136+
7137+ TR_OpaqueMethodBlock * targetJ9MethodBlock = getTargetMethodFromMemberName (invokeCacheArray, &invokeCacheAppendixNull);
7138+
7139+ if (comp->compileRelocatableCode ())
70917140 {
7092- TR::VMAccessCriticalSection getResolvedHandleMethod (fej9 ());
7093- targetJ9MethodBlock = fej9 ()->targetMethodFromMemberName ((uintptr_t ) fej9 ()->getReferenceElement (*invokeCacheArray, JSR292_invokeCacheArrayMemberNameIndex)); // this will not work in AOT or JITServer
7094- uintptr_t appendixObject = (uintptr_t ) fej9 ()->getReferenceElement (*invokeCacheArray, JSR292_invokeCacheArrayAppendixIndex);
7095- if (isInvokeCacheAppendixNull && !appendixObject) *isInvokeCacheAppendixNull = true ;
7141+ bool valid =
7142+ comp->getSymbolValidationManager ()->addHandleMethodFromCPIndex (
7143+ targetJ9MethodBlock,
7144+ getNonPersistentIdentifier (),
7145+ cpIndex,
7146+ invokeCacheAppendixNull);
7147+
7148+ if (!valid)
7149+ comp->failCompilation <J9::AOTHasInvokeHandle>(" Failed to add validation record for resolved handle method %p" , targetJ9MethodBlock);
70967150 }
7151+
70977152 result = fej9 ()->createResolvedMethod (comp->trMemory (), targetJ9MethodBlock, this );
70987153 }
70997154 else
@@ -7107,6 +7162,9 @@ TR_ResolvedJ9Method::getResolvedHandleMethod(TR::Compilation * comp, I_32 cpInde
71077162 char * linkToStaticSignature = _fe->getSignatureForLinkToStaticForInvokeHandle (comp, signature, signatureLength);
71087163 result = _fe->createResolvedMethodWithSignature (comp->trMemory (), dummyInvoke, NULL , linkToStaticSignature, signatureLength, this );
71097164 }
7165+
7166+ if (isInvokeCacheAppendixNull)
7167+ *isInvokeCacheAppendixNull = invokeCacheAppendixNull;
71107168#else
71117169
71127170 TR_OpaqueMethodBlock *dummyInvokeExact = _fe->getMethodFromName (" java/lang/invoke/MethodHandle" , " invokeExact" , JSR292_invokeExactSig);
0 commit comments