Lines Matching refs:heap
285 zend_mm_heap *heap; member
371 static ZEND_COLD ZEND_NORETURN void zend_mm_safe_error(zend_mm_heap *heap, in zend_mm_safe_error() argument
381 heap->overflow = 1; in zend_mm_safe_error()
393 heap->overflow = 0; in zend_mm_safe_error()
771 static void *zend_mm_chunk_alloc(zend_mm_heap *heap, size_t size, size_t alignment) argument
774 if (UNEXPECTED(heap->storage)) {
775 void *ptr = heap->storage->handlers.chunk_alloc(heap->storage, size, alignment);
783 static void zend_mm_chunk_free(zend_mm_heap *heap, void *addr, size_t size) argument
786 if (UNEXPECTED(heap->storage)) {
787 heap->storage->handlers.chunk_free(heap->storage, addr, size);
794 static int zend_mm_chunk_truncate(zend_mm_heap *heap, void *addr, size_t old_size, size_t new_size) argument
797 if (UNEXPECTED(heap->storage)) {
798 if (heap->storage->handlers.chunk_truncate) {
799 return heap->storage->handlers.chunk_truncate(heap->storage, addr, old_size, new_size);
813 static int zend_mm_chunk_extend(zend_mm_heap *heap, void *addr, size_t old_size, size_t new_size) argument
816 if (UNEXPECTED(heap->storage)) {
817 if (heap->storage->handlers.chunk_extend) {
818 return heap->storage->handlers.chunk_extend(heap->storage, addr, old_size, new_size);
840 static zend_always_inline void zend_mm_chunk_init(zend_mm_heap *heap, zend_mm_chunk *chunk) argument
842 chunk->heap = heap;
843 chunk->next = heap->main_chunk;
844 chunk->prev = heap->main_chunk->prev;
861 static size_t zend_mm_get_huge_block_size(zend_mm_heap *heap, void *ptr ZEND_FILE_LINE_DC ZEND_FILE…
862 static void *zend_mm_alloc_huge(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_OR…
863 static void zend_mm_free_huge(zend_mm_heap *heap, void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_D…
866 static void zend_mm_change_huge_block_size(zend_mm_heap *heap, void *ptr, size_t size, size_t dbg_s…
868 static void zend_mm_change_huge_block_size(zend_mm_heap *heap, void *ptr, size_t size ZEND_FILE_LIN…
876 static void *zend_mm_alloc_pages(zend_mm_heap *heap, uint32_t pages_count, size_t size ZEND_FILE_LI… argument
878 static void *zend_mm_alloc_pages(zend_mm_heap *heap, uint32_t pages_count ZEND_FILE_LINE_DC ZEND_FI…
881 zend_mm_chunk *chunk = heap->main_chunk;
1000 if (chunk->next == heap->main_chunk) {
1002 if (heap->cached_chunks) {
1003 heap->cached_chunks_count--;
1004 chunk = heap->cached_chunks;
1005 heap->cached_chunks = chunk->next;
1008 if (UNEXPECTED(ZEND_MM_CHUNK_SIZE > heap->limit - heap->real_size)) {
1009 if (zend_mm_gc(heap)) {
1011 } else if (heap->overflow == 0) {
1013 …zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted at %s:%d (tried to allocate %…
1015 …zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)…
1021 chunk = (zend_mm_chunk*)zend_mm_chunk_alloc(heap, ZEND_MM_CHUNK_SIZE, ZEND_MM_CHUNK_SIZE);
1024 if (zend_mm_gc(heap) &&
1025 …(chunk = (zend_mm_chunk*)zend_mm_chunk_alloc(heap, ZEND_MM_CHUNK_SIZE, ZEND_MM_CHUNK_SIZE)) != NUL…
1029 zend_mm_safe_error(heap, "Out of memory");
1031 …zend_mm_safe_error(heap, "Out of memory (allocated %zu bytes) at %s:%d (tried to allocate %zu byte…
1033 …zend_mm_safe_error(heap, "Out of memory (allocated %zu bytes) (tried to allocate %zu bytes)", heap…
1040 size_t size = heap->real_size + ZEND_MM_CHUNK_SIZE;
1041 size_t peak = MAX(heap->real_peak, size);
1042 heap->real_size = size;
1043 heap->real_peak = peak;
1046 heap->real_size += ZEND_MM_CHUNK_SIZE;
1050 heap->chunks_count++;
1051 if (heap->chunks_count > heap->peak_chunks_count) {
1052 heap->peak_chunks_count = heap->chunks_count;
1054 zend_mm_chunk_init(heap, chunk);
1069 chunk->next = heap->main_chunk->next;
1070 chunk->prev = heap->main_chunk;
1084 static zend_always_inline void *zend_mm_alloc_large_ex(zend_mm_heap *heap, size_t size ZEND_FILE_LI… argument
1088 …void *ptr = zend_mm_alloc_pages(heap, pages_count, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORI…
1090 …void *ptr = zend_mm_alloc_pages(heap, pages_count ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELA…
1094 size_t size = heap->size + pages_count * ZEND_MM_PAGE_SIZE;
1095 size_t peak = MAX(heap->peak, size);
1096 heap->size = size;
1097 heap->peak = peak;
1104 static zend_never_inline void *zend_mm_alloc_large(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_D… argument
1106 return zend_mm_alloc_large_ex(heap, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
1109 static zend_never_inline void *zend_mm_alloc_large(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_D… argument
1111 return zend_mm_alloc_large_ex(heap, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
1115 static zend_always_inline void zend_mm_delete_chunk(zend_mm_heap *heap, zend_mm_chunk *chunk) argument
1119 heap->chunks_count--;
1120 if (heap->chunks_count + heap->cached_chunks_count < heap->avg_chunks_count + 0.1
1121 || (heap->chunks_count == heap->last_chunks_delete_boundary
1122 && heap->last_chunks_delete_count >= 4)) {
1124 heap->cached_chunks_count++;
1125 chunk->next = heap->cached_chunks;
1126 heap->cached_chunks = chunk;
1129 heap->real_size -= ZEND_MM_CHUNK_SIZE;
1131 if (!heap->cached_chunks) {
1132 if (heap->chunks_count != heap->last_chunks_delete_boundary) {
1133 heap->last_chunks_delete_boundary = heap->chunks_count;
1134 heap->last_chunks_delete_count = 0;
1136 heap->last_chunks_delete_count++;
1139 if (!heap->cached_chunks || chunk->num > heap->cached_chunks->num) {
1140 zend_mm_chunk_free(heap, chunk, ZEND_MM_CHUNK_SIZE);
1143 chunk->next = heap->cached_chunks->next;
1144 zend_mm_chunk_free(heap, heap->cached_chunks, ZEND_MM_CHUNK_SIZE);
1145 heap->cached_chunks = chunk;
1150 static zend_always_inline void zend_mm_free_pages_ex(zend_mm_heap *heap, zend_mm_chunk *chunk, uint… argument
1159 …if (free_chunk && chunk != heap->main_chunk && chunk->free_pages == ZEND_MM_PAGES - ZEND_MM_FIRST_…
1160 zend_mm_delete_chunk(heap, chunk);
1164 static zend_never_inline void zend_mm_free_pages(zend_mm_heap *heap, zend_mm_chunk *chunk, int page… argument
1166 zend_mm_free_pages_ex(heap, chunk, page_num, pages_count, 1);
1169 static zend_always_inline void zend_mm_free_large(zend_mm_heap *heap, zend_mm_chunk *chunk, int pag… argument
1172 heap->size -= pages_count * ZEND_MM_PAGE_SIZE;
1174 zend_mm_free_pages(heap, chunk, page_num, pages_count);
1243 static zend_never_inline void *zend_mm_alloc_small_slow(zend_mm_heap *heap, uint32_t bin_num ZEND_F… argument
1251 …bin = (zend_mm_bin*)zend_mm_alloc_pages(heap, bin_pages[bin_num], bin_data_size[bin_num] ZEND_FILE…
1253 …bin = (zend_mm_bin*)zend_mm_alloc_pages(heap, bin_pages[bin_num] ZEND_FILE_LINE_RELAY_CC ZEND_FILE…
1274 heap->free_slot[bin_num] = p = (zend_mm_free_slot*)((char*)bin + bin_data_size[bin_num]);
1299 static zend_always_inline void *zend_mm_alloc_small(zend_mm_heap *heap, int bin_num ZEND_FILE_LINE_… argument
1303 size_t size = heap->size + bin_data_size[bin_num];
1304 size_t peak = MAX(heap->peak, size);
1305 heap->size = size;
1306 heap->peak = peak;
1310 if (EXPECTED(heap->free_slot[bin_num] != NULL)) {
1311 zend_mm_free_slot *p = heap->free_slot[bin_num];
1312 heap->free_slot[bin_num] = p->next_free_slot;
1315 …return zend_mm_alloc_small_slow(heap, bin_num ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC…
1319 static zend_always_inline void zend_mm_free_small(zend_mm_heap *heap, void *ptr, int bin_num) argument
1324 heap->size -= bin_data_size[bin_num];
1335 p->next_free_slot = heap->free_slot[bin_num];
1336 heap->free_slot[bin_num] = p;
1344 static zend_always_inline zend_mm_debug_info *zend_mm_get_debug_info(zend_mm_heap *heap, void *ptr) argument
1355 ZEND_MM_CHECK(chunk->heap == heap, "zend_mm_heap corrupted");
1367 static zend_always_inline void *zend_mm_alloc_heap(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_D… argument
1383 …ptr = zend_mm_alloc_small(heap, ZEND_MM_SMALL_SIZE_TO_BIN(size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_…
1385 dbg = zend_mm_get_debug_info(heap, ptr);
1394 ptr = zend_mm_alloc_large(heap, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
1396 dbg = zend_mm_get_debug_info(heap, ptr);
1408 return zend_mm_alloc_huge(heap, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
1412 static zend_always_inline void zend_mm_free_heap(zend_mm_heap *heap, void *ptr ZEND_FILE_LINE_DC ZE… argument
1418 zend_mm_free_huge(heap, ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
1425 ZEND_MM_CHECK(chunk->heap == heap, "zend_mm_heap corrupted");
1427 zend_mm_free_small(heap, ptr, ZEND_MM_SRUN_BIN_NUM(info));
1432 zend_mm_free_large(heap, chunk, page_num, pages_count);
1437 static size_t zend_mm_size(zend_mm_heap *heap, void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) argument
1442 …return zend_mm_get_huge_block_size(heap, ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
1446 zend_mm_debug_info *dbg = zend_mm_get_debug_info(heap, ptr);
1455 ZEND_MM_CHECK(chunk->heap == heap, "zend_mm_heap corrupted");
1465 static zend_never_inline void *zend_mm_realloc_slow(zend_mm_heap *heap, void *ptr, size_t size, siz… argument
1471 size_t orig_peak = heap->peak;
1473 ret = zend_mm_alloc_heap(heap, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
1475 zend_mm_free_heap(heap, ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
1477 heap->peak = MAX(orig_peak, heap->size);
1483 static zend_never_inline void *zend_mm_realloc_huge(zend_mm_heap *heap, void *ptr, size_t size, siz… argument
1491 …old_size = zend_mm_get_huge_block_size(heap, ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY…
1511 …zend_mm_change_huge_block_size(heap, ptr, new_size, real_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LI…
1513 …zend_mm_change_huge_block_size(heap, ptr, new_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_REL…
1518 if (zend_mm_chunk_truncate(heap, ptr, old_size, new_size)) {
1520 heap->real_size -= old_size - new_size;
1523 heap->size -= old_size - new_size;
1526 …zend_mm_change_huge_block_size(heap, ptr, new_size, real_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LI…
1528 …zend_mm_change_huge_block_size(heap, ptr, new_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_REL…
1534 if (UNEXPECTED(new_size - old_size > heap->limit - heap->real_size)) {
1535 if (zend_mm_gc(heap) && new_size - old_size <= heap->limit - heap->real_size) {
1537 } else if (heap->overflow == 0) {
1539 …zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted at %s:%d (tried to allocate %…
1541 …zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)…
1548 if (zend_mm_chunk_extend(heap, ptr, old_size, new_size)) {
1550 heap->real_size += new_size - old_size;
1553 heap->real_peak = MAX(heap->real_peak, heap->real_size);
1554 heap->size += new_size - old_size;
1555 heap->peak = MAX(heap->peak, heap->size);
1558 …zend_mm_change_huge_block_size(heap, ptr, new_size, real_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LI…
1560 …zend_mm_change_huge_block_size(heap, ptr, new_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_REL…
1567 …return zend_mm_realloc_slow(heap, ptr, size, MIN(old_size, copy_size) ZEND_FILE_LINE_RELAY_CC ZEND…
1570 static zend_always_inline void *zend_mm_realloc_heap(zend_mm_heap *heap, void *ptr, size_t size, bo… argument
1583 return _zend_mm_alloc(heap, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
1585 …return zend_mm_realloc_huge(heap, ptr, size, copy_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG…
1597 ZEND_MM_CHECK(chunk->heap == heap, "zend_mm_heap corrupted");
1609 …ret = zend_mm_alloc_small(heap, ZEND_MM_SMALL_SIZE_TO_BIN(size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_…
1612 zend_mm_free_small(heap, ptr, old_bin_num);
1622 size_t orig_peak = heap->peak;
1624 …ret = zend_mm_alloc_small(heap, ZEND_MM_SMALL_SIZE_TO_BIN(size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_…
1627 zend_mm_free_small(heap, ptr, old_bin_num);
1629 heap->peak = MAX(orig_peak, heap->size);
1638 dbg = zend_mm_get_debug_info(heap, ret);
1655 dbg = zend_mm_get_debug_info(heap, ptr);
1669 heap->size -= rest_pages_count * ZEND_MM_PAGE_SIZE;
1675 dbg = zend_mm_get_debug_info(heap, ptr);
1692 size_t size = heap->size + (new_size - old_size);
1693 size_t peak = MAX(heap->peak, size);
1694 heap->size = size;
1695 heap->peak = peak;
1702 dbg = zend_mm_get_debug_info(heap, ptr);
1720 …return zend_mm_realloc_slow(heap, ptr, size, copy_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG…
1728 static void zend_mm_add_huge_block(zend_mm_heap *heap, void *ptr, size_t size, size_t dbg_size ZEND… argument
1730 static void zend_mm_add_huge_block(zend_mm_heap *heap, void *ptr, size_t size ZEND_FILE_LINE_DC ZEN…
1733 …zend_mm_huge_list *list = (zend_mm_huge_list*)zend_mm_alloc_heap(heap, sizeof(zend_mm_huge_list) Z…
1736 list->next = heap->huge_list;
1744 heap->huge_list = list;
1747 static size_t zend_mm_del_huge_block(zend_mm_heap *heap, void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE… argument
1750 zend_mm_huge_list *list = heap->huge_list;
1758 heap->huge_list = list->next;
1761 zend_mm_free_heap(heap, list ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
1771 static size_t zend_mm_get_huge_block_size(zend_mm_heap *heap, void *ptr ZEND_FILE_LINE_DC ZEND_FILE… argument
1773 zend_mm_huge_list *list = heap->huge_list;
1785 static void zend_mm_change_huge_block_size(zend_mm_heap *heap, void *ptr, size_t size, size_t dbg_s… argument
1787 static void zend_mm_change_huge_block_size(zend_mm_heap *heap, void *ptr, size_t size ZEND_FILE_LIN…
1790 zend_mm_huge_list *list = heap->huge_list;
1807 static void *zend_mm_alloc_huge(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_OR… argument
1826 if (UNEXPECTED(new_size > heap->limit - heap->real_size)) {
1827 if (zend_mm_gc(heap) && new_size <= heap->limit - heap->real_size) {
1829 } else if (heap->overflow == 0) {
1831 …zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted at %s:%d (tried to allocate %…
1833 …zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)…
1839 ptr = zend_mm_chunk_alloc(heap, new_size, ZEND_MM_CHUNK_SIZE);
1842 if (zend_mm_gc(heap) &&
1843 (ptr = zend_mm_chunk_alloc(heap, new_size, ZEND_MM_CHUNK_SIZE)) != NULL) {
1847 zend_mm_safe_error(heap, "Out of memory");
1849 …zend_mm_safe_error(heap, "Out of memory (allocated %zu bytes) at %s:%d (tried to allocate %zu byte…
1851 …zend_mm_safe_error(heap, "Out of memory (allocated %zu bytes) (tried to allocate %zu bytes)", heap…
1857 …zend_mm_add_huge_block(heap, ptr, new_size, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY…
1859 zend_mm_add_huge_block(heap, ptr, new_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
1863 size_t size = heap->real_size + new_size;
1864 size_t peak = MAX(heap->real_peak, size);
1865 heap->real_size = size;
1866 heap->real_peak = peak;
1869 size_t size = heap->size + new_size;
1870 size_t peak = MAX(heap->peak, size);
1871 heap->size = size;
1872 heap->peak = peak;
1875 heap->real_size += new_size;
1880 static void zend_mm_free_huge(zend_mm_heap *heap, void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_D… argument
1885 size = zend_mm_del_huge_block(heap, ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
1886 zend_mm_chunk_free(heap, ptr, size);
1888 heap->real_size -= size;
1891 heap->size -= size;
1902 zend_mm_heap *heap; local
1910 heap = &chunk->heap_slot;
1911 chunk->heap = heap;
1919 heap->main_chunk = chunk;
1920 heap->cached_chunks = NULL;
1921 heap->chunks_count = 1;
1922 heap->peak_chunks_count = 1;
1923 heap->cached_chunks_count = 0;
1924 heap->avg_chunks_count = 1.0;
1925 heap->last_chunks_delete_boundary = 0;
1926 heap->last_chunks_delete_count = 0;
1928 heap->real_size = ZEND_MM_CHUNK_SIZE;
1931 heap->real_peak = ZEND_MM_CHUNK_SIZE;
1932 heap->size = 0;
1933 heap->peak = 0;
1936 heap->limit = (size_t)Z_L(-1) >> 1;
1937 heap->overflow = 0;
1940 heap->use_custom_heap = ZEND_MM_CUSTOM_HEAP_NONE;
1943 heap->storage = NULL;
1945 heap->huge_list = NULL;
1946 return heap;
1949 ZEND_API size_t zend_mm_gc(zend_mm_heap *heap) argument
1961 if (heap->use_custom_heap) {
1968 p = heap->free_slot[i];
1971 ZEND_MM_CHECK(chunk->heap == heap, "zend_mm_heap corrupted");
1996 q = &heap->free_slot[i];
2000 ZEND_MM_CHECK(chunk->heap == heap, "zend_mm_heap corrupted");
2024 chunk = heap->main_chunk;
2036 zend_mm_free_pages_ex(heap, chunk, i, pages_count, 0);
2053 zend_mm_delete_chunk(heap, chunk);
2058 } while (chunk != heap->main_chunk);
2095 static zend_long zend_mm_find_leaks(zend_mm_heap *heap, zend_mm_chunk *p, uint32_t i, zend_leak_inf… argument
2122 } while (p != heap->main_chunk);
2126 static zend_long zend_mm_find_leaks_huge(zend_mm_heap *heap, zend_mm_huge_list *list) argument
2135 zend_mm_chunk_free(heap, p->ptr, p->size);
2136 zend_mm_free_heap(heap, p, NULL, 0, NULL, 0);
2147 static void zend_mm_check_leaks(zend_mm_heap *heap) argument
2157 list = heap->huge_list;
2170 repeated = zend_mm_find_leaks_huge(heap, list);
2176 heap->huge_list = list = list->next;
2177 zend_mm_chunk_free(heap, q->ptr, q->size);
2178 zend_mm_free_heap(heap, q, NULL, 0, NULL, 0);
2182 p = heap->main_chunk;
2209 zend_mm_find_leaks(heap, p, i + bin_pages[bin_num], &leak);
2235 repeated = zend_mm_find_leaks(heap, p, i + pages_count, &leak);
2247 } while (p != heap->main_chunk);
2259 void zend_mm_shutdown(zend_mm_heap *heap, bool full, bool silent) argument
2265 if (heap->use_custom_heap) {
2266 if (heap->custom_heap.std._malloc == tracked_malloc) {
2270 zend_hash_clean(heap->tracked_allocs);
2272 zend_hash_destroy(heap->tracked_allocs);
2273 free(heap->tracked_allocs);
2275 heap->custom_heap.std._free = free;
2277 heap->size = 0;
2281 if (ZEND_DEBUG && heap->use_custom_heap == ZEND_MM_CUSTOM_HEAP_DEBUG) {
2282 heap->custom_heap.debug._free(heap ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC);
2284 heap->custom_heap.std._free(heap);
2295 zend_mm_check_leaks(heap);
2301 list = heap->huge_list;
2302 heap->huge_list = NULL;
2306 zend_mm_chunk_free(heap, q->ptr, q->size);
2310 p = heap->main_chunk->next;
2311 while (p != heap->main_chunk) {
2313 p->next = heap->cached_chunks;
2314 heap->cached_chunks = p;
2316 heap->chunks_count--;
2317 heap->cached_chunks_count++;
2322 while (heap->cached_chunks) {
2323 p = heap->cached_chunks;
2324 heap->cached_chunks = p->next;
2325 zend_mm_chunk_free(heap, p, ZEND_MM_CHUNK_SIZE);
2328 zend_mm_chunk_free(heap, heap->main_chunk, ZEND_MM_CHUNK_SIZE);
2331 heap->avg_chunks_count = (heap->avg_chunks_count + (double)heap->peak_chunks_count) / 2.0;
2332 while ((double)heap->cached_chunks_count + 0.9 > heap->avg_chunks_count &&
2333 heap->cached_chunks) {
2334 p = heap->cached_chunks;
2335 heap->cached_chunks = p->next;
2336 zend_mm_chunk_free(heap, p, ZEND_MM_CHUNK_SIZE);
2337 heap->cached_chunks_count--;
2340 p = heap->cached_chunks;
2349 p = heap->main_chunk;
2350 p->heap = &p->heap_slot;
2358 heap->size = heap->peak = 0;
2360 memset(heap->free_slot, 0, sizeof(heap->free_slot));
2362 heap->real_size = (heap->cached_chunks_count + 1) * ZEND_MM_CHUNK_SIZE;
2365 heap->real_peak = (heap->cached_chunks_count + 1) * ZEND_MM_CHUNK_SIZE;
2367 heap->chunks_count = 1;
2368 heap->peak_chunks_count = 1;
2369 heap->last_chunks_delete_boundary = 0;
2370 heap->last_chunks_delete_count = 0;
2382 ZEND_API void* ZEND_FASTCALL _zend_mm_alloc(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_DC ZEND_… argument
2384 return zend_mm_alloc_heap(heap, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
2387 ZEND_API void ZEND_FASTCALL _zend_mm_free(zend_mm_heap *heap, void *ptr ZEND_FILE_LINE_DC ZEND_FILE… argument
2389 zend_mm_free_heap(heap, ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
2392 void* ZEND_FASTCALL _zend_mm_realloc(zend_mm_heap *heap, void *ptr, size_t size ZEND_FILE_LINE_DC Z… argument
2394 …return zend_mm_realloc_heap(heap, ptr, size, 0, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_R…
2397 void* ZEND_FASTCALL _zend_mm_realloc2(zend_mm_heap *heap, void *ptr, size_t size, size_t copy_size … argument
2399 …return zend_mm_realloc_heap(heap, ptr, size, 1, copy_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_O…
2402 ZEND_API size_t ZEND_FASTCALL _zend_mm_block_size(zend_mm_heap *heap, void *ptr ZEND_FILE_LINE_DC Z… argument
2405 if (UNEXPECTED(heap->use_custom_heap)) {
2406 if (heap->custom_heap.std._malloc == tracked_malloc) {
2408 zval *size_zv = zend_hash_index_find(heap->tracked_allocs, h);
2416 return zend_mm_size(heap, ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
2562 ZEND_MM_CHECK(chunk->heap == AG(mm_heap), "zend_mm_heap corrupted"); \
2574 ZEND_MM_CHECK(chunk->heap == AG(mm_heap), "zend_mm_heap corrupted"); \
2591 …ZEND_MM_CHECK(chunk->heap == AG(mm_heap) && ZEND_MM_ALIGNED_OFFSET(page_offset, ZEND_MM_PAGE_SIZE)…
2732 zend_mm_heap *heap = AG(mm_heap); local
2734 if (UNEXPECTED(memory_limit < heap->real_size)) {
2735 if (memory_limit >= heap->real_size - heap->cached_chunks_count * ZEND_MM_CHUNK_SIZE) {
2738 zend_mm_chunk *p = heap->cached_chunks;
2739 heap->cached_chunks = p->next;
2740 zend_mm_chunk_free(heap, p, ZEND_MM_CHUNK_SIZE);
2741 heap->cached_chunks_count--;
2742 heap->real_size -= ZEND_MM_CHUNK_SIZE;
2743 } while (memory_limit < heap->real_size);
2807 static zend_always_inline void tracked_add(zend_mm_heap *heap, void *ptr, size_t size) { argument
2812 zend_hash_index_add_new(heap->tracked_allocs, h, &size_zv);
2815 static zend_always_inline zval *tracked_get_size_zv(zend_mm_heap *heap, void *ptr) { argument
2817 zval *size_zv = zend_hash_index_find(heap->tracked_allocs, h);
2822 static zend_always_inline void tracked_check_limit(zend_mm_heap *heap, size_t add_size) { argument
2823 if (add_size > heap->limit - heap->size && !heap->overflow) {
2825 zend_mm_safe_error(heap,
2827 heap->limit, "file", 0, add_size);
2829 zend_mm_safe_error(heap,
2831 heap->limit, add_size);
2838 zend_mm_heap *heap = AG(mm_heap); local
2839 tracked_check_limit(heap, size);
2846 tracked_add(heap, ptr, size);
2847 heap->size += size;
2856 zend_mm_heap *heap = AG(mm_heap); local
2857 zval *size_zv = tracked_get_size_zv(heap, ptr);
2858 heap->size -= Z_LVAL_P(size_zv);
2859 zend_hash_del_bucket(heap->tracked_allocs, (Bucket *) size_zv);
2864 zend_mm_heap *heap = AG(mm_heap); local
2868 old_size_zv = tracked_get_size_zv(heap, ptr);
2873 tracked_check_limit(heap, new_size - old_size);
2878 zend_hash_del_bucket(heap->tracked_allocs, (Bucket *) old_size_zv);
2882 tracked_add(heap, ptr, new_size);
2883 heap->size += new_size - old_size;
2981 ZEND_API void zend_mm_set_custom_handlers(zend_mm_heap *heap, argument
2987 zend_mm_heap *_heap = (zend_mm_heap*)heap;
3000 ZEND_API void zend_mm_get_custom_handlers(zend_mm_heap *heap, argument
3006 zend_mm_heap *_heap = (zend_mm_heap*)heap;
3008 if (heap->use_custom_heap) {
3025 ZEND_API void zend_mm_set_custom_debug_handlers(zend_mm_heap *heap, argument
3031 zend_mm_heap *_heap = (zend_mm_heap*)heap;
3041 ZEND_API zend_mm_storage *zend_mm_get_storage(zend_mm_heap *heap) argument
3044 return heap->storage;
3060 zend_mm_heap *heap; local
3071 heap = &chunk->heap_slot;
3072 chunk->heap = heap;
3080 heap->main_chunk = chunk;
3081 heap->cached_chunks = NULL;
3082 heap->chunks_count = 1;
3083 heap->peak_chunks_count = 1;
3084 heap->cached_chunks_count = 0;
3085 heap->avg_chunks_count = 1.0;
3086 heap->last_chunks_delete_boundary = 0;
3087 heap->last_chunks_delete_count = 0;
3089 heap->real_size = ZEND_MM_CHUNK_SIZE;
3092 heap->real_peak = ZEND_MM_CHUNK_SIZE;
3093 heap->size = 0;
3094 heap->peak = 0;
3097 heap->limit = (size_t)Z_L(-1) >> 1;
3098 heap->overflow = 0;
3101 heap->use_custom_heap = 0;
3103 heap->storage = &tmp_storage;
3104 heap->huge_list = NULL;
3105 memset(heap->free_slot, 0, sizeof(heap->free_slot));
3106 …storage = _zend_mm_alloc(heap, sizeof(zend_mm_storage) + data_size ZEND_FILE_LINE_CC ZEND_FILE_LIN…
3119 heap->storage = storage;
3120 return heap;