Skip to content

Commit dc7a0fb

Browse files
committed
Allow tracing JIT generate code when function exits from VM (e.g. for magic __get/__set)
1 parent 7562679 commit dc7a0fb

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

ext/opcache/jit/zend_jit_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ int ZEND_FASTCALL zend_jit_check_constant(const zval *key);
142142
_(RECURSIVE_CALL, "recursive call") \
143143
_(RECURSIVE_RET, "recursive return") \
144144
_(RETURN, "return") \
145+
_(RETURN_HALT, "return from interpreter") \
145146
_(LINK, "link to another trace") \
146147
/* compilation and linking successful */ \
147148
_(COMPILED, "compiled") \

ext/opcache/jit/zend_jit_trace.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4110,7 +4110,8 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
41104110
}
41114111
t->link = zend_jit_find_trace(p->opline->handler);
41124112
zend_jit_trace_link_to_root(&dasm_state, &zend_jit_traces[t->link]);
4113-
} else if (p->stop == ZEND_JIT_TRACE_STOP_RETURN) {
4113+
} else if (p->stop == ZEND_JIT_TRACE_STOP_RETURN
4114+
|| p->stop == ZEND_JIT_TRACE_STOP_RETURN_HALT) {
41144115
zend_jit_trace_return(&dasm_state, 0);
41154116
} else {
41164117
// TODO: not implemented ???
@@ -4659,6 +4660,7 @@ int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const
46594660
{
46604661
const zend_op *orig_opline;
46614662
zend_jit_trace_stop stop;
4663+
int ret = 0;
46624664
zend_op_array *op_array;
46634665
zend_jit_op_array_trace_extension *jit_extension;
46644666
size_t offset;
@@ -4706,6 +4708,9 @@ int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const
47064708
}
47074709

47084710
if (ZEND_JIT_TRACE_STOP_OK(stop)) {
4711+
if (stop == ZEND_JIT_TRACE_STOP_RETURN_HALT) {
4712+
ret = -1;
4713+
}
47094714
if (JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_STOP) {
47104715
if (stop == ZEND_JIT_TRACE_STOP_LINK) {
47114716
uint32_t idx = trace_buffer[1].last;
@@ -4730,6 +4735,9 @@ int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const
47304735
goto abort;
47314736
}
47324737
} else {
4738+
if (stop == ZEND_JIT_TRACE_STOP_HALT) {
4739+
ret = -1;
4740+
}
47334741
abort:
47344742
if (JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_ABORT) {
47354743
fprintf(stderr, "---- TRACE %d abort (%s)\n",
@@ -4755,7 +4763,7 @@ int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const
47554763
fprintf(stderr, "\n");
47564764
}
47574765

4758-
return (stop == ZEND_JIT_TRACE_STOP_HALT) ? -1 : 0;
4766+
return ret;
47594767
}
47604768

47614769
static void zend_jit_blacklist_trace_exit(uint32_t trace_num, uint32_t exit_num)
@@ -4929,6 +4937,7 @@ static zend_jit_trace_stop zend_jit_compile_side_trace(zend_jit_trace_rec *trace
49294937
int ZEND_FASTCALL zend_jit_trace_hot_side(zend_execute_data *execute_data, uint32_t parent_num, uint32_t exit_num)
49304938
{
49314939
zend_jit_trace_stop stop;
4940+
int ret = 0;
49324941
uint32_t trace_num;
49334942
zend_jit_trace_rec trace_buffer[ZEND_JIT_TRACE_MAX_LENGTH];
49344943

@@ -4965,6 +4974,9 @@ int ZEND_FASTCALL zend_jit_trace_hot_side(zend_execute_data *execute_data, uint3
49654974
}
49664975

49674976
if (ZEND_JIT_TRACE_STOP_OK(stop)) {
4977+
if (stop == ZEND_JIT_TRACE_STOP_RETURN_HALT) {
4978+
ret = -1;
4979+
}
49684980
if (JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_STOP) {
49694981
if (stop == ZEND_JIT_TRACE_STOP_LINK) {
49704982
uint32_t idx = trace_buffer[1].last;
@@ -4998,6 +5010,9 @@ int ZEND_FASTCALL zend_jit_trace_hot_side(zend_execute_data *execute_data, uint3
49985010
goto abort;
49995011
}
50005012
} else {
5013+
if (stop == ZEND_JIT_TRACE_STOP_HALT) {
5014+
ret = -1;
5015+
}
50015016
abort:
50025017
if (JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_ABORT) {
50035018
fprintf(stderr, "---- TRACE %d abort (%s)\n",
@@ -5018,7 +5033,7 @@ int ZEND_FASTCALL zend_jit_trace_hot_side(zend_execute_data *execute_data, uint3
50185033
fprintf(stderr, "\n");
50195034
}
50205035

5021-
return (stop == ZEND_JIT_TRACE_STOP_HALT) ? -1 : 0;
5036+
return ret;
50225037
}
50235038

50245039
int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registers_buf *regs)

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,15 +682,15 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
682682
#ifdef HAVE_GCC_GLOBAL_REGS
683683
handler();
684684
if (UNEXPECTED(opline == zend_jit_halt_op)) {
685-
stop = ZEND_JIT_TRACE_STOP_HALT;
685+
stop = ZEND_JIT_TRACE_STOP_RETURN_HALT;
686686
break;
687687
}
688688
if (UNEXPECTED(execute_data != prev_execute_data)) {
689689
#else
690690
rc = handler(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
691691
if (rc != 0) {
692692
if (rc < 0) {
693-
stop = ZEND_JIT_TRACE_STOP_HALT;
693+
stop = ZEND_JIT_TRACE_STOP_RETRUN_HALT;
694694
break;
695695
}
696696
execute_data = EG(current_execute_data);

0 commit comments

Comments
 (0)