From c197ea888f2fae7b0b2b8f52ada5e3f29c7bd3ae Mon Sep 17 00:00:00 2001 From: Annabelle Huo Date: Wed, 27 Nov 2024 12:12:20 -0500 Subject: [PATCH] Fix VP constraint for null-restricted array 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. Signed-off-by: Annabelle Huo --- compiler/optimizer/VPConstraint.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/compiler/optimizer/VPConstraint.cpp b/compiler/optimizer/VPConstraint.cpp index cd7cc52adef..01a0e405964 100644 --- a/compiler/optimizer/VPConstraint.cpp +++ b/compiler/optimizer/VPConstraint.cpp @@ -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); @@ -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); @@ -6088,7 +6105,7 @@ void TR::VPResolvedClass::print(TR::Compilation *comp, TR::FILE *outFile) len = static_cast(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);