com php-src: Merge branch 'PHP-7.2' into PHP-7.3: Zend/zend_a lloc.c

From: Date: Mon, 26 Aug 2019 08:26:49 +0000
Subject: com php-src: Merge branch 'PHP-7.2' into PHP-7.3: Zend/zend_a lloc.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-108046@lists.php.net to get a copy of this message
Commit: a26f63213d29b85bf44e22163ddb0b735623617f Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 26 Aug 2019 10:26:49 +0200 Parents: d1646e328aff679dccf5597476e98c182fe4365c 16d35eb643bf974554e5264021ee10fc969e2053 Branches: PHP-7.3 PHP-7.4 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a26f63213d29b85bf44e22163ddb0b735623617f Log: Merge branch 'PHP-7.2' into PHP-7.3 Changed paths: MM Zend/zend_alloc.c

diff --cc Zend/zend_alloc.c index 11f5b46,3a43027..035e23f --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@@ -1439,130 -1425,97 +1439,130 @@@ static size_t zend_mm_size(zend_mm_hea } } -static void *zend_mm_realloc_heap(zend_mm_heap *heap, void *ptr, size_t size, size_t copy_size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) +static zend_never_inline void *zend_mm_realloc_slow(zend_mm_heap *heap, void *ptr, size_t size, size_t copy_size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) +{ + void *ret; + +#if ZEND_MM_STAT + do { + size_t orig_peak = heap->peak; + size_t orig_real_peak = heap->real_peak; +#endif + ret = zend_mm_alloc_heap(heap, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + memcpy(ret, ptr, copy_size); + zend_mm_free_heap(heap, ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); +#if ZEND_MM_STAT + heap->peak = MAX(orig_peak, heap->size); + heap->real_peak = MAX(orig_real_peak, heap->real_size); + } while (0); +#endif + return ret; +} + +static zend_never_inline void *zend_mm_realloc_huge(zend_mm_heap *heap, void *ptr, size_t size, size_t copy_size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) { - size_t page_offset; size_t old_size; size_t new_size; - void *ret; #if ZEND_DEBUG size_t real_size; - zend_mm_debug_info *dbg; #endif - page_offset = ZEND_MM_ALIGNED_OFFSET(ptr, ZEND_MM_CHUNK_SIZE); - if (UNEXPECTED(page_offset == 0)) { - if (UNEXPECTED(ptr == NULL)) { - return zend_mm_alloc_heap(heap, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); - } - old_size = zend_mm_get_huge_block_size(heap, ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + old_size = zend_mm_get_huge_block_size(heap, ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); #if ZEND_DEBUG - real_size = size; - size = ZEND_MM_ALIGNED_SIZE(size) + ZEND_MM_ALIGNED_SIZE(sizeof(zend_mm_debug_info)); + real_size = size; + size = ZEND_MM_ALIGNED_SIZE(size) + ZEND_MM_ALIGNED_SIZE(sizeof(zend_mm_debug_info)); #endif - if (size > ZEND_MM_MAX_LARGE_SIZE) { + if (size > ZEND_MM_MAX_LARGE_SIZE) { #if ZEND_DEBUG - size = real_size; + size = real_size; #endif #ifdef ZEND_WIN32 - /* On Windows we don't have ability to extend huge blocks in-place. - * We allocate them with 2MB size granularity, to avoid many - * reallocations when they are extended by small pieces - */ - new_size = ZEND_MM_ALIGNED_SIZE_EX(size, MAX(REAL_PAGE_SIZE, ZEND_MM_CHUNK_SIZE)); + /* On Windows we don't have ability to extend huge blocks in-place. + * We allocate them with 2MB size granularity, to avoid many + * reallocations when they are extended by small pieces + */ + new_size = ZEND_MM_ALIGNED_SIZE_EX(size, MAX(REAL_PAGE_SIZE, ZEND_MM_CHUNK_SIZE)); #else - new_size = ZEND_MM_ALIGNED_SIZE_EX(size, REAL_PAGE_SIZE); + new_size = ZEND_MM_ALIGNED_SIZE_EX(size, REAL_PAGE_SIZE); #endif - if (new_size == old_size) { + if (new_size == old_size) { #if ZEND_DEBUG - zend_mm_change_huge_block_size(heap, ptr, new_size, real_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + zend_mm_change_huge_block_size(heap, ptr, new_size, real_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); #else - zend_mm_change_huge_block_size(heap, ptr, new_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + zend_mm_change_huge_block_size(heap, ptr, new_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); #endif - return ptr; - } else if (new_size < old_size) { - /* unmup tail */ - if (zend_mm_chunk_truncate(heap, ptr, old_size, new_size)) { + return ptr; + } else if (new_size < old_size) { + /* unmup tail */ + if (zend_mm_chunk_truncate(heap, ptr, old_size, new_size)) { #if ZEND_MM_STAT || ZEND_MM_LIMIT - heap->real_size -= old_size - new_size; + heap->real_size -= old_size - new_size; #endif #if ZEND_MM_STAT - heap->size -= old_size - new_size; + heap->size -= old_size - new_size; #endif #if ZEND_DEBUG - zend_mm_change_huge_block_size(heap, ptr, new_size, real_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + zend_mm_change_huge_block_size(heap, ptr, new_size, real_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); #else - zend_mm_change_huge_block_size(heap, ptr, new_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + zend_mm_change_huge_block_size(heap, ptr, new_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); #endif - return ptr; - } - } else /* if (new_size > old_size) */ { + return ptr; + } + } else /* if (new_size > old_size) */ { #if ZEND_MM_LIMIT - if (UNEXPECTED(heap->real_size + (new_size - old_size) > heap->limit)) { - if (zend_mm_gc(heap) && heap->real_size + (new_size - old_size) <= heap->limit) { - if (UNEXPECTED(new_size - old_size > heap->limit - heap->real_size)) { - if (zend_mm_gc(heap) && new_size - old_size <= heap->limit - heap->real_size) { - /* pass */ - } else if (heap->overflow == 0) { ++ if (UNEXPECTED(new_size - old_size > heap->limit - heap->real_size)) { ++ if (zend_mm_gc(heap) && new_size - old_size <= heap->limit - heap->real_size) { + /* pass */ + } else if (heap->overflow == 0) { #if ZEND_DEBUG - zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted at %s:%d (tried to allocate %zu bytes)", heap->limit, __zend_filename, __zend_lineno, size); + zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted at %s:%d (tried to allocate %zu bytes)", heap->limit, __zend_filename, __zend_lineno, size); #else - zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)", heap->limit, size); + zend_mm_safe_error(heap, "Allowed memory size of %zu bytes exhausted (tried to allocate %zu bytes)", heap->limit, size); #endif - return NULL; - } + return NULL; } + } #endif - /* try to map tail right after this block */ - if (zend_mm_chunk_extend(heap, ptr, old_size, new_size)) { + /* try to map tail right after this block */ + if (zend_mm_chunk_extend(heap, ptr, old_size, new_size)) { #if ZEND_MM_STAT || ZEND_MM_LIMIT - heap->real_size += new_size - old_size; + heap->real_size += new_size - old_size; #endif #if ZEND_MM_STAT - heap->real_peak = MAX(heap->real_peak, heap->real_size); - heap->size += new_size - old_size; - heap->peak = MAX(heap->peak, heap->size); + heap->real_peak = MAX(heap->real_peak, heap->real_size); + heap->size += new_size - old_size; + heap->peak = MAX(heap->peak, heap->size); #endif #if ZEND_DEBUG - zend_mm_change_huge_block_size(heap, ptr, new_size, real_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + zend_mm_change_huge_block_size(heap, ptr, new_size, real_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); #else - zend_mm_change_huge_block_size(heap, ptr, new_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + zend_mm_change_huge_block_size(heap, ptr, new_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); #endif - return ptr; - } + return ptr; } } + } + + return zend_mm_realloc_slow(heap, ptr, size, MIN(old_size, copy_size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); +} + +static zend_always_inline void *zend_mm_realloc_heap(zend_mm_heap *heap, void *ptr, size_t size, zend_bool use_copy_size, size_t copy_size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) +{ + size_t page_offset; + size_t old_size; + size_t new_size; + void *ret; +#if ZEND_DEBUG + zend_mm_debug_info *dbg; +#endif + + page_offset = ZEND_MM_ALIGNED_OFFSET(ptr, ZEND_MM_CHUNK_SIZE); + if (UNEXPECTED(page_offset == 0)) { + if (EXPECTED(ptr == NULL)) { + return _zend_mm_alloc(heap, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + } else { + return zend_mm_realloc_huge(heap, ptr, size, copy_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + } } else { zend_mm_chunk *chunk = (zend_mm_chunk*)ZEND_MM_ALIGNED_BASE(ptr, ZEND_MM_CHUNK_SIZE); int page_num = (int)(page_offset / ZEND_MM_PAGE_SIZE);
« previous php.cvs (#108046) next »