Skip to content

Commit

Permalink
Prevent trace recorder reenterancing
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Jul 9, 2020
1 parent b4ae5a2 commit 5fec155
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ext/opcache/jit/zend_jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ typedef struct _zend_jit_globals {

zend_sym_node *symbols; /* symbols for disassembler */

zend_bool tracing;

zend_jit_trace_rec *current_trace;
zend_jit_trace_stack_frame *current_frame;

Expand Down
12 changes: 11 additions & 1 deletion ext/opcache/jit/zend_jit_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -5038,6 +5038,11 @@ int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const
return 0;
}

if (JIT_G(tracing)) {
++(*ZEND_OP_TRACE_INFO(opline, offset)->counter);
return 0;
}

if (JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_START) {
fprintf(stderr, "---- TRACE %d start (%s) %s() %s:%d\n",
trace_num,
Expand All @@ -5053,8 +5058,10 @@ int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const
goto abort;
}

JIT_G(tracing) = 1;
stop = zend_jit_trace_execute(execute_data, opline, trace_buffer,
ZEND_OP_TRACE_INFO(opline, offset)->trace_flags & ZEND_JIT_TRACE_START_MASK, 0);
JIT_G(tracing) = 0;

if (UNEXPECTED(JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_BYTECODE)) {
zend_jit_dump_trace(trace_buffer, NULL);
Expand Down Expand Up @@ -5335,7 +5342,9 @@ int ZEND_FASTCALL zend_jit_trace_hot_side(zend_execute_data *execute_data, uint3
}
}

JIT_G(tracing) = 1;
stop = zend_jit_trace_execute(execute_data, EX(opline), trace_buffer, ZEND_JIT_TRACE_START_SIDE, is_megamorphic);
JIT_G(tracing) = 0;

if (UNEXPECTED(JIT_G(debug) & ZEND_JIT_DEBUG_TRACE_BYTECODE)) {
zend_jit_dump_trace(trace_buffer, NULL);
Expand Down Expand Up @@ -5468,7 +5477,7 @@ int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registers_buf
EX(opline) = opline;
}

if (EG(vm_interrupt)) {
if (EG(vm_interrupt) || JIT_G(tracing)) {
return 1;
/* Lock-free check if the side trace was already JIT-ed or blacklist-ed in another process */
} else if (t->exit_info[exit_num].flags & (ZEND_JIT_EXIT_JITED|ZEND_JIT_EXIT_BLACKLISTED)) {
Expand Down Expand Up @@ -5607,6 +5616,7 @@ static void zend_jit_trace_init_caches(void)

static void zend_jit_trace_reset_caches(void)
{
JIT_G(tracing) = 0;
}

static void zend_jit_trace_restart(void)
Expand Down

0 comments on commit 5fec155

Please sign in to comment.