Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update resolve code to support OpenJDK MH #10893

Merged
merged 5 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions runtime/bcutil/ConstantPoolMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ ConstantPoolMap::ConstantPoolMap(BufferManager *bufferManager, ROMClassCreationC
_romConstantPoolTypes(NULL),
_staticSplitEntries(NULL),
_specialSplitEntries(NULL),
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
_invokeCacheCount(0),
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
_methodTypeCount(0),
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
_varHandleMethodTypeCount(0),
_varHandleMethodTypeLookupTable(NULL),
_callSiteCount(0),
Expand Down
29 changes: 27 additions & 2 deletions runtime/bcutil/ConstantPoolMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ class ConstantPoolMap
}
}

#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
U_32 getInvokeCacheCount() const { return _invokeCacheCount; }
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
U_32 getMethodTypeCount() const { return _methodTypeCount; }
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
U_32 getVarHandleMethodTypeCount() const { return _varHandleMethodTypeCount; }
U_32 getVarHandleMethodTypePaddedCount() const { return _varHandleMethodTypeCount + (_varHandleMethodTypeCount & 0x1); /* Rounding up to an even number */ }
U_16 *getVarHandleMethodTypeLookupTable() const { return _varHandleMethodTypeLookupTable; }
Expand Down Expand Up @@ -287,8 +291,25 @@ class ConstantPoolMap
void markMethodRefAsUsedByInvokeSpecial(U_16 methodRefCfrCPIndex) { mark(methodRefCfrCPIndex, INVOKE_SPECIAL); }
void markMethodRefAsUsedByInvokeStatic(U_16 methodRefCfrCPIndex) { mark(methodRefCfrCPIndex, INVOKE_STATIC); }
void markMethodRefAsUsedByInvokeInterface(U_16 methodRefCfrCPIndex) { mark(methodRefCfrCPIndex, INVOKE_INTERFACE); }
void markMethodRefAsUsedByInvokeHandle(U_16 methodRefCfrCPIndex) { mark(methodRefCfrCPIndex, INVOKE_HANDLEEXACT); _methodTypeCount++; }
void markMethodRefAsUsedByInvokeHandleGeneric(U_16 methodRefCfrCPIndex) { mark(methodRefCfrCPIndex, INVOKE_HANDLEGENERIC); _methodTypeCount++; }

void markMethodRefAsUsedByInvokeHandle(U_16 methodRefCfrCPIndex) {
mark(methodRefCfrCPIndex, INVOKE_HANDLEEXACT);
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
_invokeCacheCount++;
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
fengxue-IS marked this conversation as resolved.
Show resolved Hide resolved
_methodTypeCount++;
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
}

void markMethodRefAsUsedByInvokeHandleGeneric(U_16 methodRefCfrCPIndex) {
mark(methodRefCfrCPIndex, INVOKE_HANDLEGENERIC);
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
_invokeCacheCount++;
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
_methodTypeCount++;
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
}


void markInvokeDynamicInfoAsUsedByInvokeDynamic(U_16 cfrCPIndex)
{
Expand Down Expand Up @@ -339,7 +360,11 @@ class ConstantPoolMap
U_8 *_romConstantPoolTypes;
U_16 *_staticSplitEntries;
U_16 *_specialSplitEntries;
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
U_32 _invokeCacheCount;
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
U_32 _methodTypeCount;
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
U_16 _varHandleMethodTypeCount;
U_16 *_varHandleMethodTypeLookupTable;
U_32 _callSiteCount;
Expand Down
4 changes: 4 additions & 0 deletions runtime/bcutil/ROMClassWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,11 @@ ROMClassWriter::writeROMClass(Cursor *cursor,
cursor->writeU32(optionalFlags, Cursor::OPTIONAL_FLAGS);
cursor->writeSRP(_optionalInfoSRPKey, Cursor::SRP_TO_GENERIC);
cursor->writeU32(_classFileOracle->getMaxBranchCount(), Cursor::GENERIC);
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
cursor->writeU32(_constantPoolMap->getInvokeCacheCount(), Cursor::GENERIC);
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
cursor->writeU32(_constantPoolMap->getMethodTypeCount(), Cursor::GENERIC);
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
cursor->writeU32(_constantPoolMap->getVarHandleMethodTypeCount(), Cursor::GENERIC);
cursor->writeU32(_classFileOracle->getBootstrapMethodCount(), Cursor::GENERIC);
cursor->writeU32(_constantPoolMap->getCallSiteCount(), Cursor::GENERIC);
Expand Down
21 changes: 21 additions & 0 deletions runtime/codert_vm/cnathelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,26 @@ old_slow_jitResolveHandleMethod(J9VMThread *currentThread)
DECLARE_JIT_PARM(void*, jitEIP, 3);
void *addr = NULL;
J9JavaVM *vm = currentThread->javaVM;

#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
J9RAMMethodRef *ramMethodRef = ((J9RAMMethodRef*)ramConstantPool) + cpIndex;
fengxue-IS marked this conversation as resolved.
Show resolved Hide resolved
UDATA invokeCacheIndex = ramMethodRef->methodIndexAndArgCount >> 8;
retry:
j9object_t *invokeCacheArray = &((J9_CLASS_FROM_CP(ramConstantPool)->invokeCache)[invokeCacheIndex]);
if (NULL == *invokeCacheArray) {
buildJITResolveFrameWithPC(currentThread, J9_SSF_JIT_RESOLVE_DATA, parmCount, true, 0, jitEIP);
/* add new resolve code which calls sendResolveInvokeHandle -> MHN.linkMethod()
* store the memberName/appendix values in invokeCache[invokeCacheIndex]
*/
vm->internalVMFunctions->resolveOpenJDKInvokeHandle(currentThread, ramConstantPool, cpIndex, J9_RESOLVE_FLAG_RUNTIME_RESOLVE);
addr = restoreJITResolveFrame(currentThread, jitEIP);
if (NULL != addr) {
goto done;
}
goto retry;
}
JIT_RETURN_UDATA(invokeCacheArray);
fengxue-IS marked this conversation as resolved.
Show resolved Hide resolved
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
j9object_t *methodTypePtr = NULL;
j9object_t *methodTypeTablePtr = NULL;
UDATA methodTypeIndex = 0;
Expand Down Expand Up @@ -2372,6 +2392,7 @@ old_slow_jitResolveHandleMethod(J9VMThread *currentThread)
}

JIT_RETURN_UDATA(methodTypePtr);
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
done:
SLOW_JIT_HELPER_EPILOGUE();
return addr;
Expand Down
10 changes: 9 additions & 1 deletion runtime/gc_structs/ClassIterator.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*******************************************************************************
* Copyright (c) 1991, 2019 IBM Corp. and others
* Copyright (c) 1991, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -85,7 +85,11 @@ class GC_ClassIterator {
, _classStaticsIterator(env, clazz)
, _constantPoolObjectSlotIterator((J9JavaVM *)env->getLanguageVM(), clazz)
, _callSitesIterator(clazz)
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
, _methodTypesIterator(clazz->romClass->invokeCacheCount, clazz->invokeCache)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this iterator be renamed given it's 1) not iterating MTs anymore, 2) it's now dealing with the invokeCache?

@amicic opinions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems reasonable, but since I don't fully understand relationship between MH and invokeCache, I'll add @dmitripivkine

Copy link
Contributor

@amicic amicic Nov 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(from my narrow perspective) I'm wondering why the ifdef build flag has METHODHANDLE in the name, and should it be INVOKECACHE ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ifdef is for the other all feature which is using the OpenJDK MH implementation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fengxue-IS Can you open an issue to track renaming the GC_MethodTypesIterator to something like GC_InvokeCacheIterator? We need to track it as a cleanup task that should be done before the final cutover but doesn't need to be included in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created #11168 to track this cleanup work

#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
, _methodTypesIterator(clazz->romClass->methodTypeCount, clazz->methodTypes)
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
, _varHandlesMethodTypesIterator(clazz->romClass->varHandleMethodTypeCount, clazz->varHandleMethodTypes)
, _valueTypesIterator(clazz)
, _shouldScanClassObject(shouldScanClassObject)
Expand All @@ -98,7 +102,11 @@ class GC_ClassIterator {
, _classStaticsIterator(extensions, clazz)
, _constantPoolObjectSlotIterator((J9JavaVM *)extensions->getOmrVM()->_language_vm, clazz)
, _callSitesIterator(clazz)
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
, _methodTypesIterator(clazz->romClass->invokeCacheCount, clazz->invokeCache)
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
, _methodTypesIterator(clazz->romClass->methodTypeCount, clazz->methodTypes)
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
, _varHandlesMethodTypesIterator(clazz->romClass->varHandleMethodTypeCount, clazz->varHandleMethodTypes)
, _valueTypesIterator(clazz)
, _shouldScanClassObject(true)
Expand Down
5 changes: 5 additions & 0 deletions runtime/gc_vlhgc/CopyForwardScheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4659,7 +4659,12 @@ MM_CopyForwardScheme::verifyClassObjectSlots(MM_EnvironmentVLHGC *env, J9Object
/*
* scan MethodTypes
*/
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
GC_MethodTypesIterator methodTypesIterator(classPtr->romClass->invokeCacheCount, classPtr->invokeCache);
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
GC_MethodTypesIterator methodTypesIterator(classPtr->romClass->methodTypeCount, classPtr->methodTypes);
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */

while(NULL != (slotPtr = methodTypesIterator.nextSlot())) {
J9Object *dstObject = *slotPtr;
if(!_abortInProgress && !isObjectInNoEvacuationRegions(env, dstObject) && verifyIsPointerInEvacute(env, dstObject)) {
Expand Down
18 changes: 18 additions & 0 deletions runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -3106,7 +3106,11 @@ typedef struct J9Class {
struct J9Class* nextClassInSegment;
UDATA* ramConstantPool;
j9object_t* callSites;
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
j9object_t* invokeCache;
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
j9object_t* methodTypes;
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
j9object_t* varHandleMethodTypes;
#if defined(J9VM_INTERP_CUSTOM_SPIN_OPTIONS)
struct J9VMCustomSpinOptions *customSpinOption;
Expand Down Expand Up @@ -3186,7 +3190,11 @@ typedef struct J9ArrayClass {
struct J9Class* nextClassInSegment;
UDATA* ramConstantPool;
j9object_t* callSites;
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
j9object_t* invokeCache;
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
j9object_t* methodTypes;
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
j9object_t* varHandleMethodTypes;
#if defined(J9VM_INTERP_CUSTOM_SPIN_OPTIONS)
struct J9VMCustomSpinOptions *customSpinOption;
Expand Down Expand Up @@ -3328,7 +3336,11 @@ typedef struct J9ROMClass {
U_32 optionalFlags;
J9SRP optionalInfo;
U_32 maxBranchCount;
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
U_32 invokeCacheCount;
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
U_32 methodTypeCount;
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
U_32 varHandleMethodTypeCount;
U_32 bsmCount;
U_32 callSiteCount;
Expand Down Expand Up @@ -3477,7 +3489,11 @@ typedef struct J9ROMReflectClass {
U_32 optionalFlags;
J9SRP optionalInfo;
U_32 maxBranchCount;
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
U_32 invokeCacheCount;
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
U_32 methodTypeCount;
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
U_32 varHandleMethodTypeCount;
U_32 bsmCount;
U_32 callSiteCount;
Expand Down Expand Up @@ -4559,8 +4575,10 @@ typedef struct J9InternalVMFunctions {
void (JNICALL *sendForGenericInvoke)(struct J9VMThread *vmThread, j9object_t methodHandle, j9object_t methodType, UDATA dropFirstArg) ;
void (JNICALL *jitFillOSRBuffer)(struct J9VMThread *vmContext, void *osrBlock) ;
void (JNICALL *sendResolveMethodHandle)(struct J9VMThread *vmThread, UDATA cpIndex, J9ConstantPool *ramCP, J9Class *definingClass, J9ROMNameAndSignature* nameAndSig) ;
j9object_t ( *resolveOpenJDKInvokeHandle)(struct J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags) ;
j9object_t ( *resolveConstantDynamic)(struct J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags) ;
j9object_t ( *resolveInvokeDynamic)(struct J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags) ;
void (JNICALL *sendResolveOpenJDKInvokeHandle)(struct J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, I_32 refKind, J9Class *resolvedClass, J9ROMNameAndSignature* nameAndSig) ;
void (JNICALL *sendResolveConstantDynamic)(struct J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, J9ROMNameAndSignature* nameAndSig, U_16* bsmData) ;
void (JNICALL *sendResolveInvokeDynamic)(struct J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA callSiteIndex, J9ROMNameAndSignature* nameAndSig, U_16* bsmData) ;
j9object_t ( *resolveMethodHandleRef)(struct J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags) ;
Expand Down
2 changes: 2 additions & 0 deletions runtime/oti/j9protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,7 @@ extern J9_CFUNC j9object_t resolveMethodTypeRef (J9VMThread *vmThread, J9Constan
extern J9_CFUNC j9object_t resolveMethodTypeRefInto(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags, J9RAMMethodTypeRef *ramCPEntry);
extern J9_CFUNC j9object_t resolveMethodHandleRef (J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags);
extern J9_CFUNC j9object_t resolveMethodHandleRefInto(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags, J9RAMMethodHandleRef *ramCPEntry);
extern J9_CFUNC j9object_t resolveOpenJDKInvokeHandle (J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags);
extern J9_CFUNC j9object_t resolveInvokeDynamic (J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags);
extern J9_CFUNC j9object_t resolveConstantDynamic (J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags);
#endif /* _J9VMRESOLVESUPPORT_ */
Expand Down Expand Up @@ -1303,6 +1304,7 @@ extern J9_CFUNC void JNICALL sidecarInvokeReflectConstructorImpl (J9VMThread *v
extern J9_CFUNC void JNICALL sendFromMethodDescriptorString (J9VMThread *vmThread, J9UTF8 *descriptor, J9ClassLoader *classLoader, J9Class *appendArgType);
extern J9_CFUNC void JNICALL sendResolveMethodHandle (J9VMThread *vmThread, UDATA cpIndex, J9ConstantPool *ramCP, J9Class *definingClass, J9ROMNameAndSignature* nameAndSig);
extern J9_CFUNC void JNICALL sendForGenericInvoke (J9VMThread *vmThread, j9object_t methodHandle, j9object_t methodType, UDATA dropFirstArg);
extern J9_CFUNC void JNICALL sendResolveOpenJDKInvokeHandle (J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, I_32 refKind, J9Class *resolvedClass, J9ROMNameAndSignature* nameAndSig);
extern J9_CFUNC void JNICALL sendResolveConstantDynamic (J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, J9ROMNameAndSignature* nameAndSig, U_16* bsmData);
extern J9_CFUNC void JNICALL sendResolveInvokeDynamic (J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA callSiteIndex, J9ROMNameAndSignature* nameAndSig, U_16* bsmData);
extern J9_CFUNC void JNICALL jitFillOSRBuffer (struct J9VMThread *vmContext, void *osrBlock);
Expand Down
4 changes: 4 additions & 0 deletions runtime/util/romclasswalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ void allSlotsInROMClassDo(J9ROMClass* romClass,
SLOT_CALLBACK(romClass, J9ROM_U32, romClass, optionalFlags);
SLOT_CALLBACK(romClass, J9ROM_SRP, romClass, optionalInfo);
SLOT_CALLBACK(romClass, J9ROM_U32, romClass, maxBranchCount);
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
SLOT_CALLBACK(romClass, J9ROM_U32, romClass, invokeCacheCount);
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
SLOT_CALLBACK(romClass, J9ROM_U32, romClass, methodTypeCount);
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
SLOT_CALLBACK(romClass, J9ROM_U16, romClass, staticSplitMethodRefCount);
SLOT_CALLBACK(romClass, J9ROM_U16, romClass, specialSplitMethodRefCount);
SLOT_CALLBACK(romClass, J9ROM_SRP, romClass, staticSplitMethodRefIndexes);
Expand Down
44 changes: 27 additions & 17 deletions runtime/vm/BytecodeInterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8017,23 +8017,34 @@ class INTERPRETER_CLASS
U_16 index = *(U_16 *)(_pc + 1);

J9ConstantPool *ramConstantPool = J9_CP_FROM_METHOD(_literals);
J9InvokeCacheEntry *invokeCache = ((J9InvokeCacheEntry *)ramConstantPool->ramClass->callSites) + index;

j9object_t memberName = invokeCache->target;

if (J9_EXPECTED(NULL != memberName)) {
if (J9OBJECT_CLAZZ(_currentThread, memberName) == J9VMJAVALANGINVOKEMEMBERNAME_OR_NULL(_vm)) {
j9object_t invokeCacheArray = (ramConstantPool->ramClass->callSites)[index];

if (J9_EXPECTED(NULL != invokeCacheArray)) {
J9Class *clazz = J9OBJECT_CLAZZ(_currentThread, invokeCacheArray);
if (J9CLASS_IS_ARRAY(clazz)) {
fengxue-IS marked this conversation as resolved.
Show resolved Hide resolved
/* Fetch target method and appendix from invokeCacheArray (2 element array)
* Stack transitions from:
* args <- SP
* MH
* To:
* invokeCacheArray[1] "appendix" <- SP
* args
* MH
*
* and sendMethod is ((J9Method *)((j.l.MemberName)invokeCacheArray[0]) + vmtargetOffset)
*/
j9object_t memberName = (j9object_t)J9JAVAARRAYOFOBJECT_LOAD(_currentThread, invokeCacheArray, 0);
_sendMethod = (J9Method *)(UDATA)J9OBJECT_U64_LOAD(_currentThread, memberName, _vm->vmtargetOffset);
*--_sp = (UDATA)invokeCache->appendix;
*--_sp = (UDATA)(j9object_t)J9JAVAARRAYOFOBJECT_LOAD(_currentThread, invokeCacheArray, 1);
} else {
VM_VMHelpers::setExceptionPending(_currentThread, memberName);
VM_VMHelpers::setExceptionPending(_currentThread, invokeCacheArray);
rc = GOTO_THROW_CURRENT_EXCEPTION;
}
} else {
buildGenericSpecialStackFrame(REGISTER_ARGS, 0);
updateVMStruct(REGISTER_ARGS);
/* The resolution is performed by MethodHandleNatives.linkCallSite(*).
* The resolved values consist of a MemberName object and a MethodHandle object.
* The resolved values consist of a MemberName object and a MethodHandle object in a Java Object array.
* The resolved values are stored in callSites[index].
*/
resolveInvokeDynamic(_currentThread, ramConstantPool, index, J9_RESOLVE_FLAG_RUNTIME_RESOLVE);
Expand Down Expand Up @@ -8120,21 +8131,20 @@ class INTERPRETER_CLASS
J9RAMMethodRef *ramMethodRef = ((J9RAMMethodRef *)ramConstantPool) + index;

UDATA invokeCacheIndex = ramMethodRef->methodIndexAndArgCount >> 8;
J9InvokeCacheEntry *resultEntry = ((J9InvokeCacheEntry *)J9_CLASS_FROM_CP(ramConstantPool)->invokeCache) + invokeCacheIndex;

j9object_t memberNameObject = resultEntry->target;
j9object_t invokeCacheArray = (J9_CLASS_FROM_CP(ramConstantPool)->invokeCache)[invokeCacheIndex];

if (J9_EXPECTED(NULL != memberNameObject)) {
*--_sp = (UDATA)resultEntry->appendix;
_sendMethod = (J9Method *)(UDATA)J9OBJECT_U64_LOAD(_currentThread, memberNameObject, _vm->vmtargetOffset);
if (J9_EXPECTED(NULL != invokeCacheArray)) {
j9object_t memberName = (j9object_t)J9JAVAARRAYOFOBJECT_LOAD(_currentThread, invokeCacheArray, 0);
*--_sp = (UDATA)(j9object_t)J9JAVAARRAYOFOBJECT_LOAD(_currentThread, invokeCacheArray, 1);
_sendMethod = (J9Method *)(UDATA)J9OBJECT_U64_LOAD(_currentThread, memberName, _vm->vmtargetOffset);
} else {
buildGenericSpecialStackFrame(REGISTER_ARGS, 0);
updateVMStruct(REGISTER_ARGS);
/* The resolution is performed by MethodHandleNatives.linkMethod(*).
* The resolved values consist of a MemberName object and a MethodHandle object.
* The resolved values consist of a MemberName object and a MethodHandle object in a Java Object array.
* The resolved values are stored in invokeCache[invokeCacheIndex].
*/
resolveMethodHandle(_currentThread, ramConstantPool, index, J9_RESOLVE_FLAG_RUNTIME_RESOLVE);
resolveOpenJDKInvokeHandle(_currentThread, ramConstantPool, index, J9_RESOLVE_FLAG_RUNTIME_RESOLVE);
VMStructHasBeenUpdated(REGISTER_ARGS);
restoreGenericSpecialStackFrame(REGISTER_ARGS);
if (immediateAsyncPending()) {
Expand Down
37 changes: 37 additions & 0 deletions runtime/vm/callin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,43 @@ sendForGenericInvoke(J9VMThread *currentThread, j9object_t methodHandle, j9objec
Trc_VM_sendForGenericInvoke_Exit(currentThread);
}

void JNICALL
sendResolveOpenJDKInvokeHandle(J9VMThread *currentThread, J9ConstantPool *ramCP, UDATA cpIndex, I_32 refKind, J9Class *resolvedClass, J9ROMNameAndSignature *nameAndSig)
{
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
Trc_VM_sendResolveOpenJDKInvokeHandle_Entry(currentThread);
J9VMEntryLocalStorage newELS;
if (buildCallInStackFrame(currentThread, &newELS, true, false)) {
/* Convert name and signature to String objects */
fengxue-IS marked this conversation as resolved.
Show resolved Hide resolved
J9JavaVM *vm = currentThread->javaVM;
J9MemoryManagerFunctions const * const mmFuncs = vm->memoryManagerFunctions;
J9UTF8 *nameUTF = J9ROMNAMEANDSIGNATURE_NAME(nameAndSig);
j9object_t nameString = mmFuncs->j9gc_createJavaLangString(currentThread, J9UTF8_DATA(nameUTF), J9UTF8_LENGTH(nameUTF), 0);
if (NULL != nameString) {
J9UTF8 *sigUTF = J9ROMNAMEANDSIGNATURE_SIGNATURE(nameAndSig);
PUSH_OBJECT_IN_SPECIAL_FRAME(currentThread, nameString);
j9object_t sigString = mmFuncs->j9gc_createJavaLangString(currentThread, J9UTF8_DATA(sigUTF), J9UTF8_LENGTH(sigUTF), 0);
nameString = POP_OBJECT_IN_SPECIAL_FRAME(currentThread);
if (NULL != sigString) {
/* Run the method */
fengxue-IS marked this conversation as resolved.
Show resolved Hide resolved
*--currentThread->sp = (UDATA)J9VM_J9CLASS_TO_HEAPCLASS(ramCP->ramClass);
*(I_32*)--currentThread->sp = refKind;
*--currentThread->sp = (UDATA)J9VM_J9CLASS_TO_HEAPCLASS(resolvedClass);
*--currentThread->sp = (UDATA)nameString;
*--currentThread->sp = (UDATA)sigString;
currentThread->returnValue = J9_BCLOOP_RUN_METHOD;
currentThread->returnValue2 = (UDATA)J9VMJAVALANGINVOKEMETHODHANDLERESOLVER_LINKCALLERMETHOD_METHOD(vm);
c_cInterpreter(currentThread);
}
}
restoreCallInFrame(currentThread);
}
Trc_VM_sendResolveOpenJDKInvokeHandle_Exit(currentThread);
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
Assert_VM_unreachable();
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
}

void JNICALL
sendResolveConstantDynamic(J9VMThread *currentThread, J9ConstantPool *ramCP, UDATA cpIndex, J9ROMNameAndSignature *nameAndSig, U_16 *bsmData)
{
Expand Down
Loading