hg: valhalla/valhalla/langtools: Add support for tracking 'any'-related opcodes

John Rose john.r.rose at oracle.com
Thu Jul 24 20:33:48 UTC 2014

On Jul 24, 2014, at 6:21 AM, Maurizio Cimadamore <maurizio.cimadamore at oracle.com> wrote:

> In other words, I don't believe equals() will ever be generated - i.e. the compiler will always use if_acmpeq and the likes, which will be tagged, eventually, in the bytecode.

For value types (according to the current "Infant Edition") we will be implementing a strong correspondence between the methods of a value type and the methods of its box type:

> The automatically created box class will properly implement the interface,
> bridging to the given `compareTo` method.  A `vinvoke` instruction can also
> directly invoke the `compareTo` method as written.

I think it would be reasonable and useful to extend this correspondence to all of 'any' (and 'any & Comparable' etc).

We can do this by fiat, saying that if a primitive (at least, a primitive type argument in a specialization instance) gets a method invocation against it, that invocation is performed on a boxed version of the primitive.

Allowing .equals and .compareTo on 'any' will allow us to build container types (List, TreeMap) with 'any' keys.

For now the designated box for a primitive (e.g., int) can be a wrapper (java.lang.Integer).  In the real system, we have discussed building new box types for this purpose (java.lang.'int', etc.).  (...Waving target type magic at it, of course, to dispel compatibility bogies.)

— John

More information about the valhalla-dev mailing list