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

JEP 397 Sealed Classes (Second Preview) #11273

Closed
pshipton opened this issue Nov 25, 2020 · 12 comments
Closed

JEP 397 Sealed Classes (Second Preview) #11273

pshipton opened this issue Nov 25, 2020 · 12 comments

Comments

@pshipton
Copy link
Member

See https://openjdk.java.net/jeps/397

@pshipton
Copy link
Member Author

@tajila

@pshipton pshipton added the jdk16 label Nov 25, 2020
@tajila
Copy link
Contributor

tajila commented Nov 25, 2020

https://mail.openjdk.java.net/pipermail/amber-spec-experts/2020-May/002161.html

Some updates

In the interest of defining a clear, conservative space where sealed classes and interfaces can be used, which we may want to refine in future iterations, here's what it sounds like we want.

For each of local classes, anonymous classes, and member classes declared within one of these (plus, eventually, local interfaces and member interfaces declared within one of these):

- It is a compile-time error to be declared 'sealed'
- It is a compile-time error to extend/implement a sealed class or interface

This limits the sealing features to top-level classes/interfaces and member classes/interfaces that can be named from the top level.

Before we finalize the feature (after one or two rounds of preview), we should consider whether it makes sense to relax these constraints to allow any of:
- Groups of member classes nested inside a local class
- Groups of local classes that, via a new feature, support mutual recursion (don't know what the feature looks like, but we know it's something we want to explore)
- Classes (including local/anonymous) that extend a sealed class but aren't in scope/nameable at the superclass's declaration

@tajila
Copy link
Contributor

tajila commented Nov 25, 2020

I think these changes will be merged sometime next week.

@tajila
Copy link
Contributor

tajila commented Nov 25, 2020

@ChengJin01 Can you please take a look at this

@ChengJin01
Copy link

I went through all these Specs mentioned above against the JEP360 related Specs at
https://openjdk.java.net/jeps/360: JEP 360: Sealed Classes (Preview)
http://cr.openjdk.java.net/~dlsmith/jep360/jep360-20200421/specs/sealed-types-jls.html
http://cr.openjdk.java.net/~dlsmith/jep360/jep360-20200421/specs/sealed-types-jvms.html

It seems the only updated descriptions related to Sealed Classes to be addressed in terms of VM is the check of sealed superclass/superinterface in http://cr.openjdk.java.net/~gbierman/jep397/jep397-20201104/specs/sealed-classes-jvms.html as follows:

Table 4.7-A. Predefined class file attributes (by section)
Attribute           | Section | class file | Java SE
PermittedSubclasses | 4.7.30 | 60.65535 | 16

5.3.5 Deriving a Class from a class File Representation
...
3. If C has a direct superclass, the symbolic reference from C to its direct superclass is resolved ...
...
    Otherwise, if the class named as the direct superclass of C has a PermittedSubclasses attribute (4.7.30)
    and any of the following are true, derivation fails with a IncompatibleClassChangeError:
---> (1)The superclass belongs to a different run-time module than C.
---> (2)C does not have its ACC_PUBLIC flag set (4.1) and the superclass belongs to a different run-time package than C.
...
4. If C has any direct superinterfaces, the symbolic references from C to its direct superinterfaces are resolved
...
  Otherwise, for each direct superinterface, if the superinterface has a PermittedSubclasses attribute (4.7.30) 
   and any of the following are true, derivation fails with a IncompatibleClassChangeError:
---> (1) The superinterface belongs to a different run-time module than C.
---> (2) C does not have its ACC_PUBLIC flag set (4.1) and the superinterface belongs to a different run-time package than C.
...

Actually these check were already mentioned in JEP 360 https://openjdk.java.net/jeps/360 but not yet emphasized in the corresponding sealed-types-jvms.html

Description
...
The classes specified by permits must be located near the superclass: 
either in the same module (if the superclass is in a named module)
or in the same package (if the superclass is in the unnamed module).
...

I will get started to prepare the code involved and hopefully they should capture all expected errors in these latest test suites in OpenJDK16.

@ChengJin01
Copy link

ChengJin01 commented Dec 1, 2020

The code is pretty much ready at ChengJin01@b49212b.
Will wait for the update of jtreg test suite specific to sealed class in JDK16.

@pshipton
Copy link
Member Author

pshipton commented Dec 8, 2020

fyi #11405

@ChengJin01
Copy link

As for #11405, there is probably no change from VM perspective given it only mentioned about the compiler (javac). Will wait & see how it goes in the latest jtreg test suites.

@pshipton
Copy link
Member Author

pshipton commented Jan 5, 2021

Note that Class.permittedSubclasses() was renamed to getPermittedSubclasses().

http://cr.openjdk.java.net/~iris/se/16/build/latest/diffsFrom15%2b36/java.base/java/lang/Class.html

@tajila
Copy link
Contributor

tajila commented Jan 5, 2021

Note that Class.permittedSubclasses() was renamed to getPermittedSubclasses().

This is tracked in #10977. @mikezhang1234567890 will be looking at it.

@tajila
Copy link
Contributor

tajila commented Feb 2, 2021

We have delivered all items for this feature.

ChengJin01 pushed a commit to ChengJin01/openj9 that referenced this issue Mar 5, 2021
The change is to add more check on the sealed classes
specified in JEP397: Sealed Classes (Second Preview)

Related: eclipse-openj9#11273

Signed-off-by: Cheng Jin <jincheng@ca.ibm.com>
ChengJin01 pushed a commit to ChengJin01/openj9 that referenced this issue Mar 9, 2021
The change is to add more check on the sealed classes
specified in JEP397: Sealed Classes (Second Preview)

Related: eclipse-openj9#11273

Signed-off-by: Cheng Jin <jincheng@ca.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants