mirror of
https://github.com/php/php-src.git
synced 2025-01-24 12:43:38 +08:00
New memory manager
This commit is contained in:
parent
7f9a43653c
commit
29ed52ffa4
1
NEWS
1
NEWS
@ -1,6 +1,7 @@
|
||||
PHP NEWS
|
||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||
?? ??? 2006, PHP 5.2.0
|
||||
- New memory manager. (Dmitry)
|
||||
- Reimplementation of Apache2Filter, PHP can now be an arbitrary filter
|
||||
in the chain and will read the script from the Apache stream. (John)
|
||||
- Added support for Apache2Filter in the Windows build including binary
|
||||
|
112
Zend/Zend.m4
112
Zend/Zend.m4
@ -129,13 +129,11 @@ AC_ARG_WITH(zend-vm,
|
||||
PHP_ZEND_VM=CALL
|
||||
])
|
||||
|
||||
AC_ARG_ENABLE(zend-memory-manager,
|
||||
[ --disable-zend-memory-manager
|
||||
Disable the Zend memory manager - FOR DEVELOPERS ONLY!!],
|
||||
AC_ARG_ENABLE(malloc-mm,
|
||||
[ --enable-malloc-mm Use environment variable for run-time malloc/emalloc
|
||||
selection - FOR DEVELOPERS ONLY!!],
|
||||
[
|
||||
ZEND_USE_ZEND_ALLOC=$enableval
|
||||
], [
|
||||
ZEND_USE_ZEND_ALLOC=yes
|
||||
ZEND_USE_MALLOC_MM=$enableval
|
||||
])
|
||||
|
||||
AC_ARG_ENABLE(maintainer-zts,
|
||||
@ -306,6 +304,108 @@ int main()
|
||||
|
||||
AC_MSG_RESULT(done)
|
||||
|
||||
dnl test for memory allocation using mmap(MAP_ANON)
|
||||
AC_MSG_CHECKING(for memory allocation using mmap(MAP_ANON))
|
||||
|
||||
AC_TRY_RUN([
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#ifndef MAP_ANON
|
||||
# ifdef MAP_ANONYMOUS
|
||||
# define MAP_ANON MAP_ANONYMOUS
|
||||
# endif
|
||||
#endif
|
||||
#ifndef MREMAP_MAYMOVE
|
||||
# define MREMAP_MAYMOVE 0
|
||||
#endif
|
||||
#ifndef MAP_FAILED
|
||||
# define MAP_FAILED ((void*)-1)
|
||||
#endif
|
||||
|
||||
#define SEG_SIZE (256*1024)
|
||||
|
||||
int main()
|
||||
{
|
||||
void *seg = mmap(NULL, SEG_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
if (seg == MAP_FAILED) {
|
||||
return 1;
|
||||
}
|
||||
if (munmap(seg, SEG_SIZE) != 0) {
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
], [
|
||||
AC_DEFINE([HAVE_MEM_MMAP_ANON], 1, [Define if the target system has support for memory allocation using mmap(MAP_ANON)])
|
||||
AC_MSG_RESULT(yes)
|
||||
], [
|
||||
AC_MSG_RESULT(no)
|
||||
], [
|
||||
dnl cross-compile needs something here
|
||||
AC_MSG_RESULT(no)
|
||||
])
|
||||
|
||||
dnl test for memory allocation using mmap("/dev/zero")
|
||||
AC_MSG_CHECKING(for memory allocation using mmap("/dev/zero"))
|
||||
|
||||
AC_TRY_RUN([
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#ifndef MAP_ANON
|
||||
# ifdef MAP_ANONYMOUS
|
||||
# define MAP_ANON MAP_ANONYMOUS
|
||||
# endif
|
||||
#endif
|
||||
#ifndef MREMAP_MAYMOVE
|
||||
# define MREMAP_MAYMOVE 0
|
||||
#endif
|
||||
#ifndef MAP_FAILED
|
||||
# define MAP_FAILED ((void*)-1)
|
||||
#endif
|
||||
|
||||
#define SEG_SIZE (256*1024)
|
||||
|
||||
int main()
|
||||
{
|
||||
int fd;
|
||||
void *seg;
|
||||
|
||||
fd = open("/dev/zero", O_RDWR, S_IRUSR | S_IWUSR);
|
||||
if (fd < 0) {
|
||||
return 1;
|
||||
}
|
||||
seg = mmap(NULL, SEG_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
|
||||
if (seg == MAP_FAILED) {
|
||||
return 2;
|
||||
}
|
||||
if (munmap(seg, SEG_SIZE) != 0) {
|
||||
return 3;
|
||||
}
|
||||
if (close(fd) != 0) {
|
||||
return 4;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
], [
|
||||
AC_DEFINE([HAVE_MEM_MMAP_ZERO], 1, [Define if the target system has support for memory allocation using mmap("/dev/zero")])
|
||||
AC_MSG_RESULT(yes)
|
||||
], [
|
||||
AC_MSG_RESULT(no)
|
||||
], [
|
||||
dnl cross-compile needs something here
|
||||
AC_MSG_RESULT(no)
|
||||
])
|
||||
|
||||
AC_CHECK_FUNCS(mremap)
|
||||
|
||||
])
|
||||
|
||||
|
||||
|
18
Zend/zend.c
18
Zend/zend.c
@ -87,7 +87,6 @@ ZEND_INI_END()
|
||||
#ifdef ZTS
|
||||
ZEND_API int compiler_globals_id;
|
||||
ZEND_API int executor_globals_id;
|
||||
ZEND_API int alloc_globals_id;
|
||||
HashTable *global_function_table;
|
||||
HashTable *global_class_table;
|
||||
HashTable *global_constants_table;
|
||||
@ -525,19 +524,8 @@ static void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC)
|
||||
zend_copy_ini_directives(TSRMLS_C);
|
||||
zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP TSRMLS_CC);
|
||||
}
|
||||
|
||||
static void alloc_globals_dtor(zend_alloc_globals *alloc_globals_p TSRMLS_DC)
|
||||
{
|
||||
shutdown_memory_manager(1, 1 TSRMLS_CC);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void alloc_globals_ctor(zend_alloc_globals *alloc_globals_p TSRMLS_DC)
|
||||
{
|
||||
start_memory_manager(TSRMLS_C);
|
||||
}
|
||||
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
/* FreeBSD and DragonFly floating point precision fix */
|
||||
#include <floatingpoint.h>
|
||||
@ -574,11 +562,7 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i
|
||||
extern zend_scanner_globals language_scanner_globals;
|
||||
#endif
|
||||
|
||||
#ifdef ZTS
|
||||
ts_allocate_id(&alloc_globals_id, sizeof(zend_alloc_globals), (ts_allocate_ctor) alloc_globals_ctor, (ts_allocate_dtor) alloc_globals_dtor);
|
||||
#else
|
||||
alloc_globals_ctor(&alloc_globals TSRMLS_CC);
|
||||
#endif
|
||||
start_memory_manager(TSRMLS_C);
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
/* FreeBSD and DragonFly floating point precision fix */
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
#include "zend_modules.h"
|
||||
#include "zend_list.h"
|
||||
#include "zend_fast_cache.h"
|
||||
#include "zend_operators.h"
|
||||
#include "zend_variables.h"
|
||||
#include "zend_execute.h"
|
||||
|
2189
Zend/zend_alloc.c
2189
Zend/zend_alloc.c
File diff suppressed because it is too large
Load Diff
@ -25,52 +25,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../TSRM/TSRM.h"
|
||||
#include "zend_globals_macros.h"
|
||||
#include "zend.h"
|
||||
|
||||
#include "zend_mm.h"
|
||||
|
||||
#define MEM_BLOCK_START_MAGIC 0x7312F8DCL
|
||||
#define MEM_BLOCK_END_MAGIC 0x2A8FCC84L
|
||||
#define MEM_BLOCK_FREED_MAGIC 0x99954317L
|
||||
#define MEM_BLOCK_CACHED_MAGIC 0xFB8277DCL
|
||||
|
||||
typedef struct _zend_mem_header {
|
||||
#if ZEND_DEBUG
|
||||
long magic;
|
||||
typedef struct _zend_leak_info {
|
||||
void *addr;
|
||||
size_t size;
|
||||
char *filename;
|
||||
uint lineno;
|
||||
int reported;
|
||||
char *orig_filename;
|
||||
uint orig_lineno;
|
||||
# ifdef ZTS
|
||||
THREAD_T thread_id;
|
||||
# endif
|
||||
#endif
|
||||
#if ZEND_DEBUG || !defined(ZEND_MM)
|
||||
struct _zend_mem_header *pNext;
|
||||
struct _zend_mem_header *pLast;
|
||||
#endif
|
||||
unsigned int size;
|
||||
} zend_mem_header;
|
||||
|
||||
typedef union _align_test {
|
||||
void *ptr;
|
||||
double dbl;
|
||||
long lng;
|
||||
} align_test;
|
||||
|
||||
#define MAX_CACHED_MEMORY 11
|
||||
#define MAX_CACHED_ENTRIES 256
|
||||
#define PRE_INIT_CACHE_ENTRIES 32
|
||||
|
||||
#if ZEND_GCC_VERSION >= 2000
|
||||
# define PLATFORM_ALIGNMENT (__alignof__ (align_test))
|
||||
#else
|
||||
# define PLATFORM_ALIGNMENT (sizeof(align_test))
|
||||
#endif
|
||||
|
||||
#define MEM_HEADER_PADDING (((PLATFORM_ALIGNMENT-sizeof(zend_mem_header))%PLATFORM_ALIGNMENT+PLATFORM_ALIGNMENT)%PLATFORM_ALIGNMENT)
|
||||
|
||||
} zend_leak_info;
|
||||
|
||||
BEGIN_EXTERN_C()
|
||||
|
||||
@ -84,28 +48,29 @@ ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LI
|
||||
ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
|
||||
ZEND_API char *_estrdup(const char *s ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC;
|
||||
ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC;
|
||||
|
||||
#if USE_ZEND_ALLOC
|
||||
ZEND_API size_t _zend_mem_block_size(void *ptr TSRMLS_DC ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
|
||||
|
||||
/* Standard wrapper macros */
|
||||
#define emalloc(size) _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define safe_emalloc(nmemb, size, offset) _safe_emalloc((nmemb), (size), (offset) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define efree(ptr) _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define ecalloc(nmemb, size) _ecalloc((nmemb), (size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define erealloc(ptr, size) _erealloc((ptr), (size), 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define erealloc_recoverable(ptr, size) _erealloc((ptr), (size), 1 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define estrdup(s) _estrdup((s) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define estrndup(s, length) _estrndup((s), (length) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define emalloc(size) _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define safe_emalloc(nmemb, size, offset) _safe_emalloc((nmemb), (size), (offset) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define efree(ptr) _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define ecalloc(nmemb, size) _ecalloc((nmemb), (size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define erealloc(ptr, size) _erealloc((ptr), (size), 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define erealloc_recoverable(ptr, size) _erealloc((ptr), (size), 1 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define estrdup(s) _estrdup((s) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define estrndup(s, length) _estrndup((s), (length) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define zend_mem_block_size(ptr) _zend_mem_block_size((ptr) TSRMLS_CC ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
|
||||
/* Relay wrapper macros */
|
||||
#define emalloc_rel(size) _emalloc((size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define safe_emalloc_rel(nmemb, size, offset) _safe_emalloc((nmemb), (size), (offset) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define efree_rel(ptr) _efree((ptr) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define ecalloc_rel(nmemb, size) _ecalloc((nmemb), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define erealloc_rel(ptr, size) _erealloc((ptr), (size), 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define erealloc_recoverable_rel(ptr, size) _erealloc((ptr), (size), 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define estrdup_rel(s) _estrdup((s) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define estrndup_rel(s, length) _estrndup((s), (length) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define emalloc_rel(size) _emalloc((size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define safe_emalloc_rel(nmemb, size, offset) _safe_emalloc((nmemb), (size), (offset) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define efree_rel(ptr) _efree((ptr) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define ecalloc_rel(nmemb, size) _ecalloc((nmemb), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define erealloc_rel(ptr, size) _erealloc((ptr), (size), 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define erealloc_recoverable_rel(ptr, size) _erealloc((ptr), (size), 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define estrdup_rel(s) _estrdup((s) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define estrndup_rel(s, length) _estrndup((s), (length) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define zend_mem_block_size_rel(ptr) _zend_mem_block_size((ptr) TSRMLS_CC ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
|
||||
/* Selective persistent/non persistent allocation macros */
|
||||
#define pemalloc(size, persistent) ((persistent)?malloc(size):emalloc(size))
|
||||
@ -123,51 +88,6 @@ ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC ZE
|
||||
#define perealloc_recoverable_rel(ptr, size, persistent) ((persistent)?realloc((ptr), (size)):erealloc_recoverable_rel((ptr), (size)))
|
||||
#define pestrdup_rel(s, persistent) ((persistent)?strdup(s):estrdup_rel(s))
|
||||
|
||||
#else
|
||||
|
||||
#undef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#include <string.h>
|
||||
#undef _GNU_SOURCE
|
||||
|
||||
/* Standard wrapper macros */
|
||||
#define emalloc(size) malloc(size)
|
||||
#define safe_emalloc(nmemb, size, offset) malloc((nmemb) * (size) + (offset))
|
||||
#define efree(ptr) free(ptr)
|
||||
#define ecalloc(nmemb, size) calloc((nmemb), (size))
|
||||
#define erealloc(ptr, size) realloc((ptr), (size))
|
||||
#define erealloc_recoverable(ptr, size) realloc((ptr), (size))
|
||||
#define estrdup(s) strdup(s)
|
||||
#define estrndup(s, length) zend_strndup((s), (length))
|
||||
|
||||
/* Relay wrapper macros */
|
||||
#define emalloc_rel(size) malloc(size)
|
||||
#define safe_emalloc_rel(nmemb, size, offset) malloc((nmemb) * (size) + (offset))
|
||||
#define efree_rel(ptr) free(ptr)
|
||||
#define ecalloc_rel(nmemb, size) calloc((nmemb), (size))
|
||||
#define erealloc_rel(ptr, size) realloc((ptr), (size))
|
||||
#define erealloc_recoverable_rel(ptr, size) realloc((ptr), (size))
|
||||
#define estrdup_rel(s) strdup(s)
|
||||
#define estrndup_rel(s, length) zend_strndup((s), (length))
|
||||
|
||||
/* Selective persistent/non persistent allocation macros */
|
||||
#define pemalloc(size, persistent) malloc(size)
|
||||
#define safe_pemalloc(nmemb, size, offset, persistent) malloc((nmemb) * (size) + (offset))
|
||||
#define pefree(ptr, persistent) free(ptr)
|
||||
#define pecalloc(nmemb, size, persistent) calloc((nmemb), (size))
|
||||
#define perealloc(ptr, size, persistent) realloc((ptr), (size))
|
||||
#define perealloc_recoverable(ptr, size, persistent) realloc((ptr), (size))
|
||||
#define pestrdup(s, persistent) strdup(s)
|
||||
|
||||
#define pemalloc_rel(size, persistent) malloc(size)
|
||||
#define pefree_rel(ptr, persistent) free(ptr)
|
||||
#define pecalloc_rel(nmemb, size, persistent) calloc((nmemb), (size))
|
||||
#define perealloc_rel(ptr, size, persistent) realloc((ptr), (size))
|
||||
#define perealloc_recoverable_rel(ptr, size, persistent) realloc((ptr), (size))
|
||||
#define pestrdup_rel(s, persistent) strdup(s)
|
||||
|
||||
#endif /* !USE_ZEND_ALLOC */
|
||||
|
||||
#define safe_estrdup(ptr) ((ptr)?(estrdup(ptr)):STR_EMPTY_ALLOC())
|
||||
#define safe_estrndup(ptr, len) ((ptr)?(estrndup((ptr), (len))):STR_EMPTY_ALLOC())
|
||||
|
||||
@ -187,8 +107,97 @@ void zend_debug_alloc_output(char *format, ...);
|
||||
#define full_mem_check(silent)
|
||||
#endif
|
||||
|
||||
#if MEMORY_LIMIT
|
||||
ZEND_API size_t zend_memory_usage(TSRMLS_D);
|
||||
ZEND_API size_t zend_memory_peak_usage(TSRMLS_D);
|
||||
#endif
|
||||
|
||||
END_EXTERN_C()
|
||||
|
||||
/* Macroses for zend_fast_cache.h compatibility */
|
||||
|
||||
#define ZEND_FAST_ALLOC(p, type, fc_type) \
|
||||
(p) = (type *) emalloc(sizeof(type))
|
||||
|
||||
#define ZEND_FAST_FREE(p, fc_type) \
|
||||
efree(p)
|
||||
|
||||
#define ZEND_FAST_ALLOC_REL(p, type, fc_type) \
|
||||
(p) = (type *) emalloc_rel(sizeof(type))
|
||||
|
||||
#define ZEND_FAST_FREE_REL(p, fc_type) \
|
||||
efree_rel(p)
|
||||
|
||||
/* fast cache for zval's */
|
||||
#define ALLOC_ZVAL(z) \
|
||||
ZEND_FAST_ALLOC(z, zval, ZVAL_CACHE_LIST)
|
||||
|
||||
#define FREE_ZVAL(z) \
|
||||
ZEND_FAST_FREE(z, ZVAL_CACHE_LIST)
|
||||
|
||||
#define ALLOC_ZVAL_REL(z) \
|
||||
ZEND_FAST_ALLOC_REL(z, zval, ZVAL_CACHE_LIST)
|
||||
|
||||
#define FREE_ZVAL_REL(z) \
|
||||
ZEND_FAST_FREE_REL(z, ZVAL_CACHE_LIST)
|
||||
|
||||
/* fast cache for HashTables */
|
||||
#define ALLOC_HASHTABLE(ht) \
|
||||
ZEND_FAST_ALLOC(ht, HashTable, HASHTABLE_CACHE_LIST)
|
||||
|
||||
#define FREE_HASHTABLE(ht) \
|
||||
ZEND_FAST_FREE(ht, HASHTABLE_CACHE_LIST)
|
||||
|
||||
#define ALLOC_HASHTABLE_REL(ht) \
|
||||
ZEND_FAST_ALLOC_REL(ht, HashTable, HASHTABLE_CACHE_LIST)
|
||||
|
||||
#define FREE_HASHTABLE_REL(ht) \
|
||||
ZEND_FAST_FREE_REL(ht, HASHTABLE_CACHE_LIST)
|
||||
|
||||
/* Heap functions */
|
||||
typedef struct _zend_mm_heap zend_mm_heap;
|
||||
|
||||
ZEND_API zend_mm_heap *zend_mm_startup(void);
|
||||
ZEND_API void zend_mm_shutdown(zend_mm_heap *heap, int full_shutdown, int silent);
|
||||
ZEND_API void *_zend_mm_alloc(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC;
|
||||
ZEND_API void _zend_mm_free(zend_mm_heap *heap, void *p ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
|
||||
ZEND_API void *_zend_mm_realloc(zend_mm_heap *heap, void *p, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
|
||||
ZEND_API size_t _zend_mm_block_size(zend_mm_heap *heap, void *p ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
|
||||
|
||||
#define zend_mm_alloc(heap, size) _zend_mm_alloc((heap), (size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define zend_mm_free(heap, p) _zend_mm_free((heap), (p) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define zend_mm_realloc(heap, p, size) _zend_mm_realloc((heap), (p), (size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
#define zend_mm_block_size(heap, p) _zend_mm_block_size((heap), (p), ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
|
||||
#define zend_mm_alloc_rel(heap, size) _zend_mm_alloc((heap), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define zend_mm_free_rel(heap, p) _zend_mm_free((heap), (p) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define zend_mm_realloc_rel(heap, p, size) _zend_mm_realloc((heap), (p), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
||||
#define zend_mm_block_size_rel(heap, p) _zend_mm_block_size((heap), (p), ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
||||
|
||||
/* Heaps with user defined storage */
|
||||
typedef struct _zend_mm_storage zend_mm_storage;
|
||||
|
||||
typedef struct _zend_mm_segment {
|
||||
size_t size;
|
||||
struct _zend_mm_segment *next_segment;
|
||||
} zend_mm_segment;
|
||||
|
||||
typedef struct _zend_mm_mem_handlers {
|
||||
const char *name;
|
||||
zend_mm_storage* (*init)(void *params);
|
||||
void (*dtor)(zend_mm_storage *storage);
|
||||
zend_mm_segment* (*_alloc)(zend_mm_storage *storage, size_t size);
|
||||
zend_mm_segment* (*_realloc)(zend_mm_storage *storage, zend_mm_segment *ptr, size_t size);
|
||||
void (*_free)(zend_mm_storage *storage, zend_mm_segment *ptr);
|
||||
} zend_mm_mem_handlers;
|
||||
|
||||
struct _zend_mm_storage {
|
||||
const zend_mm_mem_handlers *handlers;
|
||||
};
|
||||
|
||||
ZEND_API zend_mm_heap *zend_mm_startup_ex(const zend_mm_mem_handlers *handlers, size_t block_size, void *params);
|
||||
ZEND_API zend_mm_heap *zend_mm_set_heap(zend_mm_heap *new_heap TSRMLS_DC);
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "zend_constants.h"
|
||||
#include "zend_llist.h"
|
||||
#include "zend_API.h"
|
||||
#include "zend_fast_cache.h"
|
||||
|
||||
#ifdef ZEND_MULTIBYTE
|
||||
#include "zend_multibyte.h"
|
||||
|
@ -22,8 +22,6 @@
|
||||
#ifndef ZEND_CONFIG_W32_H
|
||||
#define ZEND_CONFIG_W32_H
|
||||
|
||||
#define USE_ZEND_ALLOC 1
|
||||
|
||||
#include <../main/config.w32.h>
|
||||
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "zend_ptr_stack.h"
|
||||
#include "zend_constants.h"
|
||||
#include "zend_extensions.h"
|
||||
#include "zend_fast_cache.h"
|
||||
#include "zend_ini.h"
|
||||
#include "zend_exceptions.h"
|
||||
#include "zend_interfaces.h"
|
||||
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#if 0
|
||||
#ifndef ZEND_FAST_CACHE_H
|
||||
#define ZEND_FAST_CACHE_H
|
||||
|
||||
@ -131,7 +131,7 @@ typedef struct _zend_fast_cache_list_entry {
|
||||
ZEND_FAST_FREE_REL(ht, HASHTABLE_CACHE_LIST)
|
||||
|
||||
#endif /* ZEND_FAST_CACHE_H */
|
||||
|
||||
#endif
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "zend_ptr_stack.h"
|
||||
#include "zend_hash.h"
|
||||
#include "zend_llist.h"
|
||||
#include "zend_fast_cache.h"
|
||||
#include "zend_objects.h"
|
||||
#include "zend_objects_API.h"
|
||||
#include "zend_modules.h"
|
||||
@ -48,7 +47,6 @@
|
||||
BEGIN_EXTERN_C()
|
||||
ZEND_API extern int compiler_globals_id;
|
||||
ZEND_API extern int executor_globals_id;
|
||||
ZEND_API extern int alloc_globals_id;
|
||||
END_EXTERN_C()
|
||||
|
||||
#endif
|
||||
@ -242,34 +240,6 @@ struct _zend_executor_globals {
|
||||
void *reserved[ZEND_MAX_RESERVED_RESOURCES];
|
||||
};
|
||||
|
||||
#include "zend_mm.h"
|
||||
|
||||
struct _zend_alloc_globals {
|
||||
zend_mem_header *head; /* standard list */
|
||||
void *cache[MAX_CACHED_MEMORY][MAX_CACHED_ENTRIES];
|
||||
unsigned int cache_count[MAX_CACHED_MEMORY];
|
||||
void *fast_cache_list_head[MAX_FAST_CACHE_TYPES];
|
||||
|
||||
#ifdef ZEND_WIN32
|
||||
HANDLE memory_heap;
|
||||
#endif
|
||||
|
||||
#if ZEND_DEBUG
|
||||
/* for performance tuning */
|
||||
int cache_stats[MAX_CACHED_MEMORY][2];
|
||||
int fast_cache_stats[MAX_FAST_CACHE_TYPES][2];
|
||||
#endif
|
||||
#if MEMORY_LIMIT
|
||||
unsigned int memory_limit;
|
||||
unsigned int allocated_memory;
|
||||
unsigned int allocated_memory_peak;
|
||||
unsigned char memory_exhausted;
|
||||
#endif
|
||||
#ifdef ZEND_MM
|
||||
zend_mm_heap mm_heap;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct _zend_scanner_globals {
|
||||
zend_file_handle *yy_in;
|
||||
zend_file_handle *yy_out;
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
typedef struct _zend_compiler_globals zend_compiler_globals;
|
||||
typedef struct _zend_executor_globals zend_executor_globals;
|
||||
typedef struct _zend_alloc_globals zend_alloc_globals;
|
||||
typedef struct _zend_scanner_globals zend_scanner_globals;
|
||||
|
||||
/* Compiler */
|
||||
@ -48,16 +47,6 @@ int zendparse(void);
|
||||
extern ZEND_API zend_executor_globals executor_globals;
|
||||
#endif
|
||||
|
||||
|
||||
/* Memory Manager */
|
||||
#ifdef ZTS
|
||||
# define AG(v) TSRMG(alloc_globals_id, zend_alloc_globals *, v)
|
||||
#else
|
||||
# define AG(v) (alloc_globals.v)
|
||||
extern ZEND_API zend_alloc_globals alloc_globals;
|
||||
#endif
|
||||
|
||||
|
||||
/* Language Scanner */
|
||||
#ifdef ZTS
|
||||
# define LANG_SCNG(v) TSRMG(language_scanner_globals_id, zend_scanner_globals *, v)
|
||||
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#if 0
|
||||
#include "zend.h"
|
||||
#include "zend_mm.h"
|
||||
|
||||
@ -465,7 +465,7 @@ void *zend_mm_realloc(zend_mm_heap *heap, void *p, size_t size)
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
#endif
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#if 0
|
||||
#ifndef _ZEND_MM_H
|
||||
#define _ZEND_MM_H
|
||||
|
||||
@ -75,7 +75,7 @@ void zend_mm_free(zend_mm_heap *heap, void *p);
|
||||
void *zend_mm_realloc(zend_mm_heap *heap, void *p, size_t size);
|
||||
|
||||
#endif /* _ZEND_MM_H */
|
||||
|
||||
#endif
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "zend_variables.h"
|
||||
#include "zend_globals.h"
|
||||
#include "zend_list.h"
|
||||
#include "zend_fast_cache.h"
|
||||
#include "zend_API.h"
|
||||
#include "zend_multiply.h"
|
||||
#include "zend_strtod.h"
|
||||
|
@ -911,13 +911,14 @@ PHP_FUNCTION(unserialize)
|
||||
/* {{{ proto int memory_get_usage()
|
||||
Returns the allocated by PHP memory */
|
||||
PHP_FUNCTION(memory_get_usage) {
|
||||
RETURN_LONG(AG(allocated_memory));
|
||||
|
||||
RETURN_LONG(zend_memory_usage(TSRMLS_C));
|
||||
}
|
||||
/* }}} */
|
||||
/* {{{ proto int memory_get_peak_usage()
|
||||
Returns the peak allocated by PHP memory */
|
||||
PHP_FUNCTION(memory_get_peak_usage) {
|
||||
RETURN_LONG(AG(allocated_memory_peak));
|
||||
RETURN_LONG(zend_memory_peak_usage(TSRMLS_C));
|
||||
}
|
||||
/* }}} */
|
||||
#endif
|
||||
|
@ -829,7 +829,7 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
|
||||
if (module_initialized) {
|
||||
#if MEMORY_LIMIT
|
||||
/* restore memory limit */
|
||||
AG(memory_limit) = PG(memory_limit);
|
||||
zend_set_memory_limit(PG(memory_limit));
|
||||
#endif
|
||||
efree(buffer);
|
||||
zend_objects_store_mark_destructed(&EG(objects_store) TSRMLS_CC);
|
||||
@ -964,10 +964,9 @@ static void php_message_handler_for_zend(long message, void *data)
|
||||
char memory_leak_buf[512];
|
||||
|
||||
if (message==ZMSG_MEMORY_LEAK_DETECTED) {
|
||||
zend_mem_header *t = (zend_mem_header *) data;
|
||||
void *ptr = (void *)((char *)t+sizeof(zend_mem_header)+MEM_HEADER_PADDING);
|
||||
zend_leak_info *t = (zend_leak_info *) data;
|
||||
|
||||
snprintf(memory_leak_buf, 512, "%s(%d) : Freeing 0x%.8lX (%d bytes), script=%s\n", t->filename, t->lineno, (unsigned long)ptr, t->size, SAFE_FILENAME(SG(request_info).path_translated));
|
||||
snprintf(memory_leak_buf, 512, "%s(%d) : Freeing 0x%.8lX (%d bytes), script=%s\n", t->filename, t->lineno, (unsigned long)t->addr, t->size, SAFE_FILENAME(SG(request_info).path_translated));
|
||||
if (t->orig_filename) {
|
||||
char relay_buf[512];
|
||||
|
||||
@ -1601,6 +1600,8 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
|
||||
sapi_deactivate(TSRMLS_C);
|
||||
module_startup = 0;
|
||||
|
||||
shutdown_memory_manager(1, 0 TSRMLS_CC);
|
||||
|
||||
/* we're done */
|
||||
return SUCCESS;
|
||||
}
|
||||
|
@ -684,8 +684,7 @@ static int send_parsed_php(request_rec * r)
|
||||
char *mem_usage;
|
||||
TSRMLS_FETCH();
|
||||
|
||||
mem_usage = ap_psprintf(r->pool, "%u", AG(allocated_memory_peak));
|
||||
AG(allocated_memory_peak) = 0;
|
||||
mem_usage = ap_psprintf(r->pool, "%u", zend_memory_peak_usage(TSRMLS_C));
|
||||
ap_table_setn(r->notes, "mod_php_memory_usage", mem_usage);
|
||||
}
|
||||
#endif
|
||||
|
@ -526,8 +526,7 @@ static int php_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
|
||||
{
|
||||
char *mem_usage;
|
||||
|
||||
mem_usage = apr_psprintf(ctx->r->pool, "%u", AG(allocated_memory_peak));
|
||||
AG(allocated_memory_peak) = 0;
|
||||
mem_usage = apr_psprintf(ctx->r->pool, "%u", zend_memory_peak_usage(TSRMLS_C));
|
||||
apr_table_set(ctx->r->notes, "mod_php_memory_usage", mem_usage);
|
||||
}
|
||||
#endif
|
||||
|
@ -598,7 +598,7 @@ zend_first_try {
|
||||
{
|
||||
char *mem_usage;
|
||||
|
||||
mem_usage = apr_psprintf(ctx->r->pool, "%u", AG(allocated_memory_peak));
|
||||
mem_usage = apr_psprintf(ctx->r->pool, "%u", zend_memory_peak_usage(TSRMLS_C));
|
||||
apr_table_set(r->notes, "mod_php_memory_usage", mem_usage);
|
||||
}
|
||||
#endif
|
||||
|
@ -742,8 +742,7 @@ static int send_parsed_php(request_rec * r)
|
||||
char *mem_usage;
|
||||
TSRMLS_FETCH();
|
||||
|
||||
mem_usage = ap_psprintf(r->pool, "%u", AG(allocated_memory_peak));
|
||||
AG(allocated_memory_peak) = 0;
|
||||
mem_usage = ap_psprintf(r->pool, "%u", zend_memory_peak_usage(TSRMLS_C));
|
||||
ap_table_setn(r->notes, "mod_php_memory_usage", mem_usage);
|
||||
}
|
||||
#endif
|
||||
|
@ -293,8 +293,10 @@ ADD_FLAG("CFLAGS", "/D FD_SETSIZE=" + parseInt(PHP_FD_SETSIZE));
|
||||
ARG_ENABLE("memory-limit", "Enable memory limit checking code", "no");
|
||||
AC_DEFINE('MEMORY_LIMIT', PHP_MEMORY_LIMIT == "yes" ? 1 : 0);
|
||||
|
||||
ARG_ENABLE("memory-manager", "Enable Zend memory manager", "yes");
|
||||
AC_DEFINE('USE_ZEND_ALLOC', PHP_MEMORY_MANAGER == "yes" ? 1 : 0);
|
||||
ARG_ENABLE("malloc-mm", "Use environment variable for run-time malloc/emalloc selection", "");
|
||||
if (PHP_MALLOC_MM.length) {
|
||||
AC_DEFINE('ZEND_USE_MALLOC_MM', PHP_MALLOC_MM == "yes" ? 1 : 0);
|
||||
}
|
||||
|
||||
ARG_ENABLE("zend-multibyte", "Enable Zend multibyte encoding support", "no");
|
||||
if (PHP_ZEND_MULTIBYTE == "yes") {
|
||||
|
Loading…
Reference in New Issue
Block a user