blob: 5718add8ac164ddc20f9e0069bb20602e815766d [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",
19 "-fvisibility=hidden",
20 "-Wno-unused-parameter",
Colin Cross70274782015-12-29 16:56:11 -080021 "-Wno-type-limits",
Dan Willemsen1bd78892015-09-11 13:08:19 -070022]
23
24// These parameters change the way jemalloc works.
Dan Willemsen1bd78892015-09-11 13:08:19 -070025// ANDROID_MAX_ARENAS=XX
26// The total number of arenas will be less than or equal to this number.
27// The number of arenas will be calculated as 2 * the number of cpus
28// but no larger than XX.
29// ANDROID_TCACHE_NSLOTS_SMALL_MAX=XX
30// The number of small slots held in the tcache. The higher this number
31// is, the higher amount of PSS consumed. If this number is set too low
32// then small allocations will take longer to complete.
33// ANDROID_TCACHE_NSLOTS_LARGE=XX
34// The number of large slots held in the tcache. The higher this number
35// is, the higher amount of PSS consumed. If this number is set too low
36// then large allocations will take longer to complete.
37// ANDROID_LG_TCACHE_MAXCLASS_DEFAULT=XX
38// 1 << XX is the maximum sized allocation that will be in the tcache.
39// ANDROID_LG_CHUNK_DEFAULT=XX
40// 1 << XX is the default chunk size used by the system. Decreasing this
41// usually decreases the amount of PSS used, but can increase
42// fragmentation.
Christopher Ferris53bf3352016-07-19 14:05:20 -070043
44// Default to a single arena for svelte configurations to minimize
45// PSS consumed by jemalloc.
Dan Willemsen1bd78892015-09-11 13:08:19 -070046common_cflags += [
Christopher Ferris53bf3352016-07-19 14:05:20 -070047 "-DANDROID_MAX_ARENAS=1",
Dan Willemsen1bd78892015-09-11 13:08:19 -070048 "-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16",
49]
50
Dan Willemsen1bd78892015-09-11 13:08:19 -070051common_c_local_includes = [
52 "src",
53 "include",
54]
55
Dan Willemsene67f1d52016-03-01 17:23:40 -080056common_product_variables = {
57 // Only enable the tcache on non-svelte configurations, to save PSS.
58 malloc_not_svelte: {
Christopher Ferris53bf3352016-07-19 14:05:20 -070059 cflags: [
60 "-UANDROID_MAX_ARENAS",
61 "-DANDROID_MAX_ARENAS=2",
62 "-DJEMALLOC_TCACHE",
63 "-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8",
64 "-DANDROID_TCACHE_NSLOTS_LARGE=16",
65 ],
Dan Willemsene67f1d52016-03-01 17:23:40 -080066 },
67}
68
69cc_defaults {
70 name: "jemalloc_defaults",
Dan Willemsenba738bb2016-11-04 12:25:48 -070071 defaults: ["linux_bionic_supported"],
Dan Willemsene67f1d52016-03-01 17:23:40 -080072 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,
Dan Willemsen1bd78892015-09-11 13:08:19 -0700140}
141
142//-----------------------------------------------------------------------
143// jemalloc static jet library
144//-----------------------------------------------------------------------
145cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700146 name: "libjemalloc_jet",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700147
Dan Willemsene67f1d52016-03-01 17:23:40 -0800148 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700149
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700150 cflags: [
151 "-DJEMALLOC_JET",
152 "-include android/include/libc_logging.h",
153 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700154
Dan Willemsen1bd78892015-09-11 13:08:19 -0700155 srcs: lib_src_files,
156
157}
158
159jemalloc_testlib_srcs = [
160 "test/src/btalloc.c",
161 "test/src/btalloc_0.c",
162 "test/src/btalloc_1.c",
163 "test/src/math.c",
164 "test/src/mq.c",
165 "test/src/mtx.c",
166 "test/src/SFMT.c",
167 "test/src/test.c",
168 "test/src/thd.c",
169 "test/src/timer.c",
170]
171
172//-----------------------------------------------------------------------
173// jemalloc unit test library
174//-----------------------------------------------------------------------
175cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700176 name: "libjemalloc_unittest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700177
Dan Willemsene67f1d52016-03-01 17:23:40 -0800178 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700179
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700180 cflags: [
181 "-DJEMALLOC_UNIT_TEST",
182 "-include android/include/libc_logging.h",
183 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700184
Dan Willemsene67f1d52016-03-01 17:23:40 -0800185 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700186 "test/src",
187 "test/include",
188 ],
189
190 srcs: jemalloc_testlib_srcs,
191
192 whole_static_libs: ["libjemalloc_jet"],
193
194}
195
196//-----------------------------------------------------------------------
197// jemalloc unit tests
198//-----------------------------------------------------------------------
199unit_tests = [
Christopher Ferris35452472016-06-14 14:28:47 -0700200 "test/unit/a0.c",
201 "test/unit/arena_reset.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700202 "test/unit/atomic.c",
203 "test/unit/bitmap.c",
204 "test/unit/ckh.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800205 "test/unit/decay.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700206 "test/unit/fork.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700207 "test/unit/hash.c",
208 "test/unit/junk.c",
209 "test/unit/junk_alloc.c",
210 "test/unit/junk_free.c",
211 "test/unit/lg_chunk.c",
212 "test/unit/mallctl.c",
213 "test/unit/math.c",
214 "test/unit/mq.c",
215 "test/unit/mtx.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800216 "test/unit/nstime.c",
Christopher Ferrisbf9b0182016-12-08 11:56:18 -0800217 "test/unit/pack.c",
218 "test/unit/pages.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800219 "test/unit/prng.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700220 "test/unit/prof_accum.c",
221 "test/unit/prof_active.c",
222 "test/unit/prof_gdump.c",
223 "test/unit/prof_idump.c",
224 "test/unit/prof_reset.c",
225 "test/unit/prof_thread_name.c",
226 "test/unit/ql.c",
227 "test/unit/qr.c",
228 "test/unit/quarantine.c",
229 "test/unit/rb.c",
230 "test/unit/rtree.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800231 "test/unit/run_quantize.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700232 "test/unit/SFMT.c",
233 "test/unit/size_classes.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800234 "test/unit/smoothstep.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700235 "test/unit/stats.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800236 "test/unit/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700237 "test/unit/tsd.c",
238 "test/unit/util.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700239 "test/unit/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700240 "test/unit/zero.c",
241]
242
Dan Willemsenf0f45852015-12-21 15:29:32 -0800243cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700244 name: "jemalloc_unittests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800245
246 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700247
Dan Willemsene67f1d52016-03-01 17:23:40 -0800248 product_variables: common_product_variables,
249
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700250 cflags: common_cflags + [
251 "-DJEMALLOC_UNIT_TEST",
252 "-include android/include/libc_logging.h",
253 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700254
255 local_include_dirs: common_c_local_includes + [
256 "test/src",
257 "test/include",
258 ],
259
260 srcs: unit_tests,
261
262 static_libs: ["libjemalloc_unittest"],
263
Dan Willemsene67f1d52016-03-01 17:23:40 -0800264 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700265
266 test_per_src: true,
267}
268
Dan Willemsen1bd78892015-09-11 13:08:19 -0700269//-----------------------------------------------------------------------
270// jemalloc integration test library
271//-----------------------------------------------------------------------
272cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700273 name: "libjemalloc_integrationtest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700274
Dan Willemsene67f1d52016-03-01 17:23:40 -0800275 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700276
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700277 cflags: [
278 "-DJEMALLOC_INTEGRATION_TEST",
279 "-include android/include/libc_logging.h",
280 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700281
Dan Willemsene67f1d52016-03-01 17:23:40 -0800282 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700283 "test/src",
284 "test/include",
285 ],
286
287 srcs: jemalloc_testlib_srcs + lib_src_files,
288
289}
290
291//-----------------------------------------------------------------------
292// jemalloc integration tests
293//-----------------------------------------------------------------------
294integration_tests = [
295 "test/integration/aligned_alloc.c",
296 "test/integration/allocated.c",
297 "test/integration/chunk.c",
Colin Cross6ab5f602015-12-29 16:56:53 -0800298 "test/integration/iterate.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700299 "test/integration/MALLOCX_ARENA.c",
300 "test/integration/mallocx.c",
301 "test/integration/overflow.c",
302 "test/integration/posix_memalign.c",
303 "test/integration/rallocx.c",
304 "test/integration/sdallocx.c",
305 "test/integration/thread_arena.c",
306 "test/integration/thread_tcache_enabled.c",
307 "test/integration/xallocx.c",
308]
Colin Cross89d0f3c2015-09-17 15:34:16 -0700309
Dan Willemsenf0f45852015-12-21 15:29:32 -0800310cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700311
312 name: "jemalloc_integrationtests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800313
314 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700315
Dan Willemsene67f1d52016-03-01 17:23:40 -0800316 product_variables: common_product_variables,
317
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700318 cflags: common_cflags + [
319 "-DJEMALLOC_INTEGRATION_TEST",
320 "-include android/include/libc_logging.h",
321 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700322
323 local_include_dirs: common_c_local_includes + [
324 "test/src",
325 "test/include",
326 ],
327
328 srcs: integration_tests,
329
330 static_libs: ["libjemalloc_integrationtest"],
331
Dan Willemsene67f1d52016-03-01 17:23:40 -0800332 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700333
334 test_per_src: true,
335}