Skip to content

Commit 4b5152e

Browse files
committed
Add methods to check if array class can be trusted as fixed class
If null-restricted array is enabled and the class is an array class, the null-restricted array class and the nullable array class share the same signature. The null-restricted array can be viewed as a sub-type of the nullable array. Therefore, the constraint cannot be fixed class. Related: eclipse-openj9#20522 Signed-off-by: Annabelle Huo <[email protected]>
1 parent e1af88f commit 4b5152e

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

runtime/compiler/optimizer/J9ValuePropagation.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -3835,6 +3835,54 @@ bool J9::ValuePropagation::isUnreliableSignatureType(
38353835
return true;
38363836
}
38373837

3838+
bool J9::ValuePropagation::canArrayClassBeTrustedAsFixedClass(TR_OpaqueClassBlock *arrayClass, TR_OpaqueClassBlock *componentClass)
3839+
{
3840+
if (TR::Compiler->om.areFlattenableValueTypesEnabled() &&
3841+
!TR::Compiler->cls.isArrayNullRestricted(comp(), arrayClass) && // If the array is null-restricted array, we know it is a fixed class
3842+
TR::Compiler->cls.isValueTypeClass(componentClass))
3843+
return false;
3844+
3845+
return true;
3846+
}
3847+
3848+
bool J9::ValuePropagation::canClassBeTrustedAsFixedClass(TR::SymbolReference *symRef, TR_OpaqueClassBlock *classObject)
3849+
{
3850+
if (!TR::Compiler->om.areFlattenableValueTypesEnabled())
3851+
return true;
3852+
3853+
if (!classObject && symRef && symRef->getSymbol()->isClassObject())
3854+
{
3855+
if (!symRef->isUnresolved())
3856+
{
3857+
classObject = (TR_OpaqueClassBlock*)symRef->getSymbol()->getStaticSymbol()->getStaticAddress();
3858+
}
3859+
else
3860+
{
3861+
int32_t len;
3862+
const char *name = TR::Compiler->cls.classNameChars(comp(), symRef, len);
3863+
char *sig = TR::Compiler->cls.classNameToSignature(name, len, comp());
3864+
classObject = fe()->getClassFromSignature(sig, len, symRef->getOwningMethod(comp()));
3865+
}
3866+
}
3867+
3868+
if (classObject)
3869+
{
3870+
// If null-restricted array is enabled and the class is an array class, the null-restricted array
3871+
// class and the nullable array class share the same signature. The null-restricted array can be
3872+
// viewed as a sub-type of the nullable array. Therefore, if the array is not a null-restricted array,
3873+
// it can't be trusted as a fixed class.
3874+
int32_t numDims = 0;
3875+
TR_OpaqueClassBlock *klass = comp()->fej9()->getBaseComponentClass(classObject, numDims);
3876+
3877+
if ((numDims > 0) &&
3878+
!TR::Compiler->cls.isArrayNullRestricted(comp(), classObject) && // If the array is null-restricted array, we know it is a fixed class
3879+
TR::Compiler->cls.isValueTypeClass(klass))
3880+
return false;
3881+
}
3882+
3883+
return true;
3884+
}
3885+
38383886
static void getHelperSymRefs(OMR::ValuePropagation *vp, TR::Node *curCallNode, TR::SymbolReference *&getHelpersSymRef, TR::SymbolReference *&helperSymRef, const char *helperSig, int32_t helperSigLen, TR::MethodSymbol::Kinds helperCallKind)
38393887
{
38403888
//Function to retrieve the JITHelpers.getHelpers and JITHelpers.<helperSig> method symbol references.

runtime/compiler/optimizer/J9ValuePropagation.hpp

+19
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ class ValuePropagation : public OMR::ValuePropagation
6161
bool isKnownStringObject(TR::VPConstraint *constraint);
6262
TR_YesNoMaybe isStringObject(TR::VPConstraint *constraint);
6363

64+
/**
65+
* \brief Determine whether an \p arrayClass with the \p componentClass can be trusted as a fixed class
66+
*
67+
* \param arrayClass The array class.
68+
* \param componentClass The component class of the array.
69+
*
70+
* \return true if an array with the component class can be trusted as a fixed class, and false otherwise.
71+
*/
72+
virtual bool canArrayClassBeTrustedAsFixedClass(TR_OpaqueClassBlock *arrayClass, TR_OpaqueClassBlock *componentClass);
73+
/**
74+
* \brief Determine whether a class retrieved from signature can be trusted as a fixed class
75+
*
76+
* \param symRef The symbol reference of the class object.
77+
* \param classObject The class object to be checked.
78+
*
79+
* \return true if a class can be trusted as a fixed class, and false otherwise.
80+
*/
81+
virtual bool canClassBeTrustedAsFixedClass(TR::SymbolReference *symRef, TR_OpaqueClassBlock *classObject);
82+
6483
/**
6584
* Determine whether the type is, or might be, a value type. Note that
6685
* a null reference can be cast to a value type that is not a primitive

0 commit comments

Comments
 (0)