diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c index 3b7c9e1ec4682..60c6dd63a091c 100644 --- a/ext/opcache/jit/zend_jit.c +++ b/ext/opcache/jit/zend_jit.c @@ -209,6 +209,8 @@ ZEND_EXT_API void zend_jit_status(zval *ret) add_assoc_long(&stats, "buffer_size", 0); add_assoc_long(&stats, "buffer_free", 0); } + add_assoc_long(&stats, "function_compilation_successes", JIT_G(function_compilation_successes)); + add_assoc_long(&stats, "function_compilation_failures", JIT_G(function_compilation_failures)); add_assoc_zval(ret, "jit", &stats); } @@ -1981,6 +1983,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op op_array->function_name ? ZSTR_VAL(op_array->function_name) : "{main}", ZSTR_VAL(op_array->filename), op_array->line_start); } + JIT_G(function_compilation_failures)++; return FAILURE; } } @@ -2089,7 +2092,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op if (JIT_G(opt_flags) & (ZEND_JIT_REG_ALLOC_LOCAL|ZEND_JIT_REG_ALLOC_GLOBAL)) { zend_arena_release(&CG(arena), checkpoint); } - return SUCCESS; + goto jit_success; } zend_jit_label(&dasm_state, ssa->cfg.blocks_count + b); zend_jit_prologue(&dasm_state); @@ -2104,7 +2107,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op if (JIT_G(opt_flags) & (ZEND_JIT_REG_ALLOC_LOCAL|ZEND_JIT_REG_ALLOC_GLOBAL)) { zend_arena_release(&CG(arena), checkpoint); } - return SUCCESS; + goto jit_success; } else { zend_jit_label(&dasm_state, ssa->cfg.blocks_count + b); zend_jit_prologue(&dasm_state); @@ -2974,7 +2977,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op break; case ZEND_NEW: if (!zend_jit_handler(&dasm_state, opline, 1)) { - return 0; + goto jit_success; } if (opline->extended_value == 0 && (opline+1)->opcode == ZEND_DO_FCALL) { zend_class_entry *ce = NULL; @@ -3037,6 +3040,9 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op if (JIT_G(opt_flags) & (ZEND_JIT_REG_ALLOC_LOCAL|ZEND_JIT_REG_ALLOC_GLOBAL)) { zend_arena_release(&CG(arena), checkpoint); } + +jit_success: + JIT_G(function_compilation_successes)++; return SUCCESS; jit_failure: @@ -3046,6 +3052,8 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op if (JIT_G(opt_flags) & (ZEND_JIT_REG_ALLOC_LOCAL|ZEND_JIT_REG_ALLOC_GLOBAL)) { zend_arena_release(&CG(arena), checkpoint); } + + JIT_G(function_compilation_failures)++; return FAILURE; } diff --git a/ext/opcache/jit/zend_jit.h b/ext/opcache/jit/zend_jit.h index 406e0edece004..332464fd2a577 100644 --- a/ext/opcache/jit/zend_jit.h +++ b/ext/opcache/jit/zend_jit.h @@ -117,6 +117,9 @@ typedef struct _zend_jit_globals { uint8_t bad_root_cache_stop[ZEND_JIT_TRACE_BAD_ROOT_SLOTS]; uint32_t bad_root_slot; + uint32_t function_compilation_successes; + uint32_t function_compilation_failures; + uint8_t exit_counters[ZEND_JIT_TRACE_MAX_EXIT_COUNTERS]; } zend_jit_globals; diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c index e207aa35d13fc..82cbd864ee005 100644 --- a/ext/opcache/jit/zend_jit_trace.c +++ b/ext/opcache/jit/zend_jit_trace.c @@ -5595,6 +5595,8 @@ static void zend_jit_trace_init_caches(void) memset(JIT_G(bad_root_cache_count), 0, sizeof(JIT_G(bad_root_cache_count))); memset(JIT_G(bad_root_cache_stop), 0, sizeof(JIT_G(bad_root_cache_count))); JIT_G(bad_root_slot) = 0; + JIT_G(function_compilation_successes) = 0; + JIT_G(function_compilation_failures) = 0; memset(JIT_G(exit_counters), 0, sizeof(JIT_G(exit_counters))); } diff --git a/ext/opcache/tests/jit/opcache_get_status.phpt b/ext/opcache/tests/jit/opcache_get_status.phpt new file mode 100644 index 0000000000000..53f9ea69f5e21 --- /dev/null +++ b/ext/opcache/tests/jit/opcache_get_status.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test JIT information in opcache_get_status +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit_buffer_size=1M +opcache.protect_memory=1 +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +array(9) { + ["enabled"]=> + bool(true) + ["on"]=> + bool(true) + ["kind"]=> + int(0) + ["opt_level"]=> + int(5) + ["opt_flags"]=> + int(6) + ["buffer_size"]=> + int(%d) + ["buffer_free"]=> + int(%d) + ["function_compilation_successes"]=> + int(1) + ["function_compilation_failures"]=> + int(0) +}