Skip to content

Commit 670a110

Browse files
committed
Fix incorrect faulting instruction update in BNDCHK implicit null check
When a BNDCHK has a foldedImplicitNULLCHK, the function setImplicitNULLCHKExceptionInfo attempts to correctly identify the faulting instruction. The condition checked for both CMP4MemReg and CMP4RegMem, but CMP4RegMem loads from an object field rather than the array, so it cannot be the faulting instruction for a null array access. This caused the stack walker to fail to find the stack map, hitting a fatal assertion in jswalk.c. The fix removes CMP4RegMem from the condition, keeping only CMP4MemReg which correctly identifies a cmp that loads array length from the array.
1 parent 82f4830 commit 670a110

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

runtime/compiler/x/codegen/J9TreeEvaluator.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3065,7 +3065,16 @@ void setImplicitNULLCHKExceptionInfo(TR::Node *node, TR::CodeGenerator *cg)
30653065
// The last instruction is a branch, the comparison is before.
30663066
TR::Instruction *cmpInstruction = cg->getAppendInstruction()->getPrev();
30673067
OP::Mnemonic mnemonic = cmpInstruction->getOpCodeValue();
3068-
bool isComparisonMemForm = mnemonic == OP::CMP4MemReg || mnemonic == OP::CMP4RegMem;
3068+
3069+
// CMP4MemReg: cmp [arr+4], idx_reg
3070+
// The memory operand loads the array length from the array.
3071+
// This instruction can fault if arr is null, making it the correct faulting instruction.
3072+
//
3073+
// CMP4RegMem: cmp arraylength_reg, [this+idx_offset]
3074+
// The memory operand loads idx from 'this', not from the array.
3075+
// This instruction cannot fault due to a null array access, so it
3076+
// shouldn't be selected as the faulting instruction.
3077+
bool isComparisonMemForm = mnemonic == OP::CMP4MemReg;
30693078
if (comp->useCompressedPointers() && faultingInstruction != cmpInstruction && isComparisonMemForm) {
30703079
logprintf(isTraceCG, comp->log(), "Faulting instruction (previously %p) updated to %p\n",
30713080
faultingInstruction, cmpInstruction);

0 commit comments

Comments
 (0)