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