Skip to content

Commit 9122638

Browse files
committed
Set "hybrid_ret_counters" only after links to "function entry" traces.
1 parent 3007710 commit 9122638

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

ext/opcache/jit/zend_jit_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ int ZEND_FASTCALL zend_jit_check_constant(const zval *key);
133133
zend_jit_hash(opline)
134134

135135
#define ZEND_JIT_TRACE_FUNC_COST (1*250)
136-
#define ZEND_JIT_TRACE_RET_COST (1*250-1)
136+
#define ZEND_JIT_TRACE_RET_COST (15*250)
137137
#define ZEND_JIT_TRACE_LOOP_COST (2*250)
138138
#define ZEND_JIT_TRACE_COUNTER_INIT (127*250)
139139

ext/opcache/jit/zend_jit_trace.c

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,6 +2428,21 @@ static void zend_jit_trace_clenup_stack(zend_jit_trace_stack *stack, const zend_
24282428
}
24292429
}
24302430

2431+
static void zend_jit_trace_setup_ret_counter(const zend_op *opline, size_t offset)
2432+
{
2433+
zend_op *next_opline = (zend_op*)(opline + 1);
2434+
2435+
if (!ZEND_OP_TRACE_INFO(next_opline, offset)->trace_flags) {
2436+
if (!ZEND_OP_TRACE_INFO(next_opline, offset)->counter) {
2437+
ZEND_OP_TRACE_INFO(next_opline, offset)->counter =
2438+
&zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM];
2439+
ZEND_JIT_COUNTER_NUM = (ZEND_JIT_COUNTER_NUM + 1) % ZEND_HOT_COUNTERS_COUNT;
2440+
}
2441+
ZEND_OP_TRACE_INFO(next_opline, offset)->trace_flags = ZEND_JIT_TRACE_START_RETURN;
2442+
next_opline->handler = (const void*)zend_jit_ret_counter_handler;
2443+
}
2444+
}
2445+
24312446
static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t parent_trace, uint32_t exit_num)
24322447
{
24332448
const void *handler = NULL;
@@ -3802,6 +3817,11 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
38023817
}
38033818

38043819
} else if (p->op == ZEND_JIT_TRACE_ENTER) {
3820+
if ((p+1)->op == ZEND_JIT_TRACE_END) {
3821+
p++;
3822+
zend_jit_set_opline(&dasm_state, p->opline);
3823+
break;
3824+
}
38053825
op_array = (zend_op_array*)p->op_array;
38063826
jit_extension =
38073827
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
@@ -4020,6 +4040,30 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
40204040

40214041
handler = dasm_link_and_encode(&dasm_state, NULL, NULL, NULL, NULL, ZSTR_VAL(name), ZEND_JIT_TRACE_NUM);
40224042

4043+
if (handler) {
4044+
if (p->stop == ZEND_JIT_TRACE_STOP_RECURSIVE_CALL) {
4045+
op_array = trace_buffer->op_array;
4046+
p = trace_buffer + ZEND_JIT_TRACE_START_REC_SIZE;
4047+
for (;;p++) {
4048+
if (p->op == ZEND_JIT_TRACE_VM) {
4049+
opline = p->opline;
4050+
} else if (p->op == ZEND_JIT_TRACE_ENTER) {
4051+
if (p->op_array == op_array) {
4052+
zend_jit_trace_setup_ret_counter(opline, jit_extension->offset);
4053+
}
4054+
} else if (p->op == ZEND_JIT_TRACE_END) {
4055+
break;
4056+
}
4057+
}
4058+
} else if (p->stop == ZEND_JIT_TRACE_STOP_LINK) {
4059+
if (opline->opcode == ZEND_DO_UCALL
4060+
|| opline->opcode == ZEND_DO_FCALL
4061+
|| opline->opcode == ZEND_DO_FCALL_BY_NAME) {
4062+
zend_jit_trace_setup_ret_counter(opline, jit_extension->offset);
4063+
}
4064+
}
4065+
}
4066+
40234067
jit_failure:
40244068
dasm_free(&dasm_state);
40254069

@@ -5041,20 +5085,6 @@ static int zend_jit_setup_hot_trace_counters(zend_op_array *op_array)
50415085

50425086
for (i = 0; i < cfg.blocks_count; i++) {
50435087
if (cfg.blocks[i].flags & ZEND_BB_REACHABLE) {
5044-
if (cfg.blocks[i].flags & ZEND_BB_ENTRY) {
5045-
/* continuation after return from function call */
5046-
opline = op_array->opcodes + cfg.blocks[i].start;
5047-
if (!(ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags & ZEND_JIT_TRACE_UNSUPPORTED)) {
5048-
opline->handler = (const void*)zend_jit_ret_counter_handler;
5049-
if (!ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter) {
5050-
ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter =
5051-
&zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM];
5052-
ZEND_JIT_COUNTER_NUM = (ZEND_JIT_COUNTER_NUM + 1) % ZEND_HOT_COUNTERS_COUNT;
5053-
}
5054-
ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags |=
5055-
ZEND_JIT_TRACE_START_RETURN;
5056-
}
5057-
}
50585088
if (cfg.blocks[i].flags & ZEND_BB_LOOP_HEADER) {
50595089
/* loop header */
50605090
opline = op_array->opcodes + cfg.blocks[i].start;

0 commit comments

Comments
 (0)