Simplifying reified generics with partial specialization

Ron Pressler ron at
Mon Jan 5 12:10:18 UTC 2015

Hi. I've been following the discussion here, and I think there's a simple
solution that will satisfy everyone: let us enjoy the performance gains of
specialization, maintain full backwards compatibility, keep the generic
class hierarchy simple and intuitive, and remove the need for layers. The
cost would be relying on JVM optimizations for full performance (which is,
I think, what Java has always done).

The idea is simple: a generic instantiation over a value type would
specialize fields (and array fields, obviously) and local variables, but
not arguments and return values of non-private methods. These would use the
value type's (or primitive's) boxed counterpart and will be erased (or not
-- depending on how reference erasure will be done under Valhalla).

This would mean that ArrayList<int> will implement List<Integer> (and will
therefore extend List and List<?>) and Object will essentially be the Any
type (and List<int>, if allowed, would just be an alias for List<Integer>).
It would also mean that we automatically get the performance benefits
associated with the flattened arrays used to store the ArrayList's data.
However, for full performance, it would rely on JVM employing escape
analysis (or even a simpler optimization) to elide boxing.

More advanced forms of specialization (such as those made possible by
layers) would be possible, but not by using direct Java syntax, but by
employing a library like ASM, but this is a topic for a separate discussion
(Brian implied that classdynamic is intended to be trigger custom
generation anyway).


More information about the valhalla-dev mailing list