Skip to content

Commit 7a54524

Browse files
author
wxue1
committed
JIT-long-compiled-inline-function
1 parent 964f494 commit 7a54524

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

ext/opcache/jit/zend_jit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ typedef struct _zend_jit_globals {
116116
zend_long max_recursive_calls; /* max number of recursive inlined call unrolls */
117117
zend_long max_recursive_returns; /* max number of recursive inlined return unrolls */
118118
zend_long max_polymorphic_calls; /* max number of inlined polymorphic calls */
119+
zend_long jit_trace_inline_func_limit; /* max length of inlined function in a trace */
119120

120121
zend_sym_node *symbols; /* symbols for disassembler */
121122

ext/opcache/jit/zend_jit_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ zend_constant* ZEND_FASTCALL zend_jit_check_constant(const zval *key);
340340
_(LOOP, "loop") \
341341
_(RECURSIVE_CALL, "recursive call") \
342342
_(RECURSIVE_RET, "recursive return") \
343+
_(BACKTRACK_INLINE, "backtrace inline func") \
343344
_(RETURN, "return") \
344345
_(INTERPRETER, "exit to VM interpreter") \
345346
_(LINK, "link to another trace") \

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,16 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
562562
uint8_t trace_flags, op1_type, op2_type, op3_type;
563563
zend_class_entry *ce1, *ce2;
564564
const zend_op *link_to_enter_opline = NULL;
565+
/* Remember the first opline of inline function*/
566+
const zend_op *link_to_inline_func_opline = NULL;
565567
int backtrack_link_to_enter = -1;
566568
int backtrack_recursion = -1;
567569
int backtrack_ret_recursion = -1;
568570
int backtrack_ret_recursion_level = 0;
571+
/* Remember the index of inline function opline in the trace buffer */
572+
int backtrack_link_to_inline_func = -1;
573+
int backtrack_link_to_inline_func_next = -1;
574+
bool link_to_inline_func_flag = false;
569575
int loop_unroll_limit = 0;
570576
int last_loop = -1;
571577
int last_loop_level = -1;
@@ -908,6 +914,23 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
908914
} else if (count >= JIT_G(max_recursive_calls)) {
909915
stop = ZEND_JIT_TRACE_STOP_DEEP_RECURSION;
910916
break;
917+
} else if (backtrack_link_to_inline_func < 0 && backtrack_link_to_inline_func_next < 0) {
918+
// && ZEND_OP_TRACE_INFO(opline, offset)->trace_flags & ZEND_JIT_TRACE_JITED
919+
/* enter a compiled inline function, remember the idx */
920+
backtrack_link_to_inline_func = idx;
921+
link_to_inline_func_opline = opline;
922+
} else if (backtrack_link_to_inline_func > 0 && backtrack_link_to_inline_func_next < 0) {
923+
/* enter a function the second time */
924+
backtrack_link_to_inline_func_next = idx;
925+
if (idx - backtrack_link_to_inline_func > JIT_G(jit_trace_inline_func_limit)) {
926+
link_to_inline_func_flag = true;
927+
break;
928+
} else {
929+
/* the inline function is not too long */
930+
backtrack_link_to_inline_func = backtrack_link_to_inline_func_next;
931+
link_to_inline_func_opline = opline;
932+
backtrack_link_to_inline_func_next = -1;
933+
}
911934
}
912935

913936
unrolled_calls[ret_level + level] = &EX(func)->op_array;
@@ -925,6 +948,9 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
925948
if (ret_level > ZEND_JIT_TRACE_MAX_RET_DEPTH) {
926949
stop = ZEND_JIT_TRACE_STOP_TOO_DEEP_RET;
927950
break;
951+
} else if (idx - backtrack_link_to_inline_func > JIT_G(jit_trace_inline_func_limit)) {
952+
link_to_inline_func_flag = true;
953+
break;
928954
}
929955
TRACE_RECORD(ZEND_JIT_TRACE_BACK, 0, op_array);
930956
count = zend_jit_trace_recursive_ret_count(&EX(func)->op_array, unrolled_calls, ret_level);
@@ -975,6 +1001,10 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
9751001
if (level < last_loop_level) {
9761002
last_loop_opline = NULL;
9771003
}
1004+
if (idx - backtrack_link_to_inline_func > JIT_G(jit_trace_inline_func_limit)) {
1005+
link_to_inline_func_flag = true;
1006+
break;
1007+
}
9781008
TRACE_RECORD(ZEND_JIT_TRACE_BACK, 0, op_array);
9791009
}
9801010
}
@@ -1142,6 +1172,11 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
11421172
ret_level = backtrack_ret_recursion_level;
11431173
stop = ZEND_JIT_TRACE_STOP_RECURSIVE_RET;
11441174
end_opline = orig_opline;
1175+
} else if (backtrack_link_to_inline_func > 0 && link_to_inline_func_flag == true) {
1176+
/* Reset the index and stop flag to link to the long inline function. */
1177+
idx = backtrack_link_to_inline_func;
1178+
stop = ZEND_JIT_TRACE_STOP_BACKTRACK_INLINE;
1179+
end_opline = link_to_inline_func_opline;
11451180
} else if (backtrack_link_to_enter > 0) {
11461181
if (stop == ZEND_JIT_TRACE_STOP_DEEP_RECURSION
11471182
&& zend_jit_trace_bad_stop_event(orig_opline, JIT_G(blacklist_root_trace) / 2) ==

ext/opcache/zend_accelerator_module.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ ZEND_INI_BEGIN()
302302
STD_PHP_INI_ENTRY("opcache.jit_max_recursive_calls" , "2", PHP_INI_ALL, OnUpdateUnrollC, max_recursive_calls, zend_jit_globals, jit_globals)
303303
STD_PHP_INI_ENTRY("opcache.jit_max_recursive_returns" , "2", PHP_INI_ALL, OnUpdateUnrollR, max_recursive_returns, zend_jit_globals, jit_globals)
304304
STD_PHP_INI_ENTRY("opcache.jit_max_polymorphic_calls" , "2", PHP_INI_ALL, OnUpdateLong, max_polymorphic_calls, zend_jit_globals, jit_globals)
305+
STD_PHP_INI_ENTRY("opcache.jit_trace_inline_func_limit" , "6", PHP_INI_ALL, OnUpdateLong, jit_trace_inline_func_limit, zend_jit_globals, jit_globals)
305306
#endif
306307
ZEND_INI_END()
307308

@@ -792,6 +793,7 @@ ZEND_FUNCTION(opcache_get_configuration)
792793
add_assoc_long(&directives, "opcache.jit_max_root_traces", JIT_G(max_root_traces));
793794
add_assoc_long(&directives, "opcache.jit_max_side_traces", JIT_G(max_side_traces));
794795
add_assoc_long(&directives, "opcache.jit_prof_threshold", JIT_G(prof_threshold));
796+
add_assoc_long(&directives, "opcache.jit_trace_inline_func_limit", JIT_G(jit_trace_inline_func_limit));
795797
#endif
796798

797799
add_assoc_zval(return_value, "directives", &directives);

0 commit comments

Comments
 (0)