Skip to content

Commit d9103b2

Browse files
authored
Merge pull request #20077 from hzongaro/string-constructor-exception-bound-v0.47.0
[0.47.0] Adjust bound for out-of-line call to StringUTF16.toBytes
2 parents bfaa3d6 + 3e401be commit d9103b2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

runtime/compiler/optimizer/J9RecognizedCallTransformer.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,11 @@ void J9::RecognizedCallTransformer::process_java_lang_StringUTF16_toBytes(TR::Tr
287287

288288
// The implementation of java.lang.StringUTF16.toBytes(char[],int,int) will
289289
// throw a NegativeArraySizeException or OutOfMemoryError if the specified
290-
// length is outside the range [0,0x3fffffff]. In order to avoid deciding
291-
// which to throw in the IL, fall back to the out-of-line call if the length
292-
// is negative or too great. Otherwise, create the byte array and copy the
293-
// input char array to it with java.lang.String.decompressedArrayCopy
290+
// length is outside the range [0,0x3fffffff] or [0,0x3ffffffe], depending on
291+
// the JDK level. In order to avoid deciding which to throw in the IL, fall
292+
// back to the out-of-line call if the length is negative or greater than or
293+
// equal to 0x3fffffff. Otherwise, create the byte array and copy the input
294+
// char array to it with java.lang.String.decompressedArrayCopy
294295
//
295296
// Before:
296297
//
@@ -312,7 +313,7 @@ void J9::RecognizedCallTransformer::process_java_lang_StringUTF16_toBytes(TR::Tr
312313
// | iload off |
313314
// | istore lenTemp |
314315
// | iload len |
315-
// | ifiucmpgt --> fallbackPathBlock -----------------+
316+
// | ifiucmpge --> fallbackPathBlock -----------------+
316317
// | iload lenTemp | |
317318
// | iconst 0x3fffffff | |
318319
// +--------------------+-------------------+ |
@@ -355,7 +356,7 @@ void J9::RecognizedCallTransformer::process_java_lang_StringUTF16_toBytes(TR::Tr
355356
// +----------------------------------------+
356357
//
357358
TR::Node *upperBoundConstNode = TR::Node::iconst(node, TR::getMaxSigned<TR::Int32>() >> 1);
358-
TR::Node *ifCmpNode = TR::Node::createif(TR::ifiucmpgt, lenNode, upperBoundConstNode);
359+
TR::Node *ifCmpNode = TR::Node::createif(TR::ifiucmpge, lenNode, upperBoundConstNode);
359360
TR::TreeTop *ifCmpTreeTop = TR::TreeTop::create(comp(), treetop->getPrevTreeTop(), ifCmpNode);
360361

361362
// Create temporary variable that will be used to hold result
@@ -410,7 +411,7 @@ void J9::RecognizedCallTransformer::process_java_lang_StringUTF16_toBytes(TR::Tr
410411
TR::Node::recreate(node, comp()->il.opCodeForDirectLoad(resultDataType));
411412
node->setSymbolReference(resultSymRef);
412413

413-
// Split the current block right after the ifuicmpgt
414+
// Split the current block right after the ifiucmpge
414415
TR::Block *ifCmpBlock = ifCmpTreeTop->getEnclosingBlock();
415416

416417
// Then split the inline version of the code into its own block
@@ -429,7 +430,7 @@ void J9::RecognizedCallTransformer::process_java_lang_StringUTF16_toBytes(TR::Tr
429430
fallThroughPathBlock->getExit()->insertBefore(gotoTree);
430431

431432
// Now we have fall-through block, fallback block and tail/merge block.
432-
// Set the ifuicmp's destination to the fallback block and update the CFG as well.
433+
// Set the ifiucmp's destination to the fallback block and update the CFG as well.
433434
ifCmpNode->setBranchDestination(fallbackPathBlock->getEntry());
434435
cfg->addEdge(ifCmpBlock, fallbackPathBlock);
435436
cfg->addEdge(fallThroughPathBlock, tailBlock);

0 commit comments

Comments
 (0)