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 = [ |
Alex Naidis | 84ab79d | 2016-11-19 21:03:14 +0100 | [diff] [blame] | 18 | "-std=gnu11", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 19 | "-D_REENTRANT", |
Alex Naidis | 7cc4c46 | 2016-08-19 22:57:27 +0200 | [diff] [blame] | 20 | "-O3", |
| 21 | "-funroll-loops", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 22 | "-fvisibility=hidden", |
| 23 | "-Wno-unused-parameter", |
Colin Cross | 7027478 | 2015-12-29 16:56:11 -0800 | [diff] [blame] | 24 | "-Wno-type-limits", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 25 | ] |
| 26 | |
| 27 | // These parameters change the way jemalloc works. |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 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. |
Christopher Ferris | 0879532 | 2016-07-19 14:05:20 -0700 | [diff] [blame] | 46 | |
| 47 | // Default to a single arena for svelte configurations to minimize |
| 48 | // PSS consumed by jemalloc. |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 49 | common_cflags += [ |
Christopher Ferris | 0879532 | 2016-07-19 14:05:20 -0700 | [diff] [blame] | 50 | "-DANDROID_MAX_ARENAS=1", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 51 | "-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16", |
| 52 | ] |
| 53 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 54 | common_c_local_includes = [ |
| 55 | "src", |
| 56 | "include", |
| 57 | ] |
| 58 | |
Dan Willemsen | 41f26cb | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 59 | common_product_variables = { |
| 60 | // Only enable the tcache on non-svelte configurations, to save PSS. |
| 61 | malloc_not_svelte: { |
Christopher Ferris | 0879532 | 2016-07-19 14:05:20 -0700 | [diff] [blame] | 62 | cflags: [ |
| 63 | "-UANDROID_MAX_ARENAS", |
| 64 | "-DANDROID_MAX_ARENAS=2", |
| 65 | "-DJEMALLOC_TCACHE", |
| 66 | "-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8", |
| 67 | "-DANDROID_TCACHE_NSLOTS_LARGE=16", |
| 68 | ], |
Dan Willemsen | 41f26cb | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 69 | }, |
| 70 | } |
| 71 | |
| 72 | cc_defaults { |
| 73 | name: "jemalloc_defaults", |
| 74 | cflags: common_cflags, |
| 75 | |
| 76 | product_variables: common_product_variables, |
| 77 | |
| 78 | multilib: { |
| 79 | lib32: { |
| 80 | // Use a 512K chunk size on 32 bit systems. |
| 81 | // This keeps the total amount of virtual address space consumed |
| 82 | // by jemalloc lower. |
| 83 | cflags: [ |
| 84 | "-DANDROID_LG_CHUNK_DEFAULT=19", |
| 85 | ], |
| 86 | }, |
| 87 | lib64: { |
| 88 | // Use a 2MB chunk size on 64 bit systems. |
| 89 | // This is the default currently used by 4.0.0 |
| 90 | cflags: [ |
| 91 | "-DANDROID_LG_CHUNK_DEFAULT=21", |
| 92 | ], |
| 93 | }, |
| 94 | }, |
| 95 | |
| 96 | local_include_dirs: common_c_local_includes, |
Colin Cross | 517976f | 2016-04-07 13:28:20 -0700 | [diff] [blame] | 97 | stl: "none", |
Dan Willemsen | 41f26cb | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 100 | lib_src_files = [ |
| 101 | "src/arena.c", |
| 102 | "src/atomic.c", |
| 103 | "src/base.c", |
| 104 | "src/bitmap.c", |
| 105 | "src/chunk.c", |
| 106 | "src/chunk_dss.c", |
| 107 | "src/chunk_mmap.c", |
| 108 | "src/ckh.c", |
| 109 | "src/ctl.c", |
| 110 | "src/extent.c", |
| 111 | "src/hash.c", |
| 112 | "src/huge.c", |
| 113 | "src/jemalloc.c", |
| 114 | "src/mb.c", |
| 115 | "src/mutex.c", |
Dan Willemsen | 1d84ae7 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 116 | "src/nstime.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 117 | "src/pages.c", |
Dan Willemsen | 1d84ae7 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 118 | "src/prng.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 119 | "src/prof.c", |
| 120 | "src/quarantine.c", |
| 121 | "src/rtree.c", |
| 122 | "src/stats.c", |
| 123 | "src/tcache.c", |
Dan Willemsen | 1d84ae7 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 124 | "src/ticker.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 125 | "src/tsd.c", |
| 126 | "src/util.c", |
| 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 | 41f26cb | 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 | |
| 137 | include_files: ["bionic/libc/private/libc_logging.h"], |
| 138 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 139 | srcs: lib_src_files, |
| 140 | |
Colin Cross | 517976f | 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 | 41f26cb | 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 | 41f26cb | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 154 | cflags: ["-DJEMALLOC_JET"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 155 | |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 156 | local_include_files: ["android/include/libc_logging.h"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 157 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 158 | srcs: lib_src_files, |
| 159 | |
| 160 | } |
| 161 | |
| 162 | jemalloc_testlib_srcs = [ |
| 163 | "test/src/btalloc.c", |
| 164 | "test/src/btalloc_0.c", |
| 165 | "test/src/btalloc_1.c", |
| 166 | "test/src/math.c", |
| 167 | "test/src/mq.c", |
| 168 | "test/src/mtx.c", |
| 169 | "test/src/SFMT.c", |
| 170 | "test/src/test.c", |
| 171 | "test/src/thd.c", |
| 172 | "test/src/timer.c", |
| 173 | ] |
| 174 | |
| 175 | //----------------------------------------------------------------------- |
| 176 | // jemalloc unit test library |
| 177 | //----------------------------------------------------------------------- |
| 178 | cc_library_static { |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 179 | name: "libjemalloc_unittest", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 180 | |
Dan Willemsen | 41f26cb | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 181 | defaults: ["jemalloc_defaults"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 182 | |
Dan Willemsen | 41f26cb | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 183 | cflags: ["-DJEMALLOC_UNIT_TEST"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 184 | |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 185 | local_include_files: ["android/include/libc_logging.h"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 186 | |
Dan Willemsen | 41f26cb | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 187 | local_include_dirs: [ |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 188 | "test/src", |
| 189 | "test/include", |
| 190 | ], |
| 191 | |
| 192 | srcs: jemalloc_testlib_srcs, |
| 193 | |
| 194 | whole_static_libs: ["libjemalloc_jet"], |
| 195 | |
| 196 | } |
| 197 | |
| 198 | //----------------------------------------------------------------------- |
| 199 | // jemalloc unit tests |
| 200 | //----------------------------------------------------------------------- |
| 201 | unit_tests = [ |
| 202 | "test/unit/atomic.c", |
| 203 | "test/unit/bitmap.c", |
| 204 | "test/unit/ckh.c", |
Dan Willemsen | 1d84ae7 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 205 | "test/unit/decay.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 | 1d84ae7 | 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 | 1d84ae7 | 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 | 1d84ae7 | 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 | 1d84ae7 | 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", |
| 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 | 41f26cb | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 244 | product_variables: common_product_variables, |
| 245 | |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 246 | cflags: common_cflags + ["-DJEMALLOC_UNIT_TEST"], |
| 247 | |
| 248 | local_include_files: ["android/include/libc_logging.h"], |
| 249 | |
| 250 | local_include_dirs: common_c_local_includes + [ |
| 251 | "test/src", |
| 252 | "test/include", |
| 253 | ], |
| 254 | |
| 255 | srcs: unit_tests, |
| 256 | |
| 257 | static_libs: ["libjemalloc_unittest"], |
| 258 | |
Dan Willemsen | 41f26cb | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 259 | shared_libs: ["liblog"], |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 260 | |
| 261 | test_per_src: true, |
| 262 | } |
| 263 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 264 | //----------------------------------------------------------------------- |
| 265 | // jemalloc integration test library |
| 266 | //----------------------------------------------------------------------- |
| 267 | cc_library_static { |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 268 | name: "libjemalloc_integrationtest", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 269 | |
Dan Willemsen | 41f26cb | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 270 | defaults: ["jemalloc_defaults"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 271 | |
Dan Willemsen | 41f26cb | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 272 | cflags: ["-DJEMALLOC_INTEGRATION_TEST"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 273 | |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 274 | local_include_files: ["android/include/libc_logging.h"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 275 | |
Dan Willemsen | 41f26cb | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 276 | local_include_dirs: [ |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 277 | "test/src", |
| 278 | "test/include", |
| 279 | ], |
| 280 | |
| 281 | srcs: jemalloc_testlib_srcs + lib_src_files, |
| 282 | |
| 283 | } |
| 284 | |
| 285 | //----------------------------------------------------------------------- |
| 286 | // jemalloc integration tests |
| 287 | //----------------------------------------------------------------------- |
| 288 | integration_tests = [ |
| 289 | "test/integration/aligned_alloc.c", |
| 290 | "test/integration/allocated.c", |
| 291 | "test/integration/chunk.c", |
Colin Cross | 368f61e | 2015-12-29 16:56:53 -0800 | [diff] [blame] | 292 | "test/integration/iterate.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 293 | "test/integration/MALLOCX_ARENA.c", |
| 294 | "test/integration/mallocx.c", |
| 295 | "test/integration/overflow.c", |
| 296 | "test/integration/posix_memalign.c", |
| 297 | "test/integration/rallocx.c", |
| 298 | "test/integration/sdallocx.c", |
| 299 | "test/integration/thread_arena.c", |
| 300 | "test/integration/thread_tcache_enabled.c", |
| 301 | "test/integration/xallocx.c", |
| 302 | ] |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 303 | |
Dan Willemsen | f0f4585 | 2015-12-21 15:29:32 -0800 | [diff] [blame] | 304 | cc_test { |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 305 | |
| 306 | name: "jemalloc_integrationtests", |
Dan Willemsen | f0f4585 | 2015-12-21 15:29:32 -0800 | [diff] [blame] | 307 | |
| 308 | gtest: false, |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 309 | |
Dan Willemsen | 41f26cb | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 310 | product_variables: common_product_variables, |
| 311 | |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 312 | cflags: common_cflags + ["-DJEMALLOC_INTEGRATION_TEST"], |
| 313 | |
| 314 | local_include_files: ["android/include/libc_logging.h"], |
| 315 | |
| 316 | local_include_dirs: common_c_local_includes + [ |
| 317 | "test/src", |
| 318 | "test/include", |
| 319 | ], |
| 320 | |
| 321 | srcs: integration_tests, |
| 322 | |
| 323 | static_libs: ["libjemalloc_integrationtest"], |
| 324 | |
Dan Willemsen | 41f26cb | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 325 | shared_libs: ["liblog"], |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 326 | |
| 327 | test_per_src: true, |
| 328 | } |