Skip to content

Commit 91bfed1

Browse files
author
wxue1
committed
JIT inlined function firstly if trace is too long
1 parent 964f494 commit 91bfed1

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
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 max_inline_func_length; /* max length of inlined functions */
119120

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

ext/opcache/jit/zend_jit_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ zend_constant* ZEND_FASTCALL zend_jit_check_constant(const zval *key);
359359
_(RECURSION_EXIT, "return from recursive function") \
360360
_(BLACK_LIST, "trace blacklisted") \
361361
_(INNER_LOOP, "inner loop") /* trace it */ \
362+
_(JIT_INLINE_FUNC, "JIT inline function and skip current trace") /* trace inline func */ \
362363
_(COMPILED_LOOP, "compiled loop") \
363364
_(TRAMPOLINE, "trampoline call") \
364365
_(BAD_FUNC, "bad function call") \
@@ -384,7 +385,7 @@ typedef enum _zend_jit_trace_stop {
384385
(ret < ZEND_JIT_TRACE_STOP_ERROR)
385386

386387
#define ZEND_JIT_TRACE_STOP_REPEAT(ret) \
387-
(ret == ZEND_JIT_TRACE_STOP_INNER_LOOP)
388+
(ret == ZEND_JIT_TRACE_STOP_INNER_LOOP || ret == ZEND_JIT_TRACE_STOP_JIT_INLINE_FUNC)
388389

389390
#define ZEND_JIT_TRACE_STOP_MAY_RECOVER(ret) \
390391
(ret <= ZEND_JIT_TRACE_STOP_COMPILER_ERROR)

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,13 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
10481048

10491049
trace_flags = ZEND_OP_TRACE_INFO(opline, offset)->trace_flags;
10501050
if (trace_flags) {
1051+
/* if trace a function too long, stop current tracing and restart a new one */
1052+
if (trace_buffer[idx-1].op == ZEND_JIT_TRACE_ENTER && idx > JIT_G(max_inline_func_length)) {
1053+
if (!(trace_flags & ZEND_JIT_TRACE_JITED)) {
1054+
stop = ZEND_JIT_TRACE_STOP_JIT_INLINE_FUNC;
1055+
break;
1056+
}
1057+
}
10511058
if (trace_flags & ZEND_JIT_TRACE_JITED) {
10521059
if (trace_flags & ZEND_JIT_TRACE_START_LOOP) {
10531060
if ((start & ZEND_JIT_TRACE_START_LOOP) != 0

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_max_inline_func_length" , "16", PHP_INI_SYSTEM, OnUpdateLong, max_inline_func_length,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_max_inline_func_length", JIT_G(max_inline_func_length));
795797
#endif
796798

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

0 commit comments

Comments
 (0)