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

8273360: [lworld] Invoking a reflection-generated constructor for primitive class gives InstantiationError #546

Closed

Conversation

jespersm
Copy link
Contributor

@jespersm jespersm commented Sep 5, 2021

Update constructor accessor code generation to invoke static factory method.


Progress

  • Change must not contain extraneous whitespace

Issue

  • JDK-8273360: [lworld] Invoking a reflection-generated constructor for primitive class gives InstantiationError

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/valhalla pull/546/head:pull/546
$ git checkout pull/546

Update a local copy of the PR:
$ git checkout pull/546
$ git pull https://git.openjdk.java.net/valhalla pull/546/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 546

View PR using the GUI difftool:
$ git pr show -t 546

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/valhalla/pull/546.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Sep 5, 2021

👋 Welcome back jespersm! A progress list of the required criteria for merging this PR into lworld will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

@openjdk openjdk bot commented Sep 5, 2021

@jespersm This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8273360: [lworld] Invoking a reflection-generated constructor for primitive class gives InstantiationError

Reviewed-by: mchung

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 8 new commits pushed to the lworld branch:

  • 2688bf6: 8273018: [lworld] Property annotation propagation to lacks in primitive records
  • a5cf519: Adjust problem list for initial aarch64 testing
  • c64b160: Fix header format for build setup
  • 8bed69a: 8273650: [lworld] Interpreter fails with fatal error: DEBUG MESSAGE: klass not initialized
  • e075eaf: 8270477: [lworld] bytecode testing API does not emit Q type descriptors
  • 0c0c9e1: 8267697: [lworld] [lw3] VM crashes during heap dump if Java heap contains flat arrays
  • 3111124: 8273554: [lworld] Runtime tests should not explicitly set -Xint/-Xcomp
  • 252b04b: 8273323: [lworld] Fix post-parse call devirtualization with inline type receiver

Please see this link for an up-to-date comparison between the source branch of this pull request and the lworld branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@mlchung) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@mlbridge
Copy link

@mlbridge mlbridge bot commented Sep 5, 2021

Webrevs

@jespersm
Copy link
Contributor Author

@jespersm jespersm commented Sep 5, 2021

/solves 8273360

@openjdk openjdk bot changed the title [lworld] Invoking a reflection-generated constructor for primitive class gives InstantiationError 8273360: [lworld] Invoking a reflection-generated constructor for primitive class gives InstantiationError Sep 5, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Sep 5, 2021

@jespersm The primary solved issue for a PR is set through the PR title. Since the current title does not contain an issue reference, it will now be updated.

Copy link
Member

@mlchung mlchung left a comment

@jespersm Thanks for fixing this. A couple comments.

@@ -49,7 +49,7 @@ public short getLength() {
public void emitMagicAndVersion() {
emitInt(0xCAFEBABE);
emitShort((short) 0);
emitShort((short) 49);
emitShort((short) 62);
Copy link
Member

@mlchung mlchung Sep 10, 2021

Choose a reason for hiding this comment

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

This old bytecode generator does not support stack map and so these reflection classes would need to stay in version 49. JEP 416 changes the core reflection implementation to build on top of method handles and no longer depends on this old bytecode generator.

this.isConstructingPrimitive = isConstructor && declaringClass.isPrimitiveClass();
if (this.isConstructingPrimitive ) {
returnType = declaringClass.asValueType();
}
Copy link
Member

@mlchung mlchung Sep 10, 2021

Choose a reason for hiding this comment

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

Alternatively, this method can take an additional isStaticFactory parameter. generateConstructor will determine if the declaring class is a primitive class and then call the static factory with the return type argument rather than Void.TYPE.

for (int i = 0; i < 20; ++i) {
Object o = ctor.newInstance();
assertTrue(o.getClass() == PRIMITIVE_TYPE.asPrimaryType());
}
Copy link
Member

@mlchung mlchung Sep 10, 2021

Choose a reason for hiding this comment

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

I suggest to replace this change with @run testng/othervm -Dsun.reflect.noInflation=true StaticFactoryTest so that other test cases will also verify when it's run with the generated bytecode.

Copy link
Member

@mlchung mlchung left a comment

Looks good. You can integrate once you update the StaticFactoryTest.java.

Run both variations

Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
@jespersm
Copy link
Contributor Author

@jespersm jespersm commented Sep 23, 2021

Thanks for reviewing, @mlchung !

/integrate

@openjdk openjdk bot added the sponsor label Sep 23, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Sep 23, 2021

@jespersm
Your change (at version 2afc752) is now ready to be sponsored by a Committer.

@mlchung
Copy link
Member

@mlchung mlchung commented Sep 23, 2021

/sponsor

@openjdk
Copy link

@openjdk openjdk bot commented Sep 23, 2021

Going to push as commit 1303571.
Since your change was applied there have been 8 commits pushed to the lworld branch:

  • 2688bf6: 8273018: [lworld] Property annotation propagation to lacks in primitive records
  • a5cf519: Adjust problem list for initial aarch64 testing
  • c64b160: Fix header format for build setup
  • 8bed69a: 8273650: [lworld] Interpreter fails with fatal error: DEBUG MESSAGE: klass not initialized
  • e075eaf: 8270477: [lworld] bytecode testing API does not emit Q type descriptors
  • 0c0c9e1: 8267697: [lworld] [lw3] VM crashes during heap dump if Java heap contains flat arrays
  • 3111124: 8273554: [lworld] Runtime tests should not explicitly set -Xint/-Xcomp
  • 252b04b: 8273323: [lworld] Fix post-parse call devirtualization with inline type receiver

Your commit was automatically rebased without conflicts.

@openjdk
Copy link

@openjdk openjdk bot commented Sep 23, 2021

@mlchung @jespersm Pushed as commit 1303571.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants