RFR: 8267807: C2: Downcast receiver to target holder during inlining
Vladimir Ivanov
vlivanov at openjdk.java.net
Thu Jun 3 09:04:43 UTC 2021
On Thu, 3 Jun 2021 08:46:38 GMT, Vladimir Ivanov <vlivanov at openjdk.org> wrote:
>> Anyway, as a defense in depth measure, we could still insert receiver subtype check when CHA returns a default method and hope that the check will go away once the type system better tracks interface types. Though the subtype check against an interface can be quite expensive, I don't expect any performance regressions considering CHA hasn't optimized default methods before.
>
> Evidently, it's not the whole story :-) Otherwise, we wouldn't have needed downcasts at all.
>
> It becomes more interesting when CHA discovers unique concrete method under `REFC`:
>
> 3a. `invokevirtual C.m RECV => J.m ABSTRACT, unique = K.m DEFAULT, K <: J` (`I.m` - resolved method, `REFC = C`)
> 3b. `invokeinterface I.m RECV => J.m ABSTRACT, unique = K.m DEFAULT, K <: J` (`I.m` - resolved method, `REFC = I`)
>
> (Moreover, 3b is equivalent to 3a since `actual_receiver` has to be a class and
> not an interface. Otherwise, CHA fails fast. There's additional case - unique
> implementor - but it strength-reduces invokeinterface to invokevirtual.)
>
> It is guaranteed that `RECV <: C <: J` and `RECV <: I < J`, but there's nothing except the CHA itself that
> proves `RECV <: J` always holds.
>
> In 3a and 3b case, CHA iterates all the subtypes under statically known receiver type
> (`actual_receiver`, subtype of `I`/`C`). Assuming the analysis is correct, it proves
> that `RECV <: J`.
As a summary: if we feel safer when there's a dynamic receiver subtype check always present, it could be added.
We would pay with performance (the check can become quite costly in some corner cases), but it shouldn't introduce performance regressions (compared to previous releases): CHA didn't return default methods before and interface call involves implicit receiver type check.
(Need to be cautious not to replace a type profile-guided monomorphic case with a statically determined target interface method + interface subtype check. So, additional complexity in implementation as well.)
-------------
PR: https://git.openjdk.java.net/jdk/pull/4212
More information about the hotspot-compiler-dev
mailing list