]> granicus.if.org Git - php/commitdiff
Allow counter settings to be "zero" to disable corresponding counter
authorDmitry Stogov <dmitry@zend.com>
Wed, 20 May 2020 22:06:50 +0000 (01:06 +0300)
committerDmitry Stogov <dmitry@zend.com>
Wed, 20 May 2020 22:06:50 +0000 (01:06 +0300)
ext/opcache/jit/zend_jit.c
ext/opcache/jit/zend_jit_trace.c
ext/opcache/jit/zend_jit_x86.dasc
ext/opcache/zend_accelerator_module.c

index 9a04f2dc950bcbd221e56093f76133a58c07fe61..c96a1bc97305eb00e36d345cd1e81f709d1d4200 100644 (file)
@@ -3266,19 +3266,23 @@ static int zend_jit_setup_hot_counters(zend_op_array *op_array)
        }
        ZEND_SET_FUNC_INFO(op_array, (void*)jit_extension);
 
-       if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) {
-               while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) {
-                       opline++;
+       if (JIT_G(hot_func)) {
+               if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) {
+                       while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) {
+                               opline++;
+                       }
                }
-       }
 
-       opline->handler = (const void*)zend_jit_func_hot_counter_handler;
+               opline->handler = (const void*)zend_jit_func_hot_counter_handler;
+       }
 
-       for (i = 0; i < cfg.blocks_count; i++) {
-               if ((cfg.blocks[i].flags & ZEND_BB_REACHABLE) &&
-                   (cfg.blocks[i].flags & ZEND_BB_LOOP_HEADER)) {
-                   op_array->opcodes[cfg.blocks[i].start].handler =
-                               (const void*)zend_jit_loop_hot_counter_handler;
+       if (JIT_G(hot_loop)) {
+               for (i = 0; i < cfg.blocks_count; i++) {
+                       if ((cfg.blocks[i].flags & ZEND_BB_REACHABLE) &&
+                           (cfg.blocks[i].flags & ZEND_BB_LOOP_HEADER)) {
+                           op_array->opcodes[cfg.blocks[i].start].handler =
+                                       (const void*)zend_jit_loop_hot_counter_handler;
+                       }
                }
        }
 
index 22f12ca78b8f74918ab96d2dd7a11a5716c1e5a6..22b01f4d2e14757e384dda376f0ad3e209fbf867 100644 (file)
@@ -2443,7 +2443,7 @@ static void zend_jit_trace_setup_ret_counter(const zend_op *opline, size_t offse
 {
        zend_op *next_opline = (zend_op*)(opline + 1);
 
-       if (!ZEND_OP_TRACE_INFO(next_opline, offset)->trace_flags) {
+       if (JIT_G(hot_return) && !ZEND_OP_TRACE_INFO(next_opline, offset)->trace_flags) {
                if (!ZEND_OP_TRACE_INFO(next_opline, offset)->counter) {
                        ZEND_OP_TRACE_INFO(next_opline, offset)->counter =
                                &zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM];
@@ -5056,7 +5056,7 @@ int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registers_buf
                        }
                        return 0;
                }
-       } else if (zend_jit_trace_exit_is_hot(trace_num, exit_num)) {
+       } else if (JIT_G(hot_side_exit) && zend_jit_trace_exit_is_hot(trace_num, exit_num)) {
                return zend_jit_trace_hot_side(execute_data, trace_num, exit_num);
        }
 
@@ -5086,7 +5086,6 @@ static int zend_jit_setup_hot_trace_counters(zend_op_array *op_array)
 {
        zend_op *opline;
        zend_jit_op_array_trace_extension *jit_extension;
-       zend_cfg cfg;
        uint32_t i;
 
        ZEND_ASSERT(zend_jit_func_trace_counter_handler != NULL);
@@ -5094,10 +5093,6 @@ static int zend_jit_setup_hot_trace_counters(zend_op_array *op_array)
        ZEND_ASSERT(zend_jit_loop_trace_counter_handler != NULL);
        ZEND_ASSERT(sizeof(zend_op_trace_info) == sizeof(zend_op));
 
-       if (zend_jit_build_cfg(op_array, &cfg) != SUCCESS) {
-               return FAILURE;
-       }
-
        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.num_args = -1;
@@ -5112,42 +5107,52 @@ static int zend_jit_setup_hot_trace_counters(zend_op_array *op_array)
        }
        ZEND_SET_FUNC_INFO(op_array, (void*)jit_extension);
 
-       opline = op_array->opcodes;
-       if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) {
-               while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) {
-                       opline++;
-               }
-       }
+       if (JIT_G(hot_loop)) {
+               zend_cfg cfg;
 
-       if (!(ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags & ZEND_JIT_TRACE_UNSUPPORTED)) {
-               /* function entry */
-               opline->handler = (const void*)zend_jit_func_trace_counter_handler;
-               ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter =
-                       &zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM];
-               ZEND_JIT_COUNTER_NUM = (ZEND_JIT_COUNTER_NUM + 1) % ZEND_HOT_COUNTERS_COUNT;
-               ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags |=
-                       ZEND_JIT_TRACE_START_ENTER;
-       }
+               if (zend_jit_build_cfg(op_array, &cfg) != SUCCESS) {
+                       return FAILURE;
+               }
 
-       for (i = 0; i < cfg.blocks_count; i++) {
-               if (cfg.blocks[i].flags & ZEND_BB_REACHABLE) {
-                       if (cfg.blocks[i].flags & ZEND_BB_LOOP_HEADER) {
-                               /* loop header */
-                               opline = op_array->opcodes + cfg.blocks[i].start;
-                               if (!(ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags & ZEND_JIT_TRACE_UNSUPPORTED)) {
-                                       opline->handler = (const void*)zend_jit_loop_trace_counter_handler;
-                                       if (!ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter) {
-                                               ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter =
-                                                       &zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM];
-                                               ZEND_JIT_COUNTER_NUM = (ZEND_JIT_COUNTER_NUM + 1) % ZEND_HOT_COUNTERS_COUNT;
+               for (i = 0; i < cfg.blocks_count; i++) {
+                       if (cfg.blocks[i].flags & ZEND_BB_REACHABLE) {
+                               if (cfg.blocks[i].flags & ZEND_BB_LOOP_HEADER) {
+                                       /* loop header */
+                                       opline = op_array->opcodes + cfg.blocks[i].start;
+                                       if (!(ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags & ZEND_JIT_TRACE_UNSUPPORTED)) {
+                                               opline->handler = (const void*)zend_jit_loop_trace_counter_handler;
+                                               if (!ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter) {
+                                                       ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter =
+                                                               &zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM];
+                                                       ZEND_JIT_COUNTER_NUM = (ZEND_JIT_COUNTER_NUM + 1) % ZEND_HOT_COUNTERS_COUNT;
+                                               }
+                                               ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags |=
+                                                       ZEND_JIT_TRACE_START_LOOP;
                                        }
-                                       ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags |=
-                                               ZEND_JIT_TRACE_START_LOOP;
                                }
                        }
                }
        }
 
+       if (JIT_G(hot_func)) {
+               opline = op_array->opcodes;
+               if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) {
+                       while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) {
+                               opline++;
+                       }
+               }
+
+               if (!ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags) {
+                       /* function entry */
+                       opline->handler = (const void*)zend_jit_func_trace_counter_handler;
+                       ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->counter =
+                               &zend_jit_hot_counters[ZEND_JIT_COUNTER_NUM];
+                       ZEND_JIT_COUNTER_NUM = (ZEND_JIT_COUNTER_NUM + 1) % ZEND_HOT_COUNTERS_COUNT;
+                       ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags |=
+                               ZEND_JIT_TRACE_START_ENTER;
+               }
+       }
+
        return SUCCESS;
 }
 
index a58c101080e3beacede19879d93af7a443dd09e6..f4e8d4811f7b4bfdb03f77e469d065e5d1ac27f2 100644 (file)
@@ -2246,7 +2246,7 @@ static int zend_jit_hybrid_hot_counter_stub(dasm_State **Dst, uint32_t cost)
 
 static int zend_jit_hybrid_func_hot_counter_stub(dasm_State **Dst)
 {
-       if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
+       if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_func)) {
                return 1;
        }
 
@@ -2258,7 +2258,7 @@ static int zend_jit_hybrid_func_hot_counter_stub(dasm_State **Dst)
 
 static int zend_jit_hybrid_loop_hot_counter_stub(dasm_State **Dst)
 {
-       if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
+       if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_loop)) {
                return 1;
        }
 
@@ -2303,7 +2303,7 @@ static int zend_jit_hybrid_trace_counter_stub(dasm_State **Dst, uint32_t cost)
 
 static int zend_jit_hybrid_func_trace_counter_stub(dasm_State **Dst)
 {
-       if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
+       if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_func)) {
                return 1;
        }
 
@@ -2315,7 +2315,7 @@ static int zend_jit_hybrid_func_trace_counter_stub(dasm_State **Dst)
 
 static int zend_jit_hybrid_ret_trace_counter_stub(dasm_State **Dst)
 {
-       if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
+       if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_return)) {
                return 1;
        }
 
@@ -2327,7 +2327,7 @@ static int zend_jit_hybrid_ret_trace_counter_stub(dasm_State **Dst)
 
 static int zend_jit_hybrid_loop_trace_counter_stub(dasm_State **Dst)
 {
-       if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID) {
+       if (zend_jit_vm_kind != ZEND_VM_KIND_HYBRID || !JIT_G(hot_loop)) {
                return 1;
        }
 
index 4a535591c0e37b262bc8949280072c3a0cdbc0d4..7ff085c0595246724493ce588eac700617a3d95c 100644 (file)
@@ -218,12 +218,12 @@ static ZEND_INI_MH(OnUpdateJitDebug)
 static ZEND_INI_MH(OnUpdateCounter)
 {
        zend_long val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
-       if (val > 0 && val < 256) {
+       if (val >= 0 && val < 256) {
                zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
                *p = val;
                return SUCCESS;
        }
-       zend_error(E_WARNING, "Invalid \"%s\" setting. Should be between 1 and 256", ZSTR_VAL(entry->name));
+       zend_error(E_WARNING, "Invalid \"%s\" setting. Should be between 0 and 256", ZSTR_VAL(entry->name));
        return FAILURE;
 }