Skip to content

Commit

Permalink
Fix VP constraint for null-restricted array class
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Annabelle Huo <[email protected]>
  • Loading branch information
a7ehuo committed Nov 27, 2024
1 parent 494474f commit c197ea8
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions compiler/optimizer/VPConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,15 @@ TR::VPClassType *TR::VPClassType::create(OMR::ValuePropagation *vp, TR::SymbolRe
TR_OpaqueClassBlock *classObject = (TR_OpaqueClassBlock*)symRef->getSymbol()->getStaticSymbol()->getStaticAddress();
if (isPointerToClass)
classObject = *((TR_OpaqueClassBlock**)classObject);
#ifdef J9_PROJECT_SPECIFIC
int32_t numDims = 0;
TR_OpaqueClassBlock *klass = vp->comp()->fej9()->getBaseComponentClass(classObject, numDims);
// 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.
if (TR::Compiler->om.areFlattenableValueTypesEnabled() && (numDims > 0) && TR::Compiler->cls.isValueTypeClass(klass))
return TR::VPResolvedClass::create(vp, classObject);
#endif
if (isFixedClass)
return TR::VPFixedClass::create(vp, classObject);
return TR::VPResolvedClass::create(vp, classObject);
Expand Down Expand Up @@ -1287,7 +1296,15 @@ TR::VPResolvedClass *TR::VPResolvedClass::create(OMR::ValuePropagation *vp, TR_O
//
TR_OpaqueClassBlock * baseClass = vp->fe()->getLeafComponentClassFromArrayClass(klass);
if (baseClass && TR::Compiler->cls.isClassFinal(vp->comp(), baseClass))
return TR::VPFixedClass::create(vp, klass);
{
#ifdef J9_PROJECT_SPECIFIC
// 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.
if (!TR::Compiler->om.areFlattenableValueTypesEnabled() || !TR::Compiler->cls.isValueTypeClass(baseClass))
#endif
return TR::VPFixedClass::create(vp, klass);
}
}
else
return TR::VPFixedClass::create(vp, klass);
Expand Down Expand Up @@ -6088,7 +6105,7 @@ void TR::VPResolvedClass::print(TR::Compilation *comp, TR::FILE *outFile)
len = static_cast<int32_t>(strlen(sig));
}

trfprintf(outFile, "class %.*s", len, sig);
trfprintf(outFile, "class 0x%p %.*s", _class, len, sig);
if (_typeHintClass)
{
trfprintf(outFile, " (hint 0x%p", _typeHintClass);
Expand Down

0 comments on commit c197ea8

Please sign in to comment.