Skip to content

Commit efbe961

Browse files
committed
Split "opcache.jit_max_recursion_unroll" into "opcache.jit_max_recursive_calls" and "opcache.jit_max_recursive_returns".
It's possible to disable recording of "recursive return loops" setting opcache.jit_max_recursive_returns to 0.
1 parent caca664 commit efbe961

File tree

3 files changed

+49
-38
lines changed

3 files changed

+49
-38
lines changed

ext/opcache/jit/zend_jit.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,19 @@ typedef struct _zend_jit_globals {
9393
zend_long debug;
9494
zend_long bisect_limit;
9595
double prof_threshold;
96-
zend_long max_root_traces; /* max number of root traces */
97-
zend_long max_side_traces; /* max number of side traces (per root trace) */
96+
zend_long max_root_traces; /* max number of root traces */
97+
zend_long max_side_traces; /* max number of side traces (per root trace) */
9898
zend_long hot_loop;
9999
zend_long hot_func;
100100
zend_long hot_return;
101-
zend_long hot_side_exit; /* number of exits before taking side trace */
102-
zend_long blacklist_root_trace; /* number of attempts to JIT a root trace before blacklist it */
103-
zend_long blacklist_side_trace; /* number of attempts to JIT a side trace before blacklist it */
104-
zend_long max_recursion_unroll; /* max number of recursive inlined calls/returns unrolls */
105-
zend_long max_loops_unroll; /* max number of unrolled loops */
106-
107-
zend_sym_node *symbols; /* symbols for disassembler */
101+
zend_long hot_side_exit; /* number of exits before taking side trace */
102+
zend_long blacklist_root_trace; /* number of attempts to JIT a root trace before blacklist it */
103+
zend_long blacklist_side_trace; /* number of attempts to JIT a side trace before blacklist it */
104+
zend_long max_loops_unroll; /* max number of unrolled loops */
105+
zend_long max_recursive_calls; /* max number of recursive inlined call unrolls */
106+
zend_long max_recursive_returns; /* max number of recursive inlined return unrolls */
107+
108+
zend_sym_node *symbols; /* symbols for disassembler */
108109

109110
zend_jit_trace_rec *current_trace;
110111
zend_jit_trace_stack_frame *current_frame;

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,6 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_trace_helper(ZEND_OPCODE_HAN
365365
trace_buffer[idx].level = trace_buffer[0].level = ret_level ? ret_level + 1 : 0; \
366366
trace_buffer[idx].ptr = _ptr;
367367

368-
#ifndef ZEND_JIT_RECORD_RECURSIVE_RETURN
369-
# define ZEND_JIT_RECORD_RECURSIVE_RETURN 1
370-
#endif
371-
372368
static int zend_jit_trace_recursive_call_count(const zend_op_array *op_array, const zend_op_array **unrolled_calls, int ret_level, int level)
373369
{
374370
int i;
@@ -690,12 +686,12 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
690686
count = zend_jit_trace_recursive_call_count(&EX(func)->op_array, unrolled_calls, ret_level, level);
691687

692688
if (opline == orig_opline) {
693-
if (count + 1 >= JIT_G(max_recursion_unroll)) {
689+
if (count + 1 >= JIT_G(max_recursive_calls)) {
694690
stop = ZEND_JIT_TRACE_STOP_RECURSIVE_CALL;
695691
break;
696692
}
697693
backtrack_recursion = idx;
698-
} else if (count >= JIT_G(max_recursion_unroll)) {
694+
} else if (count >= JIT_G(max_recursive_calls)) {
699695
stop = ZEND_JIT_TRACE_STOP_DEEP_RECURSION;
700696
break;
701697
}
@@ -709,8 +705,8 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
709705
if (is_toplevel) {
710706
stop = ZEND_JIT_TRACE_STOP_TOPLEVEL;
711707
break;
712-
#if ZEND_JIT_RECORD_RECURSIVE_RETURN
713708
} else if (start == ZEND_JIT_TRACE_START_RETURN
709+
&& JIT_G(max_recursive_returns) > 0
714710
&& execute_data->prev_execute_data
715711
&& execute_data->prev_execute_data->func
716712
&& execute_data->prev_execute_data->func->type == ZEND_USER_FUNCTION
@@ -722,13 +718,13 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
722718
TRACE_RECORD(ZEND_JIT_TRACE_BACK, 0, &EX(func)->op_array);
723719
count = zend_jit_trace_recursive_ret_count(&EX(func)->op_array, unrolled_calls, ret_level);
724720
if (opline == orig_opline) {
725-
if (count + 1 >= JIT_G(max_recursion_unroll)) {
721+
if (count + 1 >= JIT_G(max_recursive_returns)) {
726722
stop = ZEND_JIT_TRACE_STOP_RECURSIVE_RET;
727723
break;
728724
}
729725
backtrack_ret_recursion = idx;
730726
backtrack_ret_recursion_level = ret_level;
731-
} else if (count >= JIT_G(max_recursion_unroll)) {
727+
} else if (count >= JIT_G(max_recursive_returns)) {
732728
stop = ZEND_JIT_TRACE_STOP_DEEP_RECURSION;
733729
break;
734730
}
@@ -740,7 +736,6 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
740736
if (prev_call) {
741737
idx = zend_jit_trace_record_fake_init_call(prev_call, trace_buffer, idx);
742738
}
743-
#endif
744739
} else if (start & ZEND_JIT_TRACE_START_LOOP
745740
&& !zend_jit_trace_bad_loop_exit(orig_opline)) {
746741
/* Fail to try close the loop.

ext/opcache/zend_accelerator_module.c

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,29 @@ static ZEND_INI_MH(OnUpdateCounter)
227227
return FAILURE;
228228
}
229229

230-
static ZEND_INI_MH(OnUpdateUnrollR)
230+
static ZEND_INI_MH(OnUpdateUnrollC)
231231
{
232232
zend_long val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
233-
if (val > 0 && val < ZEND_JIT_TRACE_MAX_CALL_DEPTH && val < ZEND_JIT_TRACE_MAX_RET_DEPTH) {
233+
if (val > 0 && val < ZEND_JIT_TRACE_MAX_CALL_DEPTH) {
234234
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
235235
*p = val;
236236
return SUCCESS;
237237
}
238238
zend_error(E_WARNING, "Invalid \"%s\" setting. Should be between 1 and %d", ZSTR_VAL(entry->name),
239-
MIN(ZEND_JIT_TRACE_MAX_CALL_DEPTH, ZEND_JIT_TRACE_MAX_CALL_DEPTH));
239+
ZEND_JIT_TRACE_MAX_CALL_DEPTH);
240+
return FAILURE;
241+
}
242+
243+
static ZEND_INI_MH(OnUpdateUnrollR)
244+
{
245+
zend_long val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
246+
if (val >= 0 && val < ZEND_JIT_TRACE_MAX_RET_DEPTH) {
247+
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
248+
*p = val;
249+
return SUCCESS;
250+
}
251+
zend_error(E_WARNING, "Invalid \"%s\" setting. Should be between 0 and %d", ZSTR_VAL(entry->name),
252+
ZEND_JIT_TRACE_MAX_RET_DEPTH);
240253
return FAILURE;
241254
}
242255

@@ -312,21 +325,22 @@ ZEND_INI_BEGIN()
312325
STD_PHP_INI_ENTRY("opcache.cache_id" , "" , PHP_INI_SYSTEM, OnUpdateString, accel_directives.cache_id, zend_accel_globals, accel_globals)
313326
#endif
314327
#ifdef HAVE_JIT
315-
STD_PHP_INI_ENTRY("opcache.jit" , ZEND_JIT_DEFAULT_OPTIONS, PHP_INI_ALL, OnUpdateJit, options, zend_jit_globals, jit_globals)
316-
STD_PHP_INI_ENTRY("opcache.jit_buffer_size" , ZEND_JIT_DEFAULT_BUFFER_SIZE, PHP_INI_SYSTEM, OnUpdateLong, buffer_size, zend_jit_globals, jit_globals)
317-
STD_PHP_INI_ENTRY("opcache.jit_debug" , "0", PHP_INI_ALL, OnUpdateJitDebug, debug, zend_jit_globals, jit_globals)
318-
STD_PHP_INI_ENTRY("opcache.jit_bisect_limit" , "0", PHP_INI_ALL, OnUpdateLong, bisect_limit, zend_jit_globals, jit_globals)
319-
STD_PHP_INI_ENTRY("opcache.jit_prof_threshold" , "0.005", PHP_INI_ALL, OnUpdateReal, prof_threshold, zend_jit_globals, jit_globals)
320-
STD_PHP_INI_ENTRY("opcache.jit_max_root_traces" , "1024", PHP_INI_SYSTEM, OnUpdateLong, max_root_traces, zend_jit_globals, jit_globals)
321-
STD_PHP_INI_ENTRY("opcache.jit_max_side_traces" , "128", PHP_INI_SYSTEM, OnUpdateLong, max_side_traces, zend_jit_globals, jit_globals)
322-
STD_PHP_INI_ENTRY("opcache.jit_hot_loop" , "64", PHP_INI_SYSTEM, OnUpdateCounter, hot_loop, zend_jit_globals, jit_globals)
323-
STD_PHP_INI_ENTRY("opcache.jit_hot_func" , "127", PHP_INI_SYSTEM, OnUpdateCounter, hot_func, zend_jit_globals, jit_globals)
324-
STD_PHP_INI_ENTRY("opcache.jit_hot_return" , "8", PHP_INI_SYSTEM, OnUpdateCounter, hot_return, zend_jit_globals, jit_globals)
325-
STD_PHP_INI_ENTRY("opcache.jit_hot_side_exit" , "8", PHP_INI_ALL, OnUpdateCounter, hot_side_exit, zend_jit_globals, jit_globals)
326-
STD_PHP_INI_ENTRY("opcache.jit_blacklist_root_trace" , "16", PHP_INI_ALL, OnUpdateCounter, blacklist_root_trace, zend_jit_globals, jit_globals)
327-
STD_PHP_INI_ENTRY("opcache.jit_blacklist_side_trace" , "8", PHP_INI_ALL, OnUpdateCounter, blacklist_side_trace, zend_jit_globals, jit_globals)
328-
STD_PHP_INI_ENTRY("opcache.jit_max_recursion_unroll" , "2", PHP_INI_ALL, OnUpdateUnrollR, max_recursion_unroll, zend_jit_globals, jit_globals)
329-
STD_PHP_INI_ENTRY("opcache.jit_max_loops_unroll" , "8", PHP_INI_ALL, OnUpdateUnrollL, max_loops_unroll, zend_jit_globals, jit_globals)
328+
STD_PHP_INI_ENTRY("opcache.jit" , ZEND_JIT_DEFAULT_OPTIONS, PHP_INI_ALL, OnUpdateJit, options, zend_jit_globals, jit_globals)
329+
STD_PHP_INI_ENTRY("opcache.jit_buffer_size" , ZEND_JIT_DEFAULT_BUFFER_SIZE, PHP_INI_SYSTEM, OnUpdateLong, buffer_size, zend_jit_globals, jit_globals)
330+
STD_PHP_INI_ENTRY("opcache.jit_debug" , "0", PHP_INI_ALL, OnUpdateJitDebug, debug, zend_jit_globals, jit_globals)
331+
STD_PHP_INI_ENTRY("opcache.jit_bisect_limit" , "0", PHP_INI_ALL, OnUpdateLong, bisect_limit, zend_jit_globals, jit_globals)
332+
STD_PHP_INI_ENTRY("opcache.jit_prof_threshold" , "0.005", PHP_INI_ALL, OnUpdateReal, prof_threshold, zend_jit_globals, jit_globals)
333+
STD_PHP_INI_ENTRY("opcache.jit_max_root_traces" , "1024", PHP_INI_SYSTEM, OnUpdateLong, max_root_traces, zend_jit_globals, jit_globals)
334+
STD_PHP_INI_ENTRY("opcache.jit_max_side_traces" , "128", PHP_INI_SYSTEM, OnUpdateLong, max_side_traces, zend_jit_globals, jit_globals)
335+
STD_PHP_INI_ENTRY("opcache.jit_hot_loop" , "64", PHP_INI_SYSTEM, OnUpdateCounter, hot_loop, zend_jit_globals, jit_globals)
336+
STD_PHP_INI_ENTRY("opcache.jit_hot_func" , "127", PHP_INI_SYSTEM, OnUpdateCounter, hot_func, zend_jit_globals, jit_globals)
337+
STD_PHP_INI_ENTRY("opcache.jit_hot_return" , "8", PHP_INI_SYSTEM, OnUpdateCounter, hot_return, zend_jit_globals, jit_globals)
338+
STD_PHP_INI_ENTRY("opcache.jit_hot_side_exit" , "8", PHP_INI_ALL, OnUpdateCounter, hot_side_exit, zend_jit_globals, jit_globals)
339+
STD_PHP_INI_ENTRY("opcache.jit_blacklist_root_trace" , "16", PHP_INI_ALL, OnUpdateCounter, blacklist_root_trace, zend_jit_globals, jit_globals)
340+
STD_PHP_INI_ENTRY("opcache.jit_blacklist_side_trace" , "8", PHP_INI_ALL, OnUpdateCounter, blacklist_side_trace, zend_jit_globals, jit_globals)
341+
STD_PHP_INI_ENTRY("opcache.jit_max_loops_unroll" , "8", PHP_INI_ALL, OnUpdateUnrollL, max_loops_unroll, zend_jit_globals, jit_globals)
342+
STD_PHP_INI_ENTRY("opcache.jit_max_recursive_calls" , "2", PHP_INI_ALL, OnUpdateUnrollC, max_recursive_calls, zend_jit_globals, jit_globals)
343+
STD_PHP_INI_ENTRY("opcache.jit_max_recursive_returns" , "2", PHP_INI_ALL, OnUpdateUnrollR, max_recursive_returns, zend_jit_globals, jit_globals)
330344
#endif
331345
ZEND_INI_END()
332346

@@ -810,7 +824,8 @@ ZEND_FUNCTION(opcache_get_configuration)
810824
add_assoc_long(&directives, "opcache.jit_hot_return", JIT_G(hot_return));
811825
add_assoc_long(&directives, "opcache.jit_hot_side_exit", JIT_G(hot_side_exit));
812826
add_assoc_long(&directives, "opcache.jit_max_loops_unroll", JIT_G(max_loops_unroll));
813-
add_assoc_long(&directives, "opcache.jit_max_recursion_unroll", JIT_G(max_recursion_unroll));
827+
add_assoc_long(&directives, "opcache.jit_max_recursive_calls", JIT_G(max_recursive_calls));
828+
add_assoc_long(&directives, "opcache.jit_max_recursive_returns", JIT_G(max_recursive_returns));
814829
add_assoc_long(&directives, "opcache.jit_max_root_traces", JIT_G(max_root_traces));
815830
add_assoc_long(&directives, "opcache.jit_max_side_traces", JIT_G(max_side_traces));
816831
add_assoc_long(&directives, "opcache.jit_prof_threshold", JIT_G(prof_threshold));

0 commit comments

Comments
 (0)