8000 An attempt to implemnt "preloading" ability. · php/php-src@e584df0 · GitHub
[go: up one dir, main page]

Skip to content

Commit e584df0

Browse files
committed
An attempt to implemnt "preloading" ability.
1 parent 063a009 commit e584df0

File tree

6 files changed

+830
-3
lines changed

6 files changed

+830
-3
lines changed

Zend/zend_compile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6322,6 +6322,10 @@ void zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
63226322

63236323
CG(active_class_entry) = original_ce;
63246324

6325+
if (toplevel) {
6326+
ce->ce_flags |= ZEND_ACC_TOP_LEVEL;
6327+
}
6328+
63256329
if (toplevel
63266330
/* We currently don't early-bind classes that implement interfaces or use traits */
63276331
&& !(ce->ce_flags & (ZEND_ACC_IMPLEMENT_INTERFACES|ZEND_ACC_IMPLEMENT_TRAITS))) {

Zend/zend_compile.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ typedef struct _zend_oparray_context {
223223
/* Function has typed arguments / class has typed props | | | */
224224
#define ZEND_ACC_HAS_TYPE_HINTS (1 << 8) /* ? | X | | */
225225
/* | | | */
226-
/* Class Flags (unused: 15...) | | | */
226+
/* Class Flags (unused: 16...) | | | */
227227
/* =========== | | | */
228228
/* | | | */
229229
/* Special class types | | | */
@@ -257,6 +257,9 @@ typedef struct _zend_oparray_context {
257257
/* User class has methods with static variables | | | */
258258
#define ZEND_HAS_STATIC_IN_METHODS (1 << 14) /* X | | | */
259259
/* | | | */
260+
/* Top-level class declaration | | | */
261+
#define ZEND_ACC_TOP_LEVEL (1 << 15) /* X | | | */
262+
/* | | | */
260263
/* Function Flags (unused: 25...30) | | | */
261264
/* ============== | | | */
262265
/* | | | */

Zend/zend_execute_API.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,57 @@ void shutdown_executor(void) /* {{{ */
340340
destroy_op_array(&func->op_array);
341341
zend_string_release_ex(key, 0);
342342
} ZEND_HASH_FOREACH_END_DEL();
343+
344+
/* Cleanup preloaded immutable functions */
345+
ZEND_HASH_REVERSE_FOREACH_VAL(E 10000 G(function_table), zv) {
346+
zend_op_array *op_array = Z_PTR_P(zv);
347+
if (op_array->type == ZEND_INTERNAL_FUNCTION) {
348+
break;
349+
}
350+
ZEND_ASSERT(op_array->fn_flags & ZEND_ACC_IMMUTABLE);
351+
if (op_array->static_variables) {
352+
HashTable *ht = ZEND_MAP_PTR_GET(op_array->static_variables_ptr);
353+
if (ht) {
354+
ZEND_ASSERT(GC_REFCOUNT(ht) == 1);
355+
zend_array_destroy(ht);
356+
}
357+
}
358+
} ZEND_HASH_FOREACH_END();
359+
343360
ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL(EG(class_table), key, zv) {
344361
if (_idx == EG(persistent_classes_count)) {
345362
break;
346363
}
347364
destroy_zend_class(zv);
348365
zend_string_release_ex(key, 0);
349366
} ZEND_HASH_FOREACH_END_DEL();
367+
368+
/* Cleanup preloaded immutable classes */
369+
ZEND_HASH_REVERSE_FOREACH_VAL(EG(class_table), zv) {
370+
zend_class_entry *ce = Z_PTR_P(zv);
371+
if (ce->type == ZEND_INTERNAL_CLASS) {
372+
break;
373+
}
374+
ZEND_ASSERT(ce->ce_flags & ZEND_ACC_IMMUTABLE);
375+
if (ce->default_static_members_count) {
376+
zend_cleanup_internal_class_data(ce);
377+
}
378+
if (ce->ce_flags & ZEND_HAS_STATIC_IN_METHODS) {
379+
zend_op_array *op_array;
380+
381+
ZEND_HASH_FOREACH_PTR(&ce->function_table, op_array) {
382+
if (op_array->type == ZEND_USER_FUNCTION) {
383+
if (op_array->static_variables) {
384+
HashTable *ht = ZEND_MAP_PTR_GET(op_array->static_variables_ptr);
385+
if (ht) {
386+
ZEND_ASSERT(GC_REFCOUNT(ht) == 1);
387+
zend_array_destroy(ht);
388+
}
389+
}
390+
}
391+
} ZEND_HASH_FOREACH_END();
392+
}
393+
} ZEND_HASH_FOREACH_END();
350394
}
351395

352396
zend_cleanup_internal_classes();

0 commit comments

Comments
 (0)
0