8000 Merge branch 'master' into preload · php/php-src@9f6de1b · GitHub
[go: up one dir, main page]

Skip to content

Commit 9f6de1b

Browse files
committed
Merge branch 'master' into preload
* master: Allocate only necessary space for static properties of internal classes in ZTS mode.
2 parents f74d0a2 + a2e8334 commit 9f6de1b

10 files changed

+45
-19
lines changed

Zend/zend.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static HashTable *global_class_table = NULL;
4141
static HashTable *global_constants_table = NULL;
4242
static HashTable *global_auto_globals_table = NULL;
4343
static HashTable *global_persistent_list = NULL;
44+
static zend_uintptr_t global_last_static_member = 0;
4445
ZEND_TSRMLS_CACHE_DEFINE()
4546
# define GLOBAL_FUNCTION_TABLE global_function_table
4647
# define GLOBAL_CLASS_TABLE global_class_table
@@ -630,9 +631,9 @@ static void compiler_globals_ctor(zend_compiler_globals *compiler_globals) /* {{
630631
zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, auto_global_dtor, 1, 0);
631632
zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, auto_global_copy_ctor);
632633

633-
compiler_globals->last_static_member = zend_hash_num_elements(compiler_globals->class_table);
634+
compiler_globals->last_static_member = global_last_static_member;
634635
if (compiler_globals->last_static_member) {
635-
compiler_globals->static_members_table = calloc(compiler_globals->last_static_member, sizeof(zval*));
636+
compiler_globals->static_members_table = calloc(compiler_globals->last_static_member + 1, sizeof(zval*));
636637
} else {
637638
compiler_globals->static_members_table = NULL;
638639
}
@@ -935,6 +936,7 @@ int zend_post_startup(void) /* {{{ */
935936
*GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table;
936937
*GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
937938
*GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
939+
global_last_static_member = compiler_globals->last_static_member;
938940

939941
short_tags_default = CG(short_tags);
940942
compiler_options_default = CG(compiler_options);
@@ -1083,6 +1085,14 @@ ZEND_API void zend_activate(void) /* {{{ */
10831085
}
10841086
/* }}} */
10851087

1088+
#ifdef ZTS
1089+
void zend_reset_internal_classes(void) /* {{{ */
1090+
{
1091+
CG(last_static_member) = global_last_static_member;
1092+
}
1093+
/* }}} */
1094+
#endif
1095+
10861096
void zend_call_destructors(void) /* {{{ */
10871097
{
10881098
zend_try {

Zend/zend.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
127127
int default_static_members_count;
128128
zval *default_properties_table;
129129
zval *default_static_members_table;
130-
zval *static_members_table;
130+
union {
131+
zval *static_members_table;
132+
zend_uintptr_t static_members_table_idx;
133+
};
131134
HashTable function_table;
132135
HashTable properties_info;
133136
HashTable constants_table;
@@ -268,6 +271,8 @@ ZEND_API void zend_activate_modules(void);
268271
ZEND_API void zend_deactivate_modules(void);
269272
ZEND_API void zend_post_deactivate_modules(void);
270273

274+
void zend_reset_internal_classes(void);
275+
271276
ZEND_API void free_estring(char **str_p);
272277
END_EXTERN_C()
273278

Zend/zend_API.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3699,6 +3699,16 @@ ZEND_API int zend_declare_property_ex(zend_class_entry *ce, zend_string *name, z
36993699
ZVAL_COPY_VALUE(&ce->default_static_members_table[property_info->offset], property);
37003700
if (ce->type == ZEND_USER_CLASS) {
37013701
ce->static_members_table = ce->default_static_members_table;
3702+
#ifdef ZTS
3703+
} else if (!ce->static_members_table_idx) {
3704+
CG(last_static_member)++;
3705+
ce->static_members_table_idx = CG(last_static_member);
3706+
if (CG(static_members_table)) {
3707+
/* Support for run-time declaration: dl() */
3708+
CG(static_members_table) = realloc(CG(static_members_table), (CG(last_static_member) + 1) * sizeof(zval*));
3709+
CG(static_members_table)[ce->static_members_table_idx] = NULL;
3710+
}
3711+
#endif
37023712
}
37033713
} else {
37043714
if ((property_info_ptr = zend_hash_find_ptr(&ce->properties_info, name)) != NULL &&

Zend/zend_API.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ typedef struct _zend_fcall_info_cache {
229229
INIT_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions)
230230

231231
#ifdef ZTS
232-
# define CE_STATIC_MEMBERS(ce) (((ce)->type==ZEND_USER_CLASS)?(ce)->static_members_table:CG(static_members_table)[(zend_intptr_t)(ce)->static_members_table])
232+
# define CE_STATIC_MEMBERS(ce) (((ce)->type==ZEND_USER_CLASS)?(ce)->static_members_table:CG(static_members_table)[(ce)->static_members_table_idx])
233233
#else
234234
# define CE_STATIC_MEMBERS(ce) ((ce)->static_members_table)
235235
#endif

Zend/zend_compile.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,19 +1615,7 @@ ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify
16151615
zend_hash_init_ex(&ce->function_table, 8, NULL, ZEND_FUNCTION_DTOR, persistent_hashes, 0);
16161616

16171617
if (ce->type == ZEND_INTERNAL_CLASS) {
1618-
#ifdef ZTS
1619-
int n = zend_hash_num_elements(CG(class_table));
1620-
1621-
if (CG(static_members_table) && n >= CG(last_static_member)) {
1622-
/* Support for run-time declaration: dl() */
1623-
CG(last_static_member) = n+1;
1624-
CG(static_members_table) = realloc(CG(static_members_table), (n+1)*sizeof(zval*));
1625-
CG(static_members_table)[n] = NULL;
1626-
}
1627-
ce->static_members_table = (zval*)(zend_intptr_t)n;
1628-
#else
16291618
ce->static_members_table = NULL;
1630-
#endif
16311619
} else {
16321620
ce->static_members_table = ce->default_static_members_table;
16331621
ce->info.user.doc_comment = NULL;

Zend/zend_execute_API.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ void shutdown_executor(void) /* {{{ */
318318
zend_hash_reverse_apply(EG(zend_constants), clean_non_persistent_constant_full);
319319
zend_hash_reverse_apply(EG(function_table), clean_non_persistent_function_full);
320320
zend_hash_reverse_apply(EG(class_table), clean_non_persistent_class_full);
321+
#ifdef ZTS
322+
zend_reset_internal_classes();
323+
#endif
321324
} else {
322325
ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL(EG(zend_constants), key, zv) {
323326
zend_constant *c = Z_PTR_P(zv);

Zend/zend_globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ struct _zend_compiler_globals {
119119

120120
#ifdef ZTS
121121
zval **static_members_table;
122-
int last_static_member;
122+
zend_uintptr_t last_static_member;
123123
#endif
124124
};
125125

Zend/zend_inheritance.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,16 @@ ZEND_API void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent
932932
ce->default_static_members_count += parent_ce->default_static_members_count;
933933
if (ce->type == ZEND_USER_CLASS) {
934934
ce->static_members_table = ce->default_static_members_table;
935+
#ifdef ZTS
936+
} else if (!ce->static_members_table_idx) {
937+
CG(last_static_member)++;
938+
ce->static_members_table_idx = CG(last_static_member);
939+
if (CG(static_members_table)) {
940+
/* Support for run-time declaration: dl() */
941+
CG(static_members_table) = realloc(CG(static_members_table), (CG(last_static_member) + 1) * sizeof(zval*));
942+
CG(static_members_table)[ce->static_members_table_idx] = NULL;
943+
}
944+
#endif
935945
}
936946
}
937947

Zend/zend_object_handlers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ static void zend_intenal_class_init_statics(zend_class_entry *class_type) /* {{{
13551355
}
13561356

13571357
#if ZTS
1358-
CG(static_members_table)[(zend_intptr_t)(class_type->static_members_table)] = emalloc(sizeof(zval) * class_type->default_static_members_count);
1358+
CG(static_members_table)[class_type->static_members_table_idx] = emalloc(sizeof(zval) * class_type->default_static_members_count);
13591359
#else
13601360
class_type->static_members_table = emalloc(sizeof(zval) * class_type->default_static_members_count);
13611361
#endif

Zend/zend_opcode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ ZEND_API void zend_cleanup_internal_class_data(zend_class_entry *ce)
146146
zval *end = p + ce->default_static_members_count;
147147

148148
#ifdef ZTS
149-
CG(static_members_table)[(zend_intptr_t)(ce->static_members_table)] = NULL;
149+
CG(static_members_table)[ce->static_members_table_idx] = NULL;
150150
#else
151151
ce->static_members_table = NULL;
152152
#endif

0 commit comments

Comments
 (0)
0