Skip to content
Open
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
28 changes: 22 additions & 6 deletions runtime/compiler/x/codegen/J9TreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,7 @@ static TR::Register *generate2DArrayWithInlineAllocators(TR::Node *node, TR::Cod
bool needsAlignLeaf = (OMR::align(leafArrayElementSize, alignmentInBytes) != leafArrayElementSize);
bool needsAlignHeader = (contiguousArrayHeaderSize != OMR::align(contiguousArrayHeaderSize, alignmentInBytes));
uintptr_t referenceSize = TR::Compiler->om.sizeofReferenceField();
bool needsAlignSpine = (OMR::align(referenceSize, alignmentInBytes) != referenceSize) || needsAlignHeader;

bool use64BitClasses = !TR::Compiler->om.generateCompressedObjectHeaders();

Expand Down Expand Up @@ -1557,7 +1558,7 @@ static TR::Register *generate2DArrayWithInlineAllocators(TR::Node *node, TR::Cod
generateX86MemoryReference(spineSizeReg, firstDimReg, trailingZeroes((int32_t)referenceSize), 0, cg), cg);

// pad spine size so leaf arrays will be aligned
if (needsAlignHeader) {
if (needsAlignSpine) {
generateRegImmInstruction(TR::InstOpCode::ADD8RegImm4, node, spineSizeReg, alignmentInBytes - 1, cg);
generateRegImmInstruction(TR::InstOpCode::AND8RegImm4, node, spineSizeReg, -alignmentInBytes, cg);
}
Expand Down Expand Up @@ -1832,7 +1833,7 @@ static TR::Register *generate2DArrayWithInlineAllocators(TR::Node *node, TR::Cod
*
* NB Must only be used for arrays of at least two dimensions
*/
static TR::Register *generateMultianewArrayWithInlineAllocators(TR::Node *node, TR::CodeGenerator *cg)
static TR::Register *generate2DZeroLengthArrayWithInlineAllocators(TR::Node *node, TR::CodeGenerator *cg)
{
TR::Compilation *comp = cg->comp();

Expand Down Expand Up @@ -1884,6 +1885,10 @@ static TR::Register *generateMultianewArrayWithInlineAllocators(TR::Node *node,
// Generate the heap allocation, and the snippet that will handle heap overflow.
TR_OutlinedInstructions *outlinedHelperCall
= new (cg->trHeapMemory()) TR_OutlinedInstructions(node, TR::acall, targetReg, oolFailLabel, doneLabel, cg);
cg->generateDebugCounter(outlinedHelperCall->getFirstInstruction(),
TR::DebugCounter::debugCounterName(comp, "multianewarray/dynamic/zero-dim/helper/(%s)/%d/%d", comp->signature(),
node->getByteCodeInfo().getCallerIndex(), node->getByteCodeInfo().getByteCodeIndex()),
1, TR::DebugCounter::Cheap);
cg->getOutlinedInstructionsList().push_front(outlinedHelperCall);

dimReg = cg->evaluate(secondChild);
Expand Down Expand Up @@ -2135,7 +2140,7 @@ static TR::Register *generateMultianewArrayWithInlineAllocators(TR::Node *node,
* Generate code for multianewarray
*
* Checks the number of dimensions. For 1 dimensional arrays call the helper, for >1 call
* generateMultianewArrayWithInlineAllocators.
* generate2DArrayWithInlineAllocators or generate2DZeroLengthArrayWithInlineAllocators.
*/
TR::Register *J9::X86::TreeEvaluator::multianewArrayEvaluator(TR::Node *node, TR::CodeGenerator *cg)
{
Expand All @@ -2148,10 +2153,21 @@ TR::Register *J9::X86::TreeEvaluator::multianewArrayEvaluator(TR::Node *node, TR
// The number of dimensions should always be an iconst
TR_ASSERT_FATAL(secondChild->getOpCodeValue() == TR::iconst, "dims of multianewarray must be iconst");

// Only generate inline code if nDims > 1
// Anything with more than 2 dimensions will be replaced by a direct call when lowering trees.
uint32_t nDims = secondChild->get32bitIntegralValue();
if (nDims > 1) {
return generateMultianewArrayWithInlineAllocators(node, cg);
TR_ASSERT_FATAL(nDims <= 2,
"multianewarray with dimension >2 should have been lowered to direct call before instruction selection");

TR::Node *classNode = node->getThirdChild(); // class of the outermost dimension

if (nDims == 2) {
static const bool disable = feGetEnv("TR_Disable2DArrayWithInlineAllocators") != NULL;
int32_t leafArrayElementSize = TR::Compiler->om.getTwoDimensionalArrayComponentSize(classNode);
if (!disable && (leafArrayElementSize != -1) && !comp->getOptions()->realTimeGC()) {
return generate2DArrayWithInlineAllocators(node, cg, leafArrayElementSize);
} else {
return generate2DZeroLengthArrayWithInlineAllocators(node, cg);
}
} else {
logprintf(comp->getOption(TR_TraceCG), comp->log(),
"Disabling inline allocations for multianewarray of dim %d\n", nDims);
Expand Down