RFR: 8285487: Do not generate trampolines for runtime calls if they are not needed [v2]

Vladimir Kozlov kvn at openjdk.java.net
Thu Apr 28 22:20:02 UTC 2022


On Thu, 28 Apr 2022 19:58:38 GMT, Evgeny Astigeevich <duke at openjdk.java.net> wrote:

>> src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp line 407:
>> 
>>> 405:     // Once they are generated neither a caller nor a callee address cannot be changed.
>>> 406:     // Check whether a far branch is needed to reach the target.
>>> 407:     return target_needs_far_branch(entry.target());
>> 
>> From what I understand `target_needs_far_branch()` works only for stubs which are inside CodeCache.
>> `runtime` method, as you correctly pointed, is code in VM which can be in any distance from CodeCache.
>> For example, it will give incorrect answer if CodeCache size is small:
>> https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp#L391
>> 
>> Or I am confused by the name of this method `target_needs_trampoline` and the comment.
>> Do you actually mean `need_far_branch_for_trampoline`?
>
>> runtime method, as you correctly pointed, is code in VM which can be in any distance from CodeCache.
> 
> Good catch. The function works with assumptions of `MacroAssembler::trampoline_call`. 
> `MacroAssembler::trampoline_call` implicitly assumes the target is inside `CodeCache`:
> 
> // Maybe emit a call via a trampoline.  If the code cache is small
> // trampolines won't be emitted.
> 
> I'll move the code of `target_needs_trampoline` inside of `MacroAssembler::trampoline_call`.
> I'll also add an assert checking the target address is inside `CodeCache`.

I suggest to put somewhere description where `far` calls and `trampoline` should/can be used.

Looking on `MacroAssembler::far_call()` and based on the assert there it targets only entries inside CodeCache. Which is strange because if `runtime` entry inside the 2gb range from any place in CodeCache you can use it. We have such check for x86: https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/x86/assembler_x86.cpp#L11701
And you don't need trampoline if you can use `far` call to such `runtime` entry.

If you need trampoline there is also choice how you call/jump to **it**. Trampoline code is inside CodeCache and `target_needs_far_branch()` works to find type of instruction to reach *trampoline*.  That is what I though  your changes are doing.

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

PR: https://git.openjdk.java.net/jdk/pull/8403


More information about the hotspot-dev mailing list