blob: 0377fd99de318609018c8d2f9d5146afc0d97f87 [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",
71 cflags: common_cflags,
72
73 product_variables: common_product_variables,
74
75 multilib: {
76 lib32: {
77 // Use a 512K chunk size on 32 bit systems.
78 // This keeps the total amount of virtual address space consumed
79 // by jemalloc lower.
80 cflags: [
81 "-DANDROID_LG_CHUNK_DEFAULT=19",
82 ],
83 },
84 lib64: {
85 // Use a 2MB chunk size on 64 bit systems.
86 // This is the default currently used by 4.0.0
87 cflags: [
88 "-DANDROID_LG_CHUNK_DEFAULT=21",
89 ],
90 },
91 },
92
93 local_include_dirs: common_c_local_includes,
Colin Cross4daa75d2016-04-07 13:28:20 -070094 stl: "none",
Dan Willemsene67f1d52016-03-01 17:23:40 -080095}
96
Dan Willemsen1bd78892015-09-11 13:08:19 -070097lib_src_files = [
98 "src/arena.c",
99 "src/atomic.c",
100 "src/base.c",
101 "src/bitmap.c",
102 "src/chunk.c",
103 "src/chunk_dss.c",
104 "src/chunk_mmap.c",
105 "src/ckh.c",
106 "src/ctl.c",
107 "src/extent.c",
108 "src/hash.c",
109 "src/huge.c",
110 "src/jemalloc.c",
111 "src/mb.c",
112 "src/mutex.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800113 "src/nstime.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700114 "src/pages.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800115 "src/prng.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700116 "src/prof.c",
117 "src/quarantine.c",
118 "src/rtree.c",
Christopher Ferrisfb1f0942016-11-08 14:47:48 -0800119 "src/spin.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700120 "src/stats.c",
121 "src/tcache.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800122 "src/ticker.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700123 "src/tsd.c",
124 "src/util.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700125 "src/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700126]
127
128//-----------------------------------------------------------------------
129// jemalloc static library
130//-----------------------------------------------------------------------
131cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700132 name: "libjemalloc",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700133
Dan Willemsene67f1d52016-03-01 17:23:40 -0800134 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700135
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700136 cflags: ["-include bionic/libc/private/libc_logging.h"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700137
Dan Willemsen1bd78892015-09-11 13:08:19 -0700138 srcs: lib_src_files,
Dan Willemsen1bd78892015-09-11 13:08:19 -0700139}
140
141//-----------------------------------------------------------------------
142// jemalloc static jet library
143//-----------------------------------------------------------------------
144cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700145 name: "libjemalloc_jet",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700146
Dan Willemsene67f1d52016-03-01 17:23:40 -0800147 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700148
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700149 cflags: [
150 "-DJEMALLOC_JET",
151 "-include android/include/libc_logging.h",
152 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700153
Dan Willemsen1bd78892015-09-11 13:08:19 -0700154 srcs: lib_src_files,
155
156}
157
158jemalloc_testlib_srcs = [
159 "test/src/btalloc.c",
160 "test/src/btalloc_0.c",
161 "test/src/btalloc_1.c",
162 "test/src/math.c",
163 "test/src/mq.c",
164 "test/src/mtx.c",
165 "test/src/SFMT.c",
166 "test/src/test.c",
167 "test/src/thd.c",
168 "test/src/timer.c",
169]
170
171//-----------------------------------------------------------------------
172// jemalloc unit test library
173//-----------------------------------------------------------------------
174cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700175 name: "libjemalloc_unittest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700176
Dan Willemsene67f1d52016-03-01 17:23:40 -0800177 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700178
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700179 cflags: [
180 "-DJEMALLOC_UNIT_TEST",
181 "-include android/include/libc_logging.h",
182 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700183
Dan Willemsene67f1d52016-03-01 17:23:40 -0800184 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700185 "test/src",
186 "test/include",
187 ],
188
189 srcs: jemalloc_testlib_srcs,
190
191 whole_static_libs: ["libjemalloc_jet"],
192
193}
194
195//-----------------------------------------------------------------------
196// jemalloc unit tests
197//-----------------------------------------------------------------------
198unit_tests = [
Christopher Ferris35452472016-06-14 14:28:47 -0700199 "test/unit/a0.c",
200 "test/unit/arena_reset.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700201 "test/unit/atomic.c",
202 "test/unit/bitmap.c",
203 "test/unit/ckh.c",
Dan Willemsenec006d82016-03-07 16:22:25 -0800204 "test/unit/decay.c",
Christopher Ferris35452472016-06-14 14:28:47 -0700205 "test/unit/fork.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 Willemsenec006d82016-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 Willemsenec006d82016-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 Willemsenec006d82016-03-07 16:22:25 -0800231 "test/unit/smoothstep.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700232 "test/unit/stats.c",
Dan Willemsenec006d82016-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",
Christopher Ferris35452472016-06-14 14:28:47 -0700236 "test/unit/witness.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700237 "test/unit/zero.c",
238]
239
Dan Willemsenf0f45852015-12-21 15:29:32 -0800240cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700241 name: "jemalloc_unittests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800242
243 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700244
Dan Willemsene67f1d52016-03-01 17:23:40 -0800245 product_variables: common_product_variables,
246
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700247 cflags: common_cflags + [
248 "-DJEMALLOC_UNIT_TEST",
249 "-include android/include/libc_logging.h",
250 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700251
252 local_include_dirs: common_c_local_includes + [
253 "test/src",
254 "test/include",
255 ],
256
257 srcs: unit_tests,
258
259 static_libs: ["libjemalloc_unittest"],
260
Dan Willemsene67f1d52016-03-01 17:23:40 -0800261 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700262
263 test_per_src: true,
264}
265
Dan Willemsen1bd78892015-09-11 13:08:19 -0700266//-----------------------------------------------------------------------
267// jemalloc integration test library
268//-----------------------------------------------------------------------
269cc_library_static {
Dan Willemsen1bd78892015-09-11 13:08:19 -0700270 name: "libjemalloc_integrationtest",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700271
Dan Willemsene67f1d52016-03-01 17:23:40 -0800272 defaults: ["jemalloc_defaults"],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700273
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700274 cflags: [
275 "-DJEMALLOC_INTEGRATION_TEST",
276 "-include android/include/libc_logging.h",
277 ],
Dan Willemsen1bd78892015-09-11 13:08:19 -0700278
Dan Willemsene67f1d52016-03-01 17:23:40 -0800279 local_include_dirs: [
Dan Willemsen1bd78892015-09-11 13:08:19 -0700280 "test/src",
281 "test/include",
282 ],
283
284 srcs: jemalloc_testlib_srcs + lib_src_files,
285
286}
287
288//-----------------------------------------------------------------------
289// jemalloc integration tests
290//-----------------------------------------------------------------------
291integration_tests = [
292 "test/integration/aligned_alloc.c",
293 "test/integration/allocated.c",
294 "test/integration/chunk.c",
Colin Cross6ab5f602015-12-29 16:56:53 -0800295 "test/integration/iterate.c",
Dan Willemsen1bd78892015-09-11 13:08:19 -0700296 "test/integration/MALLOCX_ARENA.c",
297 "test/integration/mallocx.c",
298 "test/integration/overflow.c",
299 "test/integration/posix_memalign.c",
300 "test/integration/rallocx.c",
301 "test/integration/sdallocx.c",
302 "test/integration/thread_arena.c",
303 "test/integration/thread_tcache_enabled.c",
304 "test/integration/xallocx.c",
305]
Colin Cross89d0f3c2015-09-17 15:34:16 -0700306
Dan Willemsenf0f45852015-12-21 15:29:32 -0800307cc_test {
Colin Cross89d0f3c2015-09-17 15:34:16 -0700308
309 name: "jemalloc_integrationtests",
Dan Willemsenf0f45852015-12-21 15:29:32 -0800310
311 gtest: false,
Colin Cross89d0f3c2015-09-17 15:34:16 -0700312
Dan Willemsene67f1d52016-03-01 17:23:40 -0800313 product_variables: common_product_variables,
314
Dan Willemsen2ee91d82016-05-25 15:06:55 -0700315 cflags: common_cflags + [
316 "-DJEMALLOC_INTEGRATION_TEST",
317 "-include android/include/libc_logging.h",
318 ],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700319
320 local_include_dirs: common_c_local_includes + [
321 "test/src",
322 "test/include",
323 ],
324
325 srcs: integration_tests,
326
327 static_libs: ["libjemalloc_integrationtest"],
328
Dan Willemsene67f1d52016-03-01 17:23:40 -0800329 shared_libs: ["liblog"],
Colin Cross89d0f3c2015-09-17 15:34:16 -0700330
331 test_per_src: true,
332}