Skip to content

Commit

Permalink
Merge pull request #20930 from luke-li-2003/StringIndexOfOffHeapIntri…
Browse files Browse the repository at this point in the history
…nsic

Enable String.indexOf intrinsic for OffHeap on POWER
  • Loading branch information
zl-wang authored Jan 16, 2025
2 parents 64298fd + 8175809 commit 9243a1f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion runtime/compiler/p/codegen/J9CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
41 changes: 39 additions & 2 deletions runtime/compiler/p/codegen/J9TreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 9243a1f

Please sign in to comment.