Skip to content

Commit dddb403

Browse files
committed
Keep track information about used JIT trigger in ZEND_FUNC_INFO(op_array)->func_info.flags
1 parent a6ecafe commit dddb403

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

ext/opcache/Optimizer/zend_func_info.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
#define ZEND_FUNC_HAS_EXTENDED_STMT (1<<11)
3636
#define ZEND_SSA_TSSA (1<<12) /* used by tracing JIT */
3737

38+
#define ZEND_FUNC_JIT_ON_FIRST_EXEC (1<<13) /* used by JIT */
39+
#define ZEND_FUNC_JIT_ON_PROF_REQUEST (1<<14) /* used by JIT */
40+
#define ZEND_FUNC_JIT_ON_HOT_COUNTERS (1<<15) /* used by JIT */
41+
#define ZEND_FUNC_JIT_ON_HOT_TRACE (1<<16) /* used by JIT */
42+
43+
3844
typedef struct _zend_func_info zend_func_info;
3945
typedef struct _zend_call_info zend_call_info;
4046

ext/opcache/jit/zend_jit.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3452,7 +3452,12 @@ static void zend_jit_cleanup_func_info(zend_op_array *op_array)
34523452
if (JIT_G(trigger) == ZEND_JIT_ON_FIRST_EXEC ||
34533453
JIT_G(trigger) == ZEND_JIT_ON_PROF_REQUEST ||
34543454
JIT_G(trigger) == ZEND_JIT_ON_HOT_COUNTERS) {
3455-
memset(func_info, 0, sizeof(zend_func_info));
3455+
func_info->num = 0;
3456+
func_info->flags &= ZEND_FUNC_JIT_ON_FIRST_EXEC
3457+
| ZEND_FUNC_JIT_ON_PROF_REQUEST
3458+
| ZEND_FUNC_JIT_ON_HOT_COUNTERS
3459+
| ZEND_FUNC_JIT_ON_HOT_TRACE;
3460+
memset(&func_info->ssa, 0, sizeof(zend_func_info) - offsetof(zend_func_info, ssa));
34563461
} else {
34573462
ZEND_SET_FUNC_INFO(op_array, NULL);
34583463
}
@@ -3637,6 +3642,7 @@ static int zend_jit_setup_hot_counters(zend_op_array *op_array)
36373642

36383643
jit_extension = (zend_jit_op_array_hot_extension*)zend_shared_alloc(sizeof(zend_jit_op_array_hot_extension) + (op_array->last - 1) * sizeof(void*));
36393644
memset(&jit_extension->func_info, 0, sizeof(zend_func_info));
3645+
jit_extension->func_info.flags = ZEND_FUNC_JIT_ON_HOT_COUNTERS;
36403646
jit_extension->counter = &zend_jit_hot_counters[zend_jit_op_array_hash(op_array) & (ZEND_HOT_COUNTERS_COUNT - 1)];
36413647
for (i = 0; i < op_array->last; i++) {
36423648
jit_extension->orig_handlers[i] = op_array->opcodes[i].handler;
@@ -3689,6 +3695,7 @@ ZEND_EXT_API int zend_jit_op_array(zend_op_array *op_array, zend_script *script)
36893695
}
36903696
jit_extension = (zend_jit_op_array_extension*)zend_shared_alloc(sizeof(zend_jit_op_array_extension));
36913697
memset(&jit_extension->func_info, 0, sizeof(zend_func_info));
3698+
jit_extension->func_info.flags = ZEND_FUNC_JIT_ON_FIRST_EXEC;
36923699
jit_extension->orig_handler = (void*)opline->handler;
36933700
ZEND_SET_FUNC_INFO(op_array, (void*)jit_extension);
36943701
opline->handler = (const void*)zend_jit_runtime_jit_handler;
@@ -3708,6 +3715,7 @@ ZEND_EXT_API int zend_jit_op_array(zend_op_array *op_array, zend_script *script)
37083715
}
37093716
jit_extension = (zend_jit_op_array_extension*)zend_shared_alloc(sizeof(zend_jit_op_array_extension));
37103717
memset(&jit_extension->func_info, 0, sizeof(zend_func_info));
3718+
jit_extension->func_info.flags = ZEND_FUNC_JIT_ON_PROF_REQUEST;
37113719
jit_extension->orig_handler = (void*)opline->handler;
37123720
ZEND_SET_FUNC_INFO(op_array, (void*)jit_extension);
37133721
opline->handler = (const void*)zend_jit_profile_jit_handler;

ext/opcache/jit/zend_jit_trace.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,12 @@ static zend_ssa *zend_jit_trace_build_ssa(const zend_op_array *op_array, zend_sc
486486

487487
jit_extension =
488488
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
489-
memset(&jit_extension->func_info, 0, sizeof(jit_extension->func_info));
489+
jit_extension->func_info.num = 0;
490+
jit_extension->func_info.flags &= ZEND_FUNC_JIT_ON_FIRST_EXEC
491+
| ZEND_FUNC_JIT_ON_PROF_REQUEST
492+
| ZEND_FUNC_JIT_ON_HOT_COUNTERS
493+
| ZEND_FUNC_JIT_ON_HOT_TRACE;
494+
memset(&jit_extension->func_info.ssa, 0, sizeof(zend_func_info) - offsetof(zend_func_info, ssa));
490495
ssa = &jit_extension->func_info.ssa;
491496

492497
if (JIT_G(opt_level) >= ZEND_JIT_LEVEL_OPT_FUNC) {
@@ -5708,7 +5713,12 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
57085713
jit_extension =
57095714
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
57105715

5711-
memset(&jit_extension->func_info, 0, sizeof(jit_extension->func_info));
5716+
jit_extension->func_info.num = 0;
5717+
jit_extension->func_info.flags &= ZEND_FUNC_JIT_ON_FIRST_EXEC
5718+
| ZEND_FUNC_JIT_ON_PROF_REQUEST
5719+
| ZEND_FUNC_JIT_ON_HOT_COUNTERS
5720+
| ZEND_FUNC_JIT_ON_HOT_TRACE;
5721+
memset(&jit_extension->func_info.ssa, 0, sizeof(zend_func_info) - offsetof(zend_func_info, ssa));
57125722
}
57135723

57145724
zend_arena_release(&CG(arena), checkpoint);
@@ -6833,6 +6843,7 @@ static int zend_jit_setup_hot_trace_counters(zend_op_array *op_array)
68336843

68346844
jit_extension = (zend_jit_op_array_trace_extension*)zend_shared_alloc(sizeof(zend_jit_op_array_trace_extension) + (op_array->last - 1) * sizeof(zend_op_trace_info));
68356845
memset(&jit_extension->func_info, 0, sizeof(zend_func_info));
6846+
jit_extension->func_info.flags = ZEND_FUNC_JIT_ON_HOT_TRACE;
68366847
jit_extension->op_array = op_array;
68376848
jit_extension->offset = (char*)jit_extension->trace_info - (char*)op_array->opcodes;
68386849
for (i = 0; i < op_array->last; i++) {

0 commit comments

Comments
 (0)