Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Optimized cleanup loops on request shutdown

  • Loading branch information...
commit ad10a538eefa240da0287fe96a7852ab89cb7911 1 parent d21669f
Dmitry Stogov authored
1  Zend/zend_compile.h
View
@@ -517,6 +517,7 @@ ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle TSRMLS_DC);
ZEND_API void zend_file_handle_dtor(zend_file_handle *fh);
ZEND_API int zend_cleanup_class_data(zend_class_entry **pce TSRMLS_DC);
ZEND_API int zend_cleanup_function_data(zend_function *function TSRMLS_DC);
+ZEND_API int zend_cleanup_function_data_full(zend_function *function TSRMLS_DC);
ZEND_API void destroy_zend_function(zend_function *function TSRMLS_DC);
ZEND_API void zend_function_dtor(zend_function *function);
14 Zend/zend_constants.c
View
@@ -55,11 +55,13 @@ void zend_copy_constants(HashTable *target, HashTable *source)
static int clean_non_persistent_constant(zend_constant *c TSRMLS_DC)
{
- if (c->flags & CONST_PERSISTENT) {
- return EG(full_tables_cleanup) ? 0 : ZEND_HASH_APPLY_STOP;
- } else {
- return EG(full_tables_cleanup) ? 1 : ZEND_HASH_APPLY_REMOVE;
- }
+ return (c->flags & CONST_PERSISTENT) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
+}
+
+
+static int clean_non_persistent_constant_full(zend_constant *c TSRMLS_DC)
+{
+ return (c->flags & CONST_PERSISTENT) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE;
}
@@ -153,7 +155,7 @@ int zend_shutdown_constants(TSRMLS_D)
void clean_non_persistent_constants(TSRMLS_D)
{
if (EG(full_tables_cleanup)) {
- zend_hash_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant TSRMLS_CC);
+ zend_hash_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant_full TSRMLS_CC);
} else {
zend_hash_reverse_apply(EG(zend_constants), (apply_func_t) clean_non_persistent_constant TSRMLS_CC);
}
42 Zend/zend_execute_API.c
View
@@ -95,23 +95,27 @@ static void zend_extension_deactivator(zend_extension *extension TSRMLS_DC)
}
-static int is_not_internal_function(zend_function *function TSRMLS_DC)
+static int clean_non_persistent_function(zend_function *function TSRMLS_DC)
{
- if (function->type == ZEND_INTERNAL_FUNCTION) {
- return EG(full_tables_cleanup) ? 0 : ZEND_HASH_APPLY_STOP;
- } else {
- return EG(full_tables_cleanup) ? 1 : ZEND_HASH_APPLY_REMOVE;
- }
+ return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
}
-static int is_not_internal_class(zend_class_entry **ce TSRMLS_DC)
+static int clean_non_persistent_function_full(zend_function *function TSRMLS_DC)
{
- if ((*ce)->type == ZEND_INTERNAL_CLASS) {
- return EG(full_tables_cleanup) ? 0 : ZEND_HASH_APPLY_STOP;
- } else {
- return EG(full_tables_cleanup) ? 1 : ZEND_HASH_APPLY_REMOVE;
- }
+ return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE;
+}
+
+
+static int clean_non_persistent_class(zend_class_entry **ce TSRMLS_DC)
+{
+ return ((*ce)->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
+}
+
+
+static int clean_non_persistent_class_full(zend_class_entry **ce TSRMLS_DC)
+{
+ return ((*ce)->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE;
}
@@ -251,18 +255,22 @@ void shutdown_executor(TSRMLS_D)
So we want first of all to clean up all data and then move to tables destruction.
Note that only run-time accessed data need to be cleaned up, pre-defined data can
not contain objects and thus are not probelmatic */
- zend_hash_apply(EG(function_table), (apply_func_t) zend_cleanup_function_data TSRMLS_CC);
+ if (EG(full_tables_cleanup)) {
+ zend_hash_apply(EG(function_table), (apply_func_t) zend_cleanup_function_data_full TSRMLS_CC);
+ } else {
+ zend_hash_reverse_apply(EG(function_table), (apply_func_t) zend_cleanup_function_data TSRMLS_CC);
+ }
zend_hash_apply(EG(class_table), (apply_func_t) zend_cleanup_class_data TSRMLS_CC);
zend_ptr_stack_destroy(&EG(argument_stack));
/* Destroy all op arrays */
if (EG(full_tables_cleanup)) {
- zend_hash_apply(EG(function_table), (apply_func_t) is_not_internal_function TSRMLS_CC);
- zend_hash_apply(EG(class_table), (apply_func_t) is_not_internal_class TSRMLS_CC);
+ zend_hash_apply(EG(function_table), (apply_func_t) clean_non_persistent_function_full TSRMLS_CC);
+ zend_hash_apply(EG(class_table), (apply_func_t) clean_non_persistent_class_full TSRMLS_CC);
} else {
- zend_hash_reverse_apply(EG(function_table), (apply_func_t) is_not_internal_function TSRMLS_CC);
- zend_hash_reverse_apply(EG(class_table), (apply_func_t) is_not_internal_class TSRMLS_CC);
+ zend_hash_reverse_apply(EG(function_table), (apply_func_t) clean_non_persistent_function TSRMLS_CC);
+ zend_hash_reverse_apply(EG(class_table), (apply_func_t) clean_non_persistent_class TSRMLS_CC);
}
while (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
16 Zend/zend_opcode.c
View
@@ -132,8 +132,18 @@ ZEND_API int zend_cleanup_function_data(zend_function *function TSRMLS_DC)
{
if (function->type == ZEND_USER_FUNCTION) {
zend_cleanup_op_array_data((zend_op_array *) function);
- }
- return 0;
+ return ZEND_HASH_APPLY_KEEP;
+ } else {
+ return ZEND_HASH_APPLY_STOP;
+ }
+}
+
+ZEND_API int zend_cleanup_function_data_full(zend_function *function TSRMLS_DC)
+{
+ if (function->type == ZEND_USER_FUNCTION) {
+ zend_cleanup_op_array_data((zend_op_array *) function);
+ }
+ return ZEND_HASH_APPLY_KEEP;
}
ZEND_API int zend_cleanup_class_data(zend_class_entry **pce TSRMLS_DC)
@@ -142,7 +152,7 @@ ZEND_API int zend_cleanup_class_data(zend_class_entry **pce TSRMLS_DC)
/* Clean all parts that can contain run-time data */
/* Note that only run-time accessed data need to be cleaned up, pre-defined data can
not contain objects and thus are not probelmatic */
- zend_hash_apply(&(*pce)->function_table, (apply_func_t) zend_cleanup_function_data TSRMLS_CC);
+ zend_hash_apply(&(*pce)->function_table, (apply_func_t) zend_cleanup_function_data_full TSRMLS_CC);
(*pce)->static_members = NULL;
} else if (CE_STATIC_MEMBERS(*pce)) {
zend_hash_destroy(CE_STATIC_MEMBERS(*pce));
Please sign in to comment.
Something went wrong with that request. Please try again.