com php-src: Make gc_collect_cycles hookable.: UPGR ADING.INTERNALS Zend/zend.c Zend/zend_gc.c Zend/z end_gc.h
| From: | Anatol Belski | Date: | Fri, 23 Jan 2015 19:23:58 +0000 |
| Subject: | com php-src: Make gc_collect_cycles hookable.: UPGR ADING.INTERNALS Zend/zend.c Zend/zend_gc.c Zend/z end_gc.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-84351@lists.php.net to get a copy of this message | ||
Commit: eb6dc9db296bfcfad56dc091cb3a327b505bc56e
Author: Adam Harvey <aharvey@php.net> Tue, 2 Dec 2014 12:18:18 -0800
Parents: e4271887559cc2a2c8a95825a23fe33859cef41b
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=eb6dc9db296bfcfad56dc091cb3a327b505bc56e
Log:
Make gc_collect_cycles hookable.
Changed paths:
M UPGRADING.INTERNALS
M Zend/zend.c
M Zend/zend_gc.c
M Zend/zend_gc.h
Diff:
diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS
index 900ec41..426288d 100644
--- a/UPGRADING.INTERNALS
+++ b/UPGRADING.INTERNALS
@@ -15,6 +15,7 @@ PHP 7.0 INTERNALS UPGRADE NOTES
n. ZEND_ENGINE_2 removal
o. Updated final class modifier
p. TSRM changes
+ q. gc_collect_cycles() is now hookable
2. Build system changes
a. Unix build system changes
@@ -169,6 +170,12 @@ PHP 7.0 INTERNALS UPGRADE NOTES
Additionally, if an extension triggers its own threads, TSRMLS_CACHE shouldn't
be passed to that threads directly.
+ q. gc_collect_cycles() is now a function pointer, and can be replaced in the
+ same manner as zend_execute_ex() if needed (for example, to include the
+ time spent in the garbage collector in a profiler). The default
+ implementation has been renamed to zend_gc_collect_cycles(), and is
+ exported with ZEND_API.
+
========================
2. Build system changes
diff --git a/Zend/zend.c b/Zend/zend.c
index dcc95a8..d28d8ef 100644
--- a/Zend/zend.c
+++ b/Zend/zend.c
@@ -616,6 +616,9 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions) /
zend_compile_string = compile_string;
zend_throw_exception_hook = NULL;
+ /* Set up the default garbage collection implementation. */
+ gc_collect_cycles = zend_gc_collect_cycles;
+
zend_init_opcodes_handlers();
/* set up version */
diff --git a/Zend/zend_gc.c b/Zend/zend_gc.c
index 986659d..dba4900 100644
--- a/Zend/zend_gc.c
+++ b/Zend/zend_gc.c
@@ -31,6 +31,8 @@ ZEND_API int gc_globals_id;
ZEND_API zend_gc_globals gc_globals;
#endif
+ZEND_API int (*gc_collect_cycles)(TSRMLS_D);
+
#define GC_REMOVE_FROM_ROOTS(current) \
gc_remove_from_roots((current))
@@ -701,7 +703,7 @@ tail_call:
}
}
-ZEND_API int gc_collect_cycles(void)
+ZEND_API int zend_gc_collect_cycles(void)
{
int count = 0;
diff --git a/Zend/zend_gc.h b/Zend/zend_gc.h
index 80425fc..2be98ee 100644
--- a/Zend/zend_gc.h
+++ b/Zend/zend_gc.h
@@ -119,13 +119,17 @@ extern ZEND_API zend_gc_globals gc_globals;
#endif
BEGIN_EXTERN_C()
-ZEND_API int gc_collect_cycles(void);
+ZEND_API extern int (*gc_collect_cycles)(void);
+
ZEND_API void gc_possible_root(zend_refcounted *ref);
ZEND_API void gc_remove_from_buffer(zend_refcounted *ref);
ZEND_API void gc_globals_ctor(void);
ZEND_API void gc_globals_dtor(void);
ZEND_API void gc_init(void);
ZEND_API void gc_reset(void);
+
+/* The default implementation of the gc_collect_cycles callback. */
+ZEND_API int zend_gc_collect_cycles(void);
END_EXTERN_C()
#define GC_ZVAL_CHECK_POSSIBLE_ROOT(z) \