[code-reflection] RFR: Super expressions [v2]

Paul Sandoz psandoz at openjdk.org
Fri Sep 6 17:34:25 UTC 2024


On Fri, 6 Sep 2024 07:56:45 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/reflect/code/type/TypeVarRef.java line 54:
>> 
>>> 52:         TypeVariable<?>[] typeVariables = switch (owner) {
>>> 53:             case MethodRef methodRef -> {
>>> 54:                 // @@@ resolves to class or instance method
>> 
>> ouch :-)
>> The thing here is: to go to a `j.l.r.Method` you don't really need to know the kind, do you? E.g. a method handle is kind-sensitive, but a reflective method is not?
>
> Problem is we're doing the method lookup using the method handle lookup and then cracking open the method handle - perhaps reflective methods should be looked-up in a separate way.

Perhaps it's an implementation detail and does not matter? I was unsure.

Can we presume in this case that a `MethodRef` directly refers to the method? i.e., the method is declared on the referencing class.
    
Resolving a `MethodRef` to a `MethodHandle` naturally retains the referencing type since that is where the invocation occurs. When we reveal the method handle information (crack open) and reflect as a method we potentially loose the referencing type. In this case should we expect the following to hold?


MethodHandle mh = ...;
MethodHandleInfo mhi = MethodHandles.lookup().revealDirect(mh);
Method m = mhireflectAs(Method.class, MethodHandles.lookup()));
assert mhi.getDeclaringClass() == m.getDeclaringClass();
 ```

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

PR Review Comment: https://git.openjdk.org/babylon/pull/221#discussion_r1747486908


More information about the babylon-dev mailing list