]> granicus.if.org Git - php/commitdiff
Use reference-counting instead of duplication and separation, if really necessary.
authorDmitry Stogov <dmitry@zend.com>
Thu, 18 Jan 2018 22:03:24 +0000 (01:03 +0300)
committerDmitry Stogov <dmitry@zend.com>
Thu, 18 Jan 2018 22:03:24 +0000 (01:03 +0300)
Zend/zend_compile.c
ext/opcache/Optimizer/block_pass.c
ext/opcache/Optimizer/optimize_func_calls.c
ext/opcache/Optimizer/sccp.c
ext/opcache/Optimizer/zend_optimizer.c

index a574de9db6561705a3a8ad079c0fda96820920b2..e6a34371a3a3311788ed9a3029e8d10f92a5a142 100644 (file)
@@ -5009,7 +5009,7 @@ void zend_compile_switch(zend_ast *ast) /* {{{ */
                        jumptable_type == IS_LONG ? ZEND_SWITCH_LONG : ZEND_SWITCH_STRING,
                        &expr_node, &jumptable_op);
                if (opline->op1_type == IS_CONST) {
-                       zval_copy_ctor(CT_CONSTANT(opline->op1));
+                       Z_TRY_ADDREF_P(CT_CONSTANT(opline->op1));
                }
                opnum_switch = opline - CG(active_op_array)->opcodes;
        }
@@ -5044,7 +5044,7 @@ void zend_compile_switch(zend_ast *ast) /* {{{ */
                                &expr_node, &cond_node);
                        SET_NODE(opline->result, &case_node);
                        if (opline->op1_type == IS_CONST) {
-                               zval_copy_ctor(CT_CONSTANT(opline->op1));
+                               Z_TRY_ADDREF_P(CT_CONSTANT(opline->op1));
                        }
 
                        jmpnz_opnums[i] = zend_emit_cond_jump(ZEND_JMPNZ, &case_node, 0);
index 376d2295b90fb2a8f483558adf3fdf76514cf988..6568bdc1b3266b539dcdbfe799842f14579a769b 100644 (file)
@@ -57,7 +57,7 @@ int zend_optimizer_get_persistent_constant(zend_string *name, zval *result, int
                if (c->flags & CONST_PERSISTENT) {
                        ZVAL_COPY_VALUE(result, &c->value);
                        if (copy) {
-                               zval_copy_ctor(result);
+                               Z_TRY_ADDREF_P(result);
                        }
                } else {
                        retval = 0;
@@ -189,7 +189,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
                                        MAKE_NOP(src);
                                } else {
                                        zval c;
-                                       ZVAL_DUP(&c, &ZEND_OP1_LITERAL(src));
+                                       ZVAL_COPY(&c, &ZEND_OP1_LITERAL(src));
                                        if (zend_optimizer_update_op1_const(op_array, opline, &c)) {
                                                zend_optimizer_remove_live_range(op_array, op1.var);
                                                VAR_SOURCE(op1) = NULL;
@@ -258,7 +258,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
                                znode_op op2 = opline->op2;
                                zval c;
 
-                               ZVAL_DUP(&c, &ZEND_OP1_LITERAL(src));
+                               ZVAL_COPY(&c, &ZEND_OP1_LITERAL(src));
                                if (zend_optimizer_update_op2_const(op_array, opline, &c)) {
                                        zend_optimizer_remove_live_range(op_array, op2.var);
                                        VAR_SOURCE(op2) = NULL;
@@ -1152,7 +1152,7 @@ static void zend_jmp_optimization(zend_basic_block *block, zend_op_array *op_arr
                                        *last_op = *target;
                                        if (last_op->op1_type == IS_CONST) {
                                                zval zv;
-                                               ZVAL_DUP(&zv, &ZEND_OP1_LITERAL(last_op));
+                                               ZVAL_COPY(&zv, &ZEND_OP1_LITERAL(last_op));
                                                last_op->op1.constant = zend_optimizer_add_literal(op_array, &zv);
                                        }
                                        DEL_SOURCE(block, block->successors[0]);
@@ -1169,7 +1169,7 @@ static void zend_jmp_optimization(zend_basic_block *block, zend_op_array *op_arr
                                        *last_op = *target;
                                        if (last_op->op1_type == IS_CONST) {
                                                zval zv;
-                                               ZVAL_DUP(&zv, &ZEND_OP1_LITERAL(last_op));
+                                               ZVAL_COPY(&zv, &ZEND_OP1_LITERAL(last_op));
                                                last_op->op1.constant = zend_optimizer_add_literal(op_array, &zv);
                                        }
                                        DEL_SOURCE(block, block->successors[0]);
index 2cf7c91f21a169e314f7475d1d3085c1ad7dec8d..2696a64879eb11f93fcf57fa3379a58b05084e18 100644 (file)
@@ -133,7 +133,7 @@ static void zend_try_inline_call(zend_op_array *op_array, zend_op *fcall, zend_o
                        if (RETURN_VALUE_USED(opline)) {
                                zval zv;
 
-                               ZVAL_DUP(&zv, RT_CONSTANT(ret_opline, ret_opline->op1));
+                               ZVAL_COPY(&zv, RT_CONSTANT(ret_opline, ret_opline->op1));
                                opline->opcode = ZEND_QM_ASSIGN;
                                opline->op1_type = IS_CONST;
                                opline->op1.constant = zend_optimizer_add_literal(op_array, &zv);
index cbfc6de6484918c831bdac96876f81643a02e334..07fdeee7089b0ac6d4eb9eab61798c814c00b5a3 100644 (file)
@@ -474,6 +474,7 @@ static inline int ct_eval_del_array_elem(zval *result, zval *key) {
 
 static inline int ct_eval_add_array_elem(zval *result, zval *value, zval *key) {
        if (!key) {
+               SEPARATE_ARRAY(result);
                if ((value = zend_hash_next_index_insert(Z_ARR_P(result), value))) {
                        Z_TRY_ADDREF_P(value);
                        return SUCCESS;
@@ -483,22 +484,28 @@ static inline int ct_eval_add_array_elem(zval *result, zval *value, zval *key) {
 
        switch (Z_TYPE_P(key)) {
                case IS_NULL:
+                       SEPARATE_ARRAY(result);
                        value = zend_hash_update(Z_ARR_P(result), ZSTR_EMPTY_ALLOC(), value);
                        break;
                case IS_FALSE:
+                       SEPARATE_ARRAY(result);
                        value = zend_hash_index_update(Z_ARR_P(result), 0, value);
                        break;
                case IS_TRUE:
+                       SEPARATE_ARRAY(result);
                        value = zend_hash_index_update(Z_ARR_P(result), 1, value);
                        break;
                case IS_LONG:
+                       SEPARATE_ARRAY(result);
                        value = zend_hash_index_update(Z_ARR_P(result), Z_LVAL_P(key), value);
                        break;
                case IS_DOUBLE:
+                       SEPARATE_ARRAY(result);
                        value = zend_hash_index_update(
                                Z_ARR_P(result), zend_dval_to_lval(Z_DVAL_P(key)), value);
                        break;
                case IS_STRING:
+                       SEPARATE_ARRAY(result);
                        value = zend_symtable_update(Z_ARR_P(result), Z_STR_P(key), value);
                        break;
                default:
@@ -1081,7 +1088,7 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
                                if (IS_PARTIAL_ARRAY(op1)) {
                                        dup_partial_array(&zv, op1);
                                } else {
-                                       ZVAL_DUP(&zv, op1);
+                                       ZVAL_COPY(&zv, op1);
                                }
 
                                if (!op2 && IS_PARTIAL_ARRAY(&zv)) {
@@ -1398,7 +1405,7 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
                                                        if (IS_PARTIAL_ARRAY(op1)) {
                                                                dup_partial_array(&zv, op1);
                                                        } else {
-                                                               ZVAL_DUP(&zv, op1);
+                                                               ZVAL_COPY(&zv, op1);
                                                        }
                                                }
 
index 58dff9d4f7e90cd74eeddf60cfd5bc7aad039e5f..70f45882be742f73ba2b7f5bd8f9f79bac4f680c 100644 (file)
@@ -49,7 +49,7 @@ void zend_optimizer_collect_constant(zend_optimizer_ctx *ctx, zval *name, zval*
                ctx->constants = zend_arena_alloc(&ctx->arena, sizeof(HashTable));
                zend_hash_init(ctx->constants, 16, NULL, zend_optimizer_zval_dtor_wrapper, 0);
        }
-       ZVAL_DUP(&val, value);
+       ZVAL_COPY(&val, value);
        zend_hash_add(ctx->constants, Z_STR_P(name), &val);
 }
 
@@ -194,7 +194,7 @@ int zend_optimizer_get_collected_constant(HashTable *constants, zval *name, zval
        zval *val;
 
        if ((val = zend_hash_find(constants, Z_STR_P(name))) != NULL) {
-               ZVAL_DUP(value, val);
+               ZVAL_COPY(value, val);
                return 1;
        }
        return 0;
@@ -619,7 +619,7 @@ int zend_optimizer_replace_by_const(zend_op_array *op_array,
                                                        m->op1_type == type &&
                                                        m->op1.var == var) {
                                                        zval v;
-                                                       ZVAL_DUP(&v, val);
+                                                       ZVAL_COPY(&v, val);
                                                        if (Z_TYPE(v) == IS_STRING) {
                                                                zend_string_hash_val(Z_STR(v));
                                                        }
@@ -677,7 +677,7 @@ int zend_optimizer_replace_by_const(zend_op_array *op_array,
                                                                if (m->opcode == ZEND_CASE) {
                                                                        m->opcode = ZEND_IS_EQUAL;
                                                                }
-                                                               ZVAL_DUP(&v, val);
+                                                               ZVAL_COPY(&v, val);
                                                                if (Z_TYPE(v) == IS_STRING) {
                                                                        zend_string_hash_val(Z_STR(v));
                                                                }