Improved "Fast Shutdown".

This commit is contained in:
Dmitry Stogov 2018-07-17 17:31:04 +03:00
parent 7db988cc30
commit 3b6e1ee4ee
4 changed files with 29 additions and 19 deletions

View File

@ -181,6 +181,10 @@ void init_executor(void) /* {{{ */
EG(each_deprecation_thrown) = 0;
EG(persisent_constants_count) = EG(zend_constants)->nNumUsed;
EG(persistent_functions_count) = EG(function_table)->nNumUsed;
EG(persistent_classes_count) = EG(class_table)->nNumUsed;
EG(active) = 1;
}
/* }}} */
@ -279,25 +283,9 @@ void shutdown_executor(void) /* {{{ */
* Zend Memory Manager frees memory by its own. We don't have to free
* each allocated block separately.
*/
ZEND_HASH_REVERSE_FOREACH_VAL(EG(zend_constants), zv) {
zend_constant *c = Z_PTR_P(zv);
if (c->flags & CONST_PERSISTENT) {
break;
}
} ZEND_HASH_FOREACH_END_DEL();
ZEND_HASH_REVERSE_FOREACH_VAL(EG(function_table), zv) {
zend_function *func = Z_PTR_P(zv);
if (func->type == ZEND_INTERNAL_FUNCTION) {
break;
}
} ZEND_HASH_FOREACH_END_DEL();
ZEND_HASH_REVERSE_FOREACH_VAL(EG(class_table), zv) {
zend_class_entry *ce = Z_PTR_P(zv);
if (ce->type == ZEND_INTERNAL_CLASS) {
break;
}
} ZEND_HASH_FOREACH_END_DEL();
zend_hash_discard(EG(zend_constants), EG(persisent_constants_count));
zend_hash_discard(EG(function_table), EG(persistent_functions_count));
zend_hash_discard(EG(class_table), EG(persistent_classes_count));
zend_cleanup_internal_classes();
} else {
zend_hash_graceful_reverse_destroy(&EG(symbol_table));

View File

@ -164,6 +164,10 @@ struct _zend_executor_globals {
int ticks_count;
uint32_t persisent_constants_count;
uint32_t persistent_functions_count;
uint32_t persistent_classes_count;
HashTable *in_autoload;
zend_function *autoload_func;
zend_bool full_tables_cleanup;

View File

@ -327,6 +327,23 @@ ZEND_API void ZEND_FASTCALL zend_hash_extend(HashTable *ht, uint32_t nSize, zend
}
}
ZEND_API void ZEND_FASTCALL zend_hash_discard(HashTable *ht, uint32_t nNumUsed)
{
uint32_t idx;
Bucket *p;
uint32_t nIndex;
for (idx = ht->nNumUsed, p = ht->arData + idx; idx > nNumUsed; idx--) {
p--;
if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue;
ht->nNumOfElements--;
/* Collision pointers always directed from higher to lower buckets */
nIndex = p->h | ht->nTableMask;
HT_HASH(ht, nIndex) = Z_NEXT(p->val);
}
ht->nNumUsed = idx;
}
static uint32_t zend_array_recalc_elements(HashTable *ht)
{
zval *val;

View File

@ -104,6 +104,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_real_init_mixed(HashTable *ht);
ZEND_API void ZEND_FASTCALL zend_hash_packed_to_hash(HashTable *ht);
ZEND_API void ZEND_FASTCALL zend_hash_to_packed(HashTable *ht);
ZEND_API void ZEND_FASTCALL zend_hash_extend(HashTable *ht, uint32_t nSize, zend_bool packed);
ZEND_API void ZEND_FASTCALL zend_hash_discard(HashTable *ht, uint32_t nNumUsed);
/* additions/updates/changes */
ZEND_API zval* ZEND_FASTCALL _zend_hash_add_or_update(HashTable *ht, zend_string *key, zval *pData, uint32_t flag ZEND_FILE_LINE_DC);