com php-src: Eliminate hash lookup for immutable op_arrays: ext/opcache/jit/zend_jit_disasm_x86.c ext/opca che/jit/zend_jit_helpers.c
ext/opcache/jit/zend_jit _x86.dasc

From: Date: Mon, 01 Apr 2019 18:20:52 +0000
Subject: com php-src: Eliminate hash lookup for immutable op_arrays: ext/opcache/jit/zend_jit_disasm_x86.c ext/opca che/jit/zend_jit_helpers.c
ext/opcache/jit/zend_jit _x86.dasc
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-105454@lists.php.net to get a copy of this message
Commit: d196ec9b93805df1bc3e1446e834e42eada0eb8a Author: Dmitry Stogov <dmitry@zend.com> Mon, 1 Apr 2019 21:20:52 +0300 Parents: 6fccca54a20c34c972f0c98db17462a63189715e Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d196ec9b93805df1bc3e1446e834e42eada0eb8a Log: Eliminate hash lookup for immutable op_arrays Changed paths: M ext/opcache/jit/zend_jit_disasm_x86.c M ext/opcache/jit/zend_jit_helpers.c M ext/opcache/jit/zend_jit_x86.dasc Diff: diff --git a/ext/opcache/jit/zend_jit_disasm_x86.c b/ext/opcache/jit/zend_jit_disasm_x86.c index 59d147f..ef72548 100644 --- a/ext/opcache/jit/zend_jit_disasm_x86.c +++ b/ext/opcache/jit/zend_jit_disasm_x86.c @@ -391,8 +391,8 @@ static int zend_jit_disasm_init(void) zend_jit_disasm_add_symbol(#n, \ (uint64_t)(uintptr_t)n, sizeof(void*)); REGISTER_HELPER(memcmp); + REGISTER_HELPER(zend_jit_init_func_run_time_cache_helper); REGISTER_HELPER(zend_jit_find_func_helper); - REGISTER_HELPER(zend_jit_find_func_by_name_helper); REGISTER_HELPER(zend_jit_extend_stack_helper); REGISTER_HELPER(zend_jit_int_extend_stack_helper); REGISTER_HELPER(zend_jit_leave_nested_func_helper); diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index c2cdf3d..cca94c1 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -18,38 +18,41 @@ #include "Zend/zend_API.h" -static zend_function* ZEND_FASTCALL zend_jit_find_func_helper(zend_string *name) +static zend_never_inline zend_function* ZEND_FASTCALL _zend_jit_init_func_run_time_cache(zend_op_array *op_array) /* {{{ */ { - zval *func = zend_hash_find(EG(function_table), name); - zend_function *fbc; + void **run_time_cache; - if (UNEXPECTED(func == NULL)) { - zend_throw_error(NULL, "Call to undefined function %s()", ZSTR_VAL(name)); - return NULL; - } - fbc = Z_FUNC_P(func); - if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) { - void **run_time_cache = zend_arena_alloc(&CG(arena), fbc->op_array.cache_size); - memset(run_time_cache, 0, fbc->op_array.cache_size); - ZEND_MAP_PTR_SET(fbc->op_array.run_time_cache, run_time_cache); + run_time_cache = zend_arena_alloc(&CG(arena), op_array->cache_size); + memset(run_time_cache, 0, op_array->cache_size); + ZEND_MAP_PTR_SET(op_array->run_time_cache, run_time_cache); + return (zend_function*)op_array; +} +/* }}} */ + +static zend_never_inline ZEND_FASTCALL zend_op_array* zend_jit_init_func_run_time_cache_helper(zend_op_array *op_array) /* {{{ */ +{ + void **run_time_cache; + + if (!RUN_TIME_CACHE(op_array)) { + run_time_cache = zend_arena_alloc(&CG(arena), op_array->cache_size); + memset(run_time_cache, 0, op_array->cache_size); + ZEND_MAP_PTR_SET(op_array->run_time_cache, run_time_cache); } - return fbc; + return op_array; } +/* }}} */ -static zend_function* ZEND_FASTCALL zend_jit_find_func_by_name_helper(zend_string *name, zend_string *key) +static zend_function* ZEND_FASTCALL zend_jit_find_func_helper(zend_string *name) { - zval *func = zend_hash_find(EG(function_table), key); + zval *func = zend_hash_find_ex(EG(function_table), name, 1); zend_function *fbc; if (UNEXPECTED(func == NULL)) { - zend_throw_error(NULL, "Call to undefined function %s()", ZSTR_VAL(name)); return NULL; } fbc = Z_FUNC_P(func); if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) { - void **run_time_cache = zend_arena_alloc(&CG(arena), fbc->op_array.cache_size); - memset(run_time_cache, 0, fbc->op_array.cache_size); - ZEND_MAP_PTR_SET(fbc->op_array.run_time_cache, run_time_cache); + fbc = _zend_jit_init_func_run_time_cache(&fbc->op_array); } return fbc; } diff --git a/ext/opcache/jit/zend_jit_x86.dasc b/ext/opcache/jit/zend_jit_x86.dasc index e7c7b47..11435e7 100644 --- a/ext/opcache/jit/zend_jit_x86.dasc +++ b/ext/opcache/jit/zend_jit_x86.dasc @@ -2135,6 +2135,32 @@ static int zend_jit_not_obj_stub(dasm_State **Dst) return 1; } +static int zend_jit_undefined_function_stub(dasm_State **Dst) +{ + |->undefined_function: + | mov r0, aword EX->opline + |.if X64 + | xor CARG1, CARG1 + | LOAD_ADDR CARG2, "Call to undefined function %s()" + | movsxd CARG3, dword [r0 + offsetof(zend_op, op2.constant)] + | mov CARG3, aword [r0 + CARG3] + | add CARG3, offsetof(zend_string, val) + | EXT_CALL zend_throw_error, r0 + |.else + | sub r4, 4 + | mov r0, aword [r0 + offsetof(zend_op, op2.zv)] + | mov r0, aword [r0] + | add r0, offsetof(zend_string, val) + | push r0 + | push "Call to undefined function %s()" + | push 0 + | EXT_CALL zend_throw_error, r0 + | add r4, 16 + |.endif + | jmp ->exception_handler + return 1; +} + static int zend_jit_negative_shift_stub(dasm_State **Dst) { |->negative_shift: @@ -2428,6 +2454,7 @@ static const zend_jit_stub zend_jit_stubs[] = { JIT_STUB(undefined_index_ex), JIT_STUB(cannot_add_element_ex), JIT_STUB(not_obj), + JIT_STUB(undefined_function), JIT_STUB(negative_shift), JIT_STUB(mod_by_zero), JIT_STUB(double_one), @@ -7271,8 +7298,6 @@ static int zend_jit_init_fcall(dasm_State **Dst, const zend_op *opline, uint32_t /* recursive call */ | mov r0, EX->func } else { - zval *zv = RT_CONSTANT(opline, opline->op2); - | // if (CACHED_PTR(opline->result.num)) | mov r0, EX->run_time_cache | mov r0, aword [r0 + opline->result..num] @@ -7280,27 +7305,32 @@ static int zend_jit_init_fcall(dasm_State **Dst, const zend_op *opline, uint32_t | jz >1 |.cold_code |1: - | // SAVE_OPLINE(); - | SAVE_VALID_OPLINE opline - if (opline->opcode == ZEND_INIT_FCALL) { - | LOAD_ADDR FCARG1a, Z_STR_P(zv); - | EXT_CALL zend_jit_find_func_helper, r0 - } else if (opline->opcode == ZEND_INIT_FCALL_BY_NAME) { - | LOAD_ADDR FCARG1a, Z_STR_P(zv); - | LOAD_ADDR FCARG2a, Z_STR_P(zv + 1); - | EXT_CALL zend_jit_find_func_by_name_helper, r0 + if (func && func->type == ZEND_USER_FUNCTION && (func->op_array.fn_flags & ZEND_ACC_IMMUTABLE)) { + | LOAD_ADDR FCARG1a, func + | EXT_CALL zend_jit_init_func_run_time_cache_helper, r0 + | mov r1, EX->run_time_cache + | mov aword [r1 + opline->result.num], r0 + | jmp >3 } else { - ZEND_ASSERT(0); - } - if (opline->opcode != ZEND_INIT_FCALL) { - // TODO: INIT_FCALL may fail in some cases ??? + zval *zv = RT_CONSTANT(opline, opline->op2); + + if (opline->opcode == ZEND_INIT_FCALL) { + | LOAD_ADDR FCARG1a, Z_STR_P(zv); + } else if (opline->opcode == ZEND_INIT_FCALL_BY_NAME) { + | LOAD_ADDR FCARG1a, Z_STR_P(zv + 1); + } else { + ZEND_ASSERT(0); + } + | EXT_CALL zend_jit_find_func_helper, r0 + | // CACHE_PTR(opline->result.num, fbc); + | mov r1, EX->run_time_cache + | mov aword [r1 + opline->result.num], r0 | test r0, r0 - | jz ->exception_handler + | jnz >3 + | // SAVE_OPLINE(); + | SAVE_VALID_OPLINE opline + | jmp ->undefined_function } - | // CACHE_PTR(opline->result.num, fbc); - | mov r1, EX->run_time_cache - | mov aword [r1 + opline->result.num], r0 - | jmp >3 |.code |3: }

« previous php.cvs (#105454) next »