From 5100afb7dd06b2515a3c524b4be02c8d3a80a091 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 20 Feb 2015 15:38:06 +0300 Subject: [PATCH] Simplify reallocation during copying data from SHM to process memory --- ext/opcache/zend_accelerator_util_funcs.c | 48 +++-------------------- ext/opcache/zend_persist.c | 18 --------- 2 files changed, 5 insertions(+), 61 deletions(-) diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c index afe3c4e421..8a52a53103 100644 --- a/ext/opcache/zend_accelerator_util_funcs.c +++ b/ext/opcache/zend_accelerator_util_funcs.c @@ -413,30 +413,11 @@ static void zend_hash_clone_methods(HashTable *ht, HashTable *source, zend_class ZVAL_PTR(&q->val, ARENA_REALLOC(Z_PTR(p->val))); new_entry = (zend_op_array*)Z_PTR(q->val); - /* Copy constructor */ - /* we use refcount to show that op_array is referenced from several places */ - if (new_entry->refcount != NULL) { - accel_xlat_set(Z_PTR(p->val), new_entry); - new_entry->refcount = NULL; - } - - if (old_ce == new_entry->scope) { - new_entry->scope = ce; - } else { - if ((new_ce = accel_xlat_get(new_entry->scope)) != NULL) { - new_entry->scope = new_ce; - } else { - zend_error(E_ERROR, ACCELERATOR_PRODUCT_NAME " class loading error, class %s, function %s", ce->name->val, new_entry->function_name->val); - } - } + new_entry->scope = ARENA_REALLOC(new_entry->scope); /* update prototype */ if (new_entry->prototype) { - if ((new_prototype = accel_xlat_get(new_entry->prototype)) != NULL) { - new_entry->prototype = new_prototype; - } else { - zend_error(E_ERROR, ACCELERATOR_PRODUCT_NAME " class loading error, class %s, function %s", ce->name->val, new_entry->function_name->val); - } + new_entry->prototype = ARENA_REALLOC(new_entry->prototype); } } } @@ -497,24 +478,14 @@ static void zend_hash_clone_prop_info(HashTable *ht, HashTable *source, zend_cla prop_info->doc_comment = NULL; } } - if (prop_info->ce == old_ce) { - prop_info->ce = ce; - } else if ((new_ce = accel_xlat_get(prop_info->ce)) != NULL) { - prop_info->ce = new_ce; - } else { - zend_error(E_ERROR, ACCELERATOR_PRODUCT_NAME" class loading error, class %s, property %s", ce->name->val, prop_info->name->val); - } + prop_info->ce = ARENA_REALLOC(prop_info->ce); } } #define zend_update_inherited_handler(handler) \ { \ if (ce->handler != NULL) { \ - if ((new_func = accel_xlat_get(ce->handler)) != NULL) { \ - ce->handler = new_func; \ - } else { \ - zend_error(E_ERROR, ACCELERATOR_PRODUCT_NAME " class loading error, class %s", ce->name->val); \ - } \ + ce->handler = ARENA_REALLOC(ce->handler); \ } \ } @@ -529,11 +500,6 @@ static void zend_class_copy_ctor(zend_class_entry **pce) *pce = ce = ARENA_REALLOC(old_ce); ce->refcount = 1; - if (old_ce->refcount != 1) { - /* this class is not used as a parent for any other classes */ - accel_xlat_set(old_ce, ce); - } - if (old_ce->default_properties_table) { int i; @@ -583,11 +549,7 @@ static void zend_class_copy_ctor(zend_class_entry **pce) } if (ce->parent) { - if ((new_ce = accel_xlat_get(ce->parent)) != NULL) { - ce->parent = new_ce; - } else { - zend_error(E_ERROR, ACCELERATOR_PRODUCT_NAME" class loading error, class %s", ce->name->val); - } + ce->parent = ARENA_REALLOC(ce->parent); } zend_update_inherited_handler(constructor); diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index 5fb5ab2d36..1c440eceae 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -508,8 +508,6 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc if (op_array->scope && op_array->prototype) { if ((persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->prototype))) { op_array->prototype = (union _zend_function*)persist_ptr; - /* we use refcount to show that op_array is referenced from several places */ - op_array->prototype->op_array.refcount++; } } else { op_array->prototype = NULL; @@ -674,63 +672,47 @@ static int zend_update_parent_ce(zval *zv) if (ce->parent) { ce->parent = zend_shared_alloc_get_xlat_entry(ce->parent); - /* We use refcount to show if the class is used as a parent */ - ce->parent->refcount++; } /* update methods */ if (ce->constructor) { ce->constructor = zend_shared_alloc_get_xlat_entry(ce->constructor); - /* we use refcount to show that op_array is referenced from several places */ - ce->constructor->op_array.refcount++; } if (ce->destructor) { ce->destructor = zend_shared_alloc_get_xlat_entry(ce->destructor); - ce->destructor->op_array.refcount++; } if (ce->clone) { ce->clone = zend_shared_alloc_get_xlat_entry(ce->clone); - ce->clone->op_array.refcount++; } if (ce->__get) { ce->__get = zend_shared_alloc_get_xlat_entry(ce->__get); - ce->__get->op_array.refcount++; } if (ce->__set) { ce->__set = zend_shared_alloc_get_xlat_entry(ce->__set); - ce->__set->op_array.refcount++; } if (ce->__call) { ce->__call = zend_shared_alloc_get_xlat_entry(ce->__call); - ce->__call->op_array.refcount++; } if (ce->serialize_func) { ce->serialize_func = zend_shared_alloc_get_xlat_entry(ce->serialize_func); - ce->serialize_func->op_array.refcount++; } if (ce->unserialize_func) { ce->unserialize_func = zend_shared_alloc_get_xlat_entry(ce->unserialize_func); - ce->unserialize_func->op_array.refcount++; } if (ce->__isset) { ce->__isset = zend_shared_alloc_get_xlat_entry(ce->__isset); - ce->__isset->op_array.refcount++; } if (ce->__unset) { ce->__unset = zend_shared_alloc_get_xlat_entry(ce->__unset); - ce->__unset->op_array.refcount++; } if (ce->__tostring) { ce->__tostring = zend_shared_alloc_get_xlat_entry(ce->__tostring); - ce->__tostring->op_array.refcount++; } if (ce->__callstatic) { ce->__callstatic = zend_shared_alloc_get_xlat_entry(ce->__callstatic); - ce->__callstatic->op_array.refcount++; } if (ce->__debugInfo) { ce->__debugInfo = zend_shared_alloc_get_xlat_entry(ce->__debugInfo); - ce->__debugInfo->op_array.refcount++; } zend_hash_apply(&ce->properties_info, (apply_func_t) zend_update_property_info_ce); return 0; -- 2.40.0