Skip to content

Commit eb64424

Browse files
committed
Check if an array class can be trusted as a fixed class
There are cases where two different array classes could share the same signature in downstream projects. In such cases, the class retrieved from signature cannot be trusted as a fixed class. Related: eclipse-openj9/openj9#20522 Signed-off-by: Annabelle Huo <[email protected]>
1 parent 7fe2fcc commit eb64424

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

compiler/optimizer/OMRValuePropagation.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -7247,6 +7247,16 @@ bool OMR::ValuePropagation::isUnreliableSignatureType(
72477247
return false;
72487248
}
72497249

7250+
bool OMR::ValuePropagation::canArrayClassBeTrustedAsFixedClass(TR_OpaqueClassBlock *arrayClass, TR_OpaqueClassBlock *componentClass)
7251+
{
7252+
return true;
7253+
}
7254+
7255+
bool OMR::ValuePropagation::canClassBeTrustedAsFixedClass(TR::SymbolReference *symRef, TR_OpaqueClassBlock *classObject)
7256+
{
7257+
return true;
7258+
}
7259+
72507260
void OMR::ValuePropagation::doDelayedTransformations()
72517261
{
72527262
ListIterator<TR_TreeTopNodePair> treesIt1(&_scalarizedArrayCopies);

compiler/optimizer/OMRValuePropagation.hpp

+19
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,25 @@ class ValuePropagation : public TR::Optimization
662662
virtual bool isUnreliableSignatureType(
663663
TR_OpaqueClassBlock *klass, TR_OpaqueClassBlock *&erased);
664664

665+
/**
666+
* \brief Determine whether an \p arrayClass with the \p componentClass can be trusted as a fixed class
667+
*
668+
* \param arrayClass The array class.
669+
* \param componentClass The component class of the array.
670+
*
671+
* \return true if an array with the component class can be trusted as a fixed class, and false otherwise.
672+
*/
673+
virtual bool canArrayClassBeTrustedAsFixedClass(TR_OpaqueClassBlock *arrayClass, TR_OpaqueClassBlock *componentClass);
674+
/**
675+
* \brief Determine whether a class retrieved from signature can be trusted as a fixed class
676+
*
677+
* \param symRef The symbol reference of the class object.
678+
* \param classObject The class object to be checked.
679+
*
680+
* \return true if a class can be trusted as a fixed class, and false otherwise.
681+
*/
682+
virtual bool canClassBeTrustedAsFixedClass(TR::SymbolReference *symRef, TR_OpaqueClassBlock *classObject);
683+
665684
struct ObjCloneInfo {
666685
TR_ALLOC(TR_Memory::ValuePropagation)
667686

compiler/optimizer/VPConstraint.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ TR::VPResolvedClass *TR::VPResolvedClass::create(OMR::ValuePropagation *vp, TR_O
12861286
// An array class is fixed if the base class for the array is final
12871287
//
12881288
TR_OpaqueClassBlock * baseClass = vp->fe()->getLeafComponentClassFromArrayClass(klass);
1289-
if (baseClass && TR::Compiler->cls.isClassFinal(vp->comp(), baseClass))
1289+
if (baseClass && TR::Compiler->cls.isClassFinal(vp->comp(), baseClass) && vp->canArrayClassBeTrustedAsFixedClass(klass, baseClass))
12901290
return TR::VPFixedClass::create(vp, klass);
12911291
}
12921292
else
@@ -6078,7 +6078,7 @@ void TR::VPResolvedClass::print(TR::Compilation *comp, TR::FILE *outFile)
60786078
len = static_cast<int32_t>(strlen(sig));
60796079
}
60806080

6081-
trfprintf(outFile, "class %.*s", len, sig);
6081+
trfprintf(outFile, "class 0x%p %.*s", _class, len, sig);
60826082
if (_typeHintClass)
60836083
{
60846084
trfprintf(outFile, " (hint 0x%p", _typeHintClass);

compiler/optimizer/VPHandlers.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,7 @@ TR::Node *constrainAload(OMR::ValuePropagation *vp, TR::Node *node)
19381938
{
19391939
if (classBlock != jlClass)
19401940
{
1941+
isFixed = isFixed ? vp->canClassBeTrustedAsFixedClass(NULL, classBlock) : isFixed;
19411942
constraint = TR::VPClassType::create(vp, sig, len, owningMethod, isFixed, classBlock);
19421943
if (*sig == '[' || sig[0] == 'L')
19431944
{
@@ -11207,9 +11208,11 @@ static void constrainClassObjectLoadaddr(
1120711208
"constrainClassObjectLoadaddr: n%un loadaddr is not for a class\n",
1120811209
node->getGlobalIndex());
1120911210

11211+
bool isFixed = vp->canClassBeTrustedAsFixedClass(symRef, NULL);
11212+
1121011213
TR::VPConstraint *constraint = TR::VPClass::create(
1121111214
vp,
11212-
TR::VPClassType::create(vp, symRef, true),
11215+
TR::VPClassType::create(vp, symRef, isFixed),
1121311216
TR::VPNonNullObject::create(vp),
1121411217
NULL,
1121511218
NULL,

0 commit comments

Comments
 (0)