Skip to content

Commit e18f631

Browse files
committed
Use light version of zend_array_destroy() to free arrays without refcounted elements and string indexes.
1 parent 496171a commit e18f631

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,3 +1537,30 @@ static void ZEND_FASTCALL zend_jit_pre_dec(zval *var_ptr, zval *ret)
15371537
decrement_function(var_ptr);
15381538
ZVAL_COPY(ret, var_ptr);
15391539
}
1540+
1541+
#define HT_POISONED_PTR ((HashTable *) (intptr_t) -1)
1542+
1543+
static zend_never_inline void ZEND_FASTCALL _zend_hash_iterators_remove(HashTable *ht)
1544+
{
1545+
HashTableIterator *iter = EG(ht_iterators);
1546+
HashTableIterator *end = iter + EG(ht_iterators_used);
1547+
1548+
while (iter != end) {
1549+
if (iter->ht == ht) {
1550+
iter->ht = HT_POISONED_PTR;
1551+
}
1552+
iter++;
1553+
}
1554+
}
1555+
1556+
static void ZEND_FASTCALL zend_jit_array_free(HashTable *ht)
1557+
{
1558+
GC_REMOVE_FROM_BUFFER(ht);
1559+
if (UNEXPECTED(HT_HAS_ITERATORS(ht))) {
1560+
_zend_hash_iterators_remove(ht);
1561+
}
1562+
if (!(EXPECTED(HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED))) {
1563+
efree(HT_GET_DATA_ADDR(ht));
1564+
}
1565+
FREE_HASHTABLE(ht);
1566+
}

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,10 +1316,14 @@ static void* dasm_labels[zend_lb_MAX];
13161316
| EXT_CALL _efree, r0
13171317
|| break;
13181318
|| } else if (type == IS_ARRAY) {
1319-
|| if (opline) {
1320-
| SAVE_VALID_OPLINE opline, r0
1319+
|| if ((var_info) & (MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_REF)) {
1320+
|| if (opline && ((var_info) & (MAY_BE_ARRAY_OF_ARRAY|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_REF))) {
1321+
| SAVE_VALID_OPLINE opline, r0
1322+
|| }
1323+
| EXT_CALL zend_array_destroy, r0
1324+
|| } else {
1325+
| EXT_CALL zend_jit_array_free, r0|
13211326
|| }
1322-
| EXT_CALL zend_array_destroy, r0
13231327
|| break;
13241328
|| } else if (type == IS_OBJECT) {
13251329
|| if (opline) {

0 commit comments

Comments
 (0)