Deleted Added
sdiff udiff text old ( 286866 ) new ( 296221 )
full compact
1#define JEMALLOC_QUARANTINE_C_
2#include "jemalloc/internal/jemalloc_internal.h"
3
4/*
5 * Quarantine pointers close to NULL are used to encode state information that
6 * is used for cleaning up during thread shutdown.
7 */
8#define QUARANTINE_STATE_REINCARNATED ((quarantine_t *)(uintptr_t)1)

--- 9 unchanged lines hidden (view full) ---

18 size_t upper_bound);
19
20/******************************************************************************/
21
22static quarantine_t *
23quarantine_init(tsd_t *tsd, size_t lg_maxobjs)
24{
25 quarantine_t *quarantine;
26
27 assert(tsd_nominal(tsd));
28
29 quarantine = (quarantine_t *)iallocztm(tsd, offsetof(quarantine_t, objs)
30 + ((ZU(1) << lg_maxobjs) * sizeof(quarantine_obj_t)), false,
31 tcache_get(tsd, true), true, NULL);
32 if (quarantine == NULL)
33 return (NULL);
34 quarantine->curbytes = 0;
35 quarantine->curobjs = 0;
36 quarantine->first = 0;
37 quarantine->lg_maxobjs = lg_maxobjs;
38
39 return (quarantine);

--- 10 unchanged lines hidden (view full) ---

50 quarantine = quarantine_init(tsd, LG_MAXOBJS_INIT);
51 /*
52 * Check again whether quarantine has been initialized, because
53 * quarantine_init() may have triggered recursive initialization.
54 */
55 if (tsd_quarantine_get(tsd) == NULL)
56 tsd_quarantine_set(tsd, quarantine);
57 else
58 idalloctm(tsd, quarantine, tcache_get(tsd, false), true);
59}
60
61static quarantine_t *
62quarantine_grow(tsd_t *tsd, quarantine_t *quarantine)
63{
64 quarantine_t *ret;
65
66 ret = quarantine_init(tsd, quarantine->lg_maxobjs + 1);

--- 15 unchanged lines hidden (view full) ---

82 quarantine->first;
83 size_t ncopy_b = quarantine->curobjs - ncopy_a;
84
85 memcpy(ret->objs, &quarantine->objs[quarantine->first], ncopy_a
86 * sizeof(quarantine_obj_t));
87 memcpy(&ret->objs[ncopy_a], quarantine->objs, ncopy_b *
88 sizeof(quarantine_obj_t));
89 }
90 idalloctm(tsd, quarantine, tcache_get(tsd, false), true);
91
92 tsd_quarantine_set(tsd, ret);
93 return (ret);
94}
95
96static void
97quarantine_drain_one(tsd_t *tsd, quarantine_t *quarantine)
98{
99 quarantine_obj_t *obj = &quarantine->objs[quarantine->first];
100 assert(obj->usize == isalloc(obj->ptr, config_prof));
101 idalloctm(tsd, obj->ptr, NULL, false);
102 quarantine->curbytes -= obj->usize;
103 quarantine->curobjs--;
104 quarantine->first = (quarantine->first + 1) & ((ZU(1) <<
105 quarantine->lg_maxobjs) - 1);
106}
107
108static void
109quarantine_drain(tsd_t *tsd, quarantine_t *quarantine, size_t upper_bound)

--- 8 unchanged lines hidden (view full) ---

118{
119 quarantine_t *quarantine;
120 size_t usize = isalloc(ptr, config_prof);
121
122 cassert(config_fill);
123 assert(opt_quarantine);
124
125 if ((quarantine = tsd_quarantine_get(tsd)) == NULL) {
126 idalloctm(tsd, ptr, NULL, false);
127 return;
128 }
129 /*
130 * Drain one or more objects if the quarantine size limit would be
131 * exceeded by appending ptr.
132 */
133 if (quarantine->curbytes + usize > opt_quarantine) {
134 size_t upper_bound = (opt_quarantine >= usize) ? opt_quarantine

--- 22 unchanged lines hidden (view full) ---

157 if ((!config_valgrind || likely(!in_valgrind))
158 && usize <= SMALL_MAXCLASS)
159 arena_quarantine_junk_small(ptr, usize);
160 else
161 memset(ptr, 0x5a, usize);
162 }
163 } else {
164 assert(quarantine->curbytes == 0);
165 idalloctm(tsd, ptr, NULL, false);
166 }
167}
168
169void
170quarantine_cleanup(tsd_t *tsd)
171{
172 quarantine_t *quarantine;
173
174 if (!config_fill)
175 return;
176
177 quarantine = tsd_quarantine_get(tsd);
178 if (quarantine != NULL) {
179 quarantine_drain(tsd, quarantine, 0);
180 idalloctm(tsd, quarantine, tcache_get(tsd, false), true);
181 tsd_quarantine_set(tsd, NULL);
182 }
183}