RFR: 8267807: C2: Downcast receiver to target holder during inlining
John R Rose
jrose at openjdk.java.net
Tue Jun 1 20:49:14 UTC 2021
On Thu, 27 May 2021 10:40:07 GMT, Vladimir Ivanov <vlivanov at openjdk.org> wrote:
>> src/hotspot/share/opto/doCall.cpp line 1138:
>>
>>> 1136: bool is_interface_holder = cha_monomorphic_target->holder()->is_interface();
>>> 1137: if (has_receiver && !is_interface_holder) {
>>> 1138: if (!cha_monomorphic_target->holder()->is_subtype_of(receiver_type->klass())) {
>>
>> Given we can't trust interface types, shouldn't we test for receiver_type not an interface here?
>
> Though it doesn't happen in practice now, we can trust interface types on the receiver object because virtual/interface method invocation implies proper type check of the receiver.
I think you need a CheckCastPP as the comment (written by me long ago IIRC) suggests.
I’d like to believe you can trust the type of a CHA receiver, but I don’t. What the IR says about interface types is (last time I looked) just as untrustworthy as what the verifier thinks about them.
(We should fix this decisively someday. Or did we do this cleanup already and missed it? We have had dozens of bugs
in early C2 because of untrustworthy interface types.)
Suppose CHA (of default methods, yay!) says that since x is interface Foo, then default Foo::m is the only possible target
of x.m. Before we execute Foo::m we still need a type check of x, because it could be any Object whatsoever.
I suggest adding the CheckCastPP in, in all modes, with fallback to de-opt not VM crash. The IR types are saying there is not a dominating check.
-------------
PR: https://git.openjdk.java.net/jdk/pull/4212
More information about the hotspot-compiler-dev
mailing list