Skip to content

Commit

Permalink
fixup! p: NULL initialize dataAddr field for 0 size arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
VermaSh committed Jan 3, 2025
1 parent 519bedd commit 1317bac
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions runtime/compiler/p/codegen/J9TreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6165,23 +6165,24 @@ static void genInitArrayHeader(TR::Node *node, TR::Instruction *&iCursor, bool i
}

// Clear padding after size field
TR::Register *zeroReg = cg->allocateRegister();
iCursor = generateTrg1Src2Instruction(cg, TR::InstOpCode::XOR, node, zeroReg, zeroReg, zeroReg, iCursor);
if (TR::Compiler->om.compressObjectReferences())
{
// use fej9->getOffsetOfDiscontiguousArraySizeField() + 4
iCursor = generateMemSrc1Instruction(cg, TR::InstOpCode::stw, node,
TR::MemoryReference::createWithDisplacement(cg, resReg, fej9->getOffsetOfDiscontiguousArraySizeField() + 4, 4),
zeroReg, iCursor);
}
else
if (needZeroInit)
{
// use fej9->getOffsetOfContiguousArraySizeField() + 4
iCursor = generateMemSrc1Instruction(cg, TR::InstOpCode::stw, node,
TR::MemoryReference::createWithDisplacement(cg, resReg, fej9->getOffsetOfContiguousArraySizeField() + 4, 4),
zeroReg, iCursor);
TR_ASSERT_FATAL_WITH_NODE(node, zeroReg, "zeroReg is expected to be intialized but wasn't.\n");
if (TR::Compiler->om.compressObjectReferences())
{
// padding field starts at fej9->getOffsetOfDiscontiguousArraySizeField() + 4
iCursor = generateMemSrc1Instruction(cg, TR::InstOpCode::stw, node,
TR::MemoryReference::createWithDisplacement(cg, resReg, fej9->getOffsetOfDiscontiguousArraySizeField() + 4, 4),
zeroReg, iCursor);
}
else
{
// padding field starts at fej9->getOffsetOfContiguousArraySizeField() + 4
iCursor = generateMemSrc1Instruction(cg, TR::InstOpCode::stw, node,
TR::MemoryReference::createWithDisplacement(cg, resReg, fej9->getOffsetOfContiguousArraySizeField() + 4, 4),
zeroReg, iCursor);
}
}
cg->stopUsingRegister(zeroReg);
}

static void genZeroInit(TR::CodeGenerator *cg, TR::Node *node, TR::Register *objectReg, int32_t headerSize, int32_t totalSize, bool useInitInfo)
Expand Down Expand Up @@ -6541,7 +6542,7 @@ TR::Register *J9::Power::TreeEvaluator::VMnewEvaluator(TR::Node *node, TR::CodeG
dataAddrSlotMR = TR::MemoryReference::createWithDisplacement(cg, offsetReg, fej9->getOffsetOfContiguousDataAddrField(), TR::Compiler->om.sizeofReferenceAddress());

// Clear firstDataElementReg reg if dealing with 0 size arrays
iCursor = generateTrg1Src1ImmInstruction(cg,TR::InstOpCode::Op_cmpdi, node, condReg, enumReg, 0, iCursor);
iCursor = generateTrg1Src1ImmInstruction(cg,TR::InstOpCode::cmpi8, node, condReg, enumReg, 0, iCursor);
iCursor = generateTrg1Src3Instruction(cg, TR::InstOpCode::iseleq, node, firstDataElementReg, NULL, firstDataElementReg, condReg, iCursor);
}
else if (!isVariableLen && node->getFirstChild()->getOpCode().isLoadConst() && node->getFirstChild()->getInt() == 0)
Expand Down Expand Up @@ -6579,7 +6580,7 @@ TR::Register *J9::Power::TreeEvaluator::VMnewEvaluator(TR::Node *node, TR::CodeG
// Clear firstDataElementReg reg if dealing with variable len 0 size arrays
if (isVariableLen && !TR::Compiler->om.compressObjectReferences())
{
iCursor = generateTrg1Src1ImmInstruction(cg,TR::InstOpCode::Op_cmpdi, node, condReg, enumReg, 0, iCursor);
iCursor = generateTrg1Src1ImmInstruction(cg,TR::InstOpCode::cmpi8, node, condReg, enumReg, 0, iCursor);
iCursor = generateTrg1Src3Instruction(cg, TR::InstOpCode::iseleq, node, firstDataElementReg, NULL, firstDataElementReg, condReg, iCursor);
}
}
Expand Down

0 comments on commit 1317bac

Please sign in to comment.