Comment on "Revisiting default values"
Raffaello Giulietti
raffaello.giulietti at gmail.com
Mon Mar 29 20:55:05 UTC 2021
Hello,
IMO the "zero means null" proposal in [1] for instances implementing
NoGoodDefault is the most consistent with the usual way of thinking Java.
Here's a possible way to slightly lower the cost of the check against
the default (the "zero").
Of course, a default-hostile class always has proper instances in which
at least one field (not necessarily the same in all instances) is "nonzero".
Oftentimes, by design, a class mandates some specific field to be
"nonzero" in every instance. For example, the month (or the day) in
LocalDate should not be zero; name or type in DirectMethodHandleDescImpl
must be non-null; e0 in List12 must not be null; etc.
In such cases, once migrated to NoGoodDefault primitive classes, it
suffices to check any of these fields for "zero" to witness the default
value. That is, if such a field is "zero" then the instance is
necessarily the unacceptable default. There's no need to compare all
bits against "zero".
If the user could annotate such fields with something like @NonDefault
or @DefaultWitness, the vm could possibly perform better in some
circumstances, particularly on "fat" instances.
Greetings
Raffaello
----
[1]
https://mail.openjdk.java.net/pipermail/valhalla-spec-experts/2021-March/001486.html
More information about the valhalla-spec-comments
mailing list