]> granicus.if.org Git - php/commitdiff
Keep track information about used JIT trigger in ZEND_FUNC_INFO(op_array)->func_info...
authorDmitry Stogov <dmitry@zend.com>
Tue, 29 Sep 2020 10:05:24 +0000 (13:05 +0300)
committerDmitry Stogov <dmitry@zend.com>
Tue, 29 Sep 2020 10:05:24 +0000 (13:05 +0300)
ext/opcache/Optimizer/zend_func_info.h
ext/opcache/jit/zend_jit.c
ext/opcache/jit/zend_jit_trace.c

index 97f60ad37e60f7066a1b1db9406a087077c3fa37..13dd2e3127c380ee43beaddad04baec24aac38c4 100644 (file)
 #define ZEND_FUNC_HAS_EXTENDED_STMT        (1<<11)
 #define ZEND_SSA_TSSA                      (1<<12) /* used by tracing JIT */
 
+#define ZEND_FUNC_JIT_ON_FIRST_EXEC        (1<<13) /* used by JIT */
+#define ZEND_FUNC_JIT_ON_PROF_REQUEST      (1<<14) /* used by JIT */
+#define ZEND_FUNC_JIT_ON_HOT_COUNTERS      (1<<15) /* used by JIT */
+#define ZEND_FUNC_JIT_ON_HOT_TRACE         (1<<16) /* used by JIT */
+
+
 typedef struct _zend_func_info zend_func_info;
 typedef struct _zend_call_info zend_call_info;
 
index 348f15c4fccdff7e2ad8db26034d395ef7b68517..3d46fcc8b5ff83a63df33184040808590d2c9334 100644 (file)
@@ -3452,7 +3452,12 @@ static void zend_jit_cleanup_func_info(zend_op_array *op_array)
                if (JIT_G(trigger) == ZEND_JIT_ON_FIRST_EXEC ||
                    JIT_G(trigger) == ZEND_JIT_ON_PROF_REQUEST ||
                    JIT_G(trigger) == ZEND_JIT_ON_HOT_COUNTERS) {
-                       memset(func_info, 0, sizeof(zend_func_info));
+                       func_info->num = 0;
+                       func_info->flags &= ZEND_FUNC_JIT_ON_FIRST_EXEC
+                               | ZEND_FUNC_JIT_ON_PROF_REQUEST
+                               | ZEND_FUNC_JIT_ON_HOT_COUNTERS
+                               | ZEND_FUNC_JIT_ON_HOT_TRACE;
+                       memset(&func_info->ssa, 0, sizeof(zend_func_info) - offsetof(zend_func_info, ssa));
                } else {
                        ZEND_SET_FUNC_INFO(op_array, NULL);
                }
@@ -3637,6 +3642,7 @@ static int zend_jit_setup_hot_counters(zend_op_array *op_array)
 
        jit_extension = (zend_jit_op_array_hot_extension*)zend_shared_alloc(sizeof(zend_jit_op_array_hot_extension) + (op_array->last - 1) * sizeof(void*));
        memset(&jit_extension->func_info, 0, sizeof(zend_func_info));
+       jit_extension->func_info.flags = ZEND_FUNC_JIT_ON_HOT_COUNTERS;
        jit_extension->counter = &zend_jit_hot_counters[zend_jit_op_array_hash(op_array) & (ZEND_HOT_COUNTERS_COUNT - 1)];
        for (i = 0; i < op_array->last; i++) {
                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)
                }
                jit_extension = (zend_jit_op_array_extension*)zend_shared_alloc(sizeof(zend_jit_op_array_extension));
                memset(&jit_extension->func_info, 0, sizeof(zend_func_info));
+               jit_extension->func_info.flags = ZEND_FUNC_JIT_ON_FIRST_EXEC;
                jit_extension->orig_handler = (void*)opline->handler;
                ZEND_SET_FUNC_INFO(op_array, (void*)jit_extension);
                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)
                        }
                        jit_extension = (zend_jit_op_array_extension*)zend_shared_alloc(sizeof(zend_jit_op_array_extension));
                        memset(&jit_extension->func_info, 0, sizeof(zend_func_info));
+                       jit_extension->func_info.flags = ZEND_FUNC_JIT_ON_PROF_REQUEST;
                        jit_extension->orig_handler = (void*)opline->handler;
                        ZEND_SET_FUNC_INFO(op_array, (void*)jit_extension);
                        opline->handler = (const void*)zend_jit_profile_jit_handler;
index 8057e8131b9f47d2783dc387a8ce483a33f90480..cc42fcb51bc4c61e7d8d6283e5ffd03c9fa17460 100644 (file)
@@ -486,7 +486,12 @@ static zend_ssa *zend_jit_trace_build_ssa(const zend_op_array *op_array, zend_sc
 
        jit_extension =
                (zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
-       memset(&jit_extension->func_info, 0, sizeof(jit_extension->func_info));
+    jit_extension->func_info.num = 0;
+       jit_extension->func_info.flags &= ZEND_FUNC_JIT_ON_FIRST_EXEC
+               | ZEND_FUNC_JIT_ON_PROF_REQUEST
+               | ZEND_FUNC_JIT_ON_HOT_COUNTERS
+               | ZEND_FUNC_JIT_ON_HOT_TRACE;
+       memset(&jit_extension->func_info.ssa, 0, sizeof(zend_func_info) - offsetof(zend_func_info, ssa));
        ssa = &jit_extension->func_info.ssa;
 
        if (JIT_G(opt_level) >= ZEND_JIT_LEVEL_OPT_FUNC) {
@@ -5708,7 +5713,12 @@ jit_cleanup:
                jit_extension =
                        (zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
 
-               memset(&jit_extension->func_info, 0, sizeof(jit_extension->func_info));
+           jit_extension->func_info.num = 0;
+               jit_extension->func_info.flags &= ZEND_FUNC_JIT_ON_FIRST_EXEC
+                       | ZEND_FUNC_JIT_ON_PROF_REQUEST
+                       | ZEND_FUNC_JIT_ON_HOT_COUNTERS
+                       | ZEND_FUNC_JIT_ON_HOT_TRACE;
+               memset(&jit_extension->func_info.ssa, 0, sizeof(zend_func_info) - offsetof(zend_func_info, ssa));
        }
 
        zend_arena_release(&CG(arena), checkpoint);
@@ -6833,6 +6843,7 @@ static int zend_jit_setup_hot_trace_counters(zend_op_array *op_array)
 
        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));
        memset(&jit_extension->func_info, 0, sizeof(zend_func_info));
+       jit_extension->func_info.flags = ZEND_FUNC_JIT_ON_HOT_TRACE;
        jit_extension->op_array = op_array;
        jit_extension->offset = (char*)jit_extension->trace_info - (char*)op_array->opcodes;
        for (i = 0; i < op_array->last; i++) {