Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 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 | |
| 17 | common_cflags = [ |
| 18 | "-std=gnu99", |
| 19 | "-D_REENTRANT", |
| 20 | "-fvisibility=hidden", |
| 21 | "-Wno-unused-parameter", |
Colin Cross | 7027478 | 2015-12-29 16:56:11 -0800 | [diff] [blame] | 22 | "-Wno-type-limits", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 23 | ] |
| 24 | |
| 25 | // These parameters change the way jemalloc works. |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 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. |
Christopher Ferris | 53bf335 | 2016-07-19 14:05:20 -0700 | [diff] [blame] | 44 | |
| 45 | // Default to a single arena for svelte configurations to minimize |
| 46 | // PSS consumed by jemalloc. |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 47 | common_cflags += [ |
Christopher Ferris | 53bf335 | 2016-07-19 14:05:20 -0700 | [diff] [blame] | 48 | "-DANDROID_MAX_ARENAS=1", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 49 | "-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16", |
| 50 | ] |
| 51 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 52 | common_c_local_includes = [ |
| 53 | "src", |
| 54 | "include", |
| 55 | ] |
| 56 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 57 | common_product_variables = { |
| 58 | // Only enable the tcache on non-svelte configurations, to save PSS. |
| 59 | malloc_not_svelte: { |
Christopher Ferris | 53bf335 | 2016-07-19 14:05:20 -0700 | [diff] [blame] | 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 | ], |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 67 | }, |
| 68 | } |
| 69 | |
| 70 | cc_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, |
Colin Cross | 4daa75d | 2016-04-07 13:28:20 -0700 | [diff] [blame] | 95 | stl: "none", |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 98 | lib_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 Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 114 | "src/nstime.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 115 | "src/pages.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 116 | "src/prng.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 117 | "src/prof.c", |
| 118 | "src/quarantine.c", |
| 119 | "src/rtree.c", |
Christopher Ferris | fb1f094 | 2016-11-08 14:47:48 -0800 | [diff] [blame^] | 120 | "src/spin.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 121 | "src/stats.c", |
| 122 | "src/tcache.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 123 | "src/ticker.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 124 | "src/tsd.c", |
| 125 | "src/util.c", |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 126 | "src/witness.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 127 | ] |
| 128 | |
| 129 | //----------------------------------------------------------------------- |
| 130 | // jemalloc static library |
| 131 | //----------------------------------------------------------------------- |
| 132 | cc_library_static { |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 133 | name: "libjemalloc", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 134 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 135 | defaults: ["jemalloc_defaults"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 136 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 137 | cflags: ["-include bionic/libc/private/libc_logging.h"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 138 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 139 | srcs: lib_src_files, |
| 140 | |
Colin Cross | 4daa75d | 2016-04-07 13:28:20 -0700 | [diff] [blame] | 141 | sanitize: { |
| 142 | never: true, |
| 143 | }, |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | //----------------------------------------------------------------------- |
| 147 | // jemalloc static jet library |
| 148 | //----------------------------------------------------------------------- |
| 149 | cc_library_static { |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 150 | name: "libjemalloc_jet", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 151 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 152 | defaults: ["jemalloc_defaults"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 153 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 154 | cflags: [ |
| 155 | "-DJEMALLOC_JET", |
| 156 | "-include android/include/libc_logging.h", |
| 157 | ], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 158 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 159 | srcs: lib_src_files, |
| 160 | |
| 161 | } |
| 162 | |
| 163 | jemalloc_testlib_srcs = [ |
| 164 | "test/src/btalloc.c", |
| 165 | "test/src/btalloc_0.c", |
| 166 | "test/src/btalloc_1.c", |
| 167 | "test/src/math.c", |
| 168 | "test/src/mq.c", |
| 169 | "test/src/mtx.c", |
| 170 | "test/src/SFMT.c", |
| 171 | "test/src/test.c", |
| 172 | "test/src/thd.c", |
| 173 | "test/src/timer.c", |
| 174 | ] |
| 175 | |
| 176 | //----------------------------------------------------------------------- |
| 177 | // jemalloc unit test library |
| 178 | //----------------------------------------------------------------------- |
| 179 | cc_library_static { |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 180 | name: "libjemalloc_unittest", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 181 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 182 | defaults: ["jemalloc_defaults"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 183 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 184 | cflags: [ |
| 185 | "-DJEMALLOC_UNIT_TEST", |
| 186 | "-include android/include/libc_logging.h", |
| 187 | ], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 188 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 189 | local_include_dirs: [ |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 190 | "test/src", |
| 191 | "test/include", |
| 192 | ], |
| 193 | |
| 194 | srcs: jemalloc_testlib_srcs, |
| 195 | |
| 196 | whole_static_libs: ["libjemalloc_jet"], |
| 197 | |
| 198 | } |
| 199 | |
| 200 | //----------------------------------------------------------------------- |
| 201 | // jemalloc unit tests |
| 202 | //----------------------------------------------------------------------- |
| 203 | unit_tests = [ |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 204 | "test/unit/a0.c", |
| 205 | "test/unit/arena_reset.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 206 | "test/unit/atomic.c", |
| 207 | "test/unit/bitmap.c", |
| 208 | "test/unit/ckh.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 209 | "test/unit/decay.c", |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 210 | "test/unit/fork.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 211 | "test/unit/hash.c", |
| 212 | "test/unit/junk.c", |
| 213 | "test/unit/junk_alloc.c", |
| 214 | "test/unit/junk_free.c", |
| 215 | "test/unit/lg_chunk.c", |
| 216 | "test/unit/mallctl.c", |
| 217 | "test/unit/math.c", |
| 218 | "test/unit/mq.c", |
| 219 | "test/unit/mtx.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 220 | "test/unit/nstime.c", |
| 221 | "test/unit/prng.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 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", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 233 | "test/unit/run_quantize.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 234 | "test/unit/SFMT.c", |
| 235 | "test/unit/size_classes.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 236 | "test/unit/smoothstep.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 237 | "test/unit/stats.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 238 | "test/unit/ticker.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 239 | "test/unit/tsd.c", |
| 240 | "test/unit/util.c", |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 241 | "test/unit/witness.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 242 | "test/unit/zero.c", |
| 243 | ] |
| 244 | |
Dan Willemsen | f0f4585 | 2015-12-21 15:29:32 -0800 | [diff] [blame] | 245 | cc_test { |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 246 | name: "jemalloc_unittests", |
Dan Willemsen | f0f4585 | 2015-12-21 15:29:32 -0800 | [diff] [blame] | 247 | |
| 248 | gtest: false, |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 249 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 250 | product_variables: common_product_variables, |
| 251 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 252 | cflags: common_cflags + [ |
| 253 | "-DJEMALLOC_UNIT_TEST", |
| 254 | "-include android/include/libc_logging.h", |
| 255 | ], |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 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 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 266 | shared_libs: ["liblog"], |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 267 | |
| 268 | test_per_src: true, |
| 269 | } |
| 270 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 271 | //----------------------------------------------------------------------- |
| 272 | // jemalloc integration test library |
| 273 | //----------------------------------------------------------------------- |
| 274 | cc_library_static { |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 275 | name: "libjemalloc_integrationtest", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 276 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 277 | defaults: ["jemalloc_defaults"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 278 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 279 | cflags: [ |
| 280 | "-DJEMALLOC_INTEGRATION_TEST", |
| 281 | "-include android/include/libc_logging.h", |
| 282 | ], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 283 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 284 | local_include_dirs: [ |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 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 | //----------------------------------------------------------------------- |
| 296 | integration_tests = [ |
| 297 | "test/integration/aligned_alloc.c", |
| 298 | "test/integration/allocated.c", |
| 299 | "test/integration/chunk.c", |
Colin Cross | 6ab5f60 | 2015-12-29 16:56:53 -0800 | [diff] [blame] | 300 | "test/integration/iterate.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 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 | ] |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 311 | |
Dan Willemsen | f0f4585 | 2015-12-21 15:29:32 -0800 | [diff] [blame] | 312 | cc_test { |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 313 | |
| 314 | name: "jemalloc_integrationtests", |
Dan Willemsen | f0f4585 | 2015-12-21 15:29:32 -0800 | [diff] [blame] | 315 | |
| 316 | gtest: false, |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 317 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 318 | product_variables: common_product_variables, |
| 319 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 320 | cflags: common_cflags + [ |
| 321 | "-DJEMALLOC_INTEGRATION_TEST", |
| 322 | "-include android/include/libc_logging.h", |
| 323 | ], |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 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 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 334 | shared_libs: ["liblog"], |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 335 | |
| 336 | test_per_src: true, |
| 337 | } |