• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//
2// Copyright (C) 2018 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_GNU_SOURCE",
19    "-D_REENTRANT",
20    "-Wall",
21    "-Wshorten-64-to-32",
22    "-Wsign-compare",
23    "-Wundef",
24    "-Wno-format-zero-length",
25    "-pipe",
26    "-g3",
27    "-fvisibility=hidden",
28    "-O3",
29    "-funroll-loops",
30
31    // The following flags are for avoiding errors when compiling.
32    "-Wno-unused-parameter",
33    "-Wno-unused-function",
34    "-Wno-missing-field-initializers",
35
36    "-U_FORTIFY_SOURCE",
37]
38
39common_c_local_includes = [
40    "src",
41    "include",
42]
43
44// These parameters change the way jemalloc works.
45//   ANDROID_NUM_ARENAS=XX
46//     The total number of arenas to create.
47//   ANDROID_TCACHE_NSLOTS_SMALL_MIN=XX
48//     The minimum number of small slots held in the tcache. This must be
49//     at least 1.
50//   ANDROID_TCACHE_NSLOTS_SMALL_MAX=XX
51//     The number of small slots held in the tcache. The higher this number
52//     is, the higher amount of PSS consumed. If this number is set too low
53//     then small allocations will take longer to complete.
54//   ANDROID_TCACHE_NSLOTS_LARGE=XX
55//     The number of large slots held in the tcache. The higher this number
56//     is, the higher amount of PSS consumed. If this number is set too low
57//     then large allocations will take longer to complete.
58//   ANDROID_LG_TCACHE_MAXCLASS_DEFAULT=XX
59//     1 << XX is the maximum sized allocation that will be in the tcache.
60
61android_common_cflags = [
62    // Default some parameters to small values to minimize PSS.
63    // These parameters will be overridden by android_product_variables
64    // for non-svelte configs.
65    "-DANDROID_NUM_ARENAS=1",
66    // This value cannot go below 2.
67    "-DANDROID_TCACHE_NSLOTS_SMALL_MAX=2",
68    "-DANDROID_TCACHE_NSLOTS_LARGE=1",
69]
70
71android_product_variables = {
72    // Only enable the tcache on non-svelte configurations, to save PSS.
73    malloc_not_svelte: {
74        cflags: [
75            "-DANDROID_ENABLE_TCACHE",
76            "-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16",
77
78            "-UANDROID_NUM_ARENAS",
79            "-DANDROID_NUM_ARENAS=2",
80
81            "-UANDROID_TCACHE_NSLOTS_SMALL_MAX",
82            "-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8",
83
84            "-UANDROID_TCACHE_NSLOTS_LARGE",
85            "-DANDROID_TCACHE_NSLOTS_LARGE=16",
86        ],
87    },
88}
89
90cc_defaults {
91    name: "jemalloc5_defaults",
92    defaults: ["linux_bionic_supported"],
93    host_supported: true,
94    cflags: common_cflags,
95
96    target: {
97        android: {
98            cflags: android_common_cflags,
99            product_variables: android_product_variables,
100        },
101        linux_glibc: {
102            enabled: true,
103        },
104    },
105
106    local_include_dirs: common_c_local_includes,
107    stl: "none",
108}
109
110lib_src_files = [
111    "src/jemalloc.c",
112    "src/arena.c",
113    "src/background_thread.c",
114    "src/base.c",
115    "src/bin.c",
116    "src/bitmap.c",
117    "src/ckh.c",
118    "src/ctl.c",
119    "src/div.c",
120    "src/extent.c",
121    "src/extent_dss.c",
122    "src/extent_mmap.c",
123    "src/hash.c",
124    "src/hooks.c",
125    "src/large.c",
126    "src/log.c",
127    "src/malloc_io.c",
128    "src/mutex.c",
129    "src/mutex_pool.c",
130    "src/nstime.c",
131    "src/pages.c",
132    "src/prng.c",
133    "src/prof.c",
134    "src/rtree.c",
135    "src/stats.c",
136    "src/sz.c",
137    "src/tcache.c",
138    "src/ticker.c",
139    "src/tsd.c",
140    "src/witness.c",
141]
142
143//-----------------------------------------------------------------------
144// jemalloc static library
145//-----------------------------------------------------------------------
146cc_library {
147    name: "libjemalloc5",
148    recovery_available: true,
149
150    defaults: ["jemalloc5_defaults"],
151
152    srcs: lib_src_files,
153
154    target: {
155        android: {
156            shared: {
157                enabled: false,
158            },
159            system_shared_libs: [],
160        },
161        linux_bionic: {
162            system_shared_libs: [],
163        },
164    },
165}
166
167//-----------------------------------------------------------------------
168// jemalloc static jet library
169//-----------------------------------------------------------------------
170cc_library_static {
171    name: "libjemalloc5_jet",
172
173    defaults: ["jemalloc5_defaults"],
174
175    cflags: [
176        "-DJEMALLOC_JET",
177    ],
178
179    srcs: lib_src_files,
180}
181
182jemalloc5_testlib_srcs = [
183    "test/src/btalloc.c",
184    "test/src/btalloc_0.c",
185    "test/src/btalloc_1.c",
186    "test/src/math.c",
187    "test/src/mtx.c",
188    "test/src/mq.c",
189    "test/src/SFMT.c",
190    "test/src/test.c",
191    "test/src/thd.c",
192    "test/src/timer.c",
193]
194
195//-----------------------------------------------------------------------
196// jemalloc unit test library
197//-----------------------------------------------------------------------
198cc_library_static {
199    name: "libjemalloc5_unittest",
200
201    defaults: ["jemalloc5_defaults"],
202
203    cflags: [
204        "-DJEMALLOC_UNIT_TEST",
205    ],
206
207    local_include_dirs: [
208        "test/include",
209    ],
210
211    srcs: jemalloc5_testlib_srcs,
212
213    whole_static_libs: ["libjemalloc5_jet"],
214}
215
216//-----------------------------------------------------------------------
217// jemalloc unit tests
218//-----------------------------------------------------------------------
219unit_tests = [
220    "test/unit/a0.c",
221    "test/unit/arena_reset.c",
222    "test/unit/atomic.c",
223    "test/unit/background_thread.c",
224    "test/unit/background_thread_enable.c",
225    "test/unit/base.c",
226    "test/unit/bitmap.c",
227    "test/unit/ckh.c",
228    "test/unit/decay.c",
229    "test/unit/div.c",
230    "test/unit/emitter.c",
231    "test/unit/extent_quantize.c",
232    "test/unit/fork.c",
233    "test/unit/hash.c",
234    "test/unit/hooks.c",
235    "test/unit/junk.c",
236    "test/unit/junk_alloc.c",
237    "test/unit/junk_free.c",
238    "test/unit/log.c",
239    "test/unit/mallctl.c",
240    "test/unit/malloc_io.c",
241    "test/unit/math.c",
242    "test/unit/mq.c",
243    "test/unit/mtx.c",
244    "test/unit/pack.c",
245    "test/unit/pages.c",
246    "test/unit/ph.c",
247    "test/unit/prng.c",
248    "test/unit/prof_accum.c",
249    "test/unit/prof_active.c",
250    "test/unit/prof_gdump.c",
251    "test/unit/prof_idump.c",
252    "test/unit/prof_reset.c",
253    "test/unit/prof_tctx.c",
254    "test/unit/prof_thread_name.c",
255    "test/unit/ql.c",
256    "test/unit/qr.c",
257    "test/unit/rb.c",
258    "test/unit/retained.c",
259    "test/unit/rtree.c",
260    "test/unit/SFMT.c",
261    "test/unit/size_classes.c",
262    "test/unit/slab.c",
263    "test/unit/smoothstep.c",
264    "test/unit/spin.c",
265    "test/unit/stats.c",
266    "test/unit/stats_print.c",
267    "test/unit/ticker.c",
268    "test/unit/nstime.c",
269    "test/unit/tsd.c",
270    "test/unit/witness.c",
271    "test/unit/zero.c",
272]
273
274cc_test {
275    name: "jemalloc5_unittests",
276
277    defaults: ["jemalloc5_defaults"],
278
279    gtest: false,
280
281    cflags: common_cflags + [
282        "-DJEMALLOC_UNIT_TEST",
283    ],
284
285    local_include_dirs: common_c_local_includes + [
286        "test/include",
287    ],
288
289    srcs: unit_tests,
290
291    static_libs: ["libjemalloc5_unittest"],
292
293    test_per_src: true,
294
295    target: {
296        linux_glibc: {
297            enabled: true,
298            // The sanitizer does not work for these tests on the host.
299            sanitize: {
300                never: true,
301            },
302        },
303    },
304}
305
306//-----------------------------------------------------------------------
307// jemalloc integration test library
308//-----------------------------------------------------------------------
309cc_library_static {
310    name: "libjemalloc5_integrationtest",
311
312    defaults: ["jemalloc5_defaults"],
313
314    cflags: [
315        "-U_FORTIFY_SOURCE",
316        "-DJEMALLOC_INTEGRATION_TEST",
317    ],
318
319    local_include_dirs: [
320        "test/include",
321    ],
322
323    srcs: jemalloc5_testlib_srcs + lib_src_files,
324}
325
326//-----------------------------------------------------------------------
327// jemalloc integration tests
328//-----------------------------------------------------------------------
329integration_tests = [
330    "test/integration/aligned_alloc.c",
331    "test/integration/allocated.c",
332    "test/integration/extent.c",
333    "test/integration/mallocx.c",
334    "test/integration/MALLOCX_ARENA.c",
335    "test/integration/overflow.c",
336    "test/integration/posix_memalign.c",
337    "test/integration/rallocx.c",
338    "test/integration/sdallocx.c",
339    "test/integration/thread_arena.c",
340    "test/integration/xallocx.c",
341    "test/integration/cpp/basic.cpp",
342]
343
344cc_test {
345    name: "jemalloc5_integrationtests",
346
347    defaults: ["jemalloc5_defaults"],
348
349    gtest: false,
350
351    cflags: common_cflags + [
352        "-DJEMALLOC_INTEGRATION_TEST",
353    ],
354
355    local_include_dirs: common_c_local_includes + [
356        "test/include",
357    ],
358
359    srcs: integration_tests,
360
361    static_libs: ["libjemalloc5_integrationtest"],
362
363    test_per_src: true,
364
365    target: {
366        linux_glibc: {
367            // The sanitizer does not work for these tests on the host.
368            sanitize: {
369                never: true,
370            },
371        },
372    },
373
374    // Needed for basic.cpp test.
375    stl: "libc++_static",
376}
377
378//-----------------------------------------------------------------------
379// jemalloc stress test library
380//-----------------------------------------------------------------------
381cc_library_static {
382    name: "libjemalloc5_stresstestlib",
383
384    defaults: ["jemalloc5_defaults"],
385
386    cflags: [
387        "-DJEMALLOC_STRESS_TEST",
388        "-DJEMALLOC_STRESS_TESTLIB",
389    ],
390
391    local_include_dirs: [
392        "test/include",
393    ],
394
395    srcs: jemalloc5_testlib_srcs,
396}
397
398//-----------------------------------------------------------------------
399// jemalloc stress tests
400//-----------------------------------------------------------------------
401// All tests are in the same order as in the original jemalloc Makefile
402// to make it easier to track changes.
403stress_tests = [
404    "test/stress/microbench.c",
405]
406
407cc_test {
408    name: "jemalloc5_stresstests",
409
410    defaults: ["jemalloc5_defaults"],
411
412    gtest: false,
413
414    cflags: common_cflags + [
415        "-DJEMALLOC_STRESS_TEST",
416    ],
417
418    local_include_dirs: common_c_local_includes + [
419        "test/include",
420    ],
421
422    srcs: stress_tests,
423
424    static_libs: [
425        "libjemalloc5",
426        "libjemalloc5_stresstestlib",
427        "libjemalloc5_jet",
428    ],
429
430    test_per_src: true,
431
432    target: {
433        linux_glibc: {
434            // The sanitizer does not work for these tests on the host.
435            sanitize: {
436                never: true,
437            },
438        },
439    },
440}
441