Two posts on OpenJDK mailing lists today summarize the status of Project Valhalla and Project Amber's Records.
Valhalla
Brian Goetz begins his post "Valhalla -- finding the primitives" with this sentence, "I think its worth reflecting on how far we've come in Valhalla, both for the specific designs in the VM and language, and the clarity of the basic concepts." This post contains a brief history of the major design models that have been employed with Valhalla to this point and talks about the advantages and disadvantages of each of these models.
About "Q World," Goetz writes (I've added the emphasis), "The idea was that we would declare a class as either a value class or a 'regular' class, and we would derive various properties based on that." Goetz outlines these properties:
Q-World: Differentiating Properties of Regular Versus Value Classes | ||
---|---|---|
Property | Regular Classes | Value Classes |
Identity? | Yes | No |
Nullable? | Yes | No |
Reference types? | Yes | No |
Goetz explains that "there were many aspects which were either confusing or unsatisfying" (he provides several examples of these) about the "Q World" approach and that the approach lacked a "clean story for migration."
Goetz describes "conflating" certain "distinctions" when working with "L World":
- "nullable vs non-nullable"
- "pass-by-reference vs pass-by-value / flattened"
- "reference type vs value type"
- "identity-ful vs identity-free"
Goetz discusses how the current state of Valhalla builds on lessons learned from the "Q World" and "L World" stages. He writes:
The primitive that Valhalla introduces into class declaration is whether the instances of the class have identity or not. Traditional classes are now revealed to be "identity classes"; the new kind (identity-free) are called "inline classes". (This might not be the final word on the subject.)
Another lesson learned in Valhalla efforts is summarized:
A big AHA of the recent iterations is that it makes sense to talk about both values of inline classes and references to those values. Reference type has (almost) nothing to do with inline vs identity -- it has to do with whether the value set of the type contains values, or references.
Based on these summarized observations, Goetz writes about the "ref/val notation for the types":
"Inline" is a way of saying "identity free" when declaring classes, but it doesn't say anything (yet) about the semantics of how we represent variables on the heap or pass them on the stack. For this, we need an additional property of the type, and ref vs val seems to ideally describe what we mean."
Amber Records
In the post "[records] Summary so far," Gavin Bierman writes about "some remaining design decisions concerning records." This post outlines the following questions/design decisions and then provides partial or complete answers to the design decisions (see the post for the additional details related to each design decision).
- Q1. Should the distinguished supertype of records java.lang.Record be renamed?
- Q2. Accessibility of mandated members.
- Q3. Nesting.
- Q4. Abstract records.
- Q5. Deconstruction patterns.
- Q6.
@deprecated
- Q7.
.equals
and.toString
are slow. - Q8. Translation strategy.
- Q9. Hashing.
- Q10. Special annotation for explicit declaration of accessors.
- Q11. Changing the spec of
.toString
method - Q12. Transactional methods
- Q13. Factory methods instead of constructors.
Although Records are available as a preview feature in JDK 14, it's obvious much work is still being done on them. This preview status provides an opportunity for Records to be used and tested to gain feedback that can change how they are implemented. The thirteen design decisions listed above (some of which are decidedly no change and some which are possible changes) demonstrate that Records are still going to be fine-tuned.