Skip to content

Commit

Permalink
Cheaper exception checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Jun 25, 2020
1 parent 47cf18b commit 1434983
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
9 changes: 5 additions & 4 deletions ext/opcache/jit/zend_jit_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1227,18 +1227,19 @@ static zend_always_inline zend_bool zend_jit_verify_type_common(zval *arg, zend_
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)
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/zend_jit_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion ext/opcache/jit/zend_jit_vm_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
51 changes: 25 additions & 26 deletions ext/opcache/jit/zend_jit_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
}
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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:
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1434983

Please sign in to comment.