-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix GH-21267: JIT infinite loop on FETCH_OBJ_R with IS_UNDEF property #21368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dstogov
merged 1 commit into
php:PHP-8.4
from
iliaal:fix/gh-21267-jit-fetch-obj-undef-loop
Mar 16, 2026
+87
−3
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix GH-21267: JIT infinite loop on FETCH_OBJ_R with IS_UNDEF property
When the JIT defers the IS_UNDEF check for FETCH_OBJ_R to the result type guard, the deoptimization escape path dispatches to opline->handler via the trace_escape stub. If opline->handler has been overwritten with JIT code (e.g. a function entry trace), this creates an infinite loop. Fix by dispatching to the original VM handler (orig_handler from the trace extension) instead of going through the trace_escape stub. This avoids the extra IS_UNDEF guard on every property read while correctly handling the rare IS_UNDEF case during deoptimization. Also set current_op_array in zend_jit_trace_exit_to_vm so that the blacklisted exit deoptimizer can resolve orig_handler, covering the case where side trace compilation is exhausted. Closes GH-21368.
- Loading branch information
commit 4cebe12b83ba3d16aec4b5b87af3aa704ed16b58
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| --TEST-- | ||
| GH-21267 (JIT infinite loop on FETCH_OBJ_R with IS_UNDEF property in polymorphic context) | ||
| --INI-- | ||
| opcache.enable=1 | ||
| opcache.enable_cli=1 | ||
| opcache.jit=tracing | ||
| opcache.jit_buffer_size=64M | ||
| opcache.jit_hot_loop=0 | ||
| opcache.jit_hot_func=2 | ||
| opcache.jit_hot_return=0 | ||
| opcache.jit_hot_side_exit=1 | ||
| --FILE-- | ||
| <?php | ||
| class C { | ||
| public $x = true; | ||
| public function __get($name) { return null; } | ||
| public function getX() { return $this->x; } | ||
| } | ||
|
|
||
| $o1 = new C; | ||
| $o2 = new C; | ||
| $o2->x = false; | ||
| $o3 = new C; | ||
| unset($o3->x); | ||
| $a = [$o1, $o2, $o3]; | ||
|
|
||
| for ($i = 0; $i < 8; $i++) { | ||
| $m = $a[$i % 3]; | ||
| $m->getX(); | ||
| $m->getX(); | ||
| } | ||
| ?> | ||
| OK | ||
| --EXPECT-- | ||
| OK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| --TEST-- | ||
| GH-21267 (JIT infinite loop on FETCH_OBJ_R with IS_UNDEF via blacklisted trace exit) | ||
| --INI-- | ||
| opcache.enable=1 | ||
| opcache.enable_cli=1 | ||
| opcache.jit=tracing | ||
| opcache.jit_buffer_size=64M | ||
| opcache.jit_hot_loop=0 | ||
| opcache.jit_hot_func=2 | ||
| opcache.jit_hot_return=0 | ||
| opcache.jit_hot_side_exit=1 | ||
| opcache.jit_max_side_traces=0 | ||
| --FILE-- | ||
| <?php | ||
| class C { | ||
| public $x = true; | ||
| public function __get($name) { return null; } | ||
| public function getX() { return $this->x; } | ||
| } | ||
|
|
||
| $o1 = new C; | ||
| $o2 = new C; | ||
| $o2->x = false; | ||
| $o3 = new C; | ||
| unset($o3->x); | ||
| $a = [$o1, $o2, $o3]; | ||
|
|
||
| for ($i = 0; $i < 8; $i++) { | ||
| $m = $a[$i % 3]; | ||
| $m->getX(); | ||
| $m->getX(); | ||
| } | ||
| ?> | ||
| OK | ||
| --EXPECT-- | ||
| OK |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, my patch didn't handle all VM kinds right.
Anyway, I'm not completely sure if the "else" part of your patch is going to work for all VM kinds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The else branch matches the dispatch pattern used by
zend_jit_trace_exit_stub(line 2527) andzend_jit_trace_return(line 17148) on PHP-8.4:ir_CALL_1(IR_I32, ...)+ir_GUARD+ir_RETURN(ZEND_VM_ENTER). On 8.4, JIT only runs with HYBRID VM kind —GCC_GLOBAL_REGSvs CALL convention covers both paths.For a master forward-port this would need
zend_jit_tailcall_handler/zend_jit_vm_enterto also handleZEND_VM_KIND_TAILCALL.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we can use TAILCALL for the else part.