RFR: 8321509: False positive in get_trampoline fast path causes crash [v3]

Evgeny Astigeevich eastigeevich at openjdk.org
Wed Jul 10 20:10:37 UTC 2024


On Wed, 10 Jul 2024 01:42:06 GMT, Dean Long <dlong at openjdk.org> wrote:

>> Dean Long has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   cleanup
>
> So for Leyden it sounds like you need to change `is_always_within_branch_range()`.

Hi @dean-long,
Could you please check if my understanding of the bug is correct?

C2 generates code into CodeBuffer. Some calls have targets always within a branch range. Direct BL instructions are generated for them. Such calls don't have `trampoline_stub_Relocation`. When the current CodeBuffer is not enough we create a bigger CodeBuffer ("expand") and move the current code into it. Whilst moving the code we are patching instructions. Direct BLs use offsets. In some cases after "expanding" CodeBuffer, code at an offset can be a trampoline: `is_NativeCallTrampolineStub_at == true`. This invalidates a call because the fast path in `get_trampoline` is used. The fast path does not iterate over relocations. If a slow path were taken we would have patched the instruction correctly.

My current knowledge of the area:
- In CodeBuffer, trampolined BLs are calling themselves. This means offsets in them are zeros. `CodeBuffer::expand` breaks this because `CallRelocation::fix_relocation_after_move` will finalize call sites.
- Not-trampolined BLs have non-zero offsets in them which point outside of the current CodeBuffer.
- In code moved into the final location direct BLs must have non-zero offsets in them. Offsets within CodeBlob mean trampolined calls. Offsets outside CodeBlob mean non-trampolined calls. 

IMO we should fix `CodeBuffer::expand`. It should go through relocations and fix only those which are not trampolines. 

I don't think `is_always_within_branch_range()` needs any changes. As I wrote its return value is based on static CodeCache information.

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

PR Comment: https://git.openjdk.org/jdk/pull/19796#issuecomment-2220465812


More information about the hotspot-compiler-dev mailing list