blob: bc22a715a4f5a994d507e19f0deb59022eb84788 [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 = [
Dan Willemsen1bd78892015-09-11 13:08:19 -070018 "-D_REENTRANT",
Alex Naidis5a22dd02016-08-19 22:57:27 +020019 "-O3",
20 "-funroll-loops",
Dan Willemsen1bd78892015-09-11 13:08:19 -070021 "-fvisibility=hidden",
Chih-Hung Hsieh033b6fd2017-09-28 12:17:52 -070022 "-Werror",
Dan Willemsen1bd78892015-09-11 13:08:19 -070023 "-Wno-unused-parameter",
Colin Cross70274782015-12-29 16:56:11 -080024 "-Wno-type-limits",
Dan Willemsen1bd78892015-09-11 13:08:19 -070025]
26
27// These parameters change the way jemalloc works.
Dan Willemsen1bd78892015-09-11 13:08:19 -070028// ANDROID_MAX_ARENAS=XX
29// The total number of arenas will be less than or equal to this number.
30// The number of arenas will be calculated as 2 * the number of cpus
31// but no larger than XX.
32// ANDROID_TCACHE_NSLOTS_SMALL_MAX=XX
33// The number of small slots held in the tcache. The higher this number
34// is, the higher amount of PSS consumed. If this number is set too low
35// then small allocations will take longer to complete.
36// ANDROID_TCACHE_NSLOTS_LARGE=XX
37// The number of large slots held in the tcache. The higher this number
38// is, the higher amount of PSS consumed. If this number is set too low
39// then large allocations will take longer to complete.
40// ANDROID_LG_TCACHE_MAXCLASS_DEFAULT=XX
41// 1 << XX is the maximum sized allocation that will be in the tcache.
42// ANDROID_LG_CHUNK_DEFAULT=XX
43// 1 << XX is the default chunk size used by the system. Decreasing this
44// usually decreases the amount of PSS used, but can increase
45// fragmentation.
Christopher Ferris53bf3352016-07-19 14:05:20 -070046
Christopher Ferrisbb9b1cf2018-09-13 20:24:10 +000047android_common_cflags = [
48 // Default to a single arena for svelte configurations to minimize
49 // PSS. This will be overridden by android_product_variables for
50 // non-svelte configs.
Christopher Ferris53bf3352016-07-19 14:05:20 -070051 "-DANDROID_MAX_ARENAS=1",
Dan Willemsen1bd78892015-09-11 13:08:19 -070052 "-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16",
53]
54
Dan Willemsen1bd78892015-09-11 13:08:19 -070055common_c_local_includes = [
56 "src",
57 "include",
58]
59
Christopher Ferrisbb9b1cf2018-09-13 20:24:10 +000060android_product_variables = {
Dan Willemsene67f1d52016-03-01 17:23:40 -080061 // Only enable the tcache on non-svelte configurations, to save PSS.
62 malloc_not_svelte: {
Christopher Ferris53bf3352016-07-19 14:05:20 -070063 cflags: [
64 "-UANDROID_MAX_ARENAS",
65 "-DANDROID_MAX_ARENAS=2",
66 "-DJEMALLOC_TCACHE",
67 "-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8",
68 "-DANDROID_TCACHE_NSLOTS_LARGE=16",
69 ],
Dan Willemsene67f1d52016-03-01 17:23:40 -080070 },
71}
72
73cc_defaults {
74 name: "jemalloc_defaults",
Dan Willemsenba738bb2016-11-04 12:25:48 -070075 defaults: ["linux_bionic_supported"],
Christopher Ferrisbb9b1cf2018-09-13 20:24:10 +000076 host_supported: true,
Dan Willemsene67f1d52016-03-01 17:23:40 -080077 cflags: common_cflags,
78
Christopher Ferrisbb9b1cf2018-09-13 20:24:10 +000079 target: {
80 android: {
81 cflags: android_common_cflags + [
82 "-include android/include/log.h",
83 ],
84 product_variables: android_product_variables,
85 },
86 linux_glibc: {
87 enabled: true,
88 },
89 },
Dan Willemsene67f1d52016-03-01 17:23:40 -080090
91 multilib: {
92 lib32: {
93 // Use a 512K chunk size on 32 bit systems.
94 // This keeps the total amount of virtual address space consumed
95 // by jemalloc lower.
96 cflags: [
97 "-DANDROID_LG_CHUNK_DEFAULT=19",
98 ],
99 },
100 lib64: {
101 // Use a 2MB chunk size on 64 bit systems.
102 // This is the default currently used by 4.0.0
103 cflags: [
104 "-DANDROID_LG_CHUNK_DEFAULT=21",
105 ],
106 },
107 },
108
109 local_include_dirs: common_c_local_includes,
Colin Cross4daa75d2016-04-07 13:28:20 -0700110 stl: "none",
Dan Willemsene67f1d52016-03-01 17:23:40 -0800111}
112
Dan Willemsen1bd78892015-09-11 13:08:19 -0700113lib_src_files = [
114 "src/arena.c",
115 "src/atomic.c",
116 "src/base.c",
117 "src/bitmap.c",
118 "src/chunk.c",
119 "src/chunk_dss.c",
120 "src/chunk_mmap.c",
121 "src/ckh.c",
122 "src/ctl.c",
123 "src/extent.c",
124 "src/hash.c",
125 "src/huge.c",
126 "src/jemalloc.c",
127 "src/mb.c",
128 "src/mutex.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800129 "src/nstime.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700130 "src/pages.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800131 "src/prng.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700132 "src/prof.c",
133 "src/quarantine.c",
134 "src/rtree.c",
Christopher Ferrisfb1f0942016-11-08 14:47:48 -0800135 "src/spin.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700136 "src/stats.c",
137 "src/tcache.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800138 "src/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700139 "src/tsd.c",
140 "src/util.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700141 "src/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700142]
143
144//-----------------------------------------------------------------------
145// jemalloc static library
146//-----------------------------------------------------------------------
Christopher Ferrisbb9b1cf2018-09-13 20:24:10 +0000147cc_library {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700148 name: "libjemalloc",
Jiyong Park20a932e2018-04-27 21:47:48 +0900149 recovery_available: true,
Dan Willemsen1bd78892015-09-11 13:08:19 -0700150
Dan Willemsene67f1d52016-03-01 17:23:40 -0800151 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700152
Christopher Ferrisbb9b1cf2018-09-13 20:24:10 +0000153 target: {
154 android: {
155 shared: {
156 enabled: false,
157 },
158 },
159 },
Dan Willemsen1bd78892015-09-11 13:08:19 -0700160
Dan Willemsen1bd78892015-09-11 13:08:19 -0700161 srcs: lib_src_files,
Dan Willemsen1bd78892015-09-11 13:08:19 -0700162}
163
164//-----------------------------------------------------------------------
165// jemalloc static jet library
166//-----------------------------------------------------------------------
167cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700168 name: "libjemalloc_jet",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700169
Dan Willemsene67f1d52016-03-01 17:23:40 -0800170 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700171
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700172 cflags: [
173 "-DJEMALLOC_JET",
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700174 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700175
Dan Willemsen1bd78892015-09-11 13:08:19 -0700176 srcs: lib_src_files,
177
178}
179
180jemalloc_testlib_srcs = [
181 "test/src/btalloc.c",
182 "test/src/btalloc_0.c",
183 "test/src/btalloc_1.c",
184 "test/src/math.c",
185 "test/src/mq.c",
186 "test/src/mtx.c",
187 "test/src/SFMT.c",
188 "test/src/test.c",
189 "test/src/thd.c",
190 "test/src/timer.c",
191]
192
193//-----------------------------------------------------------------------
194// jemalloc unit test library
195//-----------------------------------------------------------------------
196cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700197 name: "libjemalloc_unittest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700198
Dan Willemsene67f1d52016-03-01 17:23:40 -0800199 defaults: ["jemalloc_defaults"],
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700200 cflags: [
201 "-DJEMALLOC_UNIT_TEST",
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700202 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700203
Dan Willemsene67f1d52016-03-01 17:23:40 -0800204 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700205 "test/src",
206 "test/include",
207 ],
208
209 srcs: jemalloc_testlib_srcs,
210
211 whole_static_libs: ["libjemalloc_jet"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700212}
213
214//-----------------------------------------------------------------------
215// jemalloc unit tests
216//-----------------------------------------------------------------------
217unit_tests = [
Christopher Ferris35452472016-06-14 14:28:47 -0700218 "test/unit/a0.c",
219 "test/unit/arena_reset.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700220 "test/unit/atomic.c",
221 "test/unit/bitmap.c",
222 "test/unit/ckh.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800223 "test/unit/decay.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700224 "test/unit/fork.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700225 "test/unit/hash.c",
226 "test/unit/junk.c",
227 "test/unit/junk_alloc.c",
228 "test/unit/junk_free.c",
229 "test/unit/lg_chunk.c",
230 "test/unit/mallctl.c",
231 "test/unit/math.c",
232 "test/unit/mq.c",
233 "test/unit/mtx.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800234 "test/unit/nstime.c",
Christopher Ferrisbf9b0182016-12-08 11:56:18 -0800235 "test/unit/pack.c",
236 "test/unit/pages.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800237 "test/unit/prng.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700238 "test/unit/prof_accum.c",
239 "test/unit/prof_active.c",
240 "test/unit/prof_gdump.c",
241 "test/unit/prof_idump.c",
242 "test/unit/prof_reset.c",
243 "test/unit/prof_thread_name.c",
244 "test/unit/ql.c",
245 "test/unit/qr.c",
246 "test/unit/quarantine.c",
247 "test/unit/rb.c",
248 "test/unit/rtree.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800249 "test/unit/run_quantize.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700250 "test/unit/SFMT.c",
251 "test/unit/size_classes.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800252 "test/unit/smoothstep.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700253 "test/unit/stats.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800254 "test/unit/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700255 "test/unit/tsd.c",
256 "test/unit/util.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700257 "test/unit/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700258 "test/unit/zero.c",
259]
260
Dan Willemsenf0f45852015-12-21 15:29:32 -0800261cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700262 name: "jemalloc_unittests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800263
Christopher Ferrisbb9b1cf2018-09-13 20:24:10 +0000264 defaults: ["jemalloc_defaults"],
Dan Willemsene67f1d52016-03-01 17:23:40 -0800265
Christopher Ferrisbb9b1cf2018-09-13 20:24:10 +0000266 gtest: false,
Christopher Ferrisf4496b22018-09-13 18:08:30 +0000267
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700268 cflags: common_cflags + [
269 "-DJEMALLOC_UNIT_TEST",
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700270 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700271
272 local_include_dirs: common_c_local_includes + [
273 "test/src",
274 "test/include",
275 ],
276
277 srcs: unit_tests,
278
279 static_libs: ["libjemalloc_unittest"],
280
Dan Willemsene67f1d52016-03-01 17:23:40 -0800281 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700282
283 test_per_src: true,
Christopher Ferrisbb9b1cf2018-09-13 20:24:10 +0000284
285 target: {
286 linux_glibc: {
287 // The sanitizer does not work for these tests on the host.
288 sanitize: {
289 never: true,
290 },
291 },
292 },
Colin Cross89d0f3c2015-09-17 15:34:16 -0700293}
294
Dan Willemsen1bd78892015-09-11 13:08:19 -0700295//-----------------------------------------------------------------------
296// jemalloc integration test library
297//-----------------------------------------------------------------------
298cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700299 name: "libjemalloc_integrationtest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700300
Dan Willemsene67f1d52016-03-01 17:23:40 -0800301 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700302
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700303 cflags: [
304 "-DJEMALLOC_INTEGRATION_TEST",
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700305 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700306
Dan Willemsene67f1d52016-03-01 17:23:40 -0800307 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700308 "test/src",
309 "test/include",
310 ],
311
312 srcs: jemalloc_testlib_srcs + lib_src_files,
313
314}
315
316//-----------------------------------------------------------------------
317// jemalloc integration tests
318//-----------------------------------------------------------------------
319integration_tests = [
320 "test/integration/aligned_alloc.c",
321 "test/integration/allocated.c",
322 "test/integration/chunk.c",
323 "test/integration/MALLOCX_ARENA.c",
324 "test/integration/mallocx.c",
325 "test/integration/overflow.c",
326 "test/integration/posix_memalign.c",
327 "test/integration/rallocx.c",
328 "test/integration/sdallocx.c",
329 "test/integration/thread_arena.c",
330 "test/integration/thread_tcache_enabled.c",
331 "test/integration/xallocx.c",
332]
Colin Cross89d0f3c2015-09-17 15:34:16 -0700333
Christopher Ferrisbb9b1cf2018-09-13 20:24:10 +0000334android_integration_tests = [
335 "test/integration/iterate.c",
336]
Dan Willemsenf0f45852015-12-21 15:29:32 -0800337
Christopher Ferrisbb9b1cf2018-09-13 20:24:10 +0000338cc_test {
Christopher Ferrisf4496b22018-09-13 18:08:30 +0000339 name: "jemalloc_integrationtests",
Christopher Ferrisfa930162018-09-07 15:15:16 -0700340
Christopher Ferrisbb9b1cf2018-09-13 20:24:10 +0000341 defaults: ["jemalloc_defaults"],
342
Dan Willemsenf0f45852015-12-21 15:29:32 -0800343 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700344
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700345 cflags: common_cflags + [
346 "-DJEMALLOC_INTEGRATION_TEST",
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700347 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700348
349 local_include_dirs: common_c_local_includes + [
350 "test/src",
351 "test/include",
352 ],
353
354 srcs: integration_tests,
Christopher Ferrisbb9b1cf2018-09-13 20:24:10 +0000355 target: {
356 android: {
357 srcs: android_integration_tests,
358 },
359 linux_glibc: {
360 // The sanitizer does not work for these tests on the host.
361 sanitize: {
362 never: true,
363 },
364 },
365 },
Colin Cross89d0f3c2015-09-17 15:34:16 -0700366
367 static_libs: ["libjemalloc_integrationtest"],
368
Dan Willemsene67f1d52016-03-01 17:23:40 -0800369 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700370
371 test_per_src: true,
372}