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

Remove special treatment of <init> for value types #16357

Merged

Conversation

hzongaro
Copy link
Member

@hzongaro hzongaro commented Nov 22, 2022

Early prototype handling of value type classes used <init> as a special factory method name distinct from its use as an instance initialization method name. That has been dropped in favor of <vnew> as a factory method name for value type classes. This change removes the special treatment of <init> as a value type factory method name from TR_ResolvedJ9Method::isConstructor.

Fixes #14959

Early prototype handling of value type classes used <init> as a special
factory method name distinct from its use as an instance initialization
method name.  That has been dropped in favor of <vnew> as a factory
method name for value type classes.  This change removes the special
treatment of <init> as a value type factory method name from
TR_ResolvedJ9Method::isConstructor.

Signed-off-by:  Henry Zongaro <[email protected]>
@hzongaro hzongaro force-pushed the drop-init-as-value-type-factory branch from 6399249 to ff992e8 Compare December 5, 2022 20:54
@hzongaro hzongaro marked this pull request as ready for review December 6, 2022 14:13
@hzongaro
Copy link
Member Author

hzongaro commented Dec 6, 2022

Daryl @0xdaryl, Annabelle @a7ehuo, may I ask you to review this pull request?

@a7ehuo
Copy link
Contributor

a7ehuo commented Dec 6, 2022

I found a comment as below in the VM code. Do we still need special treatment for value abstract class in the JIT?

* The spec says a method of a value class cannot be <init>. A method of an abstract class cannot be <vnew>.
* For a value abstract class, its constructor is compiled into <init> now, so allow <init> in abstract classes.
*/
if (J9_IS_CLASSFILE_VALUETYPE(classfile) && J9_ARE_NO_BITS_SET(classfile->accessFlags, CFR_ACC_ABSTRACT)) {

@a7ehuo a7ehuo self-requested a review December 6, 2022 16:55
@hzongaro
Copy link
Member Author

hzongaro commented Dec 6, 2022

Do we still need special treatment for value abstract class in the JIT?
. . .
* For a value abstract class, its constructor is compiled into <init> now, so allow <init> in abstract classes.

Good question! My understanding is that an abstract class won't be a value class, but it can have a subclass that is a value class. A concrete value class that is a subclass of such an abstract class won't have an <init> method, so its superclass's <init> method can't be called for it either. Similarly, the java.lang.Object.<init> method won't be called if an instance of a value class is created.

My understanding is that an abstract class's <init> method can only be called if an instance of a concrete identity subclass of the abstract class is being initialized. So that method will still be a constructor and only used in the context where a constructor for an identity class is used, so I don't believe the JIT requires any special handling for it.

@a7ehuo
Copy link
Contributor

a7ehuo commented Dec 7, 2022

Thanks for the clarification @hzongaro!

My understanding is that an abstract class's <init> method can only be called if an instance of a concrete identity subclass of the abstract class is being initialized.

I discussed the above code with @hangshao0. The latest spec states: If the ACC_VALUE flag is set, one of the ACC_FINAL or ACC_ABSTRACT flags must also be set. Since value types can be abstract now, both <init> and <vnew> could be invoked on a VT. Should TR_ResolvedJ9Method::isConstructor check if it is abstract value type class? If it is, <init> is a value type factory method instead of a constructor?

@hzongaro
Copy link
Member Author

hzongaro commented Dec 8, 2022

Thanks, Annabelle @a7ehuo. In response to my comment:

My understanding is that an abstract class won't be a value class

you wrote:

The latest spec states: If the ACC_VALUE flag is set, one of the ACC_FINAL or ACC_ABSTRACT flags must also be set. Since value types can be abstract now, both <init> and <vnew> could be invoked on a VT.

Sorry about that! I was looking at an older version of the draft spec. The same draft that you quoted goes on to state this:

An instance initialization method is declared with the special name .

An instance initialization method may not be declared in a value class or an interface.

So a value class shouldn't have an <init> method. If I understand Hang's comment in

* The spec says a method of a value class cannot be <init>. A method of an abstract class cannot be <vnew>.
* For a value abstract class, its constructor is compiled into <init> now, so allow <init> in abstract classes.
*/
if (J9_IS_CLASSFILE_VALUETYPE(classfile) && J9_ARE_NO_BITS_SET(classfile->accessFlags, CFR_ACC_ABSTRACT)) {
, the prototype version javac with value types support is still generating <init> methods for abstract value classes. Hang @hangshao0, can you confirm that? That sounds like a bug.

Regardless, I think it's still safe if this change doesn't provide any special case handling for that case, because such an <init> method will never be invoked for a value class instance.

@hangshao0
Copy link
Contributor

the prototype version javac with value types support is still generating <init> methods for abstract value classes. Hang @hangshao0, can you confirm that?

Yes, it is the behaviour of javac for now.

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. Thank you for all the clarification

@hzongaro
Copy link
Member Author

Jenkins test sanity,extended xlinuxval jdknext

@hzongaro
Copy link
Member Author

Jenkins test sanity all jdk8,jdk11,jdk17

@hzongaro
Copy link
Member Author

I believe the sanity.functional failure on x86 Mac was due to a long-standing intermittent problem: issue #13577

@hzongaro
Copy link
Member Author

Jenkins test sanity.functional x86-64_mac jdk17

@hzongaro hzongaro requested a review from 0xdaryl January 12, 2023 15:07
@hzongaro
Copy link
Member Author

Daryl @0xdaryl, may I ask you to review this pull request?

@0xdaryl 0xdaryl self-assigned this Jan 16, 2023
@0xdaryl 0xdaryl merged commit ff74cdf into eclipse-openj9:master Jan 16, 2023
@hzongaro hzongaro deleted the drop-init-as-value-type-factory branch August 25, 2023 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:jit project:valhalla Used to track Project Valhalla related work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch from using <init> to <new> for Value Types
4 participants