blob: 38aacf8778d5de7cae31fd119efa9651c083197a [file] [log] [blame]
Dan Willemsen1bd78892015-09-11 13:08:19 -07001//
2// Copyright (C) 2014 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17common_cflags = [
18 "-std=gnu99",
19 "-D_REENTRANT",
20 "-fvisibility=hidden",
21 "-Wno-unused-parameter",
Colin Cross70274782015-12-29 16:56:11 -080022 "-Wno-type-limits",
Dan Willemsen1bd78892015-09-11 13:08:19 -070023]
24
25// These parameters change the way jemalloc works.
Dan Willemsen1bd78892015-09-11 13:08:19 -070026// ANDROID_MAX_ARENAS=XX
27// The total number of arenas will be less than or equal to this number.
28// The number of arenas will be calculated as 2 * the number of cpus
29// but no larger than XX.
30// ANDROID_TCACHE_NSLOTS_SMALL_MAX=XX
31// The number of small slots held in the tcache. The higher this number
32// is, the higher amount of PSS consumed. If this number is set too low
33// then small allocations will take longer to complete.
34// ANDROID_TCACHE_NSLOTS_LARGE=XX
35// The number of large slots held in the tcache. The higher this number
36// is, the higher amount of PSS consumed. If this number is set too low
37// then large allocations will take longer to complete.
38// ANDROID_LG_TCACHE_MAXCLASS_DEFAULT=XX
39// 1 << XX is the maximum sized allocation that will be in the tcache.
40// ANDROID_LG_CHUNK_DEFAULT=XX
41// 1 << XX is the default chunk size used by the system. Decreasing this
42// usually decreases the amount of PSS used, but can increase
43// fragmentation.
Christopher Ferris53bf3352016-07-19 14:05:20 -070044
45// Default to a single arena for svelte configurations to minimize
46// PSS consumed by jemalloc.
Dan Willemsen1bd78892015-09-11 13:08:19 -070047common_cflags += [
Christopher Ferris53bf3352016-07-19 14:05:20 -070048 "-DANDROID_MAX_ARENAS=1",
Dan Willemsen1bd78892015-09-11 13:08:19 -070049 "-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16",
50]
51
Dan Willemsen1bd78892015-09-11 13:08:19 -070052common_c_local_includes = [
53 "src",
54 "include",
55]
56
Dan Willemsene67f1d52016-03-01 17:23:40 -080057common_product_variables = {
58 // Only enable the tcache on non-svelte configurations, to save PSS.
59 malloc_not_svelte: {
Christopher Ferris53bf3352016-07-19 14:05:20 -070060 cflags: [
61 "-UANDROID_MAX_ARENAS",
62 "-DANDROID_MAX_ARENAS=2",
63 "-DJEMALLOC_TCACHE",
64 "-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8",
65 "-DANDROID_TCACHE_NSLOTS_LARGE=16",
66 ],
Dan Willemsene67f1d52016-03-01 17:23:40 -080067 },
68}
69
70cc_defaults {
71 name: "jemalloc_defaults",
72 cflags: common_cflags,
73
74 product_variables: common_product_variables,
75
76 multilib: {
77 lib32: {
78 // Use a 512K chunk size on 32 bit systems.
79 // This keeps the total amount of virtual address space consumed
80 // by jemalloc lower.
81 cflags: [
82 "-DANDROID_LG_CHUNK_DEFAULT=19",
83 ],
84 },
85 lib64: {
86 // Use a 2MB chunk size on 64 bit systems.
87 // This is the default currently used by 4.0.0
88 cflags: [
89 "-DANDROID_LG_CHUNK_DEFAULT=21",
90 ],
91 },
92 },
93
94 local_include_dirs: common_c_local_includes,
Colin Cross4daa75d2016-04-07 13:28:20 -070095 stl: "none",
Dan Willemsene67f1d52016-03-01 17:23:40 -080096}
97
Dan Willemsen1bd78892015-09-11 13:08:19 -070098lib_src_files = [
99 "src/arena.c",
100 "src/atomic.c",
101 "src/base.c",
102 "src/bitmap.c",
103 "src/chunk.c",
104 "src/chunk_dss.c",
105 "src/chunk_mmap.c",
106 "src/ckh.c",
107 "src/ctl.c",
108 "src/extent.c",
109 "src/hash.c",
110 "src/huge.c",
111 "src/jemalloc.c",
112 "src/mb.c",
113 "src/mutex.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800114 "src/nstime.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700115 "src/pages.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800116 "src/prng.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700117 "src/prof.c",
118 "src/quarantine.c",
119 "src/rtree.c",
Christopher Ferrisfb1f0942016-11-08 14:47:48 -0800120 "src/spin.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700121 "src/stats.c",
122 "src/tcache.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800123 "src/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700124 "src/tsd.c",
125 "src/util.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700126 "src/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700127]
128
129//-----------------------------------------------------------------------
130// jemalloc static library
131//-----------------------------------------------------------------------
132cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700133 name: "libjemalloc",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700134
Dan Willemsene67f1d52016-03-01 17:23:40 -0800135 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700136
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700137 cflags: ["-include bionic/libc/private/libc_logging.h"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700138
Dan Willemsen1bd78892015-09-11 13:08:19 -0700139 srcs: lib_src_files,
140
Colin Cross4daa75d2016-04-07 13:28:20 -0700141 sanitize: {
142 never: true,
143 },
Dan Willemsen1bd78892015-09-11 13:08:19 -0700144}
145
146//-----------------------------------------------------------------------
147// jemalloc static jet library
148//-----------------------------------------------------------------------
149cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700150 name: "libjemalloc_jet",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700151
Dan Willemsene67f1d52016-03-01 17:23:40 -0800152 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700153
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700154 cflags: [
155 "-DJEMALLOC_JET",
156 "-include android/include/libc_logging.h",
157 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700158
Dan Willemsen1bd78892015-09-11 13:08:19 -0700159 srcs: lib_src_files,
160
161}
162
163jemalloc_testlib_srcs = [
164 "test/src/btalloc.c",
165 "test/src/btalloc_0.c",
166 "test/src/btalloc_1.c",
167 "test/src/math.c",
168 "test/src/mq.c",
169 "test/src/mtx.c",
170 "test/src/SFMT.c",
171 "test/src/test.c",
172 "test/src/thd.c",
173 "test/src/timer.c",
174]
175
176//-----------------------------------------------------------------------
177// jemalloc unit test library
178//-----------------------------------------------------------------------
179cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700180 name: "libjemalloc_unittest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700181
Dan Willemsene67f1d52016-03-01 17:23:40 -0800182 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700183
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700184 cflags: [
185 "-DJEMALLOC_UNIT_TEST",
186 "-include android/include/libc_logging.h",
187 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700188
Dan Willemsene67f1d52016-03-01 17:23:40 -0800189 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700190 "test/src",
191 "test/include",
192 ],
193
194 srcs: jemalloc_testlib_srcs,
195
196 whole_static_libs: ["libjemalloc_jet"],
197
198}
199
200//-----------------------------------------------------------------------
201// jemalloc unit tests
202//-----------------------------------------------------------------------
203unit_tests = [
Christopher Ferris35452472016-06-14 14:28:47 -0700204 "test/unit/a0.c",
205 "test/unit/arena_reset.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700206 "test/unit/atomic.c",
207 "test/unit/bitmap.c",
208 "test/unit/ckh.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800209 "test/unit/decay.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700210 "test/unit/fork.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700211 "test/unit/hash.c",
212 "test/unit/junk.c",
213 "test/unit/junk_alloc.c",
214 "test/unit/junk_free.c",
215 "test/unit/lg_chunk.c",
216 "test/unit/mallctl.c",
217 "test/unit/math.c",
218 "test/unit/mq.c",
219 "test/unit/mtx.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800220 "test/unit/nstime.c",
221 "test/unit/prng.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700222 "test/unit/prof_accum.c",
223 "test/unit/prof_active.c",
224 "test/unit/prof_gdump.c",
225 "test/unit/prof_idump.c",
226 "test/unit/prof_reset.c",
227 "test/unit/prof_thread_name.c",
228 "test/unit/ql.c",
229 "test/unit/qr.c",
230 "test/unit/quarantine.c",
231 "test/unit/rb.c",
232 "test/unit/rtree.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800233 "test/unit/run_quantize.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700234 "test/unit/SFMT.c",
235 "test/unit/size_classes.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800236 "test/unit/smoothstep.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700237 "test/unit/stats.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800238 "test/unit/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700239 "test/unit/tsd.c",
240 "test/unit/util.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700241 "test/unit/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700242 "test/unit/zero.c",
243]
244
Dan Willemsenf0f45852015-12-21 15:29:32 -0800245cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700246 name: "jemalloc_unittests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800247
248 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700249
Dan Willemsene67f1d52016-03-01 17:23:40 -0800250 product_variables: common_product_variables,
251
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700252 cflags: common_cflags + [
253 "-DJEMALLOC_UNIT_TEST",
254 "-include android/include/libc_logging.h",
255 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700256
257 local_include_dirs: common_c_local_includes + [
258 "test/src",
259 "test/include",
260 ],
261
262 srcs: unit_tests,
263
264 static_libs: ["libjemalloc_unittest"],
265
Dan Willemsene67f1d52016-03-01 17:23:40 -0800266 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700267
268 test_per_src: true,
269}
270
Dan Willemsen1bd78892015-09-11 13:08:19 -0700271//-----------------------------------------------------------------------
272// jemalloc integration test library
273//-----------------------------------------------------------------------
274cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700275 name: "libjemalloc_integrationtest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700276
Dan Willemsene67f1d52016-03-01 17:23:40 -0800277 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700278
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700279 cflags: [
280 "-DJEMALLOC_INTEGRATION_TEST",
281 "-include android/include/libc_logging.h",
282 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700283
Dan Willemsene67f1d52016-03-01 17:23:40 -0800284 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700285 "test/src",
286 "test/include",
287 ],
288
289 srcs: jemalloc_testlib_srcs + lib_src_files,
290
291}
292
293//-----------------------------------------------------------------------
294// jemalloc integration tests
295//-----------------------------------------------------------------------
296integration_tests = [
297 "test/integration/aligned_alloc.c",
298 "test/integration/allocated.c",
299 "test/integration/chunk.c",
Colin Cross6ab5f602015-12-29 16:56:53 -0800300 "test/integration/iterate.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700301 "test/integration/MALLOCX_ARENA.c",
302 "test/integration/mallocx.c",
303 "test/integration/overflow.c",
304 "test/integration/posix_memalign.c",
305 "test/integration/rallocx.c",
306 "test/integration/sdallocx.c",
307 "test/integration/thread_arena.c",
308 "test/integration/thread_tcache_enabled.c",
309 "test/integration/xallocx.c",
310]
Colin Cross89d0f3c2015-09-17 15:34:16 -0700311
Dan Willemsenf0f45852015-12-21 15:29:32 -0800312cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700313
314 name: "jemalloc_integrationtests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800315
316 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700317
Dan Willemsene67f1d52016-03-01 17:23:40 -0800318 product_variables: common_product_variables,
319
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700320 cflags: common_cflags + [
321 "-DJEMALLOC_INTEGRATION_TEST",
322 "-include android/include/libc_logging.h",
323 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700324
325 local_include_dirs: common_c_local_includes + [
326 "test/src",
327 "test/include",
328 ],
329
330 srcs: integration_tests,
331
332 static_libs: ["libjemalloc_integrationtest"],
333
Dan Willemsene67f1d52016-03-01 17:23:40 -0800334 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700335
336 test_per_src: true,
337}