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 = [ |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 18 | "-D_REENTRANT", |
| 19 | "-fvisibility=hidden", |
| 20 | "-Wno-unused-parameter", |
Colin Cross | 7027478 | 2015-12-29 16:56:11 -0800 | [diff] [blame] | 21 | "-Wno-type-limits", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 22 | ] |
| 23 | |
| 24 | // These parameters change the way jemalloc works. |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 25 | // 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 Ferris | 53bf335 | 2016-07-19 14:05:20 -0700 | [diff] [blame] | 43 | |
| 44 | // Default to a single arena for svelte configurations to minimize |
| 45 | // PSS consumed by jemalloc. |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 46 | common_cflags += [ |
Christopher Ferris | 53bf335 | 2016-07-19 14:05:20 -0700 | [diff] [blame] | 47 | "-DANDROID_MAX_ARENAS=1", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 48 | "-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16", |
| 49 | ] |
| 50 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 51 | common_c_local_includes = [ |
| 52 | "src", |
| 53 | "include", |
| 54 | ] |
| 55 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 56 | common_product_variables = { |
| 57 | // Only enable the tcache on non-svelte configurations, to save PSS. |
| 58 | malloc_not_svelte: { |
Christopher Ferris | 53bf335 | 2016-07-19 14:05:20 -0700 | [diff] [blame] | 59 | 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 Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 66 | }, |
| 67 | } |
| 68 | |
| 69 | cc_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 Cross | 4daa75d | 2016-04-07 13:28:20 -0700 | [diff] [blame] | 94 | stl: "none", |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 97 | lib_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 Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 113 | "src/nstime.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 114 | "src/pages.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 115 | "src/prng.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 116 | "src/prof.c", |
| 117 | "src/quarantine.c", |
| 118 | "src/rtree.c", |
Christopher Ferris | fb1f094 | 2016-11-08 14:47:48 -0800 | [diff] [blame] | 119 | "src/spin.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 120 | "src/stats.c", |
| 121 | "src/tcache.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 122 | "src/ticker.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 123 | "src/tsd.c", |
| 124 | "src/util.c", |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 125 | "src/witness.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 126 | ] |
| 127 | |
| 128 | //----------------------------------------------------------------------- |
| 129 | // jemalloc static library |
| 130 | //----------------------------------------------------------------------- |
| 131 | cc_library_static { |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 132 | name: "libjemalloc", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 133 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 134 | defaults: ["jemalloc_defaults"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 135 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 136 | cflags: ["-include bionic/libc/private/libc_logging.h"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 137 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 138 | srcs: lib_src_files, |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | //----------------------------------------------------------------------- |
| 142 | // jemalloc static jet library |
| 143 | //----------------------------------------------------------------------- |
| 144 | cc_library_static { |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 145 | name: "libjemalloc_jet", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 146 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 147 | defaults: ["jemalloc_defaults"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 148 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 149 | cflags: [ |
| 150 | "-DJEMALLOC_JET", |
| 151 | "-include android/include/libc_logging.h", |
| 152 | ], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 153 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 154 | srcs: lib_src_files, |
| 155 | |
| 156 | } |
| 157 | |
| 158 | jemalloc_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 | //----------------------------------------------------------------------- |
| 174 | cc_library_static { |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 175 | name: "libjemalloc_unittest", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 176 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 177 | defaults: ["jemalloc_defaults"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 178 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 179 | cflags: [ |
| 180 | "-DJEMALLOC_UNIT_TEST", |
| 181 | "-include android/include/libc_logging.h", |
| 182 | ], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 183 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 184 | local_include_dirs: [ |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 185 | "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 | //----------------------------------------------------------------------- |
| 198 | unit_tests = [ |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 199 | "test/unit/a0.c", |
| 200 | "test/unit/arena_reset.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 201 | "test/unit/atomic.c", |
| 202 | "test/unit/bitmap.c", |
| 203 | "test/unit/ckh.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 204 | "test/unit/decay.c", |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 205 | "test/unit/fork.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 206 | "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 Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 215 | "test/unit/nstime.c", |
| 216 | "test/unit/prng.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 217 | "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 Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 228 | "test/unit/run_quantize.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 229 | "test/unit/SFMT.c", |
| 230 | "test/unit/size_classes.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 231 | "test/unit/smoothstep.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 232 | "test/unit/stats.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 233 | "test/unit/ticker.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 234 | "test/unit/tsd.c", |
| 235 | "test/unit/util.c", |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 236 | "test/unit/witness.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 237 | "test/unit/zero.c", |
| 238 | ] |
| 239 | |
Dan Willemsen | f0f4585 | 2015-12-21 15:29:32 -0800 | [diff] [blame] | 240 | cc_test { |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 241 | name: "jemalloc_unittests", |
Dan Willemsen | f0f4585 | 2015-12-21 15:29:32 -0800 | [diff] [blame] | 242 | |
| 243 | gtest: false, |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 244 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 245 | product_variables: common_product_variables, |
| 246 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 247 | cflags: common_cflags + [ |
| 248 | "-DJEMALLOC_UNIT_TEST", |
| 249 | "-include android/include/libc_logging.h", |
| 250 | ], |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 251 | |
| 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 Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 261 | shared_libs: ["liblog"], |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 262 | |
| 263 | test_per_src: true, |
| 264 | } |
| 265 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 266 | //----------------------------------------------------------------------- |
| 267 | // jemalloc integration test library |
| 268 | //----------------------------------------------------------------------- |
| 269 | cc_library_static { |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 270 | name: "libjemalloc_integrationtest", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 271 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 272 | defaults: ["jemalloc_defaults"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 273 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 274 | cflags: [ |
| 275 | "-DJEMALLOC_INTEGRATION_TEST", |
| 276 | "-include android/include/libc_logging.h", |
| 277 | ], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 278 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 279 | local_include_dirs: [ |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 280 | "test/src", |
| 281 | "test/include", |
| 282 | ], |
| 283 | |
| 284 | srcs: jemalloc_testlib_srcs + lib_src_files, |
| 285 | |
| 286 | } |
| 287 | |
| 288 | //----------------------------------------------------------------------- |
| 289 | // jemalloc integration tests |
| 290 | //----------------------------------------------------------------------- |
| 291 | integration_tests = [ |
| 292 | "test/integration/aligned_alloc.c", |
| 293 | "test/integration/allocated.c", |
| 294 | "test/integration/chunk.c", |
Colin Cross | 6ab5f60 | 2015-12-29 16:56:53 -0800 | [diff] [blame] | 295 | "test/integration/iterate.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 296 | "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 Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 306 | |
Dan Willemsen | f0f4585 | 2015-12-21 15:29:32 -0800 | [diff] [blame] | 307 | cc_test { |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 308 | |
| 309 | name: "jemalloc_integrationtests", |
Dan Willemsen | f0f4585 | 2015-12-21 15:29:32 -0800 | [diff] [blame] | 310 | |
| 311 | gtest: false, |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 312 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 313 | product_variables: common_product_variables, |
| 314 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 315 | cflags: common_cflags + [ |
| 316 | "-DJEMALLOC_INTEGRATION_TEST", |
| 317 | "-include android/include/libc_logging.h", |
| 318 | ], |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 319 | |
| 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 Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 329 | shared_libs: ["liblog"], |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 330 | |
| 331 | test_per_src: true, |
| 332 | } |