Summary
-------
Introduce a PermittedSubclasses attribute in the class file format, so that the JVM can implement the sub-classing semantics of sealed classes.
Problem
-------
Sealed classes ([JEP 360][1]) are a preview feature of Java SE 15. The JVM will need to enforce the sub-classing semantics of sealed classes.
Solution
--------
A PermittedSubclasses attribute will be defined in the ClassFile format, containing information about which classes can extend or implement the class or interface containing the attribute. The JVM will use the attribute's contents to ensure that only those classes and interfaces named in the PermittedSubclasses attribute can extend or implement that class. Additionally, the extending (or implementing) class must have the same class loader and be in the same module as its sealed super class.
The format of the PermittedSubclasses attribute is checked even if no classes or interfaces are loaded that extend or implement the class. The checking is done at class load time, and is similar to format checking of attributes such as NestMembers. For example, the JVM checks that the attribute's constant pool indexes are valid and that the PermittedSubclasses attribute occurs at most once per-class.
Note that the PermittedSubclasses attribute could potentially be useful in other ways, for example, in determining if a class or interface is a sealed class.
Specification
-------------
Java Virtual Machine Spec changes for the PermittedSubclasses attribute are attached. Please note that JVM Spec section 5.3 is still under review by the expert group, and may change.
[1]: https://bugs.openjdk.java.net/browse/JDK-8227043