Merge branch 'PHP-7.4'

* PHP-7.4:
  Reduce overhead of delayed early binding
This commit is contained in:
Dmitry Stogov 2019-06-25 14:21:23 +03:00
commit e4f4be1a05
5 changed files with 61 additions and 33 deletions

View File

@ -1140,12 +1140,26 @@ ZEND_API void zend_do_delayed_early_binding(const zend_op_array *op_array, uint3
while (opline_num != (uint32_t)-1) {
const zend_op *opline = &op_array->opcodes[opline_num];
zval *lcname = RT_CONSTANT(opline, opline->op1);
zend_class_entry *ce = zend_hash_find_ptr(EG(class_table), Z_STR_P(lcname + 1));
zend_string *lc_parent_name = Z_STR_P(RT_CONSTANT(opline, opline->op2));
zend_class_entry *parent_ce = zend_lookup_class_ex(ce->parent_name, lc_parent_name, 0);
zval *zv = zend_hash_find_ex(EG(class_table), Z_STR_P(lcname + 1), 1);
if (ce && parent_ce && zend_can_early_bind(ce, parent_ce)) {
do_bind_class(lcname, lc_parent_name);
if (zv) {
zend_class_entry *ce = Z_CE_P(zv);
zend_string *lc_parent_name = Z_STR_P(RT_CONSTANT(opline, opline->op2));
zend_class_entry *parent_ce = zend_hash_find_ex_ptr(EG(class_table), lc_parent_name, 1);
if (parent_ce && zend_can_early_bind(ce, parent_ce)) {
zv = zend_hash_set_bucket_key(EG(class_table), (Bucket*)zv, Z_STR_P(lcname));
if (UNEXPECTED(!zv)) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), ZSTR_VAL(ce->name));
} else {
ce->ce_flags |= ZEND_ACC_LINKED;
zend_do_inheritance(ce, parent_ce);
zend_build_properties_info_table(ce);
if ((ce->ce_flags & (ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) == ZEND_ACC_IMPLICIT_ABSTRACT_CLASS) {
zend_verify_abstract_class(ce);
}
}
}
}
opline_num = op_array->opcodes[opline_num].result.opline_num;
}

View File

@ -7136,16 +7136,23 @@ ZEND_VM_HANDLER(139, ZEND_DECLARE_CLASS, CONST, ANY)
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
ZEND_VM_HANDLER(145, ZEND_DECLARE_CLASS_DELAYED, CONST, ANY)
ZEND_VM_HANDLER(145, ZEND_DECLARE_CLASS_DELAYED, CONST, CONST)
{
USE_OPLINE
zval *zce, *orig_zce;
zval *lcname, *zv;
SAVE_OPLINE();
if ((zce = zend_hash_find_ex(EG(class_table), Z_STR_P(RT_CONSTANT(opline, opline->op1)), 1)) == NULL ||
((orig_zce = zend_hash_find_ex(EG(class_table), Z_STR_P(RT_CONSTANT(opline, opline->op1)+1), 1)) != NULL &&
Z_CE_P(zce) != Z_CE_P(orig_zce))) {
do_bind_class(RT_CONSTANT(opline, opline->op1), (OP2_TYPE == IS_CONST) ? Z_STR_P(RT_CONSTANT(opline, opline->op2)) : NULL);
lcname = RT_CONSTANT(opline, opline->op1);
zv = zend_hash_find_ex(EG(class_table), Z_STR_P(lcname + 1), 1);
if (zv) {
zend_class_entry *ce = Z_CE_P(zv);
zv = zend_hash_set_bucket_key(EG(class_table), (Bucket*)zv, Z_STR_P(lcname));
if (UNEXPECTED(!zv)) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), ZSTR_VAL(ce->name));
} else {
zend_do_link_class(ce, Z_STR_P(RT_CONSTANT(opline, opline->op2)));
}
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}

View File

@ -4021,20 +4021,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DECLARE_CLASS_SPEC_CONST_HANDL
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DECLARE_CLASS_DELAYED_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
USE_OPLINE
zval *zce, *orig_zce;
SAVE_OPLINE();
if ((zce = zend_hash_find_ex(EG(class_table), Z_STR_P(RT_CONSTANT(opline, opline->op1)), 1)) == NULL ||
((orig_zce = zend_hash_find_ex(EG(class_table), Z_STR_P(RT_CONSTANT(opline, opline->op1)+1), 1)) != NULL &&
Z_CE_P(zce) != Z_CE_P(orig_zce))) {
do_bind_class(RT_CONSTANT(opline, opline->op1), (opline->op2_type == IS_CONST) ? Z_STR_P(RT_CONSTANT(opline, opline->op2)) : NULL);
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_YIELD_FROM_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
USE_OPLINE
@ -6163,6 +6149,27 @@ array_key_exists_array:
}
/* No specialization for op_types (CONST|TMPVAR|UNUSED|CV, ANY) */
static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DECLARE_CLASS_DELAYED_SPEC_CONST_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
USE_OPLINE
zval *lcname, *zv;
SAVE_OPLINE();
lcname = RT_CONSTANT(opline, opline->op1);
zv = zend_hash_find_ex(EG(class_table), Z_STR_P(lcname + 1), 1);
if (zv) {
zend_class_entry *ce = Z_CE_P(zv);
zv = zend_hash_set_bucket_key(EG(class_table), (Bucket*)zv, Z_STR_P(lcname));
if (UNEXPECTED(!zv)) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), ZSTR_VAL(ce->name));
} else {
zend_do_link_class(ce, Z_STR_P(RT_CONSTANT(opline, opline->op2)));
}
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DECLARE_CONST_SPEC_CONST_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
USE_OPLINE
@ -55662,7 +55669,7 @@ ZEND_API void execute_ex(zend_execute_data *ex)
(void*)&&ZEND_NULL_LABEL,
(void*)&&ZEND_YIELD_FROM_SPEC_CV_LABEL,
(void*)&&ZEND_DECLARE_CONST_SPEC_CONST_CONST_LABEL,
(void*)&&ZEND_DECLARE_CLASS_DELAYED_SPEC_CONST_LABEL,
(void*)&&ZEND_DECLARE_CLASS_DELAYED_SPEC_CONST_CONST_LABEL,
(void*)&&ZEND_NULL_LABEL,
(void*)&&ZEND_NULL_LABEL,
(void*)&&ZEND_NULL_LABEL,
@ -57676,10 +57683,6 @@ zend_leave_helper_SPEC_LABEL:
VM_TRACE(ZEND_DECLARE_CLASS_SPEC_CONST)
ZEND_DECLARE_CLASS_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
HYBRID_BREAK();
HYBRID_CASE(ZEND_DECLARE_CLASS_DELAYED_SPEC_CONST):
VM_TRACE(ZEND_DECLARE_CLASS_DELAYED_SPEC_CONST)
ZEND_DECLARE_CLASS_DELAYED_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
HYBRID_BREAK();
HYBRID_CASE(ZEND_YIELD_FROM_SPEC_CONST):
VM_TRACE(ZEND_YIELD_FROM_SPEC_CONST)
ZEND_YIELD_FROM_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
@ -57904,6 +57907,10 @@ zend_leave_helper_SPEC_LABEL:
VM_TRACE(ZEND_ARRAY_KEY_EXISTS_SPEC_CONST_CONST)
ZEND_ARRAY_KEY_EXISTS_SPEC_CONST_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
HYBRID_BREAK();
HYBRID_CASE(ZEND_DECLARE_CLASS_DELAYED_SPEC_CONST_CONST):
VM_TRACE(ZEND_DECLARE_CLASS_DELAYED_SPEC_CONST_CONST)
ZEND_DECLARE_CLASS_DELAYED_SPEC_CONST_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
HYBRID_BREAK();
HYBRID_CASE(ZEND_DECLARE_CONST_SPEC_CONST_CONST):
VM_TRACE(ZEND_DECLARE_CONST_SPEC_CONST_CONST)
ZEND_DECLARE_CONST_SPEC_CONST_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
@ -65371,7 +65378,7 @@ void zend_vm_init(void)
ZEND_NULL_HANDLER,
ZEND_YIELD_FROM_SPEC_CV_HANDLER,
ZEND_DECLARE_CONST_SPEC_CONST_CONST_HANDLER,
ZEND_DECLARE_CLASS_DELAYED_SPEC_CONST_HANDLER,
ZEND_DECLARE_CLASS_DELAYED_SPEC_CONST_CONST_HANDLER,
ZEND_NULL_HANDLER,
ZEND_NULL_HANDLER,
ZEND_NULL_HANDLER,

View File

@ -1422,7 +1422,7 @@
_(2703, ZEND_YIELD_FROM_SPEC_VAR) \
_(2705, ZEND_YIELD_FROM_SPEC_CV) \
_(2706, ZEND_DECLARE_CONST_SPEC_CONST_CONST) \
_(2707, ZEND_DECLARE_CLASS_DELAYED_SPEC_CONST) \
_(2707, ZEND_DECLARE_CLASS_DELAYED_SPEC_CONST_CONST) \
_(2758, ZEND_ASSIGN_DIM_SPEC_VAR_CONST_OP_DATA_CONST) \
_(2759, ZEND_ASSIGN_DIM_SPEC_VAR_CONST_OP_DATA_TMP) \
_(2760, ZEND_ASSIGN_DIM_SPEC_VAR_CONST_OP_DATA_VAR) \

View File

@ -380,7 +380,7 @@ static uint32_t zend_vm_opcodes_flags[209] = {
0x00000003,
0x00000303,
0x00000000,
0x00000003,
0x00000303,
0x00000000,
0x00006701,
0x00060757,