[code-reflection] RFR: Invocation to vararg methods

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Sep 10 14:53:28 UTC 2024


On Tue, 10 Sep 2024 01:06:13 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

> Re-consolidate to one invocation operation that explicitly declares its invoke kind and whether it is an invocation to a varargs method.
> 
> Resolution of a method reference accepts an invoke kind. The ambiguity when resolving a method reference without an invoke kind has been cleared up, in these cases we can only resolve to a direct method, one in which the referencing class is the class that declares the method.
> 
> I managed to avoid numerous changes to update the text models in language tests. Creating an invoke operation from external form is permissive in the attributes that are present. It makes the same assumptions as the invoke factory method in determining the invocation kind from the argument count and invoke descriptor count, and assumes the method is not a varargs method (the common case).

src/java.base/share/classes/java/lang/reflect/code/op/CoreOp.java line 1545:

> 1543:         }
> 1544: 
> 1545:         public List<Value> varArgOperands() {

I suspect having the varargs type would also be useful

src/java.base/share/classes/java/lang/reflect/code/op/CoreOp.java line 3789:

> 3787:      */
> 3788:     public static InvokeOp invoke(TypeElement returnType, MethodRef invokeDescriptor, List<Value> args) {
> 3789:         int paramCount = invokeDescriptor.type().parameterTypes().size();

I wonder if, for clients, it would be easier to use a descriptor for the non-varargs part, then specify a TypeElement for the varargs type, and let the API figure out how to wield those together. In a way the fact that "varargs are methods whose last parameter is an array" seems an impl detail?

-------------

PR Review Comment: https://git.openjdk.org/babylon/pull/225#discussion_r1752136485
PR Review Comment: https://git.openjdk.org/babylon/pull/225#discussion_r1752139580


More information about the babylon-dev mailing list