blob: b2cfeb8b8fd5b3e3c272a1db9f376e992e059d5b [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",
217 "test/unit/prng.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700218 "test/unit/prof_accum.c",
219 "test/unit/prof_active.c",
220 "test/unit/prof_gdump.c",
221 "test/unit/prof_idump.c",
222 "test/unit/prof_reset.c",
223 "test/unit/prof_thread_name.c",
224 "test/unit/ql.c",
225 "test/unit/qr.c",
226 "test/unit/quarantine.c",
227 "test/unit/rb.c",
228 "test/unit/rtree.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800229 "test/unit/run_quantize.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700230 "test/unit/SFMT.c",
231 "test/unit/size_classes.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800232 "test/unit/smoothstep.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700233 "test/unit/stats.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800234 "test/unit/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700235 "test/unit/tsd.c",
236 "test/unit/util.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700237 "test/unit/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700238 "test/unit/zero.c",
239]
240
Dan Willemsenf0f45852015-12-21 15:29:32 -0800241cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700242 name: "jemalloc_unittests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800243
244 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700245
Dan Willemsene67f1d52016-03-01 17:23:40 -0800246 product_variables: common_product_variables,
247
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700248 cflags: common_cflags + [
249 "-DJEMALLOC_UNIT_TEST",
250 "-include android/include/libc_logging.h",
251 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700252
253 local_include_dirs: common_c_local_includes + [
254 "test/src",
255 "test/include",
256 ],
257
258 srcs: unit_tests,
259
260 static_libs: ["libjemalloc_unittest"],
261
Dan Willemsene67f1d52016-03-01 17:23:40 -0800262 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700263
264 test_per_src: true,
265}
266
Dan Willemsen1bd78892015-09-11 13:08:19 -0700267//-----------------------------------------------------------------------
268// jemalloc integration test library
269//-----------------------------------------------------------------------
270cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700271 name: "libjemalloc_integrationtest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700272
Dan Willemsene67f1d52016-03-01 17:23:40 -0800273 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700274
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700275 cflags: [
276 "-DJEMALLOC_INTEGRATION_TEST",
277 "-include android/include/libc_logging.h",
278 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700279
Dan Willemsene67f1d52016-03-01 17:23:40 -0800280 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700281 "test/src",
282 "test/include",
283 ],
284
285 srcs: jemalloc_testlib_srcs + lib_src_files,
286
287}
288
289//-----------------------------------------------------------------------
290// jemalloc integration tests
291//-----------------------------------------------------------------------
292integration_tests = [
293 "test/integration/aligned_alloc.c",
294 "test/integration/allocated.c",
295 "test/integration/chunk.c",
Colin Cross6ab5f602015-12-29 16:56:53 -0800296 "test/integration/iterate.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700297 "test/integration/MALLOCX_ARENA.c",
298 "test/integration/mallocx.c",
299 "test/integration/overflow.c",
300 "test/integration/posix_memalign.c",
301 "test/integration/rallocx.c",
302 "test/integration/sdallocx.c",
303 "test/integration/thread_arena.c",
304 "test/integration/thread_tcache_enabled.c",
305 "test/integration/xallocx.c",
306]
Colin Cross89d0f3c2015-09-17 15:34:16 -0700307
Dan Willemsenf0f45852015-12-21 15:29:32 -0800308cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700309
310 name: "jemalloc_integrationtests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800311
312 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700313
Dan Willemsene67f1d52016-03-01 17:23:40 -0800314 product_variables: common_product_variables,
315
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700316 cflags: common_cflags + [
317 "-DJEMALLOC_INTEGRATION_TEST",
318 "-include android/include/libc_logging.h",
319 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700320
321 local_include_dirs: common_c_local_includes + [
322 "test/src",
323 "test/include",
324 ],
325
326 srcs: integration_tests,
327
328 static_libs: ["libjemalloc_integrationtest"],
329
Dan Willemsene67f1d52016-03-01 17:23:40 -0800330 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700331
332 test_per_src: true,
333}