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", |
Dan Willemsen | ba738bb | 2016-11-04 12:25:48 -0700 | [diff] [blame^] | 71 | defaults: ["linux_bionic_supported"], |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 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, |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | //----------------------------------------------------------------------- |
| 143 | // jemalloc static jet library |
| 144 | //----------------------------------------------------------------------- |
| 145 | cc_library_static { |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 146 | name: "libjemalloc_jet", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 147 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 148 | defaults: ["jemalloc_defaults"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 149 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 150 | cflags: [ |
| 151 | "-DJEMALLOC_JET", |
| 152 | "-include android/include/libc_logging.h", |
| 153 | ], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 154 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 155 | srcs: lib_src_files, |
| 156 | |
| 157 | } |
| 158 | |
| 159 | jemalloc_testlib_srcs = [ |
| 160 | "test/src/btalloc.c", |
| 161 | "test/src/btalloc_0.c", |
| 162 | "test/src/btalloc_1.c", |
| 163 | "test/src/math.c", |
| 164 | "test/src/mq.c", |
| 165 | "test/src/mtx.c", |
| 166 | "test/src/SFMT.c", |
| 167 | "test/src/test.c", |
| 168 | "test/src/thd.c", |
| 169 | "test/src/timer.c", |
| 170 | ] |
| 171 | |
| 172 | //----------------------------------------------------------------------- |
| 173 | // jemalloc unit test library |
| 174 | //----------------------------------------------------------------------- |
| 175 | cc_library_static { |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 176 | name: "libjemalloc_unittest", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 177 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 178 | defaults: ["jemalloc_defaults"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 179 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 180 | cflags: [ |
| 181 | "-DJEMALLOC_UNIT_TEST", |
| 182 | "-include android/include/libc_logging.h", |
| 183 | ], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 184 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 185 | local_include_dirs: [ |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 186 | "test/src", |
| 187 | "test/include", |
| 188 | ], |
| 189 | |
| 190 | srcs: jemalloc_testlib_srcs, |
| 191 | |
| 192 | whole_static_libs: ["libjemalloc_jet"], |
| 193 | |
| 194 | } |
| 195 | |
| 196 | //----------------------------------------------------------------------- |
| 197 | // jemalloc unit tests |
| 198 | //----------------------------------------------------------------------- |
| 199 | unit_tests = [ |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 200 | "test/unit/a0.c", |
| 201 | "test/unit/arena_reset.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 202 | "test/unit/atomic.c", |
| 203 | "test/unit/bitmap.c", |
| 204 | "test/unit/ckh.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 205 | "test/unit/decay.c", |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 206 | "test/unit/fork.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 207 | "test/unit/hash.c", |
| 208 | "test/unit/junk.c", |
| 209 | "test/unit/junk_alloc.c", |
| 210 | "test/unit/junk_free.c", |
| 211 | "test/unit/lg_chunk.c", |
| 212 | "test/unit/mallctl.c", |
| 213 | "test/unit/math.c", |
| 214 | "test/unit/mq.c", |
| 215 | "test/unit/mtx.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 216 | "test/unit/nstime.c", |
| 217 | "test/unit/prng.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 218 | "test/unit/prof_accum.c", |
| 219 | "test/unit/prof_active.c", |
| 220 | "test/unit/prof_gdump.c", |
| 221 | "test/unit/prof_idump.c", |
| 222 | "test/unit/prof_reset.c", |
| 223 | "test/unit/prof_thread_name.c", |
| 224 | "test/unit/ql.c", |
| 225 | "test/unit/qr.c", |
| 226 | "test/unit/quarantine.c", |
| 227 | "test/unit/rb.c", |
| 228 | "test/unit/rtree.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 229 | "test/unit/run_quantize.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 230 | "test/unit/SFMT.c", |
| 231 | "test/unit/size_classes.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 232 | "test/unit/smoothstep.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 233 | "test/unit/stats.c", |
Dan Willemsen | ec006d8 | 2016-03-07 16:22:25 -0800 | [diff] [blame] | 234 | "test/unit/ticker.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 235 | "test/unit/tsd.c", |
| 236 | "test/unit/util.c", |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 237 | "test/unit/witness.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 238 | "test/unit/zero.c", |
| 239 | ] |
| 240 | |
Dan Willemsen | f0f4585 | 2015-12-21 15:29:32 -0800 | [diff] [blame] | 241 | cc_test { |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 242 | name: "jemalloc_unittests", |
Dan Willemsen | f0f4585 | 2015-12-21 15:29:32 -0800 | [diff] [blame] | 243 | |
| 244 | gtest: false, |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 245 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 246 | product_variables: common_product_variables, |
| 247 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 248 | cflags: common_cflags + [ |
| 249 | "-DJEMALLOC_UNIT_TEST", |
| 250 | "-include android/include/libc_logging.h", |
| 251 | ], |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 252 | |
| 253 | local_include_dirs: common_c_local_includes + [ |
| 254 | "test/src", |
| 255 | "test/include", |
| 256 | ], |
| 257 | |
| 258 | srcs: unit_tests, |
| 259 | |
| 260 | static_libs: ["libjemalloc_unittest"], |
| 261 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 262 | shared_libs: ["liblog"], |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 263 | |
| 264 | test_per_src: true, |
| 265 | } |
| 266 | |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 267 | //----------------------------------------------------------------------- |
| 268 | // jemalloc integration test library |
| 269 | //----------------------------------------------------------------------- |
| 270 | cc_library_static { |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 271 | name: "libjemalloc_integrationtest", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 272 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 273 | defaults: ["jemalloc_defaults"], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 274 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 275 | cflags: [ |
| 276 | "-DJEMALLOC_INTEGRATION_TEST", |
| 277 | "-include android/include/libc_logging.h", |
| 278 | ], |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 279 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 280 | local_include_dirs: [ |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 281 | "test/src", |
| 282 | "test/include", |
| 283 | ], |
| 284 | |
| 285 | srcs: jemalloc_testlib_srcs + lib_src_files, |
| 286 | |
| 287 | } |
| 288 | |
| 289 | //----------------------------------------------------------------------- |
| 290 | // jemalloc integration tests |
| 291 | //----------------------------------------------------------------------- |
| 292 | integration_tests = [ |
| 293 | "test/integration/aligned_alloc.c", |
| 294 | "test/integration/allocated.c", |
| 295 | "test/integration/chunk.c", |
Colin Cross | 6ab5f60 | 2015-12-29 16:56:53 -0800 | [diff] [blame] | 296 | "test/integration/iterate.c", |
Dan Willemsen | 1bd7889 | 2015-09-11 13:08:19 -0700 | [diff] [blame] | 297 | "test/integration/MALLOCX_ARENA.c", |
| 298 | "test/integration/mallocx.c", |
| 299 | "test/integration/overflow.c", |
| 300 | "test/integration/posix_memalign.c", |
| 301 | "test/integration/rallocx.c", |
| 302 | "test/integration/sdallocx.c", |
| 303 | "test/integration/thread_arena.c", |
| 304 | "test/integration/thread_tcache_enabled.c", |
| 305 | "test/integration/xallocx.c", |
| 306 | ] |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 307 | |
Dan Willemsen | f0f4585 | 2015-12-21 15:29:32 -0800 | [diff] [blame] | 308 | cc_test { |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 309 | |
| 310 | name: "jemalloc_integrationtests", |
Dan Willemsen | f0f4585 | 2015-12-21 15:29:32 -0800 | [diff] [blame] | 311 | |
| 312 | gtest: false, |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 313 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 314 | product_variables: common_product_variables, |
| 315 | |
Dan Willemsen | 2ee91d8 | 2016-05-25 15:06:55 -0700 | [diff] [blame] | 316 | cflags: common_cflags + [ |
| 317 | "-DJEMALLOC_INTEGRATION_TEST", |
| 318 | "-include android/include/libc_logging.h", |
| 319 | ], |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 320 | |
| 321 | local_include_dirs: common_c_local_includes + [ |
| 322 | "test/src", |
| 323 | "test/include", |
| 324 | ], |
| 325 | |
| 326 | srcs: integration_tests, |
| 327 | |
| 328 | static_libs: ["libjemalloc_integrationtest"], |
| 329 | |
Dan Willemsen | e67f1d5 | 2016-03-01 17:23:40 -0800 | [diff] [blame] | 330 | shared_libs: ["liblog"], |
Colin Cross | 89d0f3c | 2015-09-17 15:34:16 -0700 | [diff] [blame] | 331 | |
| 332 | test_per_src: true, |
| 333 | } |