@@ -837,11 +837,11 @@ VarHandle$TypesAndInvokers field as the MethodHandle table exists as a field of
837837void 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