summaryrefslogtreecommitdiff
path: root/Zend/zend_closures.c
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2018-10-17 15:52:50 +0300
committerDmitry Stogov <dmitry@zend.com>2018-10-17 15:52:50 +0300
commitd57cd36e47b627dee5b825760163f8e62e23ab28 (patch)
tree250b3c1176663a2030d68f20a5f485e44aacf71d /Zend/zend_closures.c
parentad6738e886cbeb69dcd440ecc88727feaaccbe78 (diff)
downloadphp-git-d57cd36e47b627dee5b825760163f8e62e23ab28.tar.gz
Immutable clases and op_arrays.
Squashed commit of the following: commit cd0c36c3f943849e5b97a8dbe2dd029fbeab3df9 Merge: 4740dabb84 ad6738e886 Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Oct 17 14:43:38 2018 +0300 Merge branch 'master' into immutable * master: Remove the "auto" encoding Fixed bug #77025 Add vtbls for EUC-TW encoding commit 4740dabb843c6d4f7f866b4a2456073c9eaf4c77 Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Oct 17 14:12:28 2018 +0300 Reverted back ce->iterator_funcs_ptr. Initialize ce->iterator_funcs_ptr fields in immutable classes. commit ad7a78b253be970db70c2251e66f9297d8e7f829 Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Oct 17 11:46:30 2018 +0300 Added comment commit 0276ea51875bab37be01a4dc5e5a047c5698c571 Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Oct 17 11:42:43 2018 +0300 Added type cast commit c63fc5d5f19c58498108d1698055b2b442227eb3 Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Oct 17 11:36:51 2018 +0300 Moved static class members initialization into the proper place. commit b945548e9306b1826c881918858b5e5aa3eb3002 Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Oct 17 11:21:03 2018 +0300 Removed redundand assertion commit d5a41088401814c829847db212488f8aae39bcd2 Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Oct 17 11:19:13 2018 +0300 Removed duplicate code commit 8dadca8864e66de70a24bdf1181bcf7dd8fb27d7 Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Oct 17 11:05:43 2018 +0300 Hide offset encoding magic in ZEND_MAP_PTR_IS_OFFSET(), ZEND_MAP_PTR_OFFSET2PTR() and ZEND_MAP_PTR_PTR2OFFSET() macros. commit 9ef07c88bd76801e2d4fbfeab3ebfd6e6a67ac5f Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Oct 17 10:48:29 2018 +0300 typo commit a06f0f3d3aba53e766046221ee44fb9720389ecc Merge: 94099586ec 3412345ffe Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Oct 17 10:47:07 2018 +0300 Merge branch 'master' into immutable * master: Remove unused variable makefile_am_files Classify object handlers are required/optional Add support for getting SKIP_TAGSTART and SKIP_WHITE options Remove some obsolete config_vars.mk occurrences Remove bsd_converted from .gitignore Remove configuration parser and scanners ignores Remove obsolete buildconf.stamp from .gitignore [ci skip] Add magicdata.patch exception to .gitignore Remove outdated ext/spl/examples items from .gitignore Remove unused test.inc in ext/iconv/tests commit 94099586ec599117581ca01c15b1f6c5f749e23a Author: Dmitry Stogov <dmitry@zend.com> Date: Mon Oct 15 23:34:01 2018 +0300 Immutable clases and op_arrays
Diffstat (limited to 'Zend/zend_closures.c')
-rw-r--r--Zend/zend_closures.c50
1 files changed, 36 insertions, 14 deletions
diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c
index 7ad9327a32..a5e2123db1 100644
--- a/Zend/zend_closures.c
+++ b/Zend/zend_closures.c
@@ -151,9 +151,14 @@ ZEND_METHOD(Closure, call)
if (ZEND_USER_CODE(my_function.type)
&& (closure->func.common.scope != Z_OBJCE_P(newthis)
|| (closure->func.common.fn_flags & ZEND_ACC_HEAP_RT_CACHE))) {
- my_function.op_array.run_time_cache = emalloc(my_function.op_array.cache_size);
+ void *ptr;
+
my_function.op_array.fn_flags |= ZEND_ACC_HEAP_RT_CACHE;
- memset(my_function.op_array.run_time_cache, 0, my_function.op_array.cache_size);
+ ptr = emalloc(sizeof(void*) + my_function.op_array.cache_size);
+ ZEND_MAP_PTR_INIT(my_function.op_array.run_time_cache, ptr);
+ ptr = (char*)ptr + sizeof(void*);
+ ZEND_MAP_PTR_SET(my_function.op_array.run_time_cache, ptr);
+ memset(ptr, 0, my_function.op_array.cache_size);
}
}
@@ -176,7 +181,7 @@ ZEND_METHOD(Closure, call)
/* copied upon generator creation */
GC_DELREF(&closure->std);
} else if (fci_cache.function_handler->common.fn_flags & ZEND_ACC_HEAP_RT_CACHE) {
- efree(my_function.op_array.run_time_cache);
+ efree(ZEND_MAP_PTR(my_function.op_array.run_time_cache));
}
}
/* }}} */
@@ -501,7 +506,8 @@ static HashTable *zend_closure_get_debug_info(zval *object, int *is_temp) /* {{{
debug_info = zend_new_array(8);
if (closure->func.type == ZEND_USER_FUNCTION && closure->func.op_array.static_variables) {
- HashTable *static_variables = closure->func.op_array.static_variables;
+ HashTable *static_variables =
+ ZEND_MAP_PTR_GET(closure->func.op_array.static_variables_ptr);
ZVAL_ARR(&val, zend_array_dup(static_variables));
zend_hash_update(debug_info, ZSTR_KNOWN(ZEND_STR_STATIC), &val);
}
@@ -559,7 +565,7 @@ static HashTable *zend_closure_get_gc(zval *obj, zval **table, int *n) /* {{{ */
*table = Z_TYPE(closure->this_ptr) != IS_NULL ? &closure->this_ptr : NULL;
*n = Z_TYPE(closure->this_ptr) != IS_NULL ? 1 : 0;
return (closure->func.type == ZEND_USER_FUNCTION) ?
- closure->func.op_array.static_variables : NULL;
+ ZEND_MAP_PTR_GET(closure->func.op_array.static_variables_ptr) : NULL;
}
/* }}} */
@@ -654,28 +660,44 @@ ZEND_API void zend_create_closure(zval *res, zend_function *func, zend_class_ent
if (func->type == ZEND_USER_FUNCTION) {
memcpy(&closure->func, func, sizeof(zend_op_array));
closure->func.common.fn_flags |= ZEND_ACC_CLOSURE;
+ closure->func.common.fn_flags &= ~ZEND_ACC_IMMUTABLE;
+
if (closure->func.op_array.static_variables) {
closure->func.op_array.static_variables =
zend_array_dup(closure->func.op_array.static_variables);
}
+ ZEND_MAP_PTR_INIT(closure->func.op_array.static_variables_ptr,
+ &closure->func.op_array.static_variables);
/* Runtime cache is scope-dependent, so we cannot reuse it if the scope changed */
- if (!closure->func.op_array.run_time_cache
+ if (!ZEND_MAP_PTR_GET(closure->func.op_array.run_time_cache)
|| func->common.scope != scope
|| (func->common.fn_flags & ZEND_ACC_HEAP_RT_CACHE)
) {
- if (!func->op_array.run_time_cache && (func->common.fn_flags & ZEND_ACC_CLOSURE)) {
+ void *ptr;
+
+ if (!ZEND_MAP_PTR_GET(func->op_array.run_time_cache)
+ && (func->common.fn_flags & ZEND_ACC_CLOSURE)
+ && (func->common.scope == scope ||
+ !(func->common.fn_flags & ZEND_ACC_IMMUTABLE))) {
/* If a real closure is used for the first time, we create a shared runtime cache
* and remember which scope it is for. */
- func->common.scope = scope;
- func->op_array.run_time_cache = zend_arena_alloc(&CG(arena), func->op_array.cache_size);
- closure->func.op_array.run_time_cache = func->op_array.run_time_cache;
+ if (func->common.scope != scope) {
+ func->common.scope = scope;
+ }
+ closure->func.op_array.fn_flags &= ~ZEND_ACC_HEAP_RT_CACHE;
+ ptr = zend_arena_alloc(&CG(arena), func->op_array.cache_size);
+ ZEND_MAP_PTR_SET(func->op_array.run_time_cache, ptr);
+ ZEND_MAP_PTR_SET(closure->func.op_array.run_time_cache, ptr);
} else {
/* Otherwise, we use a non-shared runtime cache */
- closure->func.op_array.run_time_cache = emalloc(func->op_array.cache_size);
closure->func.op_array.fn_flags |= ZEND_ACC_HEAP_RT_CACHE;
+ ptr = emalloc(sizeof(void*) + func->op_array.cache_size);
+ ZEND_MAP_PTR_INIT(closure->func.op_array.run_time_cache, ptr);
+ ptr = (char*)ptr + sizeof(void*);
+ ZEND_MAP_PTR_SET(closure->func.op_array.run_time_cache, ptr);
}
- memset(closure->func.op_array.run_time_cache, 0, func->op_array.cache_size);
+ memset(ptr, 0, func->op_array.cache_size);
}
if (closure->func.op_array.refcount) {
(*closure->func.op_array.refcount)++;
@@ -728,7 +750,7 @@ ZEND_API void zend_create_fake_closure(zval *res, zend_function *func, zend_clas
void zend_closure_bind_var(zval *closure_zv, zend_string *var_name, zval *var) /* {{{ */
{
zend_closure *closure = (zend_closure *) Z_OBJ_P(closure_zv);
- HashTable *static_variables = closure->func.op_array.static_variables;
+ HashTable *static_variables = ZEND_MAP_PTR_GET(closure->func.op_array.static_variables_ptr);
zend_hash_update(static_variables, var_name, var);
}
/* }}} */
@@ -736,7 +758,7 @@ void zend_closure_bind_var(zval *closure_zv, zend_string *var_name, zval *var) /
void zend_closure_bind_var_ex(zval *closure_zv, uint32_t offset, zval *val) /* {{{ */
{
zend_closure *closure = (zend_closure *) Z_OBJ_P(closure_zv);
- HashTable *static_variables = closure->func.op_array.static_variables;
+ HashTable *static_variables = ZEND_MAP_PTR_GET(closure->func.op_array.static_variables_ptr);
zval *var = (zval*)((char*)static_variables->arData + offset);
zval_ptr_dtor(var);
ZVAL_COPY_VALUE(var, val);