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 methods to check if array class can be trusted as fixed class #20853

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
48 changes: 48 additions & 0 deletions runtime/compiler/optimizer/J9ValuePropagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3835,6 +3835,54 @@ bool J9::ValuePropagation::isUnreliableSignatureType(
return true;
}

bool J9::ValuePropagation::canArrayClassBeTrustedAsFixedClass(TR_OpaqueClassBlock *arrayClass, TR_OpaqueClassBlock *componentClass)
{
if (TR::Compiler->om.areFlattenableValueTypesEnabled() &&
!TR::Compiler->cls.isArrayNullRestricted(comp(), arrayClass) && // If the array is null-restricted array, we know it is a fixed class
TR::Compiler->cls.isValueTypeClass(componentClass))
return false;

return true;
}

bool J9::ValuePropagation::canClassBeTrustedAsFixedClass(TR::SymbolReference *symRef, TR_OpaqueClassBlock *classObject)
{
if (!TR::Compiler->om.areFlattenableValueTypesEnabled())
return true;

if (!classObject && symRef && symRef->getSymbol()->isClassObject())
{
if (!symRef->isUnresolved())
{
classObject = (TR_OpaqueClassBlock*)symRef->getSymbol()->getStaticSymbol()->getStaticAddress();
}
else
{
int32_t len;
const char *name = TR::Compiler->cls.classNameChars(comp(), symRef, len);
char *sig = TR::Compiler->cls.classNameToSignature(name, len, comp());
classObject = fe()->getClassFromSignature(sig, len, symRef->getOwningMethod(comp()));
}
}

if (classObject)
{
// 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, if the array is not a null-restricted array,
// it can't be trusted as a fixed class.
int32_t numDims = 0;
TR_OpaqueClassBlock *klass = comp()->fej9()->getBaseComponentClass(classObject, numDims);

if ((numDims > 0) &&
!TR::Compiler->cls.isArrayNullRestricted(comp(), classObject) && // If the array is null-restricted array, we know it is a fixed class
TR::Compiler->cls.isValueTypeClass(klass))
return false;
}

return true;
}

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)
{
//Function to retrieve the JITHelpers.getHelpers and JITHelpers.<helperSig> method symbol references.
Expand Down
19 changes: 19 additions & 0 deletions runtime/compiler/optimizer/J9ValuePropagation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ class ValuePropagation : public OMR::ValuePropagation
bool isKnownStringObject(TR::VPConstraint *constraint);
TR_YesNoMaybe isStringObject(TR::VPConstraint *constraint);

/**
* \brief Determine whether an \p arrayClass with the \p componentClass can be trusted as a fixed class
*
* \param arrayClass The array class.
* \param componentClass The component class of the array.
*
* \return true if an array with the component class can be trusted as a fixed class, and false otherwise.
*/
virtual bool canArrayClassBeTrustedAsFixedClass(TR_OpaqueClassBlock *arrayClass, TR_OpaqueClassBlock *componentClass);
/**
* \brief Determine whether a class retrieved from signature can be trusted as a fixed class
*
* \param symRef The symbol reference of the class object.
* \param classObject The class object to be checked.
*
* \return true if a class can be trusted as a fixed class, and false otherwise.
*/
virtual bool canClassBeTrustedAsFixedClass(TR::SymbolReference *symRef, TR_OpaqueClassBlock *classObject);

/**
* Determine whether the type is, or might be, a value type. Note that
* a null reference can be cast to a value type that is not a primitive
Expand Down