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

Throw ArrayStoreException if null is stored in non-nullable array #20291

Conversation

hzongaro
Copy link
Member

@hzongaro hzongaro commented Oct 2, 2024

In the value types prototype implementation, attempting to store a null reference to a non-nullable array is expected to throw an ArrayStoreException. Previously that was expected to result in a NullPointerException. This pull request modifies Tree Lowering optimization's transformation of calls to <nonNullableArrayNullStoreCheckhelper> to use ZEROCHK to call jitArrayStoreException if the value to be stored is null and the array is non-nullable.

Further, if Value Propagation determines at compile-time that an array is non-nullable, it used to generate a NULLCHK for the value. With this change, it will generate a ZEROCHK that tests whether the value is a null reference.

Finally, this change renames the utility method
TR_J9VMBase::checkArrayCompClassPrimitiveValueType to TR_J9VMBase::testIsArrayClassNullRestrictedType, to reflect more recent terminology. It also removes the argument that expected an "if" OpCode and will instead generate IL that yields a zero or non-zero result to indicate whether the array is null-restricted, leaving it to the caller to decide whether to generate IL that will branch or perform some other action based on the result.

@hzongaro hzongaro added comp:jit depends:omr Pull request is dependent on a corresponding change in OMR project:valhalla Used to track Project Valhalla related work labels Oct 2, 2024
@hzongaro hzongaro requested a review from dsouzai as a code owner October 2, 2024 21:04
@hzongaro
Copy link
Member Author

hzongaro commented Oct 2, 2024

@a7ehuo, @0xdaryl, may I ask you to review this change?

This change will require a coordinated merge with OMR pull request 7477.

Copy link
Contributor

@a7ehuo a7ehuo left a comment

Choose a reason for hiding this comment

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

LGTM, just minor comments related to code comments

runtime/compiler/optimizer/TreeLowering.cpp Show resolved Hide resolved
runtime/compiler/optimizer/TreeLowering.cpp Show resolved Hide resolved
@hzongaro
Copy link
Member Author

hzongaro commented Oct 3, 2024

I've added commit 686080c to address review comments. Once you're both OK with those changes, I can squash the commits.

Copy link
Contributor

@a7ehuo a7ehuo left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the update!

@0xdaryl
Copy link
Contributor

0xdaryl commented Oct 3, 2024

Looks fine to me. Can you squash so I can launch the acceptance tests?

@hzongaro hzongaro force-pushed the assigning-null-to-non-nullable-array-throws-ArrayStoreException branch from 686080c to 0ea95d8 Compare October 4, 2024 18:41
@hzongaro
Copy link
Member Author

hzongaro commented Oct 4, 2024

Can you squash so I can launch the acceptance tests?

@0xdaryl, done.

@0xdaryl
Copy link
Contributor

0xdaryl commented Oct 4, 2024

Jenkins test sanity.functional,sanity.openjdk all jdk8,jdk21 depends eclipse-omr/omr#7477

@hzongaro
Copy link
Member Author

hzongaro commented Oct 6, 2024

Running value types testing:

Jenkins test sanity,extended xlinuxval jdknext depends eclipse-omr/omr#7477

@0xdaryl
Copy link
Contributor

0xdaryl commented Oct 7, 2024

Non-Valhalla failures are known, as you point out.

Valhallla test failures are configuration related. Do you want to try and repair it and try again?

@hzongaro
Copy link
Member Author

hzongaro commented Oct 7, 2024

Valhallla test failures are configuration related. Do you want to try and repair it and try again?

It looks like this was due to the change recently introduced by pull request #20203. Previously, I had only intended to run sanity.functional and extended.functional with xlinuxval, both of which were successful — the sanity.openjdk testing should not have run.

I'll look at opening a pull request that will avoid expanding sanity into sanity.functional,sanity.openjdk for Valhalla testing, but I think that failure can be ignored for now.

@hzongaro
Copy link
Member Author

hzongaro commented Oct 7, 2024

I'll look at opening a pull request that will avoid expanding sanity into sanity.functional,sanity.openjdk for Valhalla testing, but I think that failure can be ignored for now.

On second thought, I'm getting myself lost in the groovy scripts for the build. @AdamBrousseau, would it be possible to only expand sanity to sanity.functional,sanity.openjdk for non-Valhalla testing?

@0xdaryl
Copy link
Contributor

0xdaryl commented Oct 7, 2024

but I think that failure can be ignored for now.

Are you saying these PRs can be merged now or should wait for that testing?

@hzongaro
Copy link
Member Author

hzongaro commented Oct 7, 2024

but I think that failure can be ignored for now.

Are you saying these PRs can be merged now or should wait for that testing?

I was saying they can be merged. Sorry for the confusion.

@AdamBrousseau
Copy link
Contributor

@hzongaro you'd probably be able to wrap this line in an if with condition based on SPEC name

TESTS["${target}.openjdk"] = [:]

if (!SPEC.contains("valhalla")) {

@0xdaryl 0xdaryl self-assigned this Oct 7, 2024
@0xdaryl 0xdaryl added depends:omr:breaking and removed depends:omr Pull request is dependent on a corresponding change in OMR labels Oct 7, 2024
@0xdaryl
Copy link
Contributor

0xdaryl commented Oct 7, 2024

There was another coordinated merge merged on Oct 4 just before the acceptance tests for this PR were launched. I'd be more comfortable if you could rebase this PR (and its OMR counterpart) to pick up those changes just to be sure there are no conflicts.

I'll use my judgement then on whether to relaunch the acceptance tests (I'm leaning toward "no" at this time from my quick inspection of the PRs).

Attempting to store a null reference to a non-nullable array is expected
to throw an ArrayStoreException.  Previously that was expected to result
in a NullPointerException.  This modifies Tree Lowering optimization's
transformation of calls to <nonNullableArrayNullStoreCheckhelper> to use
ZEROCHK to call jitArrayStoreException if the value to be stored is null
and the array is non-nullable.

Further, if Value Propagation determines at compile-time that an array
is non-nullable, it used to generate a NULLCHK for the value.  With this
change, it will generate a ZEROCHK that tests whether the value is a
null reference.

Finally, this change renames the utility method
TR_J9VMBase::checkArrayCompClassPrimitiveValueType to
TR_J9VMBase::testIsArrayClassNullRestrictedType, to reflect more recent
terminology.  It also removes the argument that expected an "if" OpCode
and will instead generate IL that yields a zero or non-zero result to
indicate whether the array is null-restricted, leaving it to the caller
to decide whether to generate IL that will branch or perform some other
action based on the result.

Signed-off-by:  Henry Zongaro <zongaro@ca.ibm.com>
@hzongaro hzongaro force-pushed the assigning-null-to-non-nullable-array-throws-ArrayStoreException branch from 0ea95d8 to 3cd0898 Compare October 7, 2024 17:20
@hzongaro
Copy link
Member Author

hzongaro commented Oct 7, 2024

Rebased changes onto current HEAD of master branch.

@0xdaryl 0xdaryl merged commit 4232598 into eclipse-openj9:master Oct 8, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:jit depends:omr:breaking project:valhalla Used to track Project Valhalla related work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants