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 "-std=gnu99", 19 "-D_REENTRANT", 20 "-fvisibility=hidden", 21 "-Wno-unused-parameter", 22 "-Wno-type-limits", 23] 24 25// These parameters change the way jemalloc works. 26// ANDROID_MAX_ARENAS=XX 27// The total number of arenas will be less than or equal to this number. 28// The number of arenas will be calculated as 2 * the number of cpus 29// but no larger than XX. 30// ANDROID_TCACHE_NSLOTS_SMALL_MAX=XX 31// The number of small slots held in the tcache. The higher this number 32// is, the higher amount of PSS consumed. If this number is set too low 33// then small allocations will take longer to complete. 34// ANDROID_TCACHE_NSLOTS_LARGE=XX 35// The number of large slots held in the tcache. The higher this number 36// is, the higher amount of PSS consumed. If this number is set too low 37// then large allocations will take longer to complete. 38// ANDROID_LG_TCACHE_MAXCLASS_DEFAULT=XX 39// 1 << XX is the maximum sized allocation that will be in the tcache. 40// ANDROID_LG_CHUNK_DEFAULT=XX 41// 1 << XX is the default chunk size used by the system. Decreasing this 42// usually decreases the amount of PSS used, but can increase 43// fragmentation. 44 45// Default to a single arena for svelte configurations to minimize 46// PSS consumed by jemalloc. 47common_cflags += [ 48 "-DANDROID_MAX_ARENAS=1", 49 "-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16", 50] 51 52common_c_local_includes = [ 53 "src", 54 "include", 55] 56 57common_product_variables = { 58 // Only enable the tcache on non-svelte configurations, to save PSS. 59 malloc_not_svelte: { 60 cflags: [ 61 "-UANDROID_MAX_ARENAS", 62 "-DANDROID_MAX_ARENAS=2", 63 "-DJEMALLOC_TCACHE", 64 "-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8", 65 "-DANDROID_TCACHE_NSLOTS_LARGE=16", 66 ], 67 }, 68} 69 70cc_defaults { 71 name: "jemalloc_defaults", 72 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, 95} 96 97lib_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", 113 "src/nstime.c", 114 "src/pages.c", 115 "src/prng.c", 116 "src/prof.c", 117 "src/quarantine.c", 118 "src/rtree.c", 119 "src/stats.c", 120 "src/tcache.c", 121 "src/ticker.c", 122 "src/tsd.c", 123 "src/util.c", 124] 125 126//----------------------------------------------------------------------- 127// jemalloc static library 128//----------------------------------------------------------------------- 129cc_library_static { 130 name: "libjemalloc", 131 132 defaults: ["jemalloc_defaults"], 133 134 include_files: ["bionic/libc/private/libc_logging.h"], 135 136 srcs: lib_src_files, 137 138 sanitize: ["never"], 139} 140 141//----------------------------------------------------------------------- 142// jemalloc static jet library 143//----------------------------------------------------------------------- 144cc_library_static { 145 name: "libjemalloc_jet", 146 147 defaults: ["jemalloc_defaults"], 148 149 cflags: ["-DJEMALLOC_JET"], 150 151 local_include_files: ["android/include/libc_logging.h"], 152 153 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 { 174 name: "libjemalloc_unittest", 175 176 defaults: ["jemalloc_defaults"], 177 178 cflags: ["-DJEMALLOC_UNIT_TEST"], 179 180 local_include_files: ["android/include/libc_logging.h"], 181 182 local_include_dirs: [ 183 "test/src", 184 "test/include", 185 ], 186 187 srcs: jemalloc_testlib_srcs, 188 189 whole_static_libs: ["libjemalloc_jet"], 190 191} 192 193//----------------------------------------------------------------------- 194// jemalloc unit tests 195//----------------------------------------------------------------------- 196unit_tests = [ 197 "test/unit/atomic.c", 198 "test/unit/bitmap.c", 199 "test/unit/ckh.c", 200 "test/unit/decay.c", 201 "test/unit/hash.c", 202 "test/unit/junk.c", 203 "test/unit/junk_alloc.c", 204 "test/unit/junk_free.c", 205 "test/unit/lg_chunk.c", 206 "test/unit/mallctl.c", 207 "test/unit/math.c", 208 "test/unit/mq.c", 209 "test/unit/mtx.c", 210 "test/unit/nstime.c", 211 "test/unit/prng.c", 212 "test/unit/prof_accum.c", 213 "test/unit/prof_active.c", 214 "test/unit/prof_gdump.c", 215 "test/unit/prof_idump.c", 216 "test/unit/prof_reset.c", 217 "test/unit/prof_thread_name.c", 218 "test/unit/ql.c", 219 "test/unit/qr.c", 220 "test/unit/quarantine.c", 221 "test/unit/rb.c", 222 "test/unit/rtree.c", 223 "test/unit/run_quantize.c", 224 "test/unit/SFMT.c", 225 "test/unit/size_classes.c", 226 "test/unit/smoothstep.c", 227 "test/unit/stats.c", 228 "test/unit/ticker.c", 229 "test/unit/tsd.c", 230 "test/unit/util.c", 231 "test/unit/zero.c", 232] 233 234cc_test { 235 name: "jemalloc_unittests", 236 237 gtest: false, 238 239 product_variables: common_product_variables, 240 241 cflags: common_cflags + ["-DJEMALLOC_UNIT_TEST"], 242 243 local_include_files: ["android/include/libc_logging.h"], 244 245 local_include_dirs: common_c_local_includes + [ 246 "test/src", 247 "test/include", 248 ], 249 250 srcs: unit_tests, 251 252 static_libs: ["libjemalloc_unittest"], 253 254 shared_libs: ["liblog"], 255 256 test_per_src: true, 257} 258 259//----------------------------------------------------------------------- 260// jemalloc integration test library 261//----------------------------------------------------------------------- 262cc_library_static { 263 name: "libjemalloc_integrationtest", 264 265 defaults: ["jemalloc_defaults"], 266 267 cflags: ["-DJEMALLOC_INTEGRATION_TEST"], 268 269 local_include_files: ["android/include/libc_logging.h"], 270 271 local_include_dirs: [ 272 "test/src", 273 "test/include", 274 ], 275 276 srcs: jemalloc_testlib_srcs + lib_src_files, 277 278} 279 280//----------------------------------------------------------------------- 281// jemalloc integration tests 282//----------------------------------------------------------------------- 283integration_tests = [ 284 "test/integration/aligned_alloc.c", 285 "test/integration/allocated.c", 286 "test/integration/chunk.c", 287 "test/integration/iterate.c", 288 "test/integration/MALLOCX_ARENA.c", 289 "test/integration/mallocx.c", 290 "test/integration/overflow.c", 291 "test/integration/posix_memalign.c", 292 "test/integration/rallocx.c", 293 "test/integration/sdallocx.c", 294 "test/integration/thread_arena.c", 295 "test/integration/thread_tcache_enabled.c", 296 "test/integration/xallocx.c", 297] 298 299cc_test { 300 301 name: "jemalloc_integrationtests", 302 303 gtest: false, 304 305 product_variables: common_product_variables, 306 307 cflags: common_cflags + ["-DJEMALLOC_INTEGRATION_TEST"], 308 309 local_include_files: ["android/include/libc_logging.h"], 310 311 local_include_dirs: common_c_local_includes + [ 312 "test/src", 313 "test/include", 314 ], 315 316 srcs: integration_tests, 317 318 static_libs: ["libjemalloc_integrationtest"], 319 320 shared_libs: ["liblog"], 321 322 test_per_src: true, 323} 324