Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle 1D arrays with multianewarray #17358

Merged
merged 1 commit into from
Jun 16, 2023

Conversation

JamesKingdon
Copy link
Contributor

@JamesKingdon JamesKingdon commented May 8, 2023

The tree evaluator for multianewarray on X and Z has an optimisation for 0 length arrays that generate inline code for allocating the array. This code assumes that the new array will always have at least two dimensions, however the VM spec permits multianewarray to be used for 1 dimensional arrays. This does not appear to be used by javac, but can appear in code generated by other languages, e.g. Groovy.

This commit updates the evaluator on X to check the number of dimensions. For arrays of dimension 2 or more the original code is used with inline allocation where possible, and for 1 dimensional arrays the much simpler code from P is used which simply calls the helper.

@JamesKingdon
Copy link
Contributor Author

Personal build 1512 with sanity.functional ran successfully on x86-64 linux

@JamesKingdon
Copy link
Contributor Author

JamesKingdon commented Jun 7, 2023

After discussion with Daryl (@0xdaryl) re issue #17360 I'm removing the wip label from this PR as we agreed on the general approach, but I expect there will be changes needed for the specific implementation

@JamesKingdon JamesKingdon changed the title WIP FIX handle 1D arrays with multianewarray FIX handle 1D arrays with multianewarray Jun 7, 2023
@0xdaryl 0xdaryl self-assigned this Jun 8, 2023
Copy link
Contributor

@0xdaryl 0xdaryl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove "FIX" from your commit title too.

*
* NB Must only be used for arrays of at least two dimensions
*/
static TR::Register * generateMultianewArrayWithInlineAllocators(TR::Compilation *comp, TR::Node *node, TR::CodeGenerator *cg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't pass both a Compilation and a CodeGenerator object. In the code generator, you typically pass the CodeGenerator object and can get the Compilation object via cg->comp().

TR::Node *thirdChild = node->getThirdChild();
TR::Node *firstChild = node->getFirstChild(); // ptr to array of sizes, one for each dimension. Array construction stops at the outermost zero size
TR::Node *secondChild = node->getSecondChild(); // Number of dimensions - this is fixed in the bytecode, so compile time constant
TR::Node *thirdChild = node->getThirdChild(); // class of the outer most dimension
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outer most -> outermost

TR::Node *secondChild = node->getSecondChild(); // Number of dimensions - this is fixed in the bytecode, so compile time constant

// if secondChild is an iconst we can read the number of dimensions. Only generate inline code if nDims > 1
if (secondChild->getOpCodeValue() == TR::iconst)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be anything other than a constant. You should make this an assert instead and get rid of the else path.

}
else
{
// This is directly copied from the evaluator on P and should result in the simplest code to call the helper
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment

The tree evaluator for multianewarray on X and Z has an optimisation for 0 length
arrays that generate inline code for allocating the array. This code assumes that
the new array will always have at least two dimensions, however the VM spec permits
multianewarray to be used for 1 dimensional arrays. This does not appear to be
used by javac, but can appear in code generated by other languages, e.g. Groovy.

This commit updates the evaluator on X to check the number of dimensions. For
arrays of dimension 2 or more the original code is used with inline allocation
where possible, and for 1 dimensional arrays the much simpler code from P is
used which simply calls the helper.
@JamesKingdon JamesKingdon changed the title FIX handle 1D arrays with multianewarray Handle 1D arrays with multianewarray Jun 13, 2023

if (useInlineAllocator)
{
return generateMultianewArrayWithInlineAllocators(node, cg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need useInlineAllocator at all? Just move this return up to where you set it.

Copy link
Contributor Author

@JamesKingdon JamesKingdon Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It made a little more sense before your last set of requested changes which I implemented too literally. I'll clean it up

}
else
{
TR::ILOpCodes opCode = node->getOpCodeValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this else body up to the else at L1823.

@0xdaryl
Copy link
Contributor

0xdaryl commented Jun 14, 2023

Jenkins test sanity.functional,sanity.system,sanity.openjdk xlinux,win,xmac jdk17

@0xdaryl
Copy link
Contributor

0xdaryl commented Jun 15, 2023

Jenkins test sanity.openjdk win jdk17

@JamesKingdon
Copy link
Contributor Author

I did a personal build+sanity on x86-64 linux for Java8 and 11. Java 8 passed, Java11 failed some tests for criu. build # 16972

@0xdaryl
Copy link
Contributor

0xdaryl commented Jun 16, 2023

I believe the five Windows failures are known and are covered by #16734 and #17598.

@0xdaryl 0xdaryl merged commit 789612c into eclipse-openj9:master Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants