Skip to content

Commit ebb94af

Browse files
committed
Fixed tracing JIT for ASSIGN to typed reference
1 parent 272b887 commit ebb94af

File tree

3 files changed

+50
-29
lines changed

3 files changed

+50
-29
lines changed

ext/opcache/jit/zend_jit_helpers.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ static void ZEND_FASTCALL zend_jit_vm_stack_free_args_helper(zend_execute_data *
16321632
zend_vm_stack_free_args(call);
16331633
}
16341634

1635-
static zend_always_inline void zend_jit_assign_to_typed_ref(zend_reference *ref, zval *value, zend_uchar value_type)
1635+
static zend_always_inline void zend_jit_assign_to_typed_ref_helper(zend_reference *ref, zval *value, zend_uchar value_type)
16361636
{
16371637
zval variable;
16381638

@@ -1642,22 +1642,22 @@ static zend_always_inline void zend_jit_assign_to_typed_ref(zend_reference *ref,
16421642

16431643
static void ZEND_FASTCALL zend_jit_assign_const_to_typed_ref(zend_reference *ref, zval *value)
16441644
{
1645-
zend_jit_assign_to_typed_ref(ref, value, IS_CONST);
1645+
zend_jit_assign_to_typed_ref_helper(ref, value, IS_CONST);
16461646
}
16471647

16481648
static void ZEND_FASTCALL zend_jit_assign_tmp_to_typed_ref(zend_reference *ref, zval *value)
16491649
{
1650-
zend_jit_assign_to_typed_ref(ref, value, IS_TMP_VAR);
1650+
zend_jit_assign_to_typed_ref_helper(ref, value, IS_TMP_VAR);
16511651
}
16521652

16531653
static void ZEND_FASTCALL zend_jit_assign_var_to_typed_ref(zend_reference *ref, zval *value)
16541654
{
1655-
zend_jit_assign_to_typed_ref(ref, value, IS_VAR);
1655+
zend_jit_assign_to_typed_ref_helper(ref, value, IS_VAR);
16561656
}
16571657

16581658
static void ZEND_FASTCALL zend_jit_assign_cv_to_typed_ref(zend_reference *ref, zval *value)
16591659
{
1660-
zend_jit_assign_to_typed_ref(ref, value, IS_CV);
1660+
zend_jit_assign_to_typed_ref_helper(ref, value, IS_CV);
16611661
}
16621662

16631663

ext/opcache/jit/zend_jit_trace.c

+3
Original file line numberDiff line numberDiff line change
@@ -3341,6 +3341,9 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
33413341
if (!zend_jit_fetch_reference(&dasm_state, opline, orig_op1_type, &op1_info, &op1_addr, 0)) {
33423342
goto jit_failure;
33433343
}
3344+
if (!zend_jit_assign_to_typed_ref(&dasm_state, opline, op_array, opline->op2_type, op2_addr, 1)) {
3345+
goto jit_failure;
3346+
}
33443347
op1_def_addr = op1_addr;
33453348
} else {
33463349
USE_OP1_TRACE_TYPE();

ext/opcache/jit/zend_jit_x86.dasc

+42-24
Original file line numberDiff line numberDiff line change
@@ -5389,6 +5389,44 @@ static int zend_jit_simple_assign(dasm_State **Dst,
53895389
return 1;
53905390
}
53915391

5392+
static int zend_jit_assign_to_typed_ref(dasm_State **Dst,
5393+
const zend_op *opline,
5394+
const zend_op_array *op_array,
5395+
zend_uchar val_type,
5396+
zend_jit_addr val_addr,
5397+
zend_bool check_exception)
5398+
{
5399+
| // if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(variable_ptr)))) {
5400+
| cmp aword [FCARG1a + offsetof(zend_reference, sources.ptr)], 0
5401+
| jnz >2
5402+
|.cold_code
5403+
|2:
5404+
| LOAD_ZVAL_ADDR FCARG2a, val_addr
5405+
| SAVE_VALID_OPLINE opline, r0
5406+
if (val_type == IS_CONST) {
5407+
| EXT_CALL zend_jit_assign_const_to_typed_ref, r0
5408+
} else if (val_type == IS_TMP_VAR) {
5409+
| EXT_CALL zend_jit_assign_tmp_to_typed_ref, r0
5410+
} else if (val_type == IS_VAR) {
5411+
| EXT_CALL zend_jit_assign_var_to_typed_ref, r0
5412+
} else if (val_type == IS_CV) {
5413+
| EXT_CALL zend_jit_assign_cv_to_typed_ref, r0
5414+
} else {
5415+
ZEND_UNREACHABLE();
5416+
}
5417+
if (check_exception) {
5418+
| // if (UNEXPECTED(EG(exception) != NULL)) {
5419+
| MEM_OP2_1_ZTS cmp, aword, executor_globals, exception, 0, r0
5420+
| je >8 // END OF zend_jit_assign_to_variable()
5421+
| jmp ->exception_handler
5422+
} else {
5423+
| jmp >8
5424+
}
5425+
|.code
5426+
5427+
return 1;
5428+
}
5429+
53925430
static int zend_jit_assign_to_variable(dasm_State **Dst,
53935431
const zend_op *opline,
53945432
const zend_op_array *op_array,
@@ -5415,26 +5453,10 @@ static int zend_jit_assign_to_variable(dasm_State **Dst,
54155453
| IF_NOT_Z_TYPE, FCARG1a, IS_REFERENCE, >1
54165454
| // if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(variable_ptr)))) {
54175455
| GET_Z_PTR FCARG1a, FCARG1a
5418-
| cmp aword [FCARG1a + offsetof(zend_reference, sources.ptr)], 0
5419-
| jnz >2
5420-
| add FCARG1a, offsetof(zend_reference, val)
5421-
|.cold_code
5422-
|2:
5423-
| LOAD_ZVAL_ADDR FCARG2a, val_addr
5424-
| SAVE_VALID_OPLINE opline, r0
5425-
if (val_type == IS_CONST) {
5426-
| EXT_CALL zend_jit_assign_const_to_typed_ref, r0
5427-
} else if (val_type == IS_TMP_VAR) {
5428-
| EXT_CALL zend_jit_assign_tmp_to_typed_ref, r0
5429-
} else if (val_type == IS_VAR) {
5430-
| EXT_CALL zend_jit_assign_var_to_typed_ref, r0
5431-
} else if (val_type == IS_CV) {
5432-
| EXT_CALL zend_jit_assign_cv_to_typed_ref, r0
5433-
} else {
5434-
ZEND_UNREACHABLE();
5456+
if (!zend_jit_assign_to_typed_ref(Dst, opline, op_array, val_type, val_addr, check_exception)) {
5457+
return 0;
54355458
}
5436-
| jmp >8
5437-
|.code
5459+
| add FCARG1a, offsetof(zend_reference, val)
54385460
|1:
54395461
}
54405462
if (var_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) {
@@ -7878,7 +7900,7 @@ static int zend_jit_assign(dasm_State **Dst, const zend_op *opline, const zend_o
78787900
}
78797901

78807902
if (!zend_jit_assign_to_variable(Dst, opline, op_array, op1_addr, op1_info, op1_def_info, opline->op2_type, opline->op2, op2_addr, op2_info, res_addr,
7881-
may_throw && !(op1_info & MAY_BE_REF) && (op1_info & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_ARRAY)))) {
7903+
may_throw)) {
78827904
return 0;
78837905
}
78847906
if (!zend_jit_store_var_if_necessary_ex(Dst, opline->op1.var, op1_addr, op1_def_info, op1_use_addr, op1_info)) {
@@ -7890,10 +7912,6 @@ static int zend_jit_assign(dasm_State **Dst, const zend_op *opline, const zend_o
78907912
}
78917913
}
78927914

7893-
if (may_throw && (op1_info & MAY_BE_REF)) {
7894-
zend_jit_check_exception(Dst);
7895-
}
7896-
78977915
return 1;
78987916
}
78997917

0 commit comments

Comments
 (0)