Initial feedback on Minimal Value Types 0.2 for discussion
brian.goetz at oracle.com
Tue Mar 28 19:23:44 UTC 2017
> Summary notes from meeting 3/15/17:
> attendees: Brian, Doug Lea, Stas, Frederic, Bjorn, Tobias, Mr Simms,
> Vladimir I, Maurizio, Karen, John
> 1. Identity Major decision:
> Doug: It is ok if a value type box does NOT retain identity.
> Do not be overly concerned with sync, ===, hashcode. Let’s see if
> the benefits outweigh the problems.
> We need to set clear expectations for customers.
> ed. note: Maurizio clarified later that it is critical that a
> value type not lose identity within
> a given method, but it is ok to lose identity across methods.
> It is ok if the vm throws an exception - e.g.
> IllegalMonitorStateException when attempting to lock a Value Type,
> ok if we do that based on a command-line flag to not slow down
> normal execution.
Somehow, this question is like the proverbial elephant -- everyone sees
the answer they want :) What I took away was: there is no need to do
anything special now for identity. Some objects have what we might call
"accidental identity", such as the result of boxing an int to an
Integer, or capturing a lambda. This identity is real -- if we
construct an object with accidential identity, the user can rely on its
stability, synchronize on it, etc (even if we think this is silly.) The
model we should pursue for value boxes is like Integer -- they have
accidental identity, and that's OK.
It would be useful in the long term to have tooling (like an -Xx flag)
that lets us detect how often box types like Integer are synchronized upon.
More generally, rather than trying to smooth the rough edges of identity
(e.g., with heisenboxes, or with identity-resistent boxes), a better
approach is to instead strive for _less boxing_. The exploration of U
types promises to eliminate a category of box operations (by deferring
them in the hopes they are not ultimately needed), and future efforts on
generics over values also dramatically reduces the sources of boxing.
Ultimately, we hope to get boxing down to the truly dynamically typed
APIs -- such as reflection -- at which point accidental identity as a
problem largely goes away.
More information about the valhalla-spec-observers