Skip to content

Commit df5cdce

Browse files
author
wxue1
committed
JIT deepest function firstly
Duplicated JITTed code brings overhead for the instruction cache. This patch reduces duplication by JITting deepest inline function first because the same function is JITTed in different root trace or side trace sometimes. It increases 3% the performance of our workload in tracing mode. Signed-off-by: Wang, Xue <[email protected]> Signed-off-by: Yang, Lin A <[email protected]>
1 parent b698108 commit df5cdce

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

ext/opcache/jit/zend_jit_internal.h

+3-1
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_DEEPER_FUNC, "JIT deeper function and skip current trace") /* trace next func */ \
362363
_(COMPILED_LOOP, "compiled loop") \
363364
_(TRAMPOLINE, "trampoline call") \
364365
_(BAD_FUNC, "bad function call") \
@@ -383,8 +384,9 @@ typedef enum _zend_jit_trace_stop {
383384
#define ZEND_JIT_TRACE_STOP_DONE(ret) \
384385
(ret < ZEND_JIT_TRACE_STOP_ERROR)
385386

387+
/* restart to trace an inner loop or a deeper function */
386388
#define ZEND_JIT_TRACE_STOP_REPEAT(ret) \
387-
(ret == ZEND_JIT_TRACE_STOP_INNER_LOOP)
389+
(ret == ZEND_JIT_TRACE_STOP_INNER_LOOP || ret == ZEND_JIT_TRACE_STOP_JIT_DEEPER_FUNC)
388390

389391
#define ZEND_JIT_TRACE_STOP_MAY_RECOVER(ret) \
390392
(ret <= ZEND_JIT_TRACE_STOP_COMPILER_ERROR)

ext/opcache/jit/zend_jit_vm_helpers.c

+7
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,13 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
10621062

10631063
trace_flags = ZEND_OP_TRACE_INFO(opline, offset)->trace_flags;
10641064
if (trace_flags) {
1065+
/* When enter a function, stop current tracing and restart a new one */
1066+
if (trace_buffer[idx-1].op == ZEND_JIT_TRACE_ENTER) {
1067+
if (!(trace_flags & ZEND_JIT_TRACE_JITED)) {
1068+
stop = ZEND_JIT_TRACE_STOP_JIT_DEEPER_FUNC;
1069+
break;
1070+
}
1071+
}
10651072
if (trace_flags & ZEND_JIT_TRACE_JITED) {
10661073
if (trace_flags & ZEND_JIT_TRACE_START_LOOP) {
10671074
if ((start & ZEND_JIT_TRACE_START_LOOP) != 0

0 commit comments

Comments
 (0)