Skip to content

Commit cb98417

Browse files
authored
Merge pull request #24292 from saad-ibm/saad/constrefs-zos-sort
Fix constref sorting on z/OS
2 parents 1a9947f + 9de4cfe commit cb98417

1 file changed

Lines changed: 24 additions & 27 deletions

File tree

runtime/compiler/codegen/J9CodeGenerator.cpp

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5056,6 +5056,26 @@ void CPGSearchState::enqueue(Place p, TR_OpaqueClassBlock *owningClass)
50565056
}
50575057
}
50585058

5059+
struct OwningClassCmp {
5060+
const TR::vector<TR_OpaqueClassBlock *, TR::Region &> &_owningClasses;
5061+
5062+
OwningClassCmp(const TR::vector<TR_OpaqueClassBlock *, TR::Region &> &owningClasses)
5063+
: _owningClasses(owningClasses)
5064+
{
5065+
// empty
5066+
}
5067+
5068+
bool operator()(TR::KnownObjectTable::Index i, TR::KnownObjectTable::Index j) const
5069+
{
5070+
// Use known object index as a tiebreaker, just because it will read
5071+
// better in log output.
5072+
std::less<TR_OpaqueClassBlock *> lt;
5073+
TR_OpaqueClassBlock *classI = _owningClasses[i];
5074+
TR_OpaqueClassBlock *classJ = _owningClasses[j];
5075+
return classI == classJ ? i < j : lt(classI, classJ);
5076+
}
5077+
};
5078+
50595079
} // anonymous namespace
50605080

50615081
void J9::CodeGenerator::sortConstRefs()
@@ -5305,38 +5325,15 @@ void J9::CodeGenerator::sortConstRefs()
53055325
log->println();
53065326
}
53075327

5308-
// Temporarily disable the sorting step on z/OS due to lack of support of the
5309-
// variant of std::sort used here in the version of XLC used for z/OS builds,
5310-
// resulting in a build error. This temporary measure is meant to allow other
5311-
// platforms to benefit from const refs sorting while an alternative
5312-
// implementation is worked on for z/OS.
5313-
#if !defined(J9ZOS390)
53145328
// Now that owning classes are assigned, sort the const refs by owning class.
53155329
// The important thing is really just grouping by owning class, which ensures
53165330
// that we'll create no more than one const ref array per class.
5317-
struct OwningClassCmp {
5318-
const TR::vector<TR_OpaqueClassBlock *, TR::Region &> &_owningClasses;
5319-
5320-
OwningClassCmp(const TR::vector<TR_OpaqueClassBlock *, TR::Region &> &owningClasses)
5321-
: _owningClasses(owningClasses)
5322-
{
5323-
// empty
5324-
}
5325-
5326-
bool operator()(TR::KnownObjectTable::Index i, TR::KnownObjectTable::Index j) const
5327-
{
5328-
// Use known object index as a tiebreaker, just because it will read
5329-
// better in log output.
5330-
std::less<TR_OpaqueClassBlock *> lt;
5331-
TR_OpaqueClassBlock *classI = _owningClasses[i];
5332-
TR_OpaqueClassBlock *classJ = _owningClasses[j];
5333-
return classI == classJ ? i < j : lt(classI, classJ);
5334-
}
5335-
};
5336-
53375331
OwningClassCmp cmp(_constRefOwningClasses);
5332+
#if defined(J9ZOS390)
5333+
std::stable_sort(_constRefSortOrder.begin(), _constRefSortOrder.end(), cmp);
5334+
#else
53385335
std::sort(_constRefSortOrder.begin(), _constRefSortOrder.end(), cmp);
5339-
#endif // !defined(J9ZOS390)
5336+
#endif
53405337

53415338
if (trace) {
53425339
log->prints("const ref sort order (with owning class):\n");

0 commit comments

Comments
 (0)