]> granicus.if.org Git - php/commitdiff
Cheaper exception checks
authorDmitry Stogov <dmitry@zend.com>
Thu, 25 Jun 2020 10:23:43 +0000 (13:23 +0300)
committerDmitry Stogov <dmitry@zend.com>
Thu, 25 Jun 2020 10:23:43 +0000 (13:23 +0300)
ext/opcache/jit/zend_jit_helpers.c
ext/opcache/jit/zend_jit_internal.h
ext/opcache/jit/zend_jit_vm_helpers.c
ext/opcache/jit/zend_jit_x86.dasc

index 6e729fdc1b6efff9bacbb783476b4ccae3a88089..9d68d6e71aeb007a26180be5c7abc855e32d4ffd 100644 (file)
@@ -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)
index ab3a7a8e4ad246684eb1e63d69cb75a1ea2d37ac..046571ffdfbd274eb7571ebc5942a94aeb0b4323 100644 (file)
@@ -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);
index 734a70ac10c1d96eaca3f4c796e55c949585f852..028219f5030c729c634c9efab030bc5c2e66cf06 100644 (file)
@@ -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)
index 5cbe71ea690378a56c5dda73e8435f53a519182d..8f9c4422010a1625bb09f0db11ab8c71a684dc34 100644 (file)
@@ -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)