From 4db230b2f33d321569e40ae6eb7ce2102e62b1fc Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 2 Aug 2021 12:28:34 +0200 Subject: [PATCH] Remove special self/parent handling in get_class_name_map_ptr() zend_accel_get_class_name_map_ptr() for "self" and "parent" will currently try to determine which class these refer to, and then initialize the CE_CACHE on those strings. However, this shouldn't be necessary: We already initialize CE_CACHE on all class declaration names, so it should be covered through that already. --- ext/opcache/ZendAccelerator.c | 2 +- ext/opcache/ZendAccelerator.h | 2 +- ext/opcache/zend_file_cache.c | 4 ++-- ext/opcache/zend_persist.c | 31 ++++++------------------------- 4 files changed, 10 insertions(+), 29 deletions(-) diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 6d00864929823..5e55d838b4425 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -750,7 +750,7 @@ static void accel_allocate_ce_cache_slots(void) ce = (zend_class_entry*)Z_PTR(p->val); if (ce->name) { - zend_accel_get_class_name_map_ptr(ce->name, ce, /* have_xlat */ false); + zend_accel_get_class_name_map_ptr(ce->name); } } ZEND_HASH_FOREACH_END(); } diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h index 0fc5c2a789166..824e3cd3575fd 100644 --- a/ext/opcache/ZendAccelerator.h +++ b/ext/opcache/ZendAccelerator.h @@ -318,7 +318,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type); zend_string* ZEND_FASTCALL accel_new_interned_string(zend_string *str); -uint32_t zend_accel_get_class_name_map_ptr(zend_string *type_name, zend_class_entry *scope, bool have_xlat); +uint32_t zend_accel_get_class_name_map_ptr(zend_string *type_name); /* memory write protection */ #define SHM_PROTECT() \ diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c index 349344e925683..9a7f0d73b1eed 100644 --- a/ext/opcache/zend_file_cache.c +++ b/ext/opcache/zend_file_cache.c @@ -1231,7 +1231,7 @@ static void zend_file_cache_unserialize_type( UNSERIALIZE_STR(type_name); ZEND_TYPE_SET_PTR(*type, type_name); if (!script->corrupted) { - zend_accel_get_class_name_map_ptr(type_name, scope, /* have_xlat */ false); + zend_accel_get_class_name_map_ptr(type_name); } } else if (ZEND_TYPE_HAS_CE(*type)) { zend_class_entry *ce = ZEND_TYPE_CE(*type); @@ -1499,7 +1499,7 @@ static void zend_file_cache_unserialize_class(zval *zv, UNSERIALIZE_STR(ce->name); if (!(ce->ce_flags & ZEND_ACC_ANON_CLASS) && !script->corrupted) { - zend_accel_get_class_name_map_ptr(ce->name, ce, /* have_xlat */ false); + zend_accel_get_class_name_map_ptr(ce->name); } if (ce->parent) { if (!(ce->ce_flags & ZEND_ACC_LINKED)) { diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index 8045784fcf8ca..52575f6fd3640 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -298,32 +298,13 @@ static HashTable *zend_persist_attributes(HashTable *attributes) return ptr; } -uint32_t zend_accel_get_class_name_map_ptr( - zend_string *type_name, zend_class_entry *scope, bool have_xlat) +uint32_t zend_accel_get_class_name_map_ptr(zend_string *type_name) { uint32_t ret; - if (zend_string_equals_literal_ci(type_name, "self")) { - if (!scope || (scope->ce_flags & ZEND_ACC_TRAIT)) { - return 0; - } - type_name = scope->name; - } else if (zend_string_equals_literal_ci(type_name, "parent")) { - if (!scope || !scope->parent) { - return 0; - } - if (scope->ce_flags & ZEND_ACC_RESOLVED_PARENT) { - /* This runs before zend_update_parent_ce(), so manually fetch the persisted parent - * class, as the original may be no longer valid. */ - zend_class_entry *new_parent; - if (have_xlat && (new_parent = zend_shared_alloc_get_xlat_entry(scope->parent))) { - type_name = new_parent->name; - } else { - type_name = scope->parent->name; - } - } else { - type_name = scope->parent_name; - } + if (zend_string_equals_literal_ci(type_name, "self") || + zend_string_equals_literal_ci(type_name, "parent")) { + return 0; } /* We use type.name.gc.refcount to keep map_ptr of corresponding type */ @@ -383,7 +364,7 @@ static void zend_persist_type(zend_type *type, zend_class_entry *scope) { zend_accel_store_interned_string(type_name); ZEND_TYPE_SET_PTR(*single_type, type_name); if (!ZCG(current_persistent_script)->corrupted) { - zend_accel_get_class_name_map_ptr(type_name, scope, /* have_xlat */ true); + zend_accel_get_class_name_map_ptr(type_name); } } } ZEND_TYPE_FOREACH_END(); @@ -893,7 +874,7 @@ zend_class_entry *zend_persist_class_entry(zend_class_entry *orig_ce) if (ZSTR_HAS_CE_CACHE(ce->name)) { ZSTR_SET_CE_CACHE(ce->name, NULL); } else { - zend_accel_get_class_name_map_ptr(ce->name, ce, /* have_xlat */ true); + zend_accel_get_class_name_map_ptr(ce->name); } } if (ce->parent_name && !(ce->ce_flags & ZEND_ACC_LINKED)) {