Skip to content

PHP 8 Opcache API #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 29 additions & 65 deletions ext/opcache/zend_file_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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);

Expand Down
59 changes: 26 additions & 33 deletions ext/opcache/zend_persist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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) {
Expand Down
27 changes: 19 additions & 8 deletions ext/opcache/zend_persist_calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
Expand Down