From 81758097d2a1d79b2fd62d7116320fcb0d5f3815 Mon Sep 17 00:00:00 2001 From: Luke Li Date: Fri, 10 Jan 2025 12:38:43 -0500 Subject: [PATCH] Enable String.indexOf intrinsic for OffHeap on POWER Calculate the address for the array data in OffHeap mode correctly for the String.indexOf instrinsic. Signed-off-by: Luke Li --- .../compiler/p/codegen/J9CodeGenerator.cpp | 2 +- .../compiler/p/codegen/J9TreeEvaluator.cpp | 41 ++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/runtime/compiler/p/codegen/J9CodeGenerator.cpp b/runtime/compiler/p/codegen/J9CodeGenerator.cpp index bbb449abb73..0ba70f5f601 100644 --- a/runtime/compiler/p/codegen/J9CodeGenerator.cpp +++ b/runtime/compiler/p/codegen/J9CodeGenerator.cpp @@ -98,7 +98,7 @@ J9::Power::CodeGenerator::initialize() if (comp->target().cpu.isAtLeast(OMR_PROCESSOR_PPC_P8) && comp->target().cpu.supportsFeature(OMR_FEATURE_PPC_HAS_VSX) && comp->target().is64Bit() && !comp->getOption(TR_DisableFastStringIndexOf) && - !TR::Compiler->om.canGenerateArraylets() && !TR::Compiler->om.isOffHeapAllocationEnabled()) + !TR::Compiler->om.canGenerateArraylets()) cg->setSupportsInlineStringIndexOf(); static bool disableStringInflateIntrinsic = feGetEnv("TR_DisableStringInflateIntrinsic") != NULL; diff --git a/runtime/compiler/p/codegen/J9TreeEvaluator.cpp b/runtime/compiler/p/codegen/J9TreeEvaluator.cpp index b0e8c1d91a3..4068127ba45 100644 --- a/runtime/compiler/p/codegen/J9TreeEvaluator.cpp +++ b/runtime/compiler/p/codegen/J9TreeEvaluator.cpp @@ -10768,7 +10768,25 @@ static TR::Register *inlineIntrinsicIndexOf_P10(TR::Node *node, TR::CodeGenerato generateTrg1Src2Instruction(cg, TR::InstOpCode::add, node, endPos, endPos, endPos); } - generateTrg1Src1ImmInstruction(cg, TR::InstOpCode::addi, node, arrAddress, array, TR::Compiler->om.contiguousArrayHeaderSizeInBytes()); + /* + * Determine the address of the first byte to read either by loading from dataAddr or adding the header size. + * This is followed by adding in the offset. + */ +#if defined(J9VM_GC_SPARSE_HEAP_ALLOCATION) + if (TR::Compiler->om.isOffHeapAllocationEnabled()) + { + generateTrg1MemInstruction( + cg, TR::InstOpCode::ld, node, arrAddress, + TR::MemoryReference::createWithDisplacement( + cg, array, TR::Compiler->om.offsetOfContiguousDataAddrField(), 8) + ); + } + else +#endif /* J9VM_GC_SPARSE_HEAP_ALLOCATION */ + { + generateTrg1Src1ImmInstruction(cg, TR::InstOpCode::addi, node, arrAddress, array, + TR::Compiler->om.contiguousArrayHeaderSizeInBytes()); + } // match first byte generateTrg1MemInstruction(cg, scalarLoadOp, node, temp, TR::MemoryReference::createWithIndexReg(cg, position, arrAddress, isLatin1 ? 1 : 2)); @@ -10954,7 +10972,26 @@ static TR::Register *inlineIntrinsicIndexOf(TR::Node *node, TR::CodeGenerator *c if (node->getChild(firstCallArgIdx+3)->getReferenceCount() == 1) srm->donateScratchRegister(length); - generateTrg1Src1ImmInstruction(cg, TR::InstOpCode::addi, node, arrAddress, array, TR::Compiler->om.contiguousArrayHeaderSizeInBytes()); + /* + * Determine the address of the first byte to read either by loading from dataAddr or adding the header size. + * This is followed by adding in the offset. + */ +#if defined(J9VM_GC_SPARSE_HEAP_ALLOCATION) + if (TR::Compiler->om.isOffHeapAllocationEnabled()) + { + generateTrg1MemInstruction( + cg, TR::InstOpCode::ld, node, arrAddress, + TR::MemoryReference::createWithDisplacement( + cg, array, TR::Compiler->om.offsetOfContiguousDataAddrField(), 8) + ); + } + else +#endif /* J9VM_GC_SPARSE_HEAP_ALLOCATION */ + { + generateTrg1Src1ImmInstruction(cg, TR::InstOpCode::addi, node, arrAddress, array, + TR::Compiler->om.contiguousArrayHeaderSizeInBytes()); + } + if (node->getChild(firstCallArgIdx)->getReferenceCount() == 1) srm->donateScratchRegister(array);