From: Dmitry Stogov Date: Thu, 25 Jun 2020 10:23:43 +0000 (+0300) Subject: Cheaper exception checks X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1434983ad15e5313276c756bcc8651252c9ea88a;p=php Cheaper exception checks --- diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index 6e729fdc1b..9d68d6e71a 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -1227,18 +1227,19 @@ builtin_types: return 0; } -//static void ZEND_FASTCALL zend_jit_verify_arg_slow(zval *arg, const zend_op_array *op_array, uint32_t arg_num, zend_arg_info *arg_info, void **cache_slot) -static int ZEND_FASTCALL zend_jit_verify_arg_slow(zval *arg, zend_arg_info *arg_info) +static zend_bool ZEND_FASTCALL zend_jit_verify_arg_slow(zval *arg, zend_arg_info *arg_info) { zend_execute_data *execute_data = EG(current_execute_data); const zend_op *opline = EX(opline); void **cache_slot = CACHE_ADDR(opline->extended_value); + zend_bool ret; - if (UNEXPECTED(!zend_jit_verify_type_common(arg, arg_info, cache_slot))) { + ret = zend_jit_verify_type_common(arg, arg_info, cache_slot); + if (UNEXPECTED(!ret)) { zend_verify_arg_error(EX(func), arg_info, opline->op1.num, cache_slot, arg); return 0; } - return 1; + return ret; } static void ZEND_FASTCALL zend_jit_verify_return_slow(zval *arg, const zend_op_array *op_array, zend_arg_info *arg_info, void **cache_slot) diff --git a/ext/opcache/jit/zend_jit_internal.h b/ext/opcache/jit/zend_jit_internal.h index ab3a7a8e4a..046571ffdf 100644 --- a/ext/opcache/jit/zend_jit_internal.h +++ b/ext/opcache/jit/zend_jit_internal.h @@ -128,7 +128,7 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_func_counter_helper(ZEND_OPCODE_H ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_counter_helper(ZEND_OPCODE_HANDLER_ARGS); void ZEND_FASTCALL zend_jit_copy_extra_args_helper(EXECUTE_DATA_D); -void ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D); +zend_bool ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D); void ZEND_FASTCALL zend_jit_get_constant(const zval *key, uint32_t flags); int ZEND_FASTCALL zend_jit_check_constant(const zval *key); diff --git a/ext/opcache/jit/zend_jit_vm_helpers.c b/ext/opcache/jit/zend_jit_vm_helpers.c index 734a70ac10..028219f503 100644 --- a/ext/opcache/jit/zend_jit_vm_helpers.c +++ b/ext/opcache/jit/zend_jit_vm_helpers.c @@ -153,7 +153,7 @@ void ZEND_FASTCALL zend_jit_copy_extra_args_helper(EXECUTE_DATA_D) } } -void ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D) +zend_bool ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D) { zend_execute_data *call = (zend_execute_data *) opline; zend_function *fbc = call->func; @@ -176,7 +176,9 @@ void ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D) } zend_vm_stack_free_call_frame(call); + return 0; } + return 1; } ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_profile_helper(ZEND_OPCODE_HANDLER_ARGS) diff --git a/ext/opcache/jit/zend_jit_x86.dasc b/ext/opcache/jit/zend_jit_x86.dasc index 5cbe71ea69..8f9c442201 100644 --- a/ext/opcache/jit/zend_jit_x86.dasc +++ b/ext/opcache/jit/zend_jit_x86.dasc @@ -5420,9 +5420,9 @@ static int zend_jit_assign_dim(dasm_State **Dst, const zend_op *opline, const ze | SAVE_VALID_OPLINE opline, r0 | EXT_CALL zend_jit_prepare_assign_dim_ref, r0 | test r0, r0 - | jz ->exception_handler_undef | mov FCARG1a, r0 - | jmp >1 + | jne >1 + | jmp ->exception_handler_undef |.code |1: op1_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FCARG1a, 0); @@ -5622,9 +5622,9 @@ static int zend_jit_assign_dim_op(dasm_State **Dst, const zend_op *opline, const | SAVE_VALID_OPLINE opline, r0 | EXT_CALL zend_jit_prepare_assign_dim_ref, r0 | test r0, r0 - | jz ->exception_handler_undef | mov FCARG1a, r0 - | jmp >1 + | jne >1 + | jmp ->exception_handler_undef |.code |1: op1_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FCARG1a, 0); @@ -8413,10 +8413,10 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend | mov FCARG1a, RX } | EXT_CALL zend_jit_deprecated_helper, r0 - | MEM_OP2_1_ZTS cmp, aword, executor_globals, exception, 0, r0 - | jne ->exception_handler + | test al, al | mov r0, EX:RX->func // reload - | jmp >1 + | jne >1 + | jmp ->exception_handler |.code |1: } @@ -8425,8 +8425,8 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend | mov FCARG1a, RX } | EXT_CALL zend_jit_deprecated_helper, r0 - | MEM_OP2_1_ZTS cmp, aword, executor_globals, exception, 0, r0 - | jne ->exception_handler + | test al, al + | je ->exception_handler } } @@ -8706,10 +8706,10 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend | mov FCARG1a, RX } | EXT_CALL zend_jit_deprecated_helper, r0 - | MEM_OP2_1_ZTS cmp, aword, executor_globals, exception, 0, r0 - | jne ->exception_handler + | test al, al | mov r0, EX:RX->func // reload - | jmp >1 + | jne >1 + | jmp ->exception_handler |.code |1: } @@ -8718,8 +8718,8 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend | mov FCARG1a, RX } | EXT_CALL zend_jit_deprecated_helper, r0 - | MEM_OP2_1_ZTS cmp, aword, executor_globals, exception, 0, r0 - | jne ->exception_handler + | test al, al + | je ->exception_handler | mov r0, EX:RX->func // reload } } @@ -10551,11 +10551,16 @@ static int zend_jit_verify_arg_type(dasm_State **Dst, const zend_op *opline, zen | EXT_CALL zend_jit_verify_arg_slow, r0 if (check_exception) { - | test eax, eax - | jz ->exception_handler - } - - if (in_cold) { + | test al, al + if (in_cold) { + | jnz >1 + | jmp ->exception_handler + |.code + |1: + } else { + | jz ->exception_handler + } + } else if (in_cold) { | jmp >1 |.code |1: @@ -10686,18 +10691,12 @@ static int zend_jit_recv_init(dasm_State **Dst, const zend_op *opline, const zen if (!ZEND_TYPE_IS_SET(arg_info->type)) { break; } - if (!zend_jit_verify_arg_type(Dst, opline, arg_info, 0)) { + if (!zend_jit_verify_arg_type(Dst, opline, arg_info, may_throw)) { return 0; } } while (0); } - if (may_throw) { - if (!zend_jit_check_exception(Dst)) { - return 0; - } - } - if (JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE) { if (is_last) { | LOAD_IP_ADDR (opline + 1)