[constant-folding] More indy experiments
maurizio.cimadamore at oracle.com
Thu May 11 09:47:02 UTC 2017
On 11/05/17 05:41, Tagir Valeev wrote:
> Hello, Maurizio!
> Thank you for your answers!
> As for (2) - the extra boxing you are observing is caused by the
> fact that Intrinsic.invokedynamic is not (yet) a polymorphic
> signature method (note that the polysig annotation is mentioned in
> the JEP). When it will be, boxing will disappear. But I think that
> if we go down the polysig path, then an explicit cast for the
> return type would be necessary (as it is for i.e.
> I'm not aware about concrete implementation details in javac, but from
> an outsider point of view it should be doable. For normal generic
> return value javac is capable to automatically insert proper checkcast
> bytecode after call. The same type exactly should be used as
> MethodType return type for polysig invokedynamic if explicit cast is
Doable yes - but note that it would require a spec change - as per JDK
8, the declaration of a polysignature method is only allowed to return
Object. If there's no cast, Object is the return type you get (unless
you are in a statement expression, in which case you get void), so to
get any other return type you need to insert a cast expression, which
will be interpreted by javac as a signal that you want to change the
return type of the underlying MethodType CP entry associated with the
polysig call. This is the status quo; I believe the idea of using return
type inference floated around at the time JDK 7 was developed, and I
think that one of the concerns in making return type inference more
magic was that if the return type is inferred as in a generic method
call, then there's a chance that your underlying signature might not be
stable in the face of subtle changes to the inference algorithm.
Note also that JEP 193 (VarHandles)  updated the rules for
polymorphic signature methods, allowing non-polymorphic return types
into the mix, which might also play a factor here.
> With best regards,
> Tagir Valeev.
More information about the amber-dev