From 97bcedeb0df0d126d777affcfcbaad04c4267e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schr=C3=B6der?= Date: Sun, 5 Apr 2020 08:02:07 +0200 Subject: [PATCH] Adjusted Opcache to PHP 8. --- ext/opcache/zend_file_cache.c | 94 ++++++++++----------------------- ext/opcache/zend_persist.c | 59 +++++++++------------ ext/opcache/zend_persist_calc.c | 27 +++++++--- 3 files changed, 74 insertions(+), 106 deletions(-) diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c index f336428ab0d85..a5d661c7a544f 100644 --- a/ext/opcache/zend_file_cache.c +++ b/ext/opcache/zend_file_cache.c @@ -158,6 +158,25 @@ static int zend_file_cache_flock(int fd, int type) } \ } while (0) +#define SERIALIZE_ATTRIBUTES(attr) do { \ + if ((attr) && !IS_SERIALIZED(attr)) { \ + HashTable *ht; \ + SERIALIZE_PTR(attr); \ + ht = (attr); \ + UNSERIALIZE_PTR(ht); \ + zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval); \ + } \ +} while (0) + +#define UNSERIALIZE_ATTRIBUTES(attr) do { \ + if ((attr) && !IS_UNSERIALIZED(attr)) { \ + HashTable *ht; \ + UNSERIALIZE_PTR(attr); \ + ht = (attr); \ + zend_file_cache_unserialize_hash(ht, script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR); \ + } \ +} while (0) + static const uint32_t uninitialized_bucket[-HT_MIN_MASK] = {HT_INVALID_IDX, HT_INVALID_IDX}; @@ -421,14 +440,7 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra SERIALIZE_PTR(op_array->live_range); SERIALIZE_PTR(op_array->scope); SERIALIZE_STR(op_array->doc_comment); - if (op_array->attributes && !IS_SERIALIZED(op_array->attributes)) { - HashTable *ht; - - SERIALIZE_PTR(op_array->attributes); - ht = op_array->attributes; - UNSERIALIZE_PTR(ht); - zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval); - } + SERIALIZE_ATTRIBUTES(op_array->attributes); SERIALIZE_PTR(op_array->try_catch_array); SERIALIZE_PTR(op_array->prototype); return; @@ -555,6 +567,7 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra SERIALIZE_PTR(op_array->live_range); SERIALIZE_PTR(op_array->scope); SERIALIZE_STR(op_array->doc_comment); + SERIALIZE_ATTRIBUTES(op_array->attributes); SERIALIZE_PTR(op_array->try_catch_array); SERIALIZE_PTR(op_array->prototype); @@ -599,15 +612,7 @@ static void zend_file_cache_serialize_prop_info(zval *zv, if (prop->doc_comment) { SERIALIZE_STR(prop->doc_comment); } - - if (prop->attributes) { - HashTable *ht; - - SERIALIZE_PTR(prop->attributes); - ht = prop->attributes; - UNSERIALIZE_PTR(ht); - zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval); - } + SERIALIZE_ATTRIBUTES(prop->attributes); zend_file_cache_serialize_type(&prop->type, script, info, buf); } @@ -636,14 +641,7 @@ static void zend_file_cache_serialize_class_constant(zval *z SERIALIZE_STR(c->doc_comment); } - if (c->attributes) { - HashTable *ht; - - SERIALIZE_PTR(c->attributes); - ht = c->attributes; - UNSERIALIZE_PTR(ht); - zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval); - } + SERIALIZE_ATTRIBUTES(c->attributes); } } } @@ -701,14 +699,7 @@ static void zend_file_cache_serialize_class(zval *zv, zend_file_cache_serialize_hash(&ce->constants_table, script, info, buf, zend_file_cache_serialize_class_constant); SERIALIZE_STR(ce->info.user.filename); SERIALIZE_STR(ce->info.user.doc_comment); - if (ce->info.user.attributes && !IS_SERIALIZED(ce->info.user.attributes)) { - HashTable *ht; - - SERIALIZE_PTR(ce->info.user.attributes); - ht = ce->info.user.attributes; - UNSERIALIZE_PTR(ht); - zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval); - } + SERIALIZE_ATTRIBUTES(ce->info.user.attributes); zend_file_cache_serialize_hash(&ce->properties_info, script, info, buf, zend_file_cache_serialize_prop_info); if (ce->properties_info_table) { @@ -1174,6 +1165,7 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr UNSERIALIZE_PTR(op_array->live_range); UNSERIALIZE_PTR(op_array->scope); UNSERIALIZE_STR(op_array->doc_comment); + UNSERIALIZE_ATTRIBUTES(op_array->attributes); UNSERIALIZE_PTR(op_array->try_catch_array); UNSERIALIZE_PTR(op_array->prototype); return; @@ -1289,14 +1281,7 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr UNSERIALIZE_PTR(op_array->live_range); UNSERIALIZE_PTR(op_array->scope); UNSERIALIZE_STR(op_array->doc_comment); - if (op_array->attributes && !IS_UNSERIALIZED(op_array->attributes)) { - HashTable *ht; - - UNSERIALIZE_PTR(op_array->attributes); - ht = op_array->attributes; - zend_file_cache_unserialize_hash(ht, - script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR); - } + UNSERIALIZE_ATTRIBUTES(op_array->attributes); UNSERIALIZE_PTR(op_array->try_catch_array); UNSERIALIZE_PTR(op_array->prototype); @@ -1350,14 +1335,7 @@ static void zend_file_cache_unserialize_prop_info(zval *zv, if (prop->doc_comment) { UNSERIALIZE_STR(prop->doc_comment); } - if (prop->attributes && !IS_UNSERIALIZED(prop->attributes)) { - HashTable *ht; - - UNSERIALIZE_PTR(prop->attributes); - ht = prop->attributes; - zend_file_cache_unserialize_hash(ht, - script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR); - } + UNSERIALIZE_ATTRIBUTES(prop->attributes); zend_file_cache_unserialize_type(&prop->type, script, buf); } } @@ -1382,14 +1360,7 @@ static void zend_file_cache_unserialize_class_constant(zval * if (c->doc_comment) { UNSERIALIZE_STR(c->doc_comment); } - if (c->attributes && !IS_UNSERIALIZED(c->attributes)) { - HashTable *ht; - - UNSERIALIZE_PTR(c->attributes); - ht = c->attributes; - zend_file_cache_unserialize_hash(ht, - script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR); - } + UNSERIALIZE_ATTRIBUTES(c->attributes); } } } @@ -1444,14 +1415,7 @@ static void zend_file_cache_unserialize_class(zval *zv, script, buf, zend_file_cache_unserialize_class_constant, NULL); UNSERIALIZE_STR(ce->info.user.filename); UNSERIALIZE_STR(ce->info.user.doc_comment); - if (ce->info.user.attributes && !IS_UNSERIALIZED(ce->info.user.attributes)) { - HashTable *ht; - - UNSERIALIZE_PTR(ce->info.user.attributes); - ht = ce->info.user.attributes; - zend_file_cache_unserialize_hash(ht, - script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR); - } + UNSERIALIZE_ATTRIBUTES(ce->info.user.attributes); zend_file_cache_unserialize_hash(&ce->properties_info, script, buf, zend_file_cache_unserialize_prop_info, NULL); diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index 4f3e84cd19f36..7199aa35b514c 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -76,6 +76,25 @@ } \ } while (0) +#define zend_persist_attributes(attr) do { \ + HashTable *ptr = zend_shared_alloc_get_xlat_entry(attr); \ + if (ptr) { \ + (attr) = ptr; \ + } else { \ + Bucket *p; \ + zend_hash_persist(attr); \ + ZEND_HASH_FOREACH_BUCKET((attr), p) { \ + if (p->key) { \ + zend_accel_store_interned_string(p->key); \ + } \ + zend_persist_zval(&p->val); \ + } ZEND_HASH_FOREACH_END(); \ + (attr) = zend_shared_memdup_put_free((attr), sizeof(HashTable)); \ + GC_SET_REFCOUNT((attr), 2); \ + GC_TYPE_INFO(attr) = IS_ARRAY | (IS_ARRAY_IMMUTABLE << GC_FLAGS_SHIFT); \ + } \ +} while (0) + typedef void (*zend_persist_func_t)(zval*); 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 op_array->doc_comment = NULL; } } + if (op_array->attributes) { + zend_persist_attributes(op_array->attributes); + } if (op_array->try_catch_array) { 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 } if (op_array->attributes) { - if (already_stored) { - op_array->attributes = zend_shared_alloc_get_xlat_entry(op_array->attributes); - ZEND_ASSERT(op_array->attributes != NULL); - } else { - zend_hash_persist(op_array->attributes, zend_persist_zval); - zend_accel_store(op_array->attributes, sizeof(HashTable)); - /* make immutable array */ - GC_REFCOUNT(op_array->attributes) = 2; - GC_TYPE_INFO(op_array->attributes) = IS_ARRAY | (IS_ARRAY_IMMUTABLE << 8); - op_array->attributes->u.flags |= HASH_FLAG_STATIC_KEYS; - op_array->attributes->u.flags &= ~HASH_FLAG_APPLY_PROTECTION; - } + zend_persist_attributes(op_array->attributes); } if (op_array->try_catch_array) { @@ -700,13 +711,7 @@ static void zend_persist_property_info(zval *zv) } } if (prop->attributes) { - zend_hash_persist(prop->attributes, zend_persist_zval); - zend_accel_store(prop->attributes, sizeof(HashTable)); - /* make immutable array */ - GC_REFCOUNT(prop->attributes) = 2; - GC_TYPE_INFO(prop->attributes) = IS_ARRAY | (IS_ARRAY_IMMUTABLE << 8); - prop->attributes->u.flags |= HASH_FLAG_STATIC_KEYS; - prop->attributes->u.flags &= ~HASH_FLAG_APPLY_PROTECTION; + zend_persist_attributes(prop->attributes); } zend_persist_type(&prop->type); } @@ -748,13 +753,7 @@ static void zend_persist_class_constant(zval *zv) } } if (c->attributes) { - zend_hash_persist(c->attributes, zend_persist_zval); - zend_accel_store(c->attributes, sizeof(HashTable)); - /* make immutable array */ - GC_REFCOUNT(c->attributes) = 2; - GC_TYPE_INFO(c->attributes) = IS_ARRAY | (IS_ARRAY_IMMUTABLE << 8); - c->attributes->u.flags |= HASH_FLAG_STATIC_KEYS; - c->attributes->u.flags &= ~HASH_FLAG_APPLY_PROTECTION; + zend_persist_attributes(c->attributes); } } @@ -843,13 +842,7 @@ static void zend_persist_class_entry(zval *zv) } } if (ce->info.user.attributes) { - zend_hash_persist(ce->info.user.attributes, zend_persist_zval); - zend_accel_store(ce->info.user.attributes, sizeof(HashTable)); - /* make immutable array */ - GC_REFCOUNT(ce->info.user.attributes) = 2; - GC_TYPE_INFO(ce->info.user.attributes) = IS_ARRAY | (IS_ARRAY_IMMUTABLE << 8); - ce->info.user.attributes->u.flags |= HASH_FLAG_STATIC_KEYS; - ce->info.user.attributes->u.flags &= ~HASH_FLAG_APPLY_PROTECTION; + zend_persist_attributes(ce->info.user.attributes); } zend_hash_persist(&ce->properties_info); ZEND_HASH_FOREACH_BUCKET(&ce->properties_info, p) { diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c index 7b0258f6da28e..ee880d53816c1 100644 --- a/ext/opcache/zend_persist_calc.c +++ b/ext/opcache/zend_persist_calc.c @@ -53,6 +53,21 @@ } \ } while (0) +#define zend_persist_attributes_calc(attr) do { \ + if (!zend_shared_alloc_get_xlat_entry(attr)) { \ + Bucket *p; \ + zend_shared_alloc_register_xlat_entry((attr), (attr)); \ + ADD_SIZE(sizeof(HashTable)); \ + zend_hash_persist_calc(attr); \ + ZEND_HASH_FOREACH_BUCKET((attr), p) { \ + if (p->key) { \ + ADD_INTERNED_STRING(p->key); \ + } \ + zend_persist_zval_calc(&p->val); \ + } ZEND_HASH_FOREACH_END(); \ + } \ +} while (0) + static void zend_persist_zval_calc(zval *z); 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) } if (op_array->attributes) { - ADD_DUP_SIZE(op_array->attributes, sizeof(HashTable)); - zend_hash_persist_calc(op_array->attributes, zend_persist_zval_calc); + zend_persist_attributes_calc(op_array->attributes); } if (op_array->try_catch_array) { @@ -329,8 +343,7 @@ static void zend_persist_property_info_calc(zval *zv) ADD_STRING(prop->doc_comment); } if (prop->attributes) { - ADD_DUP_SIZE(prop->attributes, sizeof(HashTable)); - zend_hash_persist_calc(prop->attributes, zend_persist_zval_calc); + zend_persist_attributes_calc(prop->attributes); } } } @@ -347,8 +360,7 @@ static void zend_persist_class_constant_calc(zval *zv) ADD_STRING(c->doc_comment); } if (c->attributes) { - ADD_DUP_SIZE(c->attributes, sizeof(HashTable)); - zend_hash_persist_calc(c->attributes, zend_persist_zval_calc); + zend_persist_attributes_calc(c->attributes); } } } @@ -436,8 +448,7 @@ static void zend_persist_class_entry_calc(zval *zv) ADD_STRING(ce->info.user.doc_comment); } if (ce->info.user.attributes) { - ADD_DUP_SIZE(ce->info.user.attributes, sizeof(HashTable)); - zend_hash_persist_calc(ce->info.user.attributes, zend_persist_zval_calc); + zend_persist_attributes_calc(ce->info.user.attributes); } zend_hash_persist_calc(&ce->properties_info);