RFR: 8339299: C1 will miss type profile when inline final method

Vladimir Ivanov vlivanov at openjdk.org
Fri Aug 30 22:26:25 UTC 2024


On Fri, 30 Aug 2024 21:38:33 GMT, Dean Long <dlong at openjdk.org> wrote:

>> I found sometimes C1 will miss type profile and I tried to write a test to demonstrate it.
>> It will happen with these conditions
>> 1 It's a virtual call and the callee is a final method. So c1 will think it's static bound.
>> 2 The interpreter never touch the callsite, so interpreter does not add type profile.
>> 3 In c1 compilation, it will be inlined based on CHA.
>> 4 In c2 compilation, the CHA is broken, but type profile is missing, so c2 can not inline it.
>
> src/hotspot/share/c1/c1_LIR.hpp line 2037:
> 
>> 2035:     bool callee_is_static = _profiled_callee->is_loaded() && _profiled_callee->is_static();
>> 2036:     Bytecodes::Code bc = _profiled_method->java_code_at_bci(_profiled_bci);
>> 2037:     bool call_is_virtual = (bc == Bytecodes::_invokevirtual && (UseCHA || !_profiled_callee->can_be_statically_bound())) || bc == Bytecodes::_invokeinterface;
> 
> UseCHA is on by default, so this effectively always turns on profiling.  I think it would be better if we set a flag that says if CHA was used or not.

IMO a better option is to simply drop `can_be_statically_bound()` check here. As this bug demonstrates, selected method at call site (represented by `_profiled_callee`) is not an accurate representation of call site behavior.

Instead, to keep things simple, a check for private methods (which don't participate in virtual dispatch) can be introduced.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20786#discussion_r1739466411


More information about the hotspot-compiler-dev mailing list