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

Add routines to fetch target method from MethodHandle and MemberName #10576

Merged
merged 1 commit into from
Sep 24, 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
52 changes: 52 additions & 0 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4779,6 +4779,58 @@ TR_J9VMBase::methodHandle_jitInvokeExactThunk(uintptr_t methodHandle)
"invokeExactThunk");
}

#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
TR_OpaqueMethodBlock*
TR_J9VMBase::targetMethodFromMemberName(TR::Compilation* comp, TR::KnownObjectTable::Index objIndex)
{
auto knot = comp->getKnownObjectTable();
if (objIndex != TR::KnownObjectTable::UNKNOWN &&
knot &&
!knot->isNull(objIndex))
{
TR::VMAccessCriticalSection getTarget(this);
uintptr_t object = knot->getPointer(objIndex);
return targetMethodFromMemberName(object);
}
return NULL;
}

TR_OpaqueMethodBlock*
TR_J9VMBase::targetMethodFromMemberName(uintptr_t memberName)
{
TR_ASSERT(haveAccess(), "targetFromMemberName requires VM access");
return (TR_OpaqueMethodBlock*)J9OBJECT_U64_LOAD(vmThread(), memberName, vmThread()->javaVM->vmtargetOffset);
}

TR_OpaqueMethodBlock*
TR_J9VMBase::targetMethodFromMethodHandle(TR::Compilation* comp, TR::KnownObjectTable::Index objIndex)
{
auto knot = comp->getKnownObjectTable();
if (objIndex != TR::KnownObjectTable::UNKNOWN &&
knot &&
!knot->isNull(objIndex))
{
TR::VMAccessCriticalSection getTarget(this);
uintptr_t object = knot->getPointer(objIndex);
return targetMethodFromMethodHandle(object);
}
return NULL;
}

TR_OpaqueMethodBlock*
TR_J9VMBase::targetMethodFromMethodHandle(uintptr_t methodHandle)
{
TR_ASSERT(haveAccess(), "targetFromMethodHandle requires VM access");
uintptr_t form = getReferenceField(
methodHandle,
"form", "Ljava/lang/invoke/LambdaForm;");
uintptr_t vmentry = getReferenceField(
form,
"vmentry", "Ljava/lang/invoke/MemberName;");
return targetMethodFromMemberName(vmentry);
}
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */

/**
* \brief
* Check if two java/lang/String objects are equal. Equivalent to java/lang/String.equals.
Expand Down
30 changes: 30 additions & 0 deletions runtime/compiler/env/VMJ9.h
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,36 @@ class TR_J9VMBase : public TR_FrontEnd

bool hasMethodTypesSideTable();

// Openjdk implementation
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
/*
* \brief
* Return MemberName.vmtarget, a J9method pointer for method represented by `memberName`
* Caller must acquire VM access
*/
TR_OpaqueMethodBlock* targetMethodFromMemberName(uintptr_t memberName);
/*
* \brief
* Return MemberName.vmtarget, a J9method pointer for method represented by `memberName`
* VM access is not required
*/
TR_OpaqueMethodBlock* targetMethodFromMemberName(TR::Compilation* comp, TR::KnownObjectTable::Index objIndex);
/*
* \brief
* Return MethodHandle.form.vmentry.vmtarget, J9method for the underlying java method
* The J9Method is the target to be invoked intrinsically by MethodHandle.invokeBasic
* Caller must acquire VM access
*/
TR_OpaqueMethodBlock* targetMethodFromMethodHandle(uintptr_t methodHandle);
/*
* \brief
* Return MethodHandle.form.vmentry.vmtarget, J9method for the underlying java method
* The J9Method is the target to be invoked intrinsically by MethodHandle.invokeBasic
* VM access is not required
*/
TR_OpaqueMethodBlock* targetMethodFromMethodHandle(TR::Compilation* comp, TR::KnownObjectTable::Index objIndex);
#endif

// JSR292 }}}

virtual uintptr_t getFieldOffset( TR::Compilation * comp, TR::SymbolReference* classRef, TR::SymbolReference* fieldRef);
Expand Down