Skip to content

Commit 7690439

Browse files
committed
Don't load IP when entering inlined function
1 parent 5db44e3 commit 7690439

File tree

2 files changed

+80
-86
lines changed

2 files changed

+80
-86
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,7 +3128,6 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
31283128
} else {
31293129
if (zend_jit_traces[parent_trace].exit_info[exit_num].opline == NULL) {
31303130
zend_jit_trace_opline_guard(&dasm_state, opline);
3131-
zend_jit_set_opline(opline);
31323131
} else {
31333132
zend_jit_reset_opline();
31343133
}
@@ -4759,7 +4758,6 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
47594758

47604759
if ((p+1)->op == ZEND_JIT_TRACE_END) {
47614760
p++;
4762-
zend_jit_set_opline(p->opline);
47634761
break;
47644762
}
47654763
op_array = (zend_op_array*)p->op_array;
@@ -4787,7 +4785,6 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
47874785
}
47884786
}
47894787
}
4790-
zend_jit_set_opline((p+1)->opline);
47914788
} else if (p->op == ZEND_JIT_TRACE_BACK) {
47924789
op_array = (zend_op_array*)p->op_array;
47934790
jit_extension =
@@ -4955,7 +4952,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
49554952
if (p->stop == ZEND_JIT_TRACE_STOP_LOOP
49564953
|| p->stop == ZEND_JIT_TRACE_STOP_RECURSIVE_CALL
49574954
|| p->stop == ZEND_JIT_TRACE_STOP_RECURSIVE_RET) {
4958-
if (p->stop == ZEND_JIT_TRACE_STOP_LOOP) {
4955+
if (p->stop != ZEND_JIT_TRACE_STOP_RECURSIVE_RET) {
49594956
if (!zend_jit_set_valid_ip(&dasm_state, p->opline)) {
49604957
goto jit_failure;
49614958
}

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 79 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2943,20 +2943,6 @@ static int zend_jit_trace_begin(dasm_State **Dst, uint32_t trace_num, zend_jit_t
29432943
return 1;
29442944
}
29452945

2946-
static int zend_jit_trace_opline_guard(dasm_State **Dst, const zend_op *opline)
2947-
{
2948-
uint32_t exit_point = zend_jit_trace_get_exit_point(NULL, 0);
2949-
const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point);
2950-
2951-
if (!exit_addr) {
2952-
return 0;
2953-
}
2954-
| CMP_IP opline
2955-
| jne &exit_addr
2956-
2957-
return 1;
2958-
}
2959-
29602946
/* This taken from LuaJIT. Thanks to Mike Pall. */
29612947
static uint32_t _asm_x86_inslen(const uint8_t* p)
29622948
{
@@ -3496,6 +3482,22 @@ static void zend_jit_stop_reuse_ip(void) {
34963482
reuse_ip = 0;
34973483
}
34983484

3485+
static int zend_jit_trace_opline_guard(dasm_State **Dst, const zend_op *opline)
3486+
{
3487+
uint32_t exit_point = zend_jit_trace_get_exit_point(NULL, 0);
3488+
const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point);
3489+
3490+
if (!exit_addr) {
3491+
return 0;
3492+
}
3493+
| CMP_IP opline
3494+
| jne &exit_addr
3495+
3496+
zend_jit_set_opline(opline);
3497+
3498+
return 1;
3499+
}
3500+
34993501
static int zend_jit_jmp(dasm_State **Dst, unsigned int target_label)
35003502
{
35013503
| jmp =>target_label
@@ -8864,15 +8866,6 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
88648866
| mov aword EX:RX->return_value, 0
88658867
}
88668868

8867-
if (func
8868-
&& !unknown_num_args
8869-
&& call_num_args <= func->op_array.num_args) {
8870-
for (i = call_num_args; i < func->op_array.last_var; i++) {
8871-
uint32_t n = EX_NUM_TO_VAR(i);
8872-
| SET_Z_TYPE_INFO RX + n, IS_UNDEF
8873-
}
8874-
}
8875-
88768869
//EX_LOAD_RUN_TIME_CACHE(op_array);
88778870
if (!func || func->op_array.cache_size) {
88788871
if (func && op_array == &func->op_array) {
@@ -8919,74 +8912,78 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
89198912
| mov FP, RX
89208913

89218914
| // opline = op_array->opcodes;
8922-
if (func
8923-
&& !unknown_num_args
8924-
&& call_num_args <= func->op_array.num_args) {
8925-
uint32_t num_args;
8915+
if (func && !unknown_num_args) {
89268916

8927-
if ((func->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0) {
8928-
if (trace) {
8929-
num_args = 0;
8930-
} else if (call_info) {
8931-
num_args = skip_valid_arguments(op_array, ssa, call_info);
8932-
} else {
8933-
num_args = call_num_args;
8934-
}
8935-
} else {
8936-
num_args = call_num_args;
8917+
for (i = call_num_args; i < func->op_array.last_var; i++) {
8918+
uint32_t n = EX_NUM_TO_VAR(i);
8919+
| SET_Z_TYPE_INFO RX + n, IS_UNDEF
89378920
}
8938-
if (func && zend_accel_in_shm(func->op_array.opcodes)) {
8939-
| LOAD_IP_ADDR (func->op_array.opcodes + num_args)
8940-
} else {
8941-
if (func) {
8942-
| mov r0, EX->func
8943-
}
8944-
if (GCC_GLOBAL_REGS) {
8945-
| mov IP, aword [r0 + offsetof(zend_op_array, opcodes)]
8946-
if (num_args) {
8947-
| add IP, (num_args * sizeof(zend_op))
8921+
8922+
if (call_num_args <= func->op_array.num_args) {
8923+
if (!trace || (trace->op == ZEND_JIT_TRACE_END
8924+
&& trace->stop == ZEND_JIT_TRACE_STOP_INTERPRETER)) {
8925+
uint32_t num_args;
8926+
8927+
if ((func->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0) {
8928+
if (trace) {
8929+
num_args = 0;
8930+
} else if (call_info) {
8931+
num_args = skip_valid_arguments(op_array, ssa, call_info);
8932+
} else {
8933+
num_args = call_num_args;
8934+
}
8935+
} else {
8936+
num_args = call_num_args;
89488937
}
8949-
} else {
8950-
| mov FCARG1a, aword [r0 + offsetof(zend_op_array, opcodes)]
8951-
if (num_args) {
8952-
| add FCARG1a, (num_args * sizeof(zend_op))
8938+
if (zend_accel_in_shm(func->op_array.opcodes)) {
8939+
| LOAD_IP_ADDR (func->op_array.opcodes + num_args)
8940+
} else {
8941+
| mov r0, EX->func
8942+
if (GCC_GLOBAL_REGS) {
8943+
| mov IP, aword [r0 + offsetof(zend_op_array, opcodes)]
8944+
if (num_args) {
8945+
| add IP, (num_args * sizeof(zend_op))
8946+
}
8947+
} else {
8948+
| mov FCARG1a, aword [r0 + offsetof(zend_op_array, opcodes)]
8949+
if (num_args) {
8950+
| add FCARG1a, (num_args * sizeof(zend_op))
8951+
}
8952+
| mov aword EX->opline, FCARG1a
8953+
}
89538954
}
8954-
| mov aword EX->opline, FCARG1a
8955-
}
8956-
}
89578955

8958-
if (!trace && op_array == &func->op_array) {
8959-
/* recursive call */
8956+
if (!trace && op_array == &func->op_array) {
8957+
/* recursive call */
89608958
#ifdef CONTEXT_THREADED_JIT
8961-
| call >1
8962-
|.cold_code
8963-
|1:
8964-
| pop r0
8965-
| jmp =>num_args
8966-
|.code
8959+
| call >1
8960+
|.cold_code
8961+
|1:
8962+
| pop r0
8963+
| jmp =>num_args
8964+
|.code
89678965
#else
8968-
| jmp =>num_args
8966+
| jmp =>num_args
89698967
#endif
8970-
return 1;
8971-
}
8972-
} else if (func
8973-
&& !unknown_num_args
8974-
&& call_num_args > func->op_array.num_args) {
8975-
if (func && zend_accel_in_shm(func->op_array.opcodes)) {
8976-
| LOAD_IP_ADDR (func->op_array.opcodes)
8977-
} else if (GCC_GLOBAL_REGS) {
8978-
| mov IP, aword [r0 + offsetof(zend_op_array, opcodes)]
8968+
return 1;
8969+
}
8970+
}
89798971
} else {
8980-
| mov FCARG1a, aword [r0 + offsetof(zend_op_array, opcodes)]
8981-
| mov aword EX->opline, FCARG1a
8982-
}
8983-
if (!GCC_GLOBAL_REGS) {
8984-
| mov FCARG1a, FP
8985-
}
8986-
| EXT_CALL zend_jit_copy_extra_args_helper, r0
8987-
for (i = call_num_args; i < func->op_array.last_var; i++) {
8988-
uint32_t n = EX_NUM_TO_VAR(i);
8989-
| SET_Z_TYPE_INFO FP + n, IS_UNDEF
8972+
if (!trace || (trace->op == ZEND_JIT_TRACE_END
8973+
&& trace->stop == ZEND_JIT_TRACE_STOP_INTERPRETER)) {
8974+
if (func && zend_accel_in_shm(func->op_array.opcodes)) {
8975+
| LOAD_IP_ADDR (func->op_array.opcodes)
8976+
} else if (GCC_GLOBAL_REGS) {
8977+
| mov IP, aword [r0 + offsetof(zend_op_array, opcodes)]
8978+
} else {
8979+
| mov FCARG1a, aword [r0 + offsetof(zend_op_array, opcodes)]
8980+
| mov aword EX->opline, FCARG1a
8981+
}
8982+
}
8983+
if (!GCC_GLOBAL_REGS) {
8984+
| mov FCARG1a, FP
8985+
}
8986+
| EXT_CALL zend_jit_copy_extra_args_helper, r0
89908987
}
89918988
} else {
89928989
| // opline = op_array->opcodes

0 commit comments

Comments
 (0)