Extended project meetings, 2021-03-23 & 2021-03-24
daniel.smith at oracle.com
Fri Mar 26 17:12:05 UTC 2021
On Mar 23, 2021, at 3:35 PM, Dan Smith <daniel.smith at oracle.com<mailto:daniel.smith at oracle.com>> wrote:
I'll post a short summary here when we're done.
So I thought we had useful set of presentations/discussions to encourage progress on the generics piece of Valhalla's efforts. For those who participated, please keep the momentum going by, e.g., raising questions and providing feedback in this mailing list.
For those who didn't attend, a quick overview (to be supplemented by a deeper treatment to come in JEPs and other design documents):
- The core primitive objects work in Valhalla (covered by now-candidate JEPs 401 and 402) has a significant limitation, in that Java's generics are designed to work only with reference types, erased to their bounds (e.g., Object). So generic APIs miss out on the flattening and memory efficiency benefits offered to value types in other contexts.
- We propose to address this in two stages: first, a "Universal Generics" language change that allows value types as type arguments, but continues to implement generics via erasure; and second, a "Parametric JVM" feature that Java can take advantage of to specialize classes for different value type argument layouts.
- Universal Generics will allow for compatible migration of existing generic code by introducing new warnings when developers assign nulls to type variables, and new language features to opt in to nulls in appropriate circumstances. "Null pollution" of value types will be detected at use sites.
- With the Parametric JVM, the language won't change (much), but the underlying behavior will rely on specialized classes and methods to improve performance, along with new, more eager checks to detect some forms of heap pollution. Each instance of a generic class will be associated with a specific *species* of that class.
- At the JVM level, the Parametric JVM allows for the creation of parameterized classes and methods, with parameters "passed" via the constant pool. Classes correspond to families of species, each of which has a unique parameter value and its own subset of the constant pool derived from that value. Parameterized methods have similar families of specialized methods.
- Class, method, and field references at use sites can be associated with parameters from the constant pool; these parameterized references are resolved to species and specialized methods via a handshake between the JVM and the language runtime.
- Constraints on field and method types of species are expressed with *type restrictions* derived from species parameters. These types are independent of descriptors but supplement them with additional run-time checks on passed values. The JIT is able to track type restrictions and eliminate redundant checks. Type restrictions express value and species types, allowing for flattened layout.
- Prototyping work on the Parametric JVM is occurring in the Valhalla GitHub repo, https://github.com/openjdk/valhalla, in the 'species' and 'type-restrictions' branches.
More information about the valhalla-spec-observers