Skip to content

Commit 97bcede

Browse files
committed
Adjusted Opcache to PHP 8.
1 parent 048bfa4 commit 97bcede

File tree

3 files changed

+74
-106
lines changed

3 files changed

+74
-106
lines changed

ext/opcache/zend_file_cache.c

Lines changed: 29 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,25 @@ static int zend_file_cache_flock(int fd, int type)
158158
} \
159159
} while (0)
160160

161+
#define SERIALIZE_ATTRIBUTES(attr) do { \
162+
if ((attr) && !IS_SERIALIZED(attr)) { \
163+
HashTable *ht; \
164+
SERIALIZE_PTR(attr); \
165+
ht = (attr); \
166+
UNSERIALIZE_PTR(ht); \
167+
zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval); \
168+
} \
169+
} while (0)
170+
171+
#define UNSERIALIZE_ATTRIBUTES(attr) do { \
172+
if ((attr) && !IS_UNSERIALIZED(attr)) { \
173+
HashTable *ht; \
174+
UNSERIALIZE_PTR(attr); \
175+
ht = (attr); \
176+
zend_file_cache_unserialize_hash(ht, script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR); \
177+
} \
178+
} while (0)
179+
161180
static const uint32_t uninitialized_bucket[-HT_MIN_MASK] =
162181
{HT_INVALID_IDX, HT_INVALID_IDX};
163182

@@ -421,14 +440,7 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
421440
SERIALIZE_PTR(op_array->live_range);
422441
SERIALIZE_PTR(op_array->scope);
423442
SERIALIZE_STR(op_array->doc_comment);
424-
if (op_array->attributes && !IS_SERIALIZED(op_array->attributes)) {
425-
HashTable *ht;
426-
427-
SERIALIZE_PTR(op_array->attributes);
428-
ht = op_array->attributes;
429-
UNSERIALIZE_PTR(ht);
430-
zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval);
431-
}
443+
SERIALIZE_ATTRIBUTES(op_array->attributes);
432444
SERIALIZE_PTR(op_array->try_catch_array);
433445
SERIALIZE_PTR(op_array->prototype);
434446
return;
@@ -555,6 +567,7 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
555567
SERIALIZE_PTR(op_array->live_range);
556568
SERIALIZE_PTR(op_array->scope);
557569
SERIALIZE_STR(op_array->doc_comment);
570+
SERIALIZE_ATTRIBUTES(op_array->attributes);
558571
SERIALIZE_PTR(op_array->try_catch_array);
559572
SERIALIZE_PTR(op_array->prototype);
560573

@@ -599,15 +612,7 @@ static void zend_file_cache_serialize_prop_info(zval *zv,
599612
if (prop->doc_comment) {
600613
SERIALIZE_STR(prop->doc_comment);
601614
}
602-
603-
if (prop->attributes) {
604-
HashTable *ht;
605-
606-
SERIALIZE_PTR(prop->attributes);
607-
ht = prop->attributes;
608-
UNSERIALIZE_PTR(ht);
609-
zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval);
610-
}
615+
SERIALIZE_ATTRIBUTES(prop->attributes);
611616

612617
zend_file_cache_serialize_type(&prop->type, script, info, buf);
613618
}
@@ -636,14 +641,7 @@ static void zend_file_cache_serialize_class_constant(zval *z
636641
SERIALIZE_STR(c->doc_comment);
637642
}
638643

639-
if (c->attributes) {
640-
HashTable *ht;
641-
642-
SERIALIZE_PTR(c->attributes);
643-
ht = c->attributes;
644-
UNSERIALIZE_PTR(ht);
645-
zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval);
646-
}
644+
SERIALIZE_ATTRIBUTES(c->attributes);
647645
}
648646
}
649647
}
@@ -701,14 +699,7 @@ static void zend_file_cache_serialize_class(zval *zv,
701699
zend_file_cache_serialize_hash(&ce->constants_table, script, info, buf, zend_file_cache_serialize_class_constant);
702700
SERIALIZE_STR(ce->info.user.filename);
703701
SERIALIZE_STR(ce->info.user.doc_comment);
704-
if (ce->info.user.attributes && !IS_SERIALIZED(ce->info.user.attributes)) {
705-
HashTable *ht;
706-
707-
SERIALIZE_PTR(ce->info.user.attributes);
708-
ht = ce->info.user.attributes;
709-
UNSERIALIZE_PTR(ht);
710-
zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval);
711-
}
702+
SERIALIZE_ATTRIBUTES(ce->info.user.attributes);
712703
zend_file_cache_serialize_hash(&ce->properties_info, script, info, buf, zend_file_cache_serialize_prop_info);
713704

714705
if (ce->properties_info_table) {
@@ -1174,6 +1165,7 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
11741165
UNSERIALIZE_PTR(op_array->live_range);
11751166
UNSERIALIZE_PTR(op_array->scope);
11761167
UNSERIALIZE_STR(op_array->doc_comment);
1168+
UNSERIALIZE_ATTRIBUTES(op_array->attributes);
11771169
UNSERIALIZE_PTR(op_array->try_catch_array);
11781170
UNSERIALIZE_PTR(op_array->prototype);
11791171
return;
@@ -1289,14 +1281,7 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
12891281
UNSERIALIZE_PTR(op_array->live_range);
12901282
UNSERIALIZE_PTR(op_array->scope);
12911283
UNSERIALIZE_STR(op_array->doc_comment);
1292-
if (op_array->attributes && !IS_UNSERIALIZED(op_array->attributes)) {
1293-
HashTable *ht;
1294-
1295-
UNSERIALIZE_PTR(op_array->attributes);
1296-
ht = op_array->attributes;
1297-
zend_file_cache_unserialize_hash(ht,
1298-
script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR);
1299-
}
1284+
UNSERIALIZE_ATTRIBUTES(op_array->attributes);
13001285
UNSERIALIZE_PTR(op_array->try_catch_array);
13011286
UNSERIALIZE_PTR(op_array->prototype);
13021287

@@ -1350,14 +1335,7 @@ static void zend_file_cache_unserialize_prop_info(zval *zv,
13501335
if (prop->doc_comment) {
13511336
UNSERIALIZE_STR(prop->doc_comment);
13521337
}
1353-
if (prop->attributes && !IS_UNSERIALIZED(prop->attributes)) {
1354-
HashTable *ht;
1355-
1356-
UNSERIALIZE_PTR(prop->attributes);
1357-
ht = prop->attributes;
1358-
zend_file_cache_unserialize_hash(ht,
1359-
script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR);
1360-
}
1338+
UNSERIALIZE_ATTRIBUTES(prop->attributes);
13611339
zend_file_cache_unserialize_type(&prop->type, script, buf);
13621340
}
13631341
}
@@ -1382,14 +1360,7 @@ static void zend_file_cache_unserialize_class_constant(zval *
13821360
if (c->doc_comment) {
13831361
UNSERIALIZE_STR(c->doc_comment);
13841362
}
1385-
if (c->attributes && !IS_UNSERIALIZED(c->attributes)) {
1386-
HashTable *ht;
1387-
1388-
UNSERIALIZE_PTR(c->attributes);
1389-
ht = c->attributes;
1390-
zend_file_cache_unserialize_hash(ht,
1391-
script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR);
1392-
}
1363+
UNSERIALIZE_ATTRIBUTES(c->attributes);
13931364
}
13941365
}
13951366
}
@@ -1444,14 +1415,7 @@ static void zend_file_cache_unserialize_class(zval *zv,
14441415
script, buf, zend_file_cache_unserialize_class_constant, NULL);
14451416
UNSERIALIZE_STR(ce->info.user.filename);
14461417
UNSERIALIZE_STR(ce->info.user.doc_comment);
1447-
if (ce->info.user.attributes && !IS_UNSERIALIZED(ce->info.user.attributes)) {
1448-
HashTable *ht;
1449-
1450-
UNSERIALIZE_PTR(ce->info.user.attributes);
1451-
ht = ce->info.user.attributes;
1452-
zend_file_cache_unserialize_hash(ht,
1453-
script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR);
1454-
}
1418+
UNSERIALIZE_ATTRIBUTES(ce->info.user.attributes);
14551419
zend_file_cache_unserialize_hash(&ce->properties_info,
14561420
script, buf, zend_file_cache_unserialize_prop_info, NULL);
14571421

ext/opcache/zend_persist.c

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@
7676
} \
7777
} while (0)
7878

79+
#define zend_persist_attributes(attr) do { \
80+
HashTable *ptr = zend_shared_alloc_get_xlat_entry(attr); \
81+
if (ptr) { \
82+
(attr) = ptr; \
83+
} else { \
84+
Bucket *p; \
85+
zend_hash_persist(attr); \
86+
ZEND_HASH_FOREACH_BUCKET((attr), p) { \
87+
if (p->key) { \
88+
zend_accel_store_interned_string(p->key); \
89+
} \
90+
zend_persist_zval(&p->val); \
91+
} ZEND_HASH_FOREACH_END(); \
92+
(attr) = zend_shared_memdup_put_free((attr), sizeof(HashTable)); \
93+
GC_SET_REFCOUNT((attr), 2); \
94+
GC_TYPE_INFO(attr) = IS_ARRAY | (IS_ARRAY_IMMUTABLE << GC_FLAGS_SHIFT); \
95+
} \
96+
} while (0)
97+
7998
typedef void (*zend_persist_func_t)(zval*);
8099

81100
static void zend_persist_zval(zval *z);
@@ -369,6 +388,9 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
369388
op_array->doc_comment = NULL;
370389
}
371390
}
391+
if (op_array->attributes) {
392+
zend_persist_attributes(op_array->attributes);
393+
}
372394

373395
if (op_array->try_catch_array) {
374396
op_array->try_catch_array = zend_shared_alloc_get_xlat_entry(op_array->try_catch_array);
@@ -551,18 +573,7 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
551573
}
552574

553575
if (op_array->attributes) {
554-
if (already_stored) {
555-
op_array->attributes = zend_shared_alloc_get_xlat_entry(op_array->attributes);
556-
ZEND_ASSERT(op_array->attributes != NULL);
557-
} else {
558-
zend_hash_persist(op_array->attributes, zend_persist_zval);
559-
zend_accel_store(op_array->attributes, sizeof(HashTable));
560-
/* make immutable array */
561-
GC_REFCOUNT(op_array->attributes) = 2;
562-
GC_TYPE_INFO(op_array->attributes) = IS_ARRAY | (IS_ARRAY_IMMUTABLE << 8);
563-
op_array->attributes->u.flags |= HASH_FLAG_STATIC_KEYS;
564-
op_array->attributes->u.flags &= ~HASH_FLAG_APPLY_PROTECTION;
565-
}
576+
zend_persist_attributes(op_array->attributes);
566577
}
567578

568579
if (op_array->try_catch_array) {
@@ -700,13 +711,7 @@ static void zend_persist_property_info(zval *zv)
700711
}
701712
}
702713
if (prop->attributes) {
703-
zend_hash_persist(prop->attributes, zend_persist_zval);
704-
zend_accel_store(prop->attributes, sizeof(HashTable));
705-
/* make immutable array */
706-
GC_REFCOUNT(prop->attributes) = 2;
707-
GC_TYPE_INFO(prop->attributes) = IS_ARRAY | (IS_ARRAY_IMMUTABLE << 8);
708-
prop->attributes->u.flags |= HASH_FLAG_STATIC_KEYS;
709-
prop->attributes->u.flags &= ~HASH_FLAG_APPLY_PROTECTION;
714+
zend_persist_attributes(prop->attributes);
710715
}
711716
zend_persist_type(&prop->type);
712717
}
@@ -748,13 +753,7 @@ static void zend_persist_class_constant(zval *zv)
748753
}
749754
}
750755
if (c->attributes) {
751-
zend_hash_persist(c->attributes, zend_persist_zval);
752-
zend_accel_store(c->attributes, sizeof(HashTable));
753-
/* make immutable array */
754-
GC_REFCOUNT(c->attributes) = 2;
755-
GC_TYPE_INFO(c->attributes) = IS_ARRAY | (IS_ARRAY_IMMUTABLE << 8);
756-
c->attributes->u.flags |= HASH_FLAG_STATIC_KEYS;
757-
c->attributes->u.flags &= ~HASH_FLAG_APPLY_PROTECTION;
756+
zend_persist_attributes(c->attributes);
758757
}
759758
}
760759

@@ -843,13 +842,7 @@ static void zend_persist_class_entry(zval *zv)
843842
}
844843
}
845844
if (ce->info.user.attributes) {
846-
zend_hash_persist(ce->info.user.attributes, zend_persist_zval);
847-
zend_accel_store(ce->info.user.attributes, sizeof(HashTable));
848-
/* make immutable array */
849-
GC_REFCOUNT(ce->info.user.attributes) = 2;
850-
GC_TYPE_INFO(ce->info.user.attributes) = IS_ARRAY | (IS_ARRAY_IMMUTABLE << 8);
851-
ce->info.user.attributes->u.flags |= HASH_FLAG_STATIC_KEYS;
852-
ce->info.user.attributes->u.flags &= ~HASH_FLAG_APPLY_PROTECTION;
845+
zend_persist_attributes(ce->info.user.attributes);
853846
}
854847
zend_hash_persist(&ce->properties_info);
855848
ZEND_HASH_FOREACH_BUCKET(&ce->properties_info, p) {

ext/opcache/zend_persist_calc.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@
5353
} \
5454
} while (0)
5555

56+
#define zend_persist_attributes_calc(attr) do { \
57+
if (!zend_shared_alloc_get_xlat_entry(attr)) { \
58+
Bucket *p; \
59+
zend_shared_alloc_register_xlat_entry((attr), (attr)); \
60+
ADD_SIZE(sizeof(HashTable)); \
61+
zend_hash_persist_calc(attr); \
62+
ZEND_HASH_FOREACH_BUCKET((attr), p) { \
63+
if (p->key) { \
64+
ADD_INTERNED_STRING(p->key); \
65+
} \
66+
zend_persist_zval_calc(&p->val); \
67+
} ZEND_HASH_FOREACH_END(); \
68+
} \
69+
} while (0)
70+
5671
static void zend_persist_zval_calc(zval *z);
5772

5873
static void zend_hash_persist_calc(HashTable *ht)
@@ -256,8 +271,7 @@ static void zend_persist_op_array_calc_ex(zend_op_array *op_array)
256271
}
257272

258273
if (op_array->attributes) {
259-
ADD_DUP_SIZE(op_array->attributes, sizeof(HashTable));
260-
zend_hash_persist_calc(op_array->attributes, zend_persist_zval_calc);
274+
zend_persist_attributes_calc(op_array->attributes);
261275
}
262276

263277
if (op_array->try_catch_array) {
@@ -329,8 +343,7 @@ static void zend_persist_property_info_calc(zval *zv)
329343
ADD_STRING(prop->doc_comment);
330344
}
331345
if (prop->attributes) {
332-
ADD_DUP_SIZE(prop->attributes, sizeof(HashTable));
333-
zend_hash_persist_calc(prop->attributes, zend_persist_zval_calc);
346+
zend_persist_attributes_calc(prop->attributes);
334347
}
335348
}
336349
}
@@ -347,8 +360,7 @@ static void zend_persist_class_constant_calc(zval *zv)
347360
ADD_STRING(c->doc_comment);
348361
}
349362
if (c->attributes) {
350-
ADD_DUP_SIZE(c->attributes, sizeof(HashTable));
351-
zend_hash_persist_calc(c->attributes, zend_persist_zval_calc);
363+
zend_persist_attributes_calc(c->attributes);
352364
}
353365
}
354366
}
@@ -436,8 +448,7 @@ static void zend_persist_class_entry_calc(zval *zv)
436448
ADD_STRING(ce->info.user.doc_comment);
437449
}
438450
if (ce->info.user.attributes) {
439-
ADD_DUP_SIZE(ce->info.user.attributes, sizeof(HashTable));
440-
zend_hash_persist_calc(ce->info.user.attributes, zend_persist_zval_calc);
451+
zend_persist_attributes_calc(ce->info.user.attributes);
441452
}
442453

443454
zend_hash_persist_calc(&ce->properties_info);

0 commit comments

Comments
 (0)