Looking into Java's Future: Empty Value Types
Have you ever wondered about using Java's value types? Read more here about what Java programmers have to say about the empty value type.
Join the DZone community and get the full member experience.
Join For FreeAlthough the promising Java value types are not imminent, I still enjoy nosing around occasionally in the OpenJDK Valhalla-dev mailing list to see how things are progressing and to get an idea of what is to come. Admittedly, there are some discussions that are beyond my understanding, given my limited exposure to the terms used and the low-level specifics of some messages. However, occasionally, there are messages and threads that I understand and find interesting. A recent example of this is the "Empty value type ?" thread.
Rémi Forax starts the thread by asking "Is empty value type targeted for LW1?" The example error message included with that question shows as a LinkageError and a ClassFormatError with the message "Value Types do not support zero instance size yet." The response to this question from Tobias Hartmann says, "No, empty value types are not planned to be supported for LW1."
Before moving onto the rest of the thread (which is the part that interested me the most), I'll quickly discuss "LW1." In a message on that same OpenJDK mailing list called "[lworld] LW1 - 'Minimal LWorld'," David Simms states, "we are approaching something 'usable' in terms of 'minimal L World' (LW1)" and "we will be moving of prototyping to milestone stabilization." That same message states that the "label" is "lw1." Along with that, the affected-version
and fixed-version
are both "repo-valhalla
". In other words, "LW1" is the label used to track bugs and issues related to work on the "minimal L world" implementation. You can reference John Rose's 19 November 2017 message, "abandon all U-types, welcome to L-world (or, what I learned in Burlington)" for an introduction to the "L World" term and what it means in terms of value types.
Returning to the "Empty value type?" thread, Kirk Pepperdine asked a question that also occurred to me, "How can a value type be empty?" He added, "What is an empty integer? An empty string?" He said he was "just curious" and now I am too. Here is a summary of the informative responses:
- Rémi Forax: "type [that] represents the absence of value like unit, void, or bottom"
- To which John Rose provided this informative link.
- Rémi Forax: "type that represents the result of a throw"
- Rémi Forax: "type that allows
HashSet<E>
to be defined asHashMap<E,Empty>
"- Brian Goetz's message elaborates on the value of this, "Zero-length values can be quite useful, just not directly. Look at the current implementations of Set that delegate to
HashMap
; all that wasted space. When we have specialized generics, they can specialize toHashMap<T, empty>
, and that space gets squeezed away to zero."
- Brian Goetz's message elaborates on the value of this, "Zero-length values can be quite useful, just not directly. Look at the current implementations of Set that delegate to
- Rémi Forax: "transformative type like a marker type that separate arguments" (see the message for example of this one)
I also liked the final (as of this writing) Kirk Pepperdine message on that thread where he summarizes, "Feels like a value type version of null."
Incidentally, there are some other interesting messages and threads in the June 2018 Archives of the Valhalla-dev mailing list. Here are some of them:
- Karen Kinnears posted: "Valhalla VM notes Wed Jun 6."
- I don't understand every detail documented here, but it is interesting to see some of the potential timeframes associated with potential features.
- Rémi Forax posted: "Integer vs IntBox benchmark"
- Demonstrates results for
IntBox
(Forax describes this as "a value type that stores an int") contrasted withint
andInteger
and the results forIntBox
are on par withint
(and significantly better thanInteger
). - A link to the benchmark test on GitHub is also provided.
- Demonstrates results for
- Sergey Kuksenko posted: "Valhalla LWorld microbenchmarks"
- This message does not provide benchmark results but, instead, explains that the "initial set of Valhalla LWorld microbenchmarks" have been placed "in the Valhalla repository under
test/benchmarks
directory." It also explains how to build them.
- This message does not provide benchmark results but, instead, explains that the "initial set of Valhalla LWorld microbenchmarks" have been placed "in the Valhalla repository under
- Mandy Chung posted: "Library support for generating BSM for value type's hashCode/equals/toString"
- Described as the "initial library support to generate BSM for
hashCode
/equals
/toString
for value types" based on John Rose's "Value type hash code." - "BSM" is the "bootstrap method." See the article, "Invokedynamic - Java’s Secret Weapon," for additional details.
- Described as the "initial library support to generate BSM for
- John Rose posted: "Constant pool futures."
I look forward to one day being able to apply value types in my everyday Java code. Until then, it is interesting to think about and also to see how much work is going into making these value types.
Published at DZone with permission of Dustin Marx, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments