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

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Sep 6 08:06:08 UTC 2024


On Fri, 6 Sep 2024 00:06:39 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> Support super expressions.
>> 
>> The work in the bytecode generator is not complete, and a disabled test has been added. Currently when it encounters an invoke super operation it will throw. We cannot generate invokespecial instructions as this will create invalid bytecode (the calling class is not related to the referenced class). Instead, in a subsequent PR, we need to dynamically generate method handles, pass them as class data to the defined hidden class, so they can be loaded as constants and invoked (and therefore emulating the invokespecial instruction). That subsequent PR should also address the lifting of invokespecial instructions.
>> 
>> This work has shown deficiencies in the modeling of invocation expressions and the resolution of `MethodRef`s. The latter has been partially addressed by providing additional information for resolution, namely the kind of invocation.
>> 
>> Invocation operations do not fully model invocation to vararg methods and this means we cannot reliably determine in all cases if the invocation has a receiver operand or not (a class or instance invocation). This should be fixed in a subsequent PR. The fix might require the following:
>> - explicit modeling of class and instance and invocation; and
>> - modeling var args as a prefix (sublist) of the operand list
>
> Paul Sandoz has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Remove comment.

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ReflectMethods.java line 1023:

> 1021:                 switch (sym.getKind()) {
> 1022:                     case FIELD, ENUM_CONSTANT -> {
> 1023:                         if (sym.name.equals(names._this) || sym.name.equals(names._super)) {

Not sure: don't we need super also for field access? E.g.


class A {
   Object o;
}
class B extends A {
    int o; // shadows A.o
    Object superO() { return super.o; }
}

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

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


More information about the babylon-dev mailing list