php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
zend_gc.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5 | Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 2.00 of the Zend license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.zend.com/license/2_00.txt. |
11 | If you did not receive a copy of the Zend license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@zend.com so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: David Wang <planetbeing@gmail.com> |
16 | Dmitry Stogov <dmitry@php.net> |
17 +----------------------------------------------------------------------+
18*/
19
20#ifndef ZEND_GC_H
21#define ZEND_GC_H
22
23#include "zend_hrtime.h"
24
25#ifndef GC_BENCH
26# define GC_BENCH 0
27#endif
28
30
45
46ZEND_API extern int (*gc_collect_cycles)(void);
47
50
51/* enable/disable automatic start of GC collection */
52ZEND_API bool gc_enable(bool enable);
53ZEND_API bool gc_enabled(void);
54
55/* enable/disable possible root additions */
56ZEND_API bool gc_protect(bool protect);
57ZEND_API bool gc_protected(void);
58
59#if GC_BENCH
60void gc_bench_print(void);
61#endif
62
63/* The default implementation of the gc_collect_cycles callback. */
65
67
68void gc_init(void);
69void gc_globals_ctor(void);
70void gc_globals_dtor(void);
71void gc_reset(void);
72
73#ifdef ZTS
74size_t zend_gc_globals_size(void);
75#endif
76
77#define GC_REMOVE_FROM_BUFFER(p) do { \
78 zend_refcounted *_p = (zend_refcounted*)(p); \
79 if (GC_TYPE_INFO(_p) & GC_INFO_MASK) { \
80 gc_remove_from_buffer(_p); \
81 } \
82 } while (0)
83
84#define GC_MAY_LEAK(ref) \
85 ((GC_TYPE_INFO(ref) & \
86 (GC_INFO_MASK | (GC_NOT_COLLECTABLE << GC_FLAGS_SHIFT))) == 0)
87
88static zend_always_inline void gc_check_possible_root(zend_refcounted *ref)
89{
90 if (EXPECTED(GC_TYPE_INFO(ref) == GC_REFERENCE)) {
91 zval *zv = &((zend_reference*)ref)->val;
92
93 if (!Z_COLLECTABLE_P(zv)) {
94 return;
95 }
96 ref = Z_COUNTED_P(zv);
97 }
98 if (UNEXPECTED(GC_MAY_LEAK(ref))) {
100 }
101}
102
103static zend_always_inline void gc_check_possible_root_no_ref(zend_refcounted *ref)
104{
106 if (UNEXPECTED(GC_MAY_LEAK(ref))) {
107 gc_possible_root(ref);
108 }
109}
110
111/* These APIs can be used to simplify object get_gc implementations
112 * over heterogeneous structures. See zend_generator_get_gc() for
113 * a usage example. */
114
120
123
124static zend_always_inline void zend_get_gc_buffer_add_zval(
125 zend_get_gc_buffer *gc_buffer, zval *zv) {
126 if (Z_REFCOUNTED_P(zv)) {
127 if (UNEXPECTED(gc_buffer->cur == gc_buffer->end)) {
128 zend_get_gc_buffer_grow(gc_buffer);
129 }
130 ZVAL_COPY_VALUE(gc_buffer->cur, zv);
131 gc_buffer->cur++;
132 }
133}
134
135static zend_always_inline void zend_get_gc_buffer_add_obj(
136 zend_get_gc_buffer *gc_buffer, zend_object *obj) {
137 if (UNEXPECTED(gc_buffer->cur == gc_buffer->end)) {
138 zend_get_gc_buffer_grow(gc_buffer);
139 }
140 ZVAL_OBJ(gc_buffer->cur, obj);
141 gc_buffer->cur++;
142}
143
144static zend_always_inline void zend_get_gc_buffer_add_ptr(
145 zend_get_gc_buffer *gc_buffer, void *ptr) {
146 if (UNEXPECTED(gc_buffer->cur == gc_buffer->end)) {
147 zend_get_gc_buffer_grow(gc_buffer);
148 }
149 ZVAL_PTR(gc_buffer->cur, ptr);
150 gc_buffer->cur++;
151}
152
153static zend_always_inline void zend_get_gc_buffer_use(
154 zend_get_gc_buffer *gc_buffer, zval **table, int *n) {
155 *table = gc_buffer->start;
156 *n = gc_buffer->cur - gc_buffer->start;
157}
158
160
161#endif /* ZEND_GC_H */
DNS_STATUS status
Definition dns_win32.c:49
zval * zv
Definition ffi.c:3975
zend_long n
Definition ffi.c:4979
void * ptr
Definition ffi.c:3814
uint32_t buf_size
Definition zend_gc.h:38
zend_hrtime_t collector_time
Definition zend_gc.h:41
zend_hrtime_t free_time
Definition zend_gc.h:43
uint32_t runs
Definition zend_gc.h:35
bool gc_protected
Definition zend_gc.h:33
uint32_t collected
Definition zend_gc.h:36
zend_hrtime_t dtor_time
Definition zend_gc.h:42
uint32_t threshold
Definition zend_gc.h:37
uint32_t num_roots
Definition zend_gc.h:39
zend_hrtime_t application_time
Definition zend_gc.h:40
struct _zval_struct zval
#define ZEND_API
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
ZEND_API int(* gc_collect_cycles)(void)
Definition zend_gc.c:245
#define GC_MAY_LEAK(ref)
Definition zend_gc.h:84
ZEND_API void ZEND_FASTCALL gc_remove_from_buffer(zend_refcounted *ref)
Definition zend_gc.c:773
ZEND_API void zend_get_gc_buffer_grow(zend_get_gc_buffer *gc_buffer)
Definition zend_gc.c:2138
void gc_globals_dtor(void)
Definition zend_gc.c:526
void gc_globals_ctor(void)
Definition zend_gc.c:517
ZEND_API bool gc_protect(bool protect)
Definition zend_gc.c:587
struct _zend_gc_status zend_gc_status
ZEND_API void zend_gc_get_status(zend_gc_status *status)
Definition zend_gc.c:2114
ZEND_API bool gc_enabled(void)
void gc_reset(void)
Definition zend_gc.c:533
ZEND_API zend_get_gc_buffer * zend_get_gc_buffer_create(void)
Definition zend_gc.c:2130
ZEND_API int zend_gc_collect_cycles(void)
Definition zend_gc.c:1913
ZEND_API void ZEND_FASTCALL gc_possible_root(zend_refcounted *ref)
Definition zend_gc.c:698
ZEND_API bool gc_protected(void)
Definition zend_gc.c:594
void gc_init(void)
Definition zend_gc.c:2280
uint64_t zend_hrtime_t
Definition zend_hrtime.h:75
#define END_EXTERN_C()
#define EXPECTED(condition)
#define zend_always_inline
#define ZEND_FASTCALL
#define ZEND_ASSERT(c)
#define UNEXPECTED(condition)
#define BEGIN_EXTERN_C()
struct _zend_object zend_object
#define GC_REFERENCE
Definition zend_types.h:789
#define Z_REFCOUNTED_P(zval_p)
Definition zend_types.h:921
#define Z_COUNTED_P(zval_p)
Definition zend_types.h:699
#define ZVAL_OBJ(z, o)
#define Z_COLLECTABLE_P(zval_p)
Definition zend_types.h:924
struct _zend_refcounted zend_refcounted
Definition zend_types.h:95
#define ZVAL_PTR(z, p)
#define ZVAL_COPY_VALUE(z, v)
struct _zend_reference zend_reference
Definition zend_types.h:100
#define GC_TYPE_INFO(p)
Definition zend_types.h:754