blob: f65c93483b4de9ebc88423b98499dad062f41280 [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.
26// ANDROID_ALWAYS_PURGE
27// If defined, always purge immediately when a page is purgeable.
28// 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.
46common_cflags += [
Dan Willemsen1bd78892015-09-11 13:08:19 -070047 "-DANDROID_MAX_ARENAS=2",
48 "-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8",
49 "-DANDROID_TCACHE_NSLOTS_LARGE=16",
50 "-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: {
61 cflags: ["-DJEMALLOC_TCACHE"],
62 },
63}
64
65cc_defaults {
66 name: "jemalloc_defaults",
67 cflags: common_cflags,
68
69 product_variables: common_product_variables,
70
71 multilib: {
72 lib32: {
73 // Use a 512K chunk size on 32 bit systems.
74 // This keeps the total amount of virtual address space consumed
75 // by jemalloc lower.
76 cflags: [
77 "-DANDROID_LG_CHUNK_DEFAULT=19",
78 ],
79 },
80 lib64: {
81 // Use a 2MB chunk size on 64 bit systems.
82 // This is the default currently used by 4.0.0
83 cflags: [
84 "-DANDROID_LG_CHUNK_DEFAULT=21",
85 ],
86 },
87 },
88
89 local_include_dirs: common_c_local_includes,
Colin Cross4daa75d2016-04-07 13:28:20 -070090 stl: "none",
Dan Willemsene67f1d52016-03-01 17:23:40 -080091}
92
Dan Willemsen1bd78892015-09-11 13:08:19 -070093lib_src_files = [
94 "src/arena.c",
95 "src/atomic.c",
96 "src/base.c",
97 "src/bitmap.c",
98 "src/chunk.c",
99 "src/chunk_dss.c",
100 "src/chunk_mmap.c",
101 "src/ckh.c",
102 "src/ctl.c",
103 "src/extent.c",
104 "src/hash.c",
105 "src/huge.c",
106 "src/jemalloc.c",
107 "src/mb.c",
108 "src/mutex.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800109 "src/nstime.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700110 "src/pages.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800111 "src/prng.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700112 "src/prof.c",
113 "src/quarantine.c",
114 "src/rtree.c",
115 "src/stats.c",
116 "src/tcache.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800117 "src/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700118 "src/tsd.c",
119 "src/util.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700120 "src/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700121]
122
123//-----------------------------------------------------------------------
124// jemalloc static library
125//-----------------------------------------------------------------------
126cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700127 name: "libjemalloc",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700128
Dan Willemsene67f1d52016-03-01 17:23:40 -0800129 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700130
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700131 cflags: ["-include bionic/libc/private/libc_logging.h"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700132
Dan Willemsen1bd78892015-09-11 13:08:19 -0700133 srcs: lib_src_files,
134
Colin Cross4daa75d2016-04-07 13:28:20 -0700135 sanitize: {
136 never: true,
137 },
Dan Willemsen1bd78892015-09-11 13:08:19 -0700138}
139
140//-----------------------------------------------------------------------
141// jemalloc static jet library
142//-----------------------------------------------------------------------
143cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700144 name: "libjemalloc_jet",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700145
Dan Willemsene67f1d52016-03-01 17:23:40 -0800146 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700147
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700148 cflags: [
149 "-DJEMALLOC_JET",
150 "-include android/include/libc_logging.h",
151 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700152
Dan Willemsen1bd78892015-09-11 13:08:19 -0700153 srcs: lib_src_files,
154
155}
156
157jemalloc_testlib_srcs = [
158 "test/src/btalloc.c",
159 "test/src/btalloc_0.c",
160 "test/src/btalloc_1.c",
161 "test/src/math.c",
162 "test/src/mq.c",
163 "test/src/mtx.c",
164 "test/src/SFMT.c",
165 "test/src/test.c",
166 "test/src/thd.c",
167 "test/src/timer.c",
168]
169
170//-----------------------------------------------------------------------
171// jemalloc unit test library
172//-----------------------------------------------------------------------
173cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700174 name: "libjemalloc_unittest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700175
Dan Willemsene67f1d52016-03-01 17:23:40 -0800176 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700177
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700178 cflags: [
179 "-DJEMALLOC_UNIT_TEST",
180 "-include android/include/libc_logging.h",
181 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700182
Dan Willemsene67f1d52016-03-01 17:23:40 -0800183 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700184 "test/src",
185 "test/include",
186 ],
187
188 srcs: jemalloc_testlib_srcs,
189
190 whole_static_libs: ["libjemalloc_jet"],
191
192}
193
194//-----------------------------------------------------------------------
195// jemalloc unit tests
196//-----------------------------------------------------------------------
197unit_tests = [
Christopher Ferris35452472016-06-14 14:28:47 -0700198 "test/unit/a0.c",
199 "test/unit/arena_reset.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700200 "test/unit/atomic.c",
201 "test/unit/bitmap.c",
202 "test/unit/ckh.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800203 "test/unit/decay.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700204 "test/unit/fork.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700205 "test/unit/hash.c",
206 "test/unit/junk.c",
207 "test/unit/junk_alloc.c",
208 "test/unit/junk_free.c",
209 "test/unit/lg_chunk.c",
210 "test/unit/mallctl.c",
211 "test/unit/math.c",
212 "test/unit/mq.c",
213 "test/unit/mtx.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800214 "test/unit/nstime.c",
215 "test/unit/prng.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700216 "test/unit/prof_accum.c",
217 "test/unit/prof_active.c",
218 "test/unit/prof_gdump.c",
219 "test/unit/prof_idump.c",
220 "test/unit/prof_reset.c",
221 "test/unit/prof_thread_name.c",
222 "test/unit/ql.c",
223 "test/unit/qr.c",
224 "test/unit/quarantine.c",
225 "test/unit/rb.c",
226 "test/unit/rtree.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800227 "test/unit/run_quantize.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700228 "test/unit/SFMT.c",
229 "test/unit/size_classes.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800230 "test/unit/smoothstep.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700231 "test/unit/stats.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800232 "test/unit/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700233 "test/unit/tsd.c",
234 "test/unit/util.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700235 "test/unit/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700236 "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 Willemsene67f1d52016-03-01 17:23:40 -0800244 product_variables: common_product_variables,
245
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700246 cflags: common_cflags + [
247 "-DJEMALLOC_UNIT_TEST",
248 "-include android/include/libc_logging.h",
249 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700250
251 local_include_dirs: common_c_local_includes + [
252 "test/src",
253 "test/include",
254 ],
255
256 srcs: unit_tests,
257
258 static_libs: ["libjemalloc_unittest"],
259
Dan Willemsene67f1d52016-03-01 17:23:40 -0800260 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700261
262 test_per_src: true,
263}
264
Dan Willemsen1bd78892015-09-11 13:08:19 -0700265//-----------------------------------------------------------------------
266// jemalloc integration test library
267//-----------------------------------------------------------------------
268cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700269 name: "libjemalloc_integrationtest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700270
Dan Willemsene67f1d52016-03-01 17:23:40 -0800271 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700272
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700273 cflags: [
274 "-DJEMALLOC_INTEGRATION_TEST",
275 "-include android/include/libc_logging.h",
276 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700277
Dan Willemsene67f1d52016-03-01 17:23:40 -0800278 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700279 "test/src",
280 "test/include",
281 ],
282
283 srcs: jemalloc_testlib_srcs + lib_src_files,
284
285}
286
287//-----------------------------------------------------------------------
288// jemalloc integration tests
289//-----------------------------------------------------------------------
290integration_tests = [
291 "test/integration/aligned_alloc.c",
292 "test/integration/allocated.c",
293 "test/integration/chunk.c",
Colin Cross6ab5f602015-12-29 16:56:53 -0800294 "test/integration/iterate.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700295 "test/integration/MALLOCX_ARENA.c",
296 "test/integration/mallocx.c",
297 "test/integration/overflow.c",
298 "test/integration/posix_memalign.c",
299 "test/integration/rallocx.c",
300 "test/integration/sdallocx.c",
301 "test/integration/thread_arena.c",
302 "test/integration/thread_tcache_enabled.c",
303 "test/integration/xallocx.c",
304]
Colin Cross89d0f3c2015-09-17 15:34:16 -0700305
Dan Willemsenf0f45852015-12-21 15:29:32 -0800306cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700307
308 name: "jemalloc_integrationtests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800309
310 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700311
Dan Willemsene67f1d52016-03-01 17:23:40 -0800312 product_variables: common_product_variables,
313
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700314 cflags: common_cflags + [
315 "-DJEMALLOC_INTEGRATION_TEST",
316 "-include android/include/libc_logging.h",
317 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700318
319 local_include_dirs: common_c_local_includes + [
320 "test/src",
321 "test/include",
322 ],
323
324 srcs: integration_tests,
325
326 static_libs: ["libjemalloc_integrationtest"],
327
Dan Willemsene67f1d52016-03-01 17:23:40 -0800328 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700329
330 test_per_src: true,
331}