Skip to content

Commit 709e45d

Browse files
committed
Avoid unnecessary static_variables persistence
static_variables should be treated the same way as all other op_array components nowadays (only static_variables_ptr is special). There's no need to persist/serialize it is separately per shared op_array.
1 parent 994d419 commit 709e45d

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

ext/opcache/zend_file_cache.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -461,18 +461,10 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
461461
return;
462462
}
463463

464-
if (op_array->static_variables) {
465-
HashTable *ht;
466-
467-
SERIALIZE_PTR(op_array->static_variables);
468-
ht = op_array->static_variables;
469-
UNSERIALIZE_PTR(ht);
470-
zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval);
471-
}
472-
473464
if (op_array->scope) {
474465
if (UNEXPECTED(zend_shared_alloc_get_xlat_entry(op_array->opcodes))) {
475466
op_array->refcount = (uint32_t*)(intptr_t)-1;
467+
SERIALIZE_PTR(op_array->static_variables);
476468
SERIALIZE_PTR(op_array->literals);
477469
SERIALIZE_PTR(op_array->opcodes);
478470
SERIALIZE_PTR(op_array->arg_info);
@@ -490,6 +482,15 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
490482
zend_shared_alloc_register_xlat_entry(op_array->opcodes, op_array->opcodes);
491483
}
492484

485+
if (op_array->static_variables) {
486+
HashTable *ht;
487+
488+
SERIALIZE_PTR(op_array->static_variables);
489+
ht = op_array->static_variables;
490+
UNSERIALIZE_PTR(ht);
491+
zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval);
492+
}
493+
493494
if (op_array->literals) {
494495
zval *p, *end;
495496

@@ -1274,17 +1275,9 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
12741275
return;
12751276
}
12761277

1277-
if (op_array->static_variables) {
1278-
HashTable *ht;
1279-
1280-
UNSERIALIZE_PTR(op_array->static_variables);
1281-
ht = op_array->static_variables;
1282-
zend_file_cache_unserialize_hash(ht,
1283-
script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR);
1284-
}
1285-
12861278
if (op_array->refcount) {
12871279
op_array->refcount = NULL;
1280+
UNSERIALIZE_PTR(op_array->static_variables);
12881281
UNSERIALIZE_PTR(op_array->literals);
12891282
UNSERIALIZE_PTR(op_array->opcodes);
12901283
UNSERIALIZE_PTR(op_array->arg_info);
@@ -1300,6 +1293,15 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
13001293
return;
13011294
}
13021295

1296+
if (op_array->static_variables) {
1297+
HashTable *ht;
1298+
1299+
UNSERIALIZE_PTR(op_array->static_variables);
1300+
ht = op_array->static_variables;
1301+
zend_file_cache_unserialize_hash(ht,
1302+
script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR);
1303+
}
1304+
13031305
if (op_array->literals) {
13041306
zval *p, *end;
13051307

ext/opcache/zend_persist.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,12 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
480480
op_array->prototype = NULL;
481481
}
482482

483+
if (op_array->scope
484+
&& !(op_array->fn_flags & ZEND_ACC_CLOSURE)
485+
&& (op_array->scope->ce_flags & ZEND_ACC_CACHED)) {
486+
return;
487+
}
488+
483489
if (op_array->static_variables && !zend_accel_in_shm(op_array->static_variables)) {
484490
Bucket *p;
485491

@@ -495,12 +501,6 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
495501
GC_TYPE_INFO(op_array->static_variables) = GC_ARRAY | ((IS_ARRAY_IMMUTABLE|GC_NOT_COLLECTABLE) << GC_FLAGS_SHIFT);
496502
}
497503

498-
if (op_array->scope
499-
&& !(op_array->fn_flags & ZEND_ACC_CLOSURE)
500-
&& (op_array->scope->ce_flags & ZEND_ACC_CACHED)) {
501-
return;
502-
}
503-
504504
if (op_array->literals) {
505505
zval *p, *end;
506506

ext/opcache/zend_persist_calc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ static void zend_persist_op_array_calc_ex(zend_op_array *op_array)
203203
}
204204
}
205205

206+
if (op_array->scope
207+
&& !(op_array->fn_flags & ZEND_ACC_CLOSURE)
208+
&& (op_array->scope->ce_flags & ZEND_ACC_CACHED)) {
209+
return;
210+
}
211+
206212
if (op_array->static_variables && !zend_accel_in_shm(op_array->static_variables)) {
207213
if (!zend_shared_alloc_get_xlat_entry(op_array->static_variables)) {
208214
Bucket *p;
@@ -218,12 +224,6 @@ static void zend_persist_op_array_calc_ex(zend_op_array *op_array)
218224
}
219225
}
220226

221-
if (op_array->scope
222-
&& !(op_array->fn_flags & ZEND_ACC_CLOSURE)
223-
&& (op_array->scope->ce_flags & ZEND_ACC_CACHED)) {
224-
return;
225-
}
226-
227227
if (op_array->literals) {
228228
zval *p = op_array->literals;
229229
zval *end = p + op_array->last_literal;

0 commit comments

Comments
 (0)