Skip to content

Commit 3042b2b

Browse files
committed
Dump information about trace side exits
1 parent 6a67067 commit 3042b2b

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

ext/opcache/jit/zend_jit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
#define ZEND_JIT_DEBUG_TRACE_BLACKLIST (1<<17)
8585
#define ZEND_JIT_DEBUG_TRACE_BYTECODE (1<<18)
8686
#define ZEND_JIT_DEBUG_TRACE_TSSA (1<<19)
87+
#define ZEND_JIT_DEBUG_TRACE_EXIT_INFO (1<<20)
8788

8889
ZEND_EXT_API int zend_jit_op_array(zend_op_array *op_array, zend_script *script);
8990
ZEND_EXT_API int zend_jit_script(zend_script *script);

ext/opcache/jit/zend_jit_trace.c

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ static zend_ssa *zend_jit_trace_build_ssa(const zend_op_array *op_array, zend_sc
457457
}
458458

459459
static void zend_jit_dump_trace(zend_jit_trace_rec *trace_buffer, zend_ssa *tssa);
460+
static void zend_jit_dump_exit_info(zend_jit_trace_info *t);
460461

461462
static zend_always_inline int zend_jit_trace_op_len(const zend_op *opline)
462463
{
@@ -3168,7 +3169,7 @@ static zend_jit_trace_stop zend_jit_compile_root_trace(zend_jit_trace_rec *trace
31683169
{
31693170
zend_jit_trace_stop ret;
31703171
const void *handler;
3171-
zend_jit_trace_info *t;
3172+
zend_jit_trace_info *t = NULL;
31723173
zend_jit_trace_exit_info exit_info[ZEND_JIT_TRACE_MAX_EXITS];
31733174

31743175
zend_shared_alloc_lock();
@@ -3260,6 +3261,12 @@ static zend_jit_trace_stop zend_jit_compile_root_trace(zend_jit_trace_rec *trace
32603261

32613262
zend_shared_alloc_unlock();
32623263

3264+
if ((ZCG(accel_directives).jit_debug & ZEND_JIT_DEBUG_TRACE_EXIT_INFO) != 0
3265+
&& ret == ZEND_JIT_TRACE_STOP_COMPILED
3266+
&& t->exit_count > 0) {
3267+
zend_jit_dump_exit_info(t);
3268+
}
3269+
32633270
return ret;
32643271
}
32653272

@@ -3499,6 +3506,47 @@ static void zend_jit_dump_trace(zend_jit_trace_rec *trace_buffer, zend_ssa *tssa
34993506
}
35003507
}
35013508

3509+
static void zend_jit_dump_exit_info(zend_jit_trace_info *t)
3510+
{
3511+
int i, j;
3512+
3513+
fprintf(stderr, "---- TRACE %d exit info\n", t->id);
3514+
for (i = 0; i < t->exit_count; i++) {
3515+
uint32_t stack_size = t->exit_info[i].stack_size;
3516+
zend_jit_trace_stack *stack = t->stack_map + t->exit_info[i].stack_offset;
3517+
3518+
fprintf(stderr, " exit_%d:", i);
3519+
if (t->exit_info[i].opline) {
3520+
// TODO: print exit opline number ???
3521+
//fprintf(stderr, " %04d/", t->exit_info[i].opline - op_array->opcodes);
3522+
fprintf(stderr, " XXXX/");
3523+
} else {
3524+
fprintf(stderr, " ----/");
3525+
}
3526+
if (t->exit_info[i].stack_size) {
3527+
fprintf(stderr, "%04d/%d", t->exit_info[i].stack_offset, t->exit_info[i].stack_size);
3528+
} else {
3529+
fprintf(stderr, "----/0");
3530+
}
3531+
for (j = 0; j < stack_size; j++) {
3532+
zend_uchar type = STACK_TYPE(stack, j);
3533+
if (type != IS_UNKNOWN) {
3534+
// TODO: print CV insted of X ???
3535+
fprintf(stderr, " X%d:", j);
3536+
if (type == IS_UNDEF) {
3537+
fprintf(stderr, "undef");
3538+
} else {
3539+
fprintf(stderr, "%s", zend_get_type_by_const(type));
3540+
if (STACK_REG(stack, j) != ZREG_NONE) {
3541+
fprintf(stderr, "(%s)", zend_reg_name[STACK_REG(stack, j)]);
3542+
}
3543+
}
3544+
}
3545+
}
3546+
fprintf(stderr, "\n");
3547+
}
3548+
}
3549+
35023550
int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const zend_op *opline)
35033551
{
35043552
const zend_op *orig_opline;
@@ -3771,6 +3819,12 @@ static zend_jit_trace_stop zend_jit_compile_side_trace(zend_jit_trace_rec *trace
37713819

37723820
zend_shared_alloc_unlock();
37733821

3822+
if ((ZCG(accel_directives).jit_debug & ZEND_JIT_DEBUG_TRACE_EXIT_INFO) != 0
3823+
&& ret == ZEND_JIT_TRACE_STOP_COMPILED
3824+
&& t->exit_count > 0) {
3825+
zend_jit_dump_exit_info(t);
3826+
}
3827+
37743828
return ret;
37753829
}
37763830

0 commit comments

Comments
 (0)