• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//
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    "-D_REENTRANT",
19    "-O3",
20    "-funroll-loops",
21    "-fvisibility=hidden",
22    "-Wno-unused-parameter",
23    "-Wno-type-limits",
24]
25
26// These parameters change the way jemalloc works.
27//   ANDROID_MAX_ARENAS=XX
28//     The total number of arenas will be less than or equal to this number.
29//     The number of arenas will be calculated as 2 * the number of cpus
30//     but no larger than XX.
31//   ANDROID_TCACHE_NSLOTS_SMALL_MAX=XX
32//     The number of small slots held in the tcache. The higher this number
33//     is, the higher amount of PSS consumed. If this number is set too low
34//     then small allocations will take longer to complete.
35//   ANDROID_TCACHE_NSLOTS_LARGE=XX
36//     The number of large slots held in the tcache. The higher this number
37//     is, the higher amount of PSS consumed. If this number is set too low
38//     then large allocations will take longer to complete.
39//   ANDROID_LG_TCACHE_MAXCLASS_DEFAULT=XX
40//     1 << XX is the maximum sized allocation that will be in the tcache.
41//   ANDROID_LG_CHUNK_DEFAULT=XX
42//     1 << XX is the default chunk size used by the system. Decreasing this
43//     usually decreases the amount of PSS used, but can increase
44//     fragmentation.
45
46// Default to a single arena for svelte configurations to minimize
47// PSS consumed by jemalloc.
48common_cflags += [
49    "-DANDROID_MAX_ARENAS=1",
50    "-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16",
51]
52
53common_c_local_includes = [
54    "src",
55    "include",
56]
57
58common_product_variables = {
59    // Only enable the tcache on non-svelte configurations, to save PSS.
60    malloc_not_svelte: {
61        cflags: [
62            "-UANDROID_MAX_ARENAS",
63            "-DANDROID_MAX_ARENAS=2",
64            "-DJEMALLOC_TCACHE",
65            "-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8",
66            "-DANDROID_TCACHE_NSLOTS_LARGE=16",
67        ],
68    },
69}
70
71cc_defaults {
72    name: "jemalloc_defaults",
73    defaults: ["linux_bionic_supported"],
74    cflags: common_cflags,
75
76    product_variables: common_product_variables,
77
78    multilib: {
79        lib32: {
80            // Use a 512K chunk size on 32 bit systems.
81            // This keeps the total amount of virtual address space consumed
82            // by jemalloc lower.
83            cflags: [
84                "-DANDROID_LG_CHUNK_DEFAULT=19",
85            ],
86        },
87        lib64: {
88            // Use a 2MB chunk size on 64 bit systems.
89            // This is the default currently used by 4.0.0
90            cflags: [
91                "-DANDROID_LG_CHUNK_DEFAULT=21",
92            ],
93        },
94    },
95
96    local_include_dirs: common_c_local_includes,
97    stl: "none",
98}
99
100lib_src_files = [
101    "src/arena.c",
102    "src/atomic.c",
103    "src/base.c",
104    "src/bitmap.c",
105    "src/chunk.c",
106    "src/chunk_dss.c",
107    "src/chunk_mmap.c",
108    "src/ckh.c",
109    "src/ctl.c",
110    "src/extent.c",
111    "src/hash.c",
112    "src/huge.c",
113    "src/jemalloc.c",
114    "src/mb.c",
115    "src/mutex.c",
116    "src/nstime.c",
117    "src/pages.c",
118    "src/prng.c",
119    "src/prof.c",
120    "src/quarantine.c",
121    "src/rtree.c",
122    "src/spin.c",
123    "src/stats.c",
124    "src/tcache.c",
125    "src/ticker.c",
126    "src/tsd.c",
127    "src/util.c",
128    "src/witness.c",
129]
130
131//-----------------------------------------------------------------------
132// jemalloc static library
133//-----------------------------------------------------------------------
134cc_library_static {
135    name: "libjemalloc",
136
137    defaults: ["jemalloc_defaults"],
138
139    cflags: ["-include bionic/libc/async_safe/include/async_safe/log.h"],
140
141    srcs: lib_src_files,
142}
143
144//-----------------------------------------------------------------------
145// jemalloc static jet library
146//-----------------------------------------------------------------------
147cc_library_static {
148    name: "libjemalloc_jet",
149
150    defaults: ["jemalloc_defaults"],
151
152    cflags: [
153        "-DJEMALLOC_JET",
154        "-include android/include/log.h",
155    ],
156
157    srcs: lib_src_files,
158
159}
160
161jemalloc_testlib_srcs = [
162    "test/src/btalloc.c",
163    "test/src/btalloc_0.c",
164    "test/src/btalloc_1.c",
165    "test/src/math.c",
166    "test/src/mq.c",
167    "test/src/mtx.c",
168    "test/src/SFMT.c",
169    "test/src/test.c",
170    "test/src/thd.c",
171    "test/src/timer.c",
172]
173
174//-----------------------------------------------------------------------
175// jemalloc unit test library
176//-----------------------------------------------------------------------
177cc_library_static {
178    name: "libjemalloc_unittest",
179
180    defaults: ["jemalloc_defaults"],
181
182    cflags: [
183        "-DJEMALLOC_UNIT_TEST",
184        "-include android/include/log.h",
185    ],
186
187    local_include_dirs: [
188        "test/src",
189        "test/include",
190    ],
191
192    srcs: jemalloc_testlib_srcs,
193
194    whole_static_libs: ["libjemalloc_jet"],
195
196}
197
198//-----------------------------------------------------------------------
199// jemalloc unit tests
200//-----------------------------------------------------------------------
201unit_tests = [
202    "test/unit/a0.c",
203    "test/unit/arena_reset.c",
204    "test/unit/atomic.c",
205    "test/unit/bitmap.c",
206    "test/unit/ckh.c",
207    "test/unit/decay.c",
208    "test/unit/fork.c",
209    "test/unit/hash.c",
210    "test/unit/junk.c",
211    "test/unit/junk_alloc.c",
212    "test/unit/junk_free.c",
213    "test/unit/lg_chunk.c",
214    "test/unit/mallctl.c",
215    "test/unit/math.c",
216    "test/unit/mq.c",
217    "test/unit/mtx.c",
218    "test/unit/nstime.c",
219    "test/unit/pack.c",
220    "test/unit/pages.c",
221    "test/unit/prng.c",
222    "test/unit/prof_accum.c",
223    "test/unit/prof_active.c",
224    "test/unit/prof_gdump.c",
225    "test/unit/prof_idump.c",
226    "test/unit/prof_reset.c",
227    "test/unit/prof_thread_name.c",
228    "test/unit/ql.c",
229    "test/unit/qr.c",
230    "test/unit/quarantine.c",
231    "test/unit/rb.c",
232    "test/unit/rtree.c",
233    "test/unit/run_quantize.c",
234    "test/unit/SFMT.c",
235    "test/unit/size_classes.c",
236    "test/unit/smoothstep.c",
237    "test/unit/stats.c",
238    "test/unit/ticker.c",
239    "test/unit/tsd.c",
240    "test/unit/util.c",
241    "test/unit/witness.c",
242    "test/unit/zero.c",
243]
244
245cc_test {
246    name: "jemalloc_unittests",
247
248    gtest: false,
249
250    product_variables: common_product_variables,
251
252    cflags: common_cflags + [
253        "-DJEMALLOC_UNIT_TEST",
254        "-include android/include/log.h",
255    ],
256
257    local_include_dirs: common_c_local_includes + [
258        "test/src",
259        "test/include",
260    ],
261
262    srcs: unit_tests,
263
264    static_libs: ["libjemalloc_unittest"],
265
266    shared_libs: ["liblog"],
267
268    test_per_src: true,
269}
270
271//-----------------------------------------------------------------------
272// jemalloc integration test library
273//-----------------------------------------------------------------------
274cc_library_static {
275    name: "libjemalloc_integrationtest",
276
277    defaults: ["jemalloc_defaults"],
278
279    cflags: [
280        "-DJEMALLOC_INTEGRATION_TEST",
281        "-include android/include/log.h",
282    ],
283
284    local_include_dirs: [
285        "test/src",
286        "test/include",
287    ],
288
289    srcs: jemalloc_testlib_srcs + lib_src_files,
290
291}
292
293//-----------------------------------------------------------------------
294// jemalloc integration tests
295//-----------------------------------------------------------------------
296integration_tests = [
297    "test/integration/aligned_alloc.c",
298    "test/integration/allocated.c",
299    "test/integration/chunk.c",
300    "test/integration/iterate.c",
301    "test/integration/MALLOCX_ARENA.c",
302    "test/integration/mallocx.c",
303    "test/integration/overflow.c",
304    "test/integration/posix_memalign.c",
305    "test/integration/rallocx.c",
306    "test/integration/sdallocx.c",
307    "test/integration/thread_arena.c",
308    "test/integration/thread_tcache_enabled.c",
309    "test/integration/xallocx.c",
310]
311
312cc_test {
313
314    name: "jemalloc_integrationtests",
315
316    gtest: false,
317
318    product_variables: common_product_variables,
319
320    cflags: common_cflags + [
321        "-DJEMALLOC_INTEGRATION_TEST",
322        "-include android/include/log.h",
323    ],
324
325    local_include_dirs: common_c_local_includes + [
326        "test/src",
327        "test/include",
328    ],
329
330    srcs: integration_tests,
331
332    static_libs: ["libjemalloc_integrationtest"],
333
334    shared_libs: ["liblog"],
335
336    test_per_src: true,
337}
338