blob: 342c70d56d9ed10786a49d29f9dcd506e3e26a9e [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 = [
Alex Naidis84ab79d2016-11-19 21:03:14 +010018 "-std=gnu11",
Dan Willemsen1bd78892015-09-11 13:08:19 -070019 "-D_REENTRANT",
Alex Naidis7cc4c462016-08-19 22:57:27 +020020 "-O3",
21 "-funroll-loops",
Dan Willemsen1bd78892015-09-11 13:08:19 -070022 "-fvisibility=hidden",
23 "-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 Ferris08795322016-07-19 14:05:20 -070046
47// Default to a single arena for svelte configurations to minimize
48// PSS consumed by jemalloc.
Dan Willemsen1bd78892015-09-11 13:08:19 -070049common_cflags += [
Christopher Ferris08795322016-07-19 14:05:20 -070050 "-DANDROID_MAX_ARENAS=1",
Dan Willemsen1bd78892015-09-11 13:08:19 -070051 "-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16",
52]
53
Dan Willemsen1bd78892015-09-11 13:08:19 -070054common_c_local_includes = [
55 "src",
56 "include",
57]
58
Dan Willemsen41f26cb2016-03-01 17:23:40 -080059common_product_variables = {
60 // Only enable the tcache on non-svelte configurations, to save PSS.
61 malloc_not_svelte: {
Christopher Ferris08795322016-07-19 14:05:20 -070062 cflags: [
63 "-UANDROID_MAX_ARENAS",
64 "-DANDROID_MAX_ARENAS=2",
65 "-DJEMALLOC_TCACHE",
66 "-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8",
67 "-DANDROID_TCACHE_NSLOTS_LARGE=16",
68 ],
Dan Willemsen41f26cb2016-03-01 17:23:40 -080069 },
70}
71
72cc_defaults {
73 name: "jemalloc_defaults",
74 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 Cross517976f2016-04-07 13:28:20 -070097 stl: "none",
Dan Willemsen41f26cb2016-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 Willemsen1d84ae72016-03-07 16:22:25 -0800116 "src/nstime.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700117 "src/pages.c",
Dan Willemsen1d84ae72016-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",
122 "src/stats.c",
123 "src/tcache.c",
Dan Willemsen1d84ae72016-03-07 16:22:25 -0800124 "src/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700125 "src/tsd.c",
126 "src/util.c",
127]
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 Willemsen41f26cb2016-03-01 17:23:40 -0800135 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700136
137 include_files: ["bionic/libc/private/libc_logging.h"],
138
Dan Willemsen1bd78892015-09-11 13:08:19 -0700139 srcs: lib_src_files,
140
Colin Cross517976f2016-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 Willemsen41f26cb2016-03-01 17:23:40 -0800152 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700153
Dan Willemsen41f26cb2016-03-01 17:23:40 -0800154 cflags: ["-DJEMALLOC_JET"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700155
Colin Cross89d0f3c2015-09-17 15:34:16 -0700156 local_include_files: ["android/include/libc_logging.h"],
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 Willemsen41f26cb2016-03-01 17:23:40 -0800181 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700182
Dan Willemsen41f26cb2016-03-01 17:23:40 -0800183 cflags: ["-DJEMALLOC_UNIT_TEST"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700184
Colin Cross89d0f3c2015-09-17 15:34:16 -0700185 local_include_files: ["android/include/libc_logging.h"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700186
Dan Willemsen41f26cb2016-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 = [
202 "test/unit/atomic.c",
203 "test/unit/bitmap.c",
204 "test/unit/ckh.c",
Dan Willemsen1d84ae72016-03-07 16:22:25 -0800205 "test/unit/decay.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700206 "test/unit/hash.c",
207 "test/unit/junk.c",
208 "test/unit/junk_alloc.c",
209 "test/unit/junk_free.c",
210 "test/unit/lg_chunk.c",
211 "test/unit/mallctl.c",
212 "test/unit/math.c",
213 "test/unit/mq.c",
214 "test/unit/mtx.c",
Dan Willemsen1d84ae72016-03-07 16:22:25 -0800215 "test/unit/nstime.c",
216 "test/unit/prng.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700217 "test/unit/prof_accum.c",
218 "test/unit/prof_active.c",
219 "test/unit/prof_gdump.c",
220 "test/unit/prof_idump.c",
221 "test/unit/prof_reset.c",
222 "test/unit/prof_thread_name.c",
223 "test/unit/ql.c",
224 "test/unit/qr.c",
225 "test/unit/quarantine.c",
226 "test/unit/rb.c",
227 "test/unit/rtree.c",
Dan Willemsen1d84ae72016-03-07 16:22:25 -0800228 "test/unit/run_quantize.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700229 "test/unit/SFMT.c",
230 "test/unit/size_classes.c",
Dan Willemsen1d84ae72016-03-07 16:22:25 -0800231 "test/unit/smoothstep.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700232 "test/unit/stats.c",
Dan Willemsen1d84ae72016-03-07 16:22:25 -0800233 "test/unit/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700234 "test/unit/tsd.c",
235 "test/unit/util.c",
236 "test/unit/zero.c",
237]
238
Dan Willemsenf0f45852015-12-21 15:29:32 -0800239cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700240 name: "jemalloc_unittests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800241
242 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700243
Dan Willemsen41f26cb2016-03-01 17:23:40 -0800244 product_variables: common_product_variables,
245
Colin Cross89d0f3c2015-09-17 15:34:16 -0700246 cflags: common_cflags + ["-DJEMALLOC_UNIT_TEST"],
247
248 local_include_files: ["android/include/libc_logging.h"],
249
250 local_include_dirs: common_c_local_includes + [
251 "test/src",
252 "test/include",
253 ],
254
255 srcs: unit_tests,
256
257 static_libs: ["libjemalloc_unittest"],
258
Dan Willemsen41f26cb2016-03-01 17:23:40 -0800259 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700260
261 test_per_src: true,
262}
263
Dan Willemsen1bd78892015-09-11 13:08:19 -0700264//-----------------------------------------------------------------------
265// jemalloc integration test library
266//-----------------------------------------------------------------------
267cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700268 name: "libjemalloc_integrationtest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700269
Dan Willemsen41f26cb2016-03-01 17:23:40 -0800270 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700271
Dan Willemsen41f26cb2016-03-01 17:23:40 -0800272 cflags: ["-DJEMALLOC_INTEGRATION_TEST"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700273
Colin Cross89d0f3c2015-09-17 15:34:16 -0700274 local_include_files: ["android/include/libc_logging.h"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700275
Dan Willemsen41f26cb2016-03-01 17:23:40 -0800276 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700277 "test/src",
278 "test/include",
279 ],
280
281 srcs: jemalloc_testlib_srcs + lib_src_files,
282
283}
284
285//-----------------------------------------------------------------------
286// jemalloc integration tests
287//-----------------------------------------------------------------------
288integration_tests = [
289 "test/integration/aligned_alloc.c",
290 "test/integration/allocated.c",
291 "test/integration/chunk.c",
Colin Cross368f61e2015-12-29 16:56:53 -0800292 "test/integration/iterate.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700293 "test/integration/MALLOCX_ARENA.c",
294 "test/integration/mallocx.c",
295 "test/integration/overflow.c",
296 "test/integration/posix_memalign.c",
297 "test/integration/rallocx.c",
298 "test/integration/sdallocx.c",
299 "test/integration/thread_arena.c",
300 "test/integration/thread_tcache_enabled.c",
301 "test/integration/xallocx.c",
302]
Colin Cross89d0f3c2015-09-17 15:34:16 -0700303
Dan Willemsenf0f45852015-12-21 15:29:32 -0800304cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700305
306 name: "jemalloc_integrationtests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800307
308 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700309
Dan Willemsen41f26cb2016-03-01 17:23:40 -0800310 product_variables: common_product_variables,
311
Colin Cross89d0f3c2015-09-17 15:34:16 -0700312 cflags: common_cflags + ["-DJEMALLOC_INTEGRATION_TEST"],
313
314 local_include_files: ["android/include/libc_logging.h"],
315
316 local_include_dirs: common_c_local_includes + [
317 "test/src",
318 "test/include",
319 ],
320
321 srcs: integration_tests,
322
323 static_libs: ["libjemalloc_integrationtest"],
324
Dan Willemsen41f26cb2016-03-01 17:23:40 -0800325 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700326
327 test_per_src: true,
328}