Skip to content

Commit

Permalink
Merge pull request #2406 from fjeremic/accelerate-tobytes
Browse files Browse the repository at this point in the history
Accelerate java/lang/StringUTF16.toBytes for performance
  • Loading branch information
vijaysun-omr committed Jul 20, 2018
2 parents 91eb871 + 1855b0a commit 930bbbe
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtime/compiler/codegen/J9RecognizedMethodsEnum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
java_lang_String_getChars_byteArray,

java_lang_StringUTF16_getChar,
java_lang_StringUTF16_toBytes,

java_lang_StringBuffer_append,
java_lang_StringBuffer_capacityInternal,
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3285,6 +3285,7 @@ int TR_J9VMBase::checkInlineableTarget (TR_CallTarget* target, TR_CallSite* call
case TR::com_ibm_jit_JITHelpers_getJ9ClassFromObject64:
case TR::com_ibm_jit_JITHelpers_getClassInitializeStatus:
case TR::java_lang_StringUTF16_getChar:
case TR::java_lang_StringUTF16_toBytes:
case TR::java_lang_invoke_MethodHandle_asType_instance:
return DontInline_Callee;
default:
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/env/j9method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3326,6 +3326,7 @@ TR_ResolvedJ9Method::TR_ResolvedJ9Method(TR_OpaqueMethodBlock * aMethod, TR_Fron
static X StringUTF16Methods[] =
{
{ x(TR::java_lang_StringUTF16_getChar, "getChar", "([BI)C")},
{ x(TR::java_lang_StringUTF16_toBytes, "toBytes", "([CII)[B")},
{ TR::unknownMethod }
};

Expand Down
41 changes: 41 additions & 0 deletions runtime/compiler/optimizer/J9RecognizedCallTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,42 @@ void J9::RecognizedCallTransformer::processIntrinsicFunction(TR::TreeTop* treeto
TR::TransformUtil::removeTree(comp(), treetop);
}

void J9::RecognizedCallTransformer::process_java_lang_StringUTF16_toBytes(TR::TreeTop* treetop, TR::Node* node)
{
TR_J9VMBase* fej9 = static_cast<TR_J9VMBase*>(comp()->fe());

TR::Node* valueNode = node->getChild(0);
TR::Node* offNode = node->getChild(1);
TR::Node* lenNode = node->getChild(2);

anchorAllChildren(node, treetop);
prepareToReplaceNode(node);

int32_t byteArrayType = fej9->getNewArrayTypeFromClass(reinterpret_cast<TR_OpaqueClassBlock*>(fej9->getJ9JITConfig()->javaVM->byteArrayClass));

TR::Node::recreateWithoutProperties(node, TR::newarray, 2,
TR::Node::create(TR::ishl, 2,
lenNode,
TR::Node::iconst(1)),
TR::Node::iconst(byteArrayType),

getSymRefTab()->findOrCreateNewArraySymbolRef(node->getSymbolReference()->getOwningMethodSymbol(comp())));

TR::Node* newByteArrayNode = node;
newByteArrayNode->setCanSkipZeroInitialization(true);
newByteArrayNode->setIsNonNull(true);

TR::Node* newCallNode = TR::Node::createWithSymRef(node, TR::call, 5,
getSymRefTab()->methodSymRefFromName(comp()->getMethodSymbol(), "java/lang/String", "decompressedArrayCopy", "([CI[BII)V", TR::MethodSymbol::Static));
newCallNode->setAndIncChild(0, valueNode);
newCallNode->setAndIncChild(1, offNode);
newCallNode->setAndIncChild(2, newByteArrayNode);
newCallNode->setAndIncChild(3, TR::Node::iconst(0));
newCallNode->setAndIncChild(4, lenNode);

treetop->insertAfter(TR::TreeTop::create(comp(), TR::Node::create(node, TR::treetop, 1, newCallNode)));
}

bool J9::RecognizedCallTransformer::isInlineable(TR::TreeTop* treetop)
{
auto node = treetop->getNode()->getFirstChild();
Expand All @@ -66,6 +102,8 @@ bool J9::RecognizedCallTransformer::isInlineable(TR::TreeTop* treetop)
case TR::java_lang_Math_max_L:
case TR::java_lang_Math_min_L:
return !comp()->getOption(TR_DisableMaxMinOptimization);
case TR::java_lang_StringUTF16_toBytes:
return !comp()->compileRelocatableCode();
default:
return false;
}
Expand Down Expand Up @@ -106,6 +144,9 @@ void J9::RecognizedCallTransformer::transform(TR::TreeTop* treetop)
case TR::java_lang_Math_min_L:
processIntrinsicFunction(treetop, node, TR::lmin);
break;
case TR::java_lang_StringUTF16_toBytes:
process_java_lang_StringUTF16_toBytes(treetop, node);
break;
default:
break;
}
Expand Down
19 changes: 19 additions & 0 deletions runtime/compiler/optimizer/J9RecognizedCallTransformer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ class RecognizedCallTransformer : public OMR::RecognizedCallTransformer

private:
void processIntrinsicFunction(TR::TreeTop* treetop, TR::Node* node, TR::ILOpCodes opcode);

/** \brief
* Transforms java/lang/StringUTF16.toBytes([CII)[B into a fast allocate and arraycopy sequence with equivalent
* semantics.
*
* \param treetop
* The treetop which anchors the call node.
* \param node
* The call node representing a call to java/lang/StringUTF16.toBytes([CII)[B which has the following shape:
*
* \code
* acall <java/lang/StringUTF16.toBytes([CII)[B>
* <value>
* <off>
* <len>
* \endcode
*/
void process_java_lang_StringUTF16_toBytes(TR::TreeTop* treetop, TR::Node* node);
};

}
Expand Down

0 comments on commit 930bbbe

Please sign in to comment.