From 499b25c3036cc6e61ab1b024ed77e105f3249ba4 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 22 Apr 2019 20:19:34 +0300 Subject: [PATCH] Fixed JIT for DEFINED opcode --- ext/opcache/jit/zend_jit_vm_helpers.c | 3 +- ext/opcache/jit/zend_jit_x86.dasc | 21 ++++++++++++-- ext/opcache/tests/jit/defined_001.phpt | 38 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 ext/opcache/tests/jit/defined_001.phpt diff --git a/ext/opcache/jit/zend_jit_vm_helpers.c b/ext/opcache/jit/zend_jit_vm_helpers.c index 0ddab1d84e..9681f1f2c4 100644 --- a/ext/opcache/jit/zend_jit_vm_helpers.c +++ b/ext/opcache/jit/zend_jit_vm_helpers.c @@ -238,8 +238,8 @@ static zend_always_inline int _zend_quick_get_constant( { #ifndef HAVE_GCC_GLOBAL_REGS zend_execute_data *execute_data = EG(current_execute_data); - const zend_op *opline = EX(opline); #endif + const zend_op *opline = EX(opline); zval *zv; zend_constant *c = NULL; @@ -260,6 +260,7 @@ static zend_always_inline int _zend_quick_get_constant( zend_throw_error(NULL, "Undefined constant '%s'", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))); ZVAL_UNDEF(EX_VAR(opline->result.var)); } + CACHE_PTR(opline->extended_value, ENCODE_SPECIAL_CACHE_NUM(zend_hash_num_elements(EG(zend_constants)))); return FAILURE; } diff --git a/ext/opcache/jit/zend_jit_x86.dasc b/ext/opcache/jit/zend_jit_x86.dasc index 9b47d8ffb7..fc618051f6 100644 --- a/ext/opcache/jit/zend_jit_x86.dasc +++ b/ext/opcache/jit/zend_jit_x86.dasc @@ -8237,8 +8237,24 @@ static int zend_jit_defined(dasm_State **Dst, const zend_op *opline, int b, int | mov r0, aword [r0 + opline->extended_value] | test r0, r0 | jz >1 + | test r0, 0x1 + | jnz >4 |.cold_code + |4: + | MEM_OP2_2_ZTS mov, FCARG1a, aword, executor_globals, zend_constants, FCARG1a + | shl r0, 1 + | cmp dword [FCARG1a + offsetof(HashTable, nNumOfElements)], eax + if (smart_branch) { + if (undefined_label != (uint32_t)-1) { + | jz =>undefined_label + } else { + | jz >3 + } + } else { + | jz >2 + } |1: + | SAVE_VALID_OPLINE opline | LOAD_ADDR FCARG1a, zv | EXT_CALL zend_jit_check_constant, r0 | test r0, r0 @@ -8255,9 +8271,7 @@ static int zend_jit_defined(dasm_State **Dst, const zend_op *opline, int b, int } } else { res_addr = zend_jit_decode_op(op_array, opline->result_type, opline->result, opline, NULL, -1); - | jnz >2 - | SET_ZVAL_TYPE_INFO res_addr, IS_TRUE - | jmp >3 + | jz >1 |2: | SET_ZVAL_TYPE_INFO res_addr, IS_FALSE | jmp >3 @@ -8268,6 +8282,7 @@ static int zend_jit_defined(dasm_State **Dst, const zend_op *opline, int b, int | jmp =>defined_label } } else { + |1: | SET_ZVAL_TYPE_INFO res_addr, IS_TRUE } |3: diff --git a/ext/opcache/tests/jit/defined_001.phpt b/ext/opcache/tests/jit/defined_001.phpt new file mode 100644 index 0000000000..45946dbc1d --- /dev/null +++ b/ext/opcache/tests/jit/defined_001.phpt @@ -0,0 +1,38 @@ +--TEST-- +JIT DEFINED: 001 +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit_buffer_size=1M +opcache.jit=1235 +--SKIPIF-- + +--FILE-- + +--EXPECT-- +ok -- 2.40.0