blob: 0dd1e94b77756e1487df1dccb32b4e3fa2f5d6b1 [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
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 Ferris53bf3352016-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 Willemsene67f1d52016-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 Ferris53bf3352016-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 Willemsene67f1d52016-03-01 17:23:40 -080069 },
70}
71
72cc_defaults {
73 name: "jemalloc_defaults",
Dan Willemsenba738bb2016-11-04 12:25:48 -070074 defaults: ["linux_bionic_supported"],
Dan Willemsene67f1d52016-03-01 17:23:40 -080075 cflags: common_cflags,
76
77 product_variables: common_product_variables,
78
79 multilib: {
80 lib32: {
81 // Use a 512K chunk size on 32 bit systems.
82 // This keeps the total amount of virtual address space consumed
83 // by jemalloc lower.
84 cflags: [
85 "-DANDROID_LG_CHUNK_DEFAULT=19",
86 ],
87 },
88 lib64: {
89 // Use a 2MB chunk size on 64 bit systems.
90 // This is the default currently used by 4.0.0
91 cflags: [
92 "-DANDROID_LG_CHUNK_DEFAULT=21",
93 ],
94 },
95 },
96
97 local_include_dirs: common_c_local_includes,
Colin Cross4daa75d2016-04-07 13:28:20 -070098 stl: "none",
Dan Willemsene67f1d52016-03-01 17:23:40 -080099}
100
Dan Willemsen1bd78892015-09-11 13:08:19 -0700101lib_src_files = [
102 "src/arena.c",
103 "src/atomic.c",
104 "src/base.c",
105 "src/bitmap.c",
106 "src/chunk.c",
107 "src/chunk_dss.c",
108 "src/chunk_mmap.c",
109 "src/ckh.c",
110 "src/ctl.c",
111 "src/extent.c",
112 "src/hash.c",
113 "src/huge.c",
114 "src/jemalloc.c",
115 "src/mb.c",
116 "src/mutex.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800117 "src/nstime.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700118 "src/pages.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800119 "src/prng.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700120 "src/prof.c",
121 "src/quarantine.c",
122 "src/rtree.c",
Christopher Ferrisfb1f0942016-11-08 14:47:48 -0800123 "src/spin.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700124 "src/stats.c",
125 "src/tcache.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800126 "src/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700127 "src/tsd.c",
128 "src/util.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700129 "src/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700130]
131
132//-----------------------------------------------------------------------
133// jemalloc static library
134//-----------------------------------------------------------------------
135cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700136 name: "libjemalloc",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700137
Dan Willemsene67f1d52016-03-01 17:23:40 -0800138 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700139
Christopher Ferrisbe92dfd2017-04-25 13:25:48 -0700140 cflags: ["-include bionic/libc/async_safe/include/async_safe/log.h"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700141
Dan Willemsen1bd78892015-09-11 13:08:19 -0700142 srcs: lib_src_files,
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",
Christopher Ferrisbe92dfd2017-04-25 13:25:48 -0700155 "-include android/include/log.h",
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700156 ],
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",
Christopher Ferrisbe92dfd2017-04-25 13:25:48 -0700185 "-include android/include/log.h",
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700186 ],
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",
Christopher Ferrisbf9b0182016-12-08 11:56:18 -0800220 "test/unit/pack.c",
221 "test/unit/pages.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800222 "test/unit/prng.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700223 "test/unit/prof_accum.c",
224 "test/unit/prof_active.c",
225 "test/unit/prof_gdump.c",
226 "test/unit/prof_idump.c",
227 "test/unit/prof_reset.c",
228 "test/unit/prof_thread_name.c",
229 "test/unit/ql.c",
230 "test/unit/qr.c",
231 "test/unit/quarantine.c",
232 "test/unit/rb.c",
233 "test/unit/rtree.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800234 "test/unit/run_quantize.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700235 "test/unit/SFMT.c",
236 "test/unit/size_classes.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800237 "test/unit/smoothstep.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700238 "test/unit/stats.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800239 "test/unit/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700240 "test/unit/tsd.c",
241 "test/unit/util.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700242 "test/unit/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700243 "test/unit/zero.c",
244]
245
Dan Willemsenf0f45852015-12-21 15:29:32 -0800246cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700247 name: "jemalloc_unittests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800248
249 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700250
Dan Willemsene67f1d52016-03-01 17:23:40 -0800251 product_variables: common_product_variables,
252
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700253 cflags: common_cflags + [
254 "-DJEMALLOC_UNIT_TEST",
Christopher Ferrisbe92dfd2017-04-25 13:25:48 -0700255 "-include android/include/log.h",
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700256 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700257
258 local_include_dirs: common_c_local_includes + [
259 "test/src",
260 "test/include",
261 ],
262
263 srcs: unit_tests,
264
265 static_libs: ["libjemalloc_unittest"],
266
Dan Willemsene67f1d52016-03-01 17:23:40 -0800267 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700268
269 test_per_src: true,
270}
271
Dan Willemsen1bd78892015-09-11 13:08:19 -0700272//-----------------------------------------------------------------------
273// jemalloc integration test library
274//-----------------------------------------------------------------------
275cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700276 name: "libjemalloc_integrationtest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700277
Dan Willemsene67f1d52016-03-01 17:23:40 -0800278 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700279
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700280 cflags: [
281 "-DJEMALLOC_INTEGRATION_TEST",
Christopher Ferrisbe92dfd2017-04-25 13:25:48 -0700282 "-include android/include/log.h",
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700283 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700284
Dan Willemsene67f1d52016-03-01 17:23:40 -0800285 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700286 "test/src",
287 "test/include",
288 ],
289
290 srcs: jemalloc_testlib_srcs + lib_src_files,
291
292}
293
294//-----------------------------------------------------------------------
295// jemalloc integration tests
296//-----------------------------------------------------------------------
297integration_tests = [
298 "test/integration/aligned_alloc.c",
299 "test/integration/allocated.c",
300 "test/integration/chunk.c",
Colin Cross6ab5f602015-12-29 16:56:53 -0800301 "test/integration/iterate.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700302 "test/integration/MALLOCX_ARENA.c",
303 "test/integration/mallocx.c",
304 "test/integration/overflow.c",
305 "test/integration/posix_memalign.c",
306 "test/integration/rallocx.c",
307 "test/integration/sdallocx.c",
308 "test/integration/thread_arena.c",
309 "test/integration/thread_tcache_enabled.c",
310 "test/integration/xallocx.c",
311]
Colin Cross89d0f3c2015-09-17 15:34:16 -0700312
Dan Willemsenf0f45852015-12-21 15:29:32 -0800313cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700314
315 name: "jemalloc_integrationtests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800316
317 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700318
Dan Willemsene67f1d52016-03-01 17:23:40 -0800319 product_variables: common_product_variables,
320
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700321 cflags: common_cflags + [
322 "-DJEMALLOC_INTEGRATION_TEST",
Christopher Ferrisbe92dfd2017-04-25 13:25:48 -0700323 "-include android/include/log.h",
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700324 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700325
326 local_include_dirs: common_c_local_includes + [
327 "test/src",
328 "test/include",
329 ],
330
331 srcs: integration_tests,
332
333 static_libs: ["libjemalloc_integrationtest"],
334
Dan Willemsene67f1d52016-03-01 17:23:40 -0800335 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700336
337 test_per_src: true,
338}