]> granicus.if.org Git - php/commitdiff
Avoid useless SHM data duplication
authorDmitry Stogov <dmitry@zend.com>
Thu, 11 Feb 2021 13:51:08 +0000 (16:51 +0300)
committerDmitry Stogov <dmitry@zend.com>
Thu, 11 Feb 2021 13:51:08 +0000 (16:51 +0300)
ext/opcache/zend_persist.c
ext/opcache/zend_persist_calc.c

index 139bac438b3cf1b847c03e269004f75f9ebb438b..e5aad26133fac9d628e6799696ddace96e803bca 100644 (file)
@@ -210,6 +210,9 @@ static void zend_persist_zval(zval *z)
                        if (new_ptr) {
                                Z_ARR_P(z) = new_ptr;
                                Z_TYPE_FLAGS_P(z) = 0;
+                       } else if (!ZCG(current_persistent_script)->corrupted
+                        && zend_accel_in_shm(Z_ARR_P(z))) {
+                               /* pass */
                        } else {
                                Bucket *p;
 
@@ -237,7 +240,8 @@ static void zend_persist_zval(zval *z)
                        if (new_ptr) {
                                Z_AST_P(z) = new_ptr;
                                Z_TYPE_FLAGS_P(z) = 0;
-                       } else if (!zend_accel_in_shm(Z_AST_P(z))) {
+                       } else if (ZCG(current_persistent_script)->corrupted
+                        || !zend_accel_in_shm(Z_AST_P(z))) {
                                zend_ast_ref *old_ref = Z_AST_P(z);
                                Z_AST_P(z) = zend_shared_memdup_put(Z_AST_P(z), sizeof(zend_ast_ref));
                                zend_persist_ast(GC_AST(old_ref));
@@ -260,7 +264,8 @@ static HashTable *zend_persist_attributes(HashTable *attributes)
                uint32_t i;
                zval *v;
 
-               if (zend_accel_in_shm(attributes)) {
+               if (!ZCG(current_persistent_script)->corrupted
+                && zend_accel_in_shm(attributes)) {
                        return attributes;
                }
 
@@ -792,6 +797,9 @@ static void zend_persist_class_constant(zval *zv)
        if (c) {
                Z_PTR_P(zv) = c;
                return;
+       } else if (!ZCG(current_persistent_script)->corrupted
+        && zend_accel_in_shm(Z_PTR_P(zv))) {
+               return;
        }
        c = Z_PTR_P(zv) = zend_shared_memdup_put(Z_PTR_P(zv), sizeof(zend_class_constant));
        zend_persist_zval(&c->value);
index 5728414eec55e1a98445d6b9c6c0a1086bbc7ba6..d708758a338ddc2ffc2603b4182dc71e2abf1a8a 100644 (file)
@@ -105,6 +105,10 @@ static void zend_persist_zval_calc(zval *z)
                        }
                        break;
                case IS_ARRAY:
+                       if (!ZCG(current_persistent_script)->corrupted
+                        && zend_accel_in_shm(Z_ARR_P(z))) {
+                               return;
+                       }
                        size = zend_shared_memdup_size(Z_ARR_P(z), sizeof(zend_array));
                        if (size) {
                                Bucket *p;
@@ -120,7 +124,8 @@ static void zend_persist_zval_calc(zval *z)
                        }
                        break;
                case IS_CONSTANT_AST:
-                       if (!zend_accel_in_shm(Z_AST_P(z))) {
+                       if (ZCG(current_persistent_script)->corrupted
+                        || !zend_accel_in_shm(Z_AST_P(z))) {
                                size = zend_shared_memdup_size(Z_AST_P(z), sizeof(zend_ast_ref));
                                if (size) {
                                        ADD_SIZE(size);
@@ -137,7 +142,8 @@ static void zend_persist_zval_calc(zval *z)
 static void zend_persist_attributes_calc(HashTable *attributes)
 {
        if (!zend_shared_alloc_get_xlat_entry(attributes)
-        && !zend_accel_in_shm(attributes)) {
+        && (ZCG(current_persistent_script)->corrupted
+         || !zend_accel_in_shm(attributes))) {
                zend_attribute *attr;
                uint32_t i;
 
@@ -352,6 +358,10 @@ static void zend_persist_class_constant_calc(zval *zv)
        zend_class_constant *c = Z_PTR_P(zv);
 
        if (!zend_shared_alloc_get_xlat_entry(c)) {
+               if (!ZCG(current_persistent_script)->corrupted
+                && zend_accel_in_shm(Z_PTR_P(zv))) {
+                       return;
+               }
                zend_shared_alloc_register_xlat_entry(c, c);
                ADD_SIZE(sizeof(zend_class_constant));
                zend_persist_zval_calc(&c->value);