blob: 38ddce059390350408b222a2e95aa554ee9e3c6a [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",
22 "-Wno-unused-parameter",
Colin Cross70274782015-12-29 16:56:11 -080023 "-Wno-type-limits",
Dan Willemsen1bd78892015-09-11 13:08:19 -070024]
25
26// These parameters change the way jemalloc works.
Dan Willemsen1bd78892015-09-11 13:08:19 -070027// ANDROID_MAX_ARENAS=XX
28// The total number of arenas will be less than or equal to this number.
29// The number of arenas will be calculated as 2 * the number of cpus
30// but no larger than XX.
31// ANDROID_TCACHE_NSLOTS_SMALL_MAX=XX
32// The number of small slots held in the tcache. The higher this number
33// is, the higher amount of PSS consumed. If this number is set too low
34// then small allocations will take longer to complete.
35// ANDROID_TCACHE_NSLOTS_LARGE=XX
36// The number of large slots held in the tcache. The higher this number
37// is, the higher amount of PSS consumed. If this number is set too low
38// then large allocations will take longer to complete.
39// ANDROID_LG_TCACHE_MAXCLASS_DEFAULT=XX
40// 1 << XX is the maximum sized allocation that will be in the tcache.
41// ANDROID_LG_CHUNK_DEFAULT=XX
42// 1 << XX is the default chunk size used by the system. Decreasing this
43// usually decreases the amount of PSS used, but can increase
44// fragmentation.
Christopher Ferris53bf3352016-07-19 14:05:20 -070045
46// Default to a single arena for svelte configurations to minimize
47// PSS consumed by jemalloc.
Dan Willemsen1bd78892015-09-11 13:08:19 -070048common_cflags += [
Christopher Ferris53bf3352016-07-19 14:05:20 -070049 "-DANDROID_MAX_ARENAS=1",
Dan Willemsen1bd78892015-09-11 13:08:19 -070050 "-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16",
51]
52
Dan Willemsen1bd78892015-09-11 13:08:19 -070053common_c_local_includes = [
54 "src",
55 "include",
56]
57
Dan Willemsene67f1d52016-03-01 17:23:40 -080058common_product_variables = {
59 // Only enable the tcache on non-svelte configurations, to save PSS.
60 malloc_not_svelte: {
Christopher Ferris53bf3352016-07-19 14:05:20 -070061 cflags: [
62 "-UANDROID_MAX_ARENAS",
63 "-DANDROID_MAX_ARENAS=2",
64 "-DJEMALLOC_TCACHE",
65 "-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8",
66 "-DANDROID_TCACHE_NSLOTS_LARGE=16",
67 ],
Dan Willemsene67f1d52016-03-01 17:23:40 -080068 },
69}
70
71cc_defaults {
72 name: "jemalloc_defaults",
Dan Willemsenba738bb2016-11-04 12:25:48 -070073 defaults: ["linux_bionic_supported"],
Dan Willemsene67f1d52016-03-01 17:23:40 -080074 cflags: common_cflags,
75
76 product_variables: common_product_variables,
77
78 multilib: {
79 lib32: {
80 // Use a 512K chunk size on 32 bit systems.
81 // This keeps the total amount of virtual address space consumed
82 // by jemalloc lower.
83 cflags: [
84 "-DANDROID_LG_CHUNK_DEFAULT=19",
85 ],
86 },
87 lib64: {
88 // Use a 2MB chunk size on 64 bit systems.
89 // This is the default currently used by 4.0.0
90 cflags: [
91 "-DANDROID_LG_CHUNK_DEFAULT=21",
92 ],
93 },
94 },
95
96 local_include_dirs: common_c_local_includes,
Colin Cross4daa75d2016-04-07 13:28:20 -070097 stl: "none",
Dan Willemsene67f1d52016-03-01 17:23:40 -080098}
99
Dan Willemsen1bd78892015-09-11 13:08:19 -0700100lib_src_files = [
101 "src/arena.c",
102 "src/atomic.c",
103 "src/base.c",
104 "src/bitmap.c",
105 "src/chunk.c",
106 "src/chunk_dss.c",
107 "src/chunk_mmap.c",
108 "src/ckh.c",
109 "src/ctl.c",
110 "src/extent.c",
111 "src/hash.c",
112 "src/huge.c",
113 "src/jemalloc.c",
114 "src/mb.c",
115 "src/mutex.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800116 "src/nstime.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700117 "src/pages.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800118 "src/prng.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700119 "src/prof.c",
120 "src/quarantine.c",
121 "src/rtree.c",
Christopher Ferrisfb1f0942016-11-08 14:47:48 -0800122 "src/spin.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700123 "src/stats.c",
124 "src/tcache.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800125 "src/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700126 "src/tsd.c",
127 "src/util.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700128 "src/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700129]
130
131//-----------------------------------------------------------------------
132// jemalloc static library
133//-----------------------------------------------------------------------
134cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700135 name: "libjemalloc",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700136
Dan Willemsene67f1d52016-03-01 17:23:40 -0800137 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700138
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700139 cflags: ["-include bionic/libc/private/libc_logging.h"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700140
Dan Willemsen1bd78892015-09-11 13:08:19 -0700141 srcs: lib_src_files,
Dan Willemsen1bd78892015-09-11 13:08:19 -0700142}
143
144//-----------------------------------------------------------------------
145// jemalloc static jet library
146//-----------------------------------------------------------------------
147cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700148 name: "libjemalloc_jet",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700149
Dan Willemsene67f1d52016-03-01 17:23:40 -0800150 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700151
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700152 cflags: [
153 "-DJEMALLOC_JET",
154 "-include android/include/libc_logging.h",
155 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700156
Dan Willemsen1bd78892015-09-11 13:08:19 -0700157 srcs: lib_src_files,
158
159}
160
161jemalloc_testlib_srcs = [
162 "test/src/btalloc.c",
163 "test/src/btalloc_0.c",
164 "test/src/btalloc_1.c",
165 "test/src/math.c",
166 "test/src/mq.c",
167 "test/src/mtx.c",
168 "test/src/SFMT.c",
169 "test/src/test.c",
170 "test/src/thd.c",
171 "test/src/timer.c",
172]
173
174//-----------------------------------------------------------------------
175// jemalloc unit test library
176//-----------------------------------------------------------------------
177cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700178 name: "libjemalloc_unittest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700179
Dan Willemsene67f1d52016-03-01 17:23:40 -0800180 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700181
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700182 cflags: [
183 "-DJEMALLOC_UNIT_TEST",
184 "-include android/include/libc_logging.h",
185 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700186
Dan Willemsene67f1d52016-03-01 17:23:40 -0800187 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700188 "test/src",
189 "test/include",
190 ],
191
192 srcs: jemalloc_testlib_srcs,
193
194 whole_static_libs: ["libjemalloc_jet"],
195
196}
197
198//-----------------------------------------------------------------------
199// jemalloc unit tests
200//-----------------------------------------------------------------------
201unit_tests = [
Christopher Ferris35452472016-06-14 14:28:47 -0700202 "test/unit/a0.c",
203 "test/unit/arena_reset.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700204 "test/unit/atomic.c",
205 "test/unit/bitmap.c",
206 "test/unit/ckh.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800207 "test/unit/decay.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700208 "test/unit/fork.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700209 "test/unit/hash.c",
210 "test/unit/junk.c",
211 "test/unit/junk_alloc.c",
212 "test/unit/junk_free.c",
213 "test/unit/lg_chunk.c",
214 "test/unit/mallctl.c",
215 "test/unit/math.c",
216 "test/unit/mq.c",
217 "test/unit/mtx.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800218 "test/unit/nstime.c",
Christopher Ferrisbf9b0182016-12-08 11:56:18 -0800219 "test/unit/pack.c",
220 "test/unit/pages.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800221 "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}