RFR: 8373633: C2: Use interface receiver type to improve CHA decisions [v2]

Quan Anh Mai qamai at openjdk.org
Fri Jan 30 02:11:40 UTC 2026


On Fri, 30 Jan 2026 02:05:57 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:

>> What makes it more complicated is the requirement to return a subtype of declared interface. `_interfaces` contain a closure of a set of interfaces. A dependency on an unrelated interface (in the context of the call site) is not enough to ensure correctness of interface->virtual strength reduction.
>
> Can you use `ciInstanceKlass::unique_implementor` during the creation of the `TypeInstPtr`, will this work?
> 
>     diff --git a/src/hotspot/share/opto/type.cpp b/src/hotspot/share/opto/type.cpp
>     index eb825b81a93..7e395fca743 100644
>     --- a/src/hotspot/share/opto/type.cpp
>     +++ b/src/hotspot/share/opto/type.cpp
>     @@ -3702,6 +3702,13 @@ const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_
>                deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
>                klass = ik = sub;
>                klass_is_exact = sub->is_final();
>     +        } else if (ik->is_interface() && interface_handling == trust_interfaces) {
>     +          sub = ik->unique_implementor();
>     +          if (sub != nullptr) {
>     +            deps->assert_unique_implementor(ik, sub);
>     +            klass = ik = sub;
>     +            klass_is_exact = sub->is_final();
>     +          }
>              }
>            }
>            if (!klass_is_exact && try_for_exact && deps != nullptr &&

I would imagine it has this effect:

    interface I1 {}

    interface I2 {
        int get();
    }

    class K1 implements I1, I2 {}
    class K2 implements I2 {}

    Object v;
    I1 i = (I1) v;   --> Then it can be inferred that i is an instance of type K1
    int x = i.I2::get();   --> There is no need to do devirtualization here

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28811#discussion_r2744312726


More information about the hotspot-compiler-dev mailing list