[php-src] PR #18408: JIT: Snapshotted poly_func / poly_this may be spilled
| From: | arnaud-lb | Date: | Wed, 23 Apr 2025 16:23:58 +0000 |
| Subject: | [php-src] PR #18408: JIT: Snapshotted poly_func / poly_this may be spilled | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-31499@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/18408
Author: arnaud-lb
Polymorphic calls pass
this and the function to side traces via snapshotting. However,
we assume that this/func are in registers, when in fact they may be
spilled.
zend_jit_trace_exit_info.{poly_func_ref,poly_this_ref} are set by
zend_jit_init_method_call(): https://github.com/php/php-src/blob/2bba3dc3b55c54f8c133836cc536fbd13ee3cc8c/ext/opcache/jit/zend_jit_ir.c#L9140-L9141
Then, after compilation, zend_jit_trace_exit_info.{poly_func_reg,poly_this_reg} are set
by zend_jit_snapshot_handler() from register numbers provided by the snapshot
mechanism: https://github.com/php/php-src/blob/2bba3dc3b55c54f8c133836cc536fbd13ee3cc8c/ext/opcache/jit/zend_jit_ir.c#L735-L736
However, these registers may be spilled.
This is properly handled for stack variables, but the code is specialized for stack variables /
zvals.
Here I update snapshotting of poly_func/poly_this to support spilling:
- In zend_jit_snapshot_handler, store the C stack offset of the spilled register in
poly_func_ref/poly_this_ref, in a way similar to how stack variables are handled here: https://github.com/php/php-src/blob/2bba3dc3b55c54f8c133836cc536fbd13ee3cc8c/ext/opcache/jit/zend_jit_ir.c#L775
- In zend_jit_start, do not pre-load the registers if they were spilled
- In zend_jit_trace_exit / zend_jit_trace_deoptimization, load from the
stack if the register was spilled
- Store a reference to poly_func/poly_this in zend_jit_ctx so we can use that directly
in the side trace
Note:
- I'm targeting 8.4 as a bugfix, but I don't mind targetting master