RFR: 8312909: C1 should not inline through interface calls with non-subtype receiver

Christian Hagedorn chagedorn at openjdk.org
Thu Aug 3 10:25:32 UTC 2023


On Tue, 25 Jul 2023 12:47:00 GMT, Tobias Hartmann <thartmann at openjdk.org> wrote:

> This is a problem with C1 compiling an interface call with an invalid receiver (see `TestInvokeinterfaceWithBadReceiverHelper`):
> ``` 
>     ldc	String "42";
>     invokeinterface	InterfaceMethod MyInterface.get:"()Ljava/lang/String;",  1;
> 
> 
> `String` does not implement `MyInterface` but Class Hierarchy Analysis determined that there is only one implementor of MyInterface:
> 
> class MyClass implements MyInterface {
>     @Stable
>     String field = "42";
> 
>     public String get() {
>         return field;
>     }    
> }
> 
> C1 emits a receiver subtype check (that will obviously fail at runtime and trigger an `IncompatibleClassChangeError`) and proceeds with inlining the `MyClass::get` method on the `String` receiver. It then tries to fold a stable field load by loading it's value at compile time which asserts/fails because the `String` receiver does not have such a field. The fix is to bail out from inlining when we can statically determine that the receiver subtype check will always fail at runtime.
> 
> Thanks,
> Tobias

Looks good!

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

Marked as reviewed by chagedorn (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/15018#pullrequestreview-1560774657


More information about the hotspot-compiler-dev mailing list