Skip to content

Commit ef45d4d

Browse files
committed
Avoid loop throgh side_exit from the first trace instruction.
1 parent 5d9063a commit ef45d4d

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4895,6 +4895,7 @@ int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registers_buf
48954895
{
48964896
uint32_t trace_num = (uint32_t)(uintptr_t)EG(reserved)[zend_func_info_rid];
48974897
zend_execute_data *execute_data = EG(current_execute_data);
4898+
const zend_op *orig_opline = EX(opline);
48984899
const zend_op *opline;
48994900
zend_jit_trace_info *t = &zend_jit_traces[trace_num];
49004901

@@ -4922,7 +4923,7 @@ int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registers_buf
49224923
}
49234924

49244925
if (EG(vm_interrupt)) {
4925-
return 0;
4926+
return 1;
49264927
/* Lock-free check if the side trace was already JIT-ed or blacklist-ed in another process */
49274928
} else if (t->exit_info[exit_num].flags & (ZEND_JIT_EXIT_JITED|ZEND_JIT_EXIT_BLACKLISTED)) {
49284929
return 0;
@@ -4949,12 +4950,14 @@ int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registers_buf
49494950
fprintf(stderr, "---- EXIT %d/%d blacklisted\n",
49504951
trace_num, exit_num);
49514952
}
4953+
return 0;
49524954
}
49534955
} else if (zend_jit_trace_exit_is_hot(trace_num, exit_num)) {
49544956
return zend_jit_trace_hot_side(execute_data, trace_num, exit_num);
49554957
}
49564958

4957-
return 0;
4959+
/* Return 1 to call original handler instead of the same JIT-ed trace */
4960+
return (orig_opline == t->opline && EX(opline) == orig_opline);
49584961
}
49594962

49604963
static zend_always_inline uint8_t zend_jit_trace_supported(const zend_op *opline)

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,28 +2383,17 @@ static int zend_jit_trace_exit_stub(dasm_State **Dst)
23832383
| add r4, 8*4+8*8 /* CPU regs + SSE regs */
23842384
|.endif
23852385

2386-
| // check for interrupt (try to avoid this ???)
2387-
| MEM_OP2_1_ZTS cmp, byte, executor_globals, vm_interrupt, 0, r0
2388-
| jne ->interrupt_handler
2386+
| test eax, eax
2387+
| jne >1
23892388

23902389
| // execute_data = EG(current_execute_data)
23912390
| MEM_OP2_2_ZTS mov, FP, aword, executor_globals, current_execute_data, r0
2392-
| test eax, eax
2393-
| jl ->trace_halt
23942391
| // opline = EX(opline)
23952392
| LOAD_OPLINE
23962393

23972394
if (zend_jit_vm_kind == ZEND_VM_KIND_HYBRID) {
2398-
#if 1
2399-
//TODO: this doesn't work for exit from first instruction ???
24002395
| add r4, HYBRID_SPAD
24012396
| JMP_IP
2402-
#else
2403-
| mov r0, EX->func
2404-
| mov r1, aword [r0 + offsetof(zend_op_array, reserved[zend_func_info_rid])]
2405-
| mov r1, aword [r1 + offsetof(zend_jit_op_array_trace_extension, offset)]
2406-
| jmp aword [IP + r1]
2407-
#endif
24082397
} else if (GCC_GLOBAL_REGS) {
24092398
| add r4, SPAD // stack alignment
24102399
| JMP_IP
@@ -2416,6 +2405,44 @@ static int zend_jit_trace_exit_stub(dasm_State **Dst)
24162405
| ret
24172406
}
24182407

2408+
|1:
2409+
| jl ->trace_halt
2410+
2411+
| // execute_data = EG(current_execute_data)
2412+
| MEM_OP2_2_ZTS mov, FP, aword, executor_globals, current_execute_data, r0
2413+
| // opline = EX(opline)
2414+
| LOAD_OPLINE
2415+
2416+
| // check for interrupt (try to avoid this ???)
2417+
| MEM_OP2_1_ZTS cmp, byte, executor_globals, vm_interrupt, 0, r0
2418+
| jne ->interrupt_handler
2419+
2420+
if (zend_jit_vm_kind == ZEND_VM_KIND_HYBRID) {
2421+
| add r4, HYBRID_SPAD
2422+
| mov r0, EX->func
2423+
| mov r0, aword [r0 + offsetof(zend_op_array, reserved[zend_func_info_rid])]
2424+
| mov r0, aword [r0 + offsetof(zend_jit_op_array_trace_extension, offset)]
2425+
| jmp aword [IP + r0]
2426+
} else if (GCC_GLOBAL_REGS) {
2427+
| add r4, SPAD // stack alignment
2428+
| mov r0, EX->func
2429+
| mov r0, aword [r0 + offsetof(zend_op_array, reserved[zend_func_info_rid])]
2430+
| mov r0, aword [r0 + offsetof(zend_jit_op_array_trace_extension, offset)]
2431+
| jmp aword [IP + r0]
2432+
} else {
2433+
| mov IP, aword EX->opline
2434+
| mov FCARG1a, FP
2435+
| mov r0, EX->func
2436+
| mov r0, aword [r0 + offsetof(zend_op_array, reserved[zend_func_info_rid])]
2437+
| mov r0, aword [r0 + offsetof(zend_jit_op_array_trace_extension, offset)]
2438+
| call aword [IP + r0]
2439+
| mov FP, aword T2 // restore FP
2440+
| mov RX, aword T3 // restore IP
2441+
| add r4, NR_SPAD // stack alignment
2442+
| mov r0, 1 // ZEND_VM_ENTER
2443+
| ret
2444+
}
2445+
24192446
return 1;
24202447
}
24212448

0 commit comments

Comments
 (0)