blob: 3d55e6f58a75e191343dc71bb82ae2e0d1b9439c [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",
120 "src/stats.c",
121 "src/tcache.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800122 "src/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700123 "src/tsd.c",
124 "src/util.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700125 "src/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700126]
127
128//-----------------------------------------------------------------------
129// jemalloc static library
130//-----------------------------------------------------------------------
131cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700132 name: "libjemalloc",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700133
Dan Willemsene67f1d52016-03-01 17:23:40 -0800134 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700135
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700136 cflags: ["-include bionic/libc/private/libc_logging.h"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700137
Dan Willemsen1bd78892015-09-11 13:08:19 -0700138 srcs: lib_src_files,
139
Colin Cross4daa75d2016-04-07 13:28:20 -0700140 sanitize: {
141 never: true,
142 },
Dan Willemsen1bd78892015-09-11 13:08:19 -0700143}
144
145//-----------------------------------------------------------------------
146// jemalloc static jet library
147//-----------------------------------------------------------------------
148cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700149 name: "libjemalloc_jet",
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
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700153 cflags: [
154 "-DJEMALLOC_JET",
155 "-include android/include/libc_logging.h",
156 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700157
Dan Willemsen1bd78892015-09-11 13:08:19 -0700158 srcs: lib_src_files,
159
160}
161
162jemalloc_testlib_srcs = [
163 "test/src/btalloc.c",
164 "test/src/btalloc_0.c",
165 "test/src/btalloc_1.c",
166 "test/src/math.c",
167 "test/src/mq.c",
168 "test/src/mtx.c",
169 "test/src/SFMT.c",
170 "test/src/test.c",
171 "test/src/thd.c",
172 "test/src/timer.c",
173]
174
175//-----------------------------------------------------------------------
176// jemalloc unit test library
177//-----------------------------------------------------------------------
178cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700179 name: "libjemalloc_unittest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700180
Dan Willemsene67f1d52016-03-01 17:23:40 -0800181 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700182
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700183 cflags: [
184 "-DJEMALLOC_UNIT_TEST",
185 "-include android/include/libc_logging.h",
186 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700187
Dan Willemsene67f1d52016-03-01 17:23:40 -0800188 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700189 "test/src",
190 "test/include",
191 ],
192
193 srcs: jemalloc_testlib_srcs,
194
195 whole_static_libs: ["libjemalloc_jet"],
196
197}
198
199//-----------------------------------------------------------------------
200// jemalloc unit tests
201//-----------------------------------------------------------------------
202unit_tests = [
Christopher Ferris35452472016-06-14 14:28:47 -0700203 "test/unit/a0.c",
204 "test/unit/arena_reset.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700205 "test/unit/atomic.c",
206 "test/unit/bitmap.c",
207 "test/unit/ckh.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800208 "test/unit/decay.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700209 "test/unit/fork.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700210 "test/unit/hash.c",
211 "test/unit/junk.c",
212 "test/unit/junk_alloc.c",
213 "test/unit/junk_free.c",
214 "test/unit/lg_chunk.c",
215 "test/unit/mallctl.c",
216 "test/unit/math.c",
217 "test/unit/mq.c",
218 "test/unit/mtx.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800219 "test/unit/nstime.c",
220 "test/unit/prng.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700221 "test/unit/prof_accum.c",
222 "test/unit/prof_active.c",
223 "test/unit/prof_gdump.c",
224 "test/unit/prof_idump.c",
225 "test/unit/prof_reset.c",
226 "test/unit/prof_thread_name.c",
227 "test/unit/ql.c",
228 "test/unit/qr.c",
229 "test/unit/quarantine.c",
230 "test/unit/rb.c",
231 "test/unit/rtree.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800232 "test/unit/run_quantize.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700233 "test/unit/SFMT.c",
234 "test/unit/size_classes.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800235 "test/unit/smoothstep.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700236 "test/unit/stats.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800237 "test/unit/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700238 "test/unit/tsd.c",
239 "test/unit/util.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700240 "test/unit/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700241 "test/unit/zero.c",
242]
243
Dan Willemsenf0f45852015-12-21 15:29:32 -0800244cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700245 name: "jemalloc_unittests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800246
247 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700248
Dan Willemsene67f1d52016-03-01 17:23:40 -0800249 product_variables: common_product_variables,
250
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700251 cflags: common_cflags + [
252 "-DJEMALLOC_UNIT_TEST",
253 "-include android/include/libc_logging.h",
254 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700255
256 local_include_dirs: common_c_local_includes + [
257 "test/src",
258 "test/include",
259 ],
260
261 srcs: unit_tests,
262
263 static_libs: ["libjemalloc_unittest"],
264
Dan Willemsene67f1d52016-03-01 17:23:40 -0800265 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700266
267 test_per_src: true,
268}
269
Dan Willemsen1bd78892015-09-11 13:08:19 -0700270//-----------------------------------------------------------------------
271// jemalloc integration test library
272//-----------------------------------------------------------------------
273cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700274 name: "libjemalloc_integrationtest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700275
Dan Willemsene67f1d52016-03-01 17:23:40 -0800276 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700277
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700278 cflags: [
279 "-DJEMALLOC_INTEGRATION_TEST",
280 "-include android/include/libc_logging.h",
281 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700282
Dan Willemsene67f1d52016-03-01 17:23:40 -0800283 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700284 "test/src",
285 "test/include",
286 ],
287
288 srcs: jemalloc_testlib_srcs + lib_src_files,
289
290}
291
292//-----------------------------------------------------------------------
293// jemalloc integration tests
294//-----------------------------------------------------------------------
295integration_tests = [
296 "test/integration/aligned_alloc.c",
297 "test/integration/allocated.c",
298 "test/integration/chunk.c",
Colin Cross6ab5f602015-12-29 16:56:53 -0800299 "test/integration/iterate.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700300 "test/integration/MALLOCX_ARENA.c",
301 "test/integration/mallocx.c",
302 "test/integration/overflow.c",
303 "test/integration/posix_memalign.c",
304 "test/integration/rallocx.c",
305 "test/integration/sdallocx.c",
306 "test/integration/thread_arena.c",
307 "test/integration/thread_tcache_enabled.c",
308 "test/integration/xallocx.c",
309]
Colin Cross89d0f3c2015-09-17 15:34:16 -0700310
Dan Willemsenf0f45852015-12-21 15:29:32 -0800311cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700312
313 name: "jemalloc_integrationtests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800314
315 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700316
Dan Willemsene67f1d52016-03-01 17:23:40 -0800317 product_variables: common_product_variables,
318
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700319 cflags: common_cflags + [
320 "-DJEMALLOC_INTEGRATION_TEST",
321 "-include android/include/libc_logging.h",
322 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700323
324 local_include_dirs: common_c_local_includes + [
325 "test/src",
326 "test/include",
327 ],
328
329 srcs: integration_tests,
330
331 static_libs: ["libjemalloc_integrationtest"],
332
Dan Willemsene67f1d52016-03-01 17:23:40 -0800333 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700334
335 test_per_src: true,
336}