Skip to content

Commit 21a124f

Browse files
authored
Merge pull request #23639 from matthewhall2/fold_vh_checkGenericType
Fold Invokers.checkVarHandleGenericType using const refs
2 parents 2f3adf1 + f5605da commit 21a124f

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

runtime/compiler/env/VMJ9.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4903,8 +4903,26 @@ TR::KnownObjectTable::Index TR_J9VMBase::getMethodHandleTableEntryIndex(TR::Comp
49034903
uintptr_t methodTypeObj = getReferenceField(methodHandleObj, "type", "Ljava/lang/invoke/MethodType;");
49044904
uintptr_t symbolicMTInvokerObj
49054905
= getReferenceField(accessDescriptorObj, "symbolicMethodTypeInvoker", "Ljava/lang/invoke/MethodType;");
4906-
if (methodTypeObj != symbolicMTInvokerObj)
4906+
4907+
// the cached methodhandle will not be in the table; MethodHandleTransformer's processing of
4908+
// checkVarHandleGenericType may not work properly if TR_ALLOW_NON_CONST_KNOWN_OBJECTS is defined.
4909+
#ifdef TR_ALLOW_NON_CONST_KNOWN_OBJECTS
4910+
if (methodTypeObj != symbolicMTInvokerObj) {
49074911
return result;
4912+
}
4913+
#else // TR_ALLOW_NON_CONST_KNOWN_OBJECTS
4914+
if (methodTypeObj != symbolicMTInvokerObj) {
4915+
uintptr_t cachedMT = 0;
4916+
uintptr_t cachedMH = getReferenceField(methodHandleObj, "asTypeCache", "Ljava/lang/invoke/MethodHandle;");
4917+
if (cachedMH != 0)
4918+
cachedMT = getReferenceField(cachedMH, "type", "Ljava/lang/invoke/MethodType;");
4919+
4920+
if (cachedMT != 0 && symbolicMTInvokerObj == cachedMT)
4921+
methodHandleObj = cachedMH;
4922+
else
4923+
return result;
4924+
}
4925+
#endif // TR_ALLOW_NON_CONST_KNOWN_OBJECTS
49084926

49094927
result = knot->getOrCreateIndex(methodHandleObj);
49104928

runtime/compiler/optimizer/MethodHandleTransformer.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,11 +837,11 @@ VarHandle$TypesAndInvokers field as the MethodHandle table exists as a field of
837837
void TR_MethodHandleTransformer::process_java_lang_invoke_Invokers_checkVarHandleGenericType(TR::TreeTop *tt,
838838
TR::Node *node)
839839
{
840-
#ifdef TR_ALLOW_NON_CONST_KNOWN_OBJECTS
841840
static const bool disableFoldingVHGenType = feGetEnv("TR_disableFoldingVHGenType") != NULL;
842841
if (disableFoldingVHGenType) {
843842
return;
844843
}
844+
#ifdef TR_ALLOW_NON_CONST_KNOWN_OBJECTS
845845

846846
auto vhIndex = getObjectInfoOfNode(node->getFirstArgument());
847847
auto adIndex = getObjectInfoOfNode(node->getLastChild());
@@ -950,6 +950,30 @@ void TR_MethodHandleTransformer::process_java_lang_invoke_Invokers_checkVarHandl
950950
if (comp()->useCompressedPointers()) {
951951
tt->insertBefore(TR::TreeTop::create(comp(), TR::Node::createCompressedRefsAnchor(node)));
952952
}
953+
#else // TR_ALLOW_NON_CONST_KNOWN_OBJECTS
954+
auto vhIndex = getObjectInfoOfNode(node->getFirstArgument());
955+
auto adIndex = getObjectInfoOfNode(node->getLastChild());
956+
auto knot = comp()->getKnownObjectTable();
957+
if (knot == NULL || !isKnownObject(adIndex) || !isKnownObject(vhIndex) || knot->isNull(vhIndex)
958+
|| knot->isNull(adIndex)) {
959+
return;
960+
}
961+
962+
auto mhIndex = comp()->fej9()->getMethodHandleTableEntryIndex(comp(), vhIndex, adIndex);
963+
if (TR::KnownObjectTable::UNKNOWN == mhIndex)
964+
return;
965+
966+
if (!performTransformation(comp(), "%sReplacing VarHandle access node n%un [%p] with MethodHandle known obj %d\n",
967+
optDetailString(), node->getGlobalIndex(), node, mhIndex))
968+
return;
969+
970+
J9::ConstProvenanceGraph *cpg = comp()->constProvenanceGraph();
971+
cpg->addEdge(cpg->knownObject(vhIndex), cpg->knownObject(mhIndex));
972+
973+
anchorAllChildren(node, tt);
974+
node->removeAllChildren();
975+
TR::Node::recreateWithSymRef(node, TR::aload, knot->constSymRef(mhIndex));
976+
return;
953977
#endif // TR_ALLOW_NON_CONST_KNOWN_OBJECTS
954978
}
955979

0 commit comments

Comments
 (0)