Skip to content

Commit dcf3892

Browse files
committed
Avoid useless SHM data duplication
1 parent 808da26 commit dcf3892

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

ext/opcache/zend_persist.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ static void zend_persist_zval(zval *z)
210210
if (new_ptr) {
211211
Z_ARR_P(z) = new_ptr;
212212
Z_TYPE_FLAGS_P(z) = 0;
213+
} else if (!ZCG(current_persistent_script)->corrupted
214+
&& zend_accel_in_shm(Z_ARR_P(z))) {
215+
/* pass */
213216
} else {
214217
Bucket *p;
215218

@@ -237,7 +240,8 @@ static void zend_persist_zval(zval *z)
237240
if (new_ptr) {
238241
Z_AST_P(z) = new_ptr;
239242
Z_TYPE_FLAGS_P(z) = 0;
240-
} else if (!zend_accel_in_shm(Z_AST_P(z))) {
243+
} else if (ZCG(current_persistent_script)->corrupted
244+
|| !zend_accel_in_shm(Z_AST_P(z))) {
241245
zend_ast_ref *old_ref = Z_AST_P(z);
242246
Z_AST_P(z) = zend_shared_memdup_put(Z_AST_P(z), sizeof(zend_ast_ref));
243247
zend_persist_ast(GC_AST(old_ref));
@@ -260,7 +264,8 @@ static HashTable *zend_persist_attributes(HashTable *attributes)
260264
uint32_t i;
261265
zval *v;
262266

263-
if (zend_accel_in_shm(attributes)) {
267+
if (!ZCG(current_persistent_script)->corrupted
268+
&& zend_accel_in_shm(attributes)) {
264269
return attributes;
265270
}
266271

@@ -792,6 +797,9 @@ static void zend_persist_class_constant(zval *zv)
792797
if (c) {
793798
Z_PTR_P(zv) = c;
794799
return;
800+
} else if (!ZCG(current_persistent_script)->corrupted
801+
&& zend_accel_in_shm(Z_PTR_P(zv))) {
802+
return;
795803
}
796804
c = Z_PTR_P(zv) = zend_shared_memdup_put(Z_PTR_P(zv), sizeof(zend_class_constant));
797805
zend_persist_zval(&c->value);

ext/opcache/zend_persist_calc.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ static void zend_persist_zval_calc(zval *z)
105105
}
106106
break;
107107
case IS_ARRAY:
108+
if (!ZCG(current_persistent_script)->corrupted
109+
&& zend_accel_in_shm(Z_ARR_P(z))) {
110+
return;
111+
}
108112
size = zend_shared_memdup_size(Z_ARR_P(z), sizeof(zend_array));
109113
if (size) {
110114
Bucket *p;
@@ -120,7 +124,8 @@ static void zend_persist_zval_calc(zval *z)
120124
}
121125
break;
122126
case IS_CONSTANT_AST:
123-
if (!zend_accel_in_shm(Z_AST_P(z))) {
127+
if (ZCG(current_persistent_script)->corrupted
128+
|| !zend_accel_in_shm(Z_AST_P(z))) {
124129
size = zend_shared_memdup_size(Z_AST_P(z), sizeof(zend_ast_ref));
125130
if (size) {
126131
ADD_SIZE(size);
@@ -137,7 +142,8 @@ static void zend_persist_zval_calc(zval *z)
137142
static void zend_persist_attributes_calc(HashTable *attributes)
138143
{
139144
if (!zend_shared_alloc_get_xlat_entry(attributes)
140-
&& !zend_accel_in_shm(attributes)) {
145+
&& (ZCG(current_persistent_script)->corrupted
146+
|| !zend_accel_in_shm(attributes))) {
141147
zend_attribute *attr;
142148
uint32_t i;
143149

@@ -352,6 +358,10 @@ static void zend_persist_class_constant_calc(zval *zv)
352358
zend_class_constant *c = Z_PTR_P(zv);
353359

354360
if (!zend_shared_alloc_get_xlat_entry(c)) {
361+
if (!ZCG(current_persistent_script)->corrupted
362+
&& zend_accel_in_shm(Z_PTR_P(zv))) {
363+
return;
364+
}
355365
zend_shared_alloc_register_xlat_entry(c, c);
356366
ADD_SIZE(sizeof(zend_class_constant));
357367
zend_persist_zval_calc(&c->value);

0 commit comments

Comments
 (0)