diff options
Diffstat (limited to 'Zend/zend_objects_API.c')
| -rw-r--r-- | Zend/zend_objects_API.c | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/Zend/zend_objects_API.c b/Zend/zend_objects_API.c index f757f282bc..ed2c99af68 100644 --- a/Zend/zend_objects_API.c +++ b/Zend/zend_objects_API.c @@ -49,9 +49,8 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_call_destructors(zend_objects_sto if (!(OBJ_FLAGS(obj) & IS_OBJ_DESTRUCTOR_CALLED)) { GC_ADD_FLAGS(obj, IS_OBJ_DESTRUCTOR_CALLED); - if (obj->handlers->dtor_obj - && (obj->handlers->dtor_obj != zend_objects_destroy_object - || obj->ce->destructor)) { + if (obj->handlers->dtor_obj != zend_objects_destroy_object + || obj->ce->destructor) { GC_ADDREF(obj); obj->handlers->dtor_obj(obj); GC_DELREF(obj); @@ -98,7 +97,7 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_free_object_storage(zend_objects_ if (IS_OBJ_VALID(obj)) { if (!(OBJ_FLAGS(obj) & IS_OBJ_FREE_CALLED)) { GC_ADD_FLAGS(obj, IS_OBJ_FREE_CALLED); - if (obj->handlers->free_obj && obj->handlers->free_obj != zend_object_std_dtor) { + if (obj->handlers->free_obj != zend_object_std_dtor) { GC_ADDREF(obj); obj->handlers->free_obj(obj); GC_DELREF(obj); @@ -113,11 +112,9 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_free_object_storage(zend_objects_ if (IS_OBJ_VALID(obj)) { if (!(OBJ_FLAGS(obj) & IS_OBJ_FREE_CALLED)) { GC_ADD_FLAGS(obj, IS_OBJ_FREE_CALLED); - if (obj->handlers->free_obj) { - GC_ADDREF(obj); - obj->handlers->free_obj(obj); - GC_DELREF(obj); - } + GC_ADDREF(obj); + obj->handlers->free_obj(obj); + GC_DELREF(obj); } } } while (obj_ptr != end); @@ -126,6 +123,18 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_free_object_storage(zend_objects_ /* Store objects API */ +static ZEND_COLD zend_never_inline void ZEND_FASTCALL zend_objects_store_put_cold(zend_object *object) +{ + int handle; + uint32_t new_size = 2 * EG(objects_store).size; + + EG(objects_store).object_buckets = (zend_object **) erealloc(EG(objects_store).object_buckets, new_size * sizeof(zend_object*)); + /* Assign size after realloc, in case it fails */ + EG(objects_store).size = new_size; + handle = EG(objects_store).top++; + object->handle = handle; + EG(objects_store).object_buckets[handle] = object; +} ZEND_API void ZEND_FASTCALL zend_objects_store_put(zend_object *object) { @@ -134,16 +143,13 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_put(zend_object *object) /* When in shutdown sequesnce - do not reuse previously freed handles, to make sure * the dtors for newly created objects are called in zend_objects_store_call_destructors() loop */ - if (!(EG(flags) & EG_FLAGS_IN_SHUTDOWN) && EG(objects_store).free_list_head != -1) { + if (EG(objects_store).free_list_head != -1 && EXPECTED(!(EG(flags) & EG_FLAGS_IN_SHUTDOWN))) { handle = EG(objects_store).free_list_head; EG(objects_store).free_list_head = GET_OBJ_BUCKET_NUMBER(EG(objects_store).object_buckets[handle]); + } else if (UNEXPECTED(EG(objects_store).top == EG(objects_store).size)) { + zend_objects_store_put_cold(object); + return; } else { - if (EG(objects_store).top == EG(objects_store).size) { - uint32_t new_size = 2 * EG(objects_store).size; - EG(objects_store).object_buckets = (zend_object **) erealloc(EG(objects_store).object_buckets, new_size * sizeof(zend_object*)); - /* Assign size after realloc, in case it fails */ - EG(objects_store).size = new_size; - } handle = EG(objects_store).top++; } object->handle = handle; @@ -156,17 +162,14 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_del(zend_object *object) /* {{{ * otherwise, when the destructor ends the storage might be freed when the refcount reaches 0 a second time */ - ZEND_ASSERT(EG(objects_store).object_buckets != NULL); - ZEND_ASSERT(IS_OBJ_VALID(EG(objects_store).object_buckets[object->handle])); ZEND_ASSERT(GC_REFCOUNT(object) == 0); if (!(OBJ_FLAGS(object) & IS_OBJ_DESTRUCTOR_CALLED)) { GC_ADD_FLAGS(object, IS_OBJ_DESTRUCTOR_CALLED); - if (object->handlers->dtor_obj - && (object->handlers->dtor_obj != zend_objects_destroy_object - || object->ce->destructor)) { - GC_ADDREF(object); + if (object->handlers->dtor_obj != zend_objects_destroy_object + || object->ce->destructor) { + GC_SET_REFCOUNT(object, 1); object->handlers->dtor_obj(object); GC_DELREF(object); } @@ -176,14 +179,13 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_del(zend_object *object) /* {{{ * uint32_t handle = object->handle; void *ptr; + ZEND_ASSERT(EG(objects_store).object_buckets != NULL); + ZEND_ASSERT(IS_OBJ_VALID(EG(objects_store).object_buckets[handle])); EG(objects_store).object_buckets[handle] = SET_OBJ_INVALID(object); if (!(OBJ_FLAGS(object) & IS_OBJ_FREE_CALLED)) { GC_ADD_FLAGS(object, IS_OBJ_FREE_CALLED); - if (object->handlers->free_obj) { - GC_ADDREF(object); - object->handlers->free_obj(object); - GC_DELREF(object); - } + GC_SET_REFCOUNT(object, 1); + object->handlers->free_obj(object); } ptr = ((char*)object) - object->handlers->offset; GC_REMOVE_FROM_BUFFER(object); |
