1// 2// Copyright (C) 2018 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 17package { 18 default_applicable_licenses: ["external_jemalloc_new_license"], 19} 20 21// Added automatically by a large-scale-change that took the approach of 22// 'apply every license found to every target'. While this makes sure we respect 23// every license restriction, it may not be entirely correct. 24// 25// e.g. GPL in an MIT project might only apply to the contrib/ directory. 26// 27// Please consider splitting the single license below into multiple licenses, 28// taking care not to lose any license_kind information, and overriding the 29// default license using the 'licenses: [...]' property on targets as needed. 30// 31// For unused files, consider creating a 'fileGroup' with "//visibility:private" 32// to attach the license to, and including a comment whether the files may be 33// used in the current project. 34// See: http://go/android-license-faq 35license { 36 name: "external_jemalloc_new_license", 37 visibility: [":__subpackages__"], 38 license_kinds: [ 39 "SPDX-license-identifier-Apache-2.0", 40 "SPDX-license-identifier-BSD", 41 "SPDX-license-identifier-ISC", 42 "SPDX-license-identifier-MIT", 43 "legacy_unencumbered", 44 ], 45 license_text: [ 46 "COPYING", 47 ], 48} 49 50common_cflags = [ 51 "-D_GNU_SOURCE", 52 "-D_REENTRANT", 53 "-Wall", 54 "-Wshorten-64-to-32", 55 "-Wsign-compare", 56 "-Wundef", 57 "-Wno-format-zero-length", 58 "-pipe", 59 "-g3", 60 "-fvisibility=hidden", 61 "-O3", 62 "-funroll-loops", 63 64 // The following flags are for avoiding errors when compiling. 65 "-Wno-unused-parameter", 66 "-Wno-unused-function", 67 "-Wno-missing-field-initializers", 68 69 "-U_FORTIFY_SOURCE", 70] 71 72common_c_local_includes = [ 73 "src", 74 "include", 75] 76 77// These parameters change the way jemalloc works. 78// ANDROID_NUM_ARENAS=XX 79// The total number of arenas to create. 80// ANDROID_TCACHE_NSLOTS_SMALL_MIN=XX 81// The minimum number of small slots held in the tcache. This must be 82// at least 1. 83// ANDROID_TCACHE_NSLOTS_SMALL_MAX=XX 84// The number of small slots held in the tcache. The higher this number 85// is, the higher amount of PSS consumed. If this number is set too low 86// then small allocations will take longer to complete. 87// ANDROID_TCACHE_NSLOTS_LARGE=XX 88// The number of large slots held in the tcache. The higher this number 89// is, the higher amount of PSS consumed. If this number is set too low 90// then large allocations will take longer to complete. 91// ANDROID_LG_TCACHE_MAXCLASS_DEFAULT=XX 92// 1 << XX is the maximum sized allocation that will be in the tcache. 93 94android_common_cflags = [ 95 // Default some parameters to small values to minimize PSS. 96 // These parameters will be overridden by android_product_variables 97 // for non-svelte configs. 98 "-DANDROID_NUM_ARENAS=1", 99 // This value cannot go below 2. 100 "-DANDROID_TCACHE_NSLOTS_SMALL_MAX=2", 101 "-DANDROID_TCACHE_NSLOTS_LARGE=1", 102] 103 104android_product_variables = { 105 // Only enable the tcache on non-svelte configurations, to save PSS. 106 malloc_not_svelte: { 107 cflags: [ 108 "-DANDROID_ENABLE_TCACHE", 109 "-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16", 110 111 "-UANDROID_NUM_ARENAS", 112 "-DANDROID_NUM_ARENAS=2", 113 114 "-UANDROID_TCACHE_NSLOTS_SMALL_MAX", 115 "-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8", 116 117 "-UANDROID_TCACHE_NSLOTS_LARGE", 118 "-DANDROID_TCACHE_NSLOTS_LARGE=16", 119 ], 120 }, 121} 122 123cc_defaults { 124 name: "jemalloc5_defaults", 125 host_supported: true, 126 native_bridge_supported: true, 127 cflags: common_cflags, 128 129 target: { 130 android: { 131 cflags: android_common_cflags, 132 product_variables: android_product_variables, 133 }, 134 linux_bionic: { 135 enabled: true, 136 }, 137 }, 138 139 local_include_dirs: common_c_local_includes, 140 stl: "none", 141} 142 143lib_src_files = [ 144 "src/jemalloc.c", 145 "src/arena.c", 146 "src/background_thread.c", 147 "src/base.c", 148 "src/bin.c", 149 "src/bitmap.c", 150 "src/ckh.c", 151 "src/ctl.c", 152 "src/div.c", 153 "src/extent.c", 154 "src/extent_dss.c", 155 "src/extent_mmap.c", 156 "src/hash.c", 157 "src/hooks.c", 158 "src/large.c", 159 "src/log.c", 160 "src/malloc_io.c", 161 "src/mutex.c", 162 "src/mutex_pool.c", 163 "src/nstime.c", 164 "src/pages.c", 165 "src/prng.c", 166 "src/prof.c", 167 "src/rtree.c", 168 "src/stats.c", 169 "src/sz.c", 170 "src/tcache.c", 171 "src/ticker.c", 172 "src/tsd.c", 173 "src/witness.c", 174] 175 176//----------------------------------------------------------------------- 177// jemalloc static library 178//----------------------------------------------------------------------- 179cc_library { 180 name: "libjemalloc5", 181 ramdisk_available: true, 182 vendor_ramdisk_available: true, 183 recovery_available: true, 184 185 defaults: ["jemalloc5_defaults"], 186 187 srcs: lib_src_files, 188 189 export_include_dirs: ["include"], 190 191 target: { 192 android: { 193 shared: { 194 enabled: false, 195 }, 196 system_shared_libs: [], 197 header_libs: ["libc_headers"], 198 }, 199 linux_bionic: { 200 system_shared_libs: [], 201 header_libs: ["libc_headers"], 202 }, 203 musl: { 204 // Linking against musl uses libjemalloc5 by default, list only 205 // libc_musl here to avoid a circular dependency. 206 system_shared_libs: ["libc_musl"], 207 }, 208 }, 209} 210 211//----------------------------------------------------------------------- 212// jemalloc static jet library 213//----------------------------------------------------------------------- 214cc_library_static { 215 name: "libjemalloc5_jet", 216 217 defaults: ["jemalloc5_defaults"], 218 219 cflags: [ 220 "-DJEMALLOC_JET", 221 ], 222 223 srcs: lib_src_files, 224} 225 226jemalloc5_testlib_srcs = [ 227 "test/src/btalloc.c", 228 "test/src/btalloc_0.c", 229 "test/src/btalloc_1.c", 230 "test/src/math.c", 231 "test/src/mtx.c", 232 "test/src/mq.c", 233 "test/src/SFMT.c", 234 "test/src/test.c", 235 "test/src/thd.c", 236 "test/src/timer.c", 237] 238 239//----------------------------------------------------------------------- 240// jemalloc unit test library 241//----------------------------------------------------------------------- 242cc_library_static { 243 name: "libjemalloc5_unittest", 244 245 defaults: ["jemalloc5_defaults"], 246 247 cflags: [ 248 "-DJEMALLOC_UNIT_TEST", 249 ], 250 251 local_include_dirs: [ 252 "test/include", 253 ], 254 255 srcs: jemalloc5_testlib_srcs, 256 257 whole_static_libs: ["libjemalloc5_jet"], 258} 259 260//----------------------------------------------------------------------- 261// jemalloc unit tests 262//----------------------------------------------------------------------- 263unit_tests = [ 264 "test/unit/a0.c", 265 "test/unit/arena_reset.c", 266 "test/unit/atomic.c", 267 "test/unit/background_thread.c", 268 "test/unit/background_thread_enable.c", 269 "test/unit/base.c", 270 "test/unit/bitmap.c", 271 "test/unit/ckh.c", 272 "test/unit/decay.c", 273 "test/unit/div.c", 274 "test/unit/emitter.c", 275 "test/unit/extent_quantize.c", 276 "test/unit/fork.c", 277 "test/unit/hash.c", 278 "test/unit/hooks.c", 279 "test/unit/junk.c", 280 "test/unit/junk_alloc.c", 281 "test/unit/junk_free.c", 282 "test/unit/log.c", 283 "test/unit/mallctl.c", 284 "test/unit/malloc_io.c", 285 "test/unit/math.c", 286 "test/unit/mq.c", 287 "test/unit/mtx.c", 288 "test/unit/pack.c", 289 "test/unit/pages.c", 290 "test/unit/ph.c", 291 "test/unit/prng.c", 292 "test/unit/prof_accum.c", 293 "test/unit/prof_active.c", 294 "test/unit/prof_gdump.c", 295 "test/unit/prof_idump.c", 296 "test/unit/prof_reset.c", 297 "test/unit/prof_tctx.c", 298 "test/unit/prof_thread_name.c", 299 "test/unit/ql.c", 300 "test/unit/qr.c", 301 "test/unit/rb.c", 302 "test/unit/retained.c", 303 "test/unit/rtree.c", 304 "test/unit/SFMT.c", 305 "test/unit/size_classes.c", 306 "test/unit/slab.c", 307 "test/unit/smoothstep.c", 308 "test/unit/spin.c", 309 "test/unit/stats.c", 310 "test/unit/stats_print.c", 311 "test/unit/ticker.c", 312 "test/unit/nstime.c", 313 "test/unit/tsd.c", 314 "test/unit/witness.c", 315 "test/unit/zero.c", 316] 317 318cc_test { 319 name: "jemalloc5_unittests", 320 321 defaults: ["jemalloc5_defaults"], 322 323 gtest: false, 324 325 cflags: common_cflags + [ 326 "-DJEMALLOC_UNIT_TEST", 327 ], 328 329 local_include_dirs: common_c_local_includes + [ 330 "test/include", 331 ], 332 333 srcs: unit_tests, 334 335 static_libs: ["libjemalloc5_unittest"], 336 337 test_per_src: true, 338 339 target: { 340 linux_bionic: { 341 enabled: true, 342 }, 343 linux_glibc: { 344 // The sanitizer does not work for these tests on the host. 345 sanitize: { 346 never: true, 347 }, 348 }, 349 }, 350} 351 352//----------------------------------------------------------------------- 353// jemalloc integration test library 354//----------------------------------------------------------------------- 355cc_library_static { 356 name: "libjemalloc5_integrationtest", 357 358 defaults: ["jemalloc5_defaults"], 359 360 cflags: [ 361 "-U_FORTIFY_SOURCE", 362 "-DJEMALLOC_INTEGRATION_TEST", 363 "-DJEMALLOC_NO_RENAME", 364 ], 365 366 local_include_dirs: [ 367 "test/include", 368 ], 369 370 srcs: jemalloc5_testlib_srcs + lib_src_files, 371} 372 373//----------------------------------------------------------------------- 374// jemalloc integration tests 375//----------------------------------------------------------------------- 376integration_tests = [ 377 "test/integration/aligned_alloc.c", 378 "test/integration/allocated.c", 379 "test/integration/extent.c", 380 "test/integration/mallocx.c", 381 "test/integration/MALLOCX_ARENA.c", 382 "test/integration/overflow.c", 383 "test/integration/posix_memalign.c", 384 "test/integration/rallocx.c", 385 "test/integration/sdallocx.c", 386 "test/integration/thread_arena.c", 387 "test/integration/xallocx.c", 388 "test/integration/cpp/basic.cpp", 389] 390 391cc_test { 392 name: "jemalloc5_integrationtests", 393 394 defaults: ["jemalloc5_defaults"], 395 396 gtest: false, 397 398 cflags: common_cflags + [ 399 "-DJEMALLOC_INTEGRATION_TEST", 400 "-DJEMALLOC_NO_RENAME", 401 ], 402 403 local_include_dirs: common_c_local_includes + [ 404 "test/include", 405 ], 406 407 srcs: integration_tests, 408 409 static_libs: ["libjemalloc5_integrationtest"], 410 411 test_per_src: true, 412 413 target: { 414 linux_glibc: { 415 // The sanitizer does not work for these tests on the host. 416 sanitize: { 417 never: true, 418 }, 419 }, 420 }, 421 422 // Needed for basic.cpp test. 423 stl: "libc++_static", 424} 425 426//----------------------------------------------------------------------- 427// jemalloc stress test library 428//----------------------------------------------------------------------- 429cc_library_static { 430 name: "libjemalloc5_stresstestlib", 431 432 defaults: ["jemalloc5_defaults"], 433 434 cflags: [ 435 "-DJEMALLOC_STRESS_TEST", 436 "-DJEMALLOC_STRESS_TESTLIB", 437 ], 438 439 local_include_dirs: [ 440 "test/include", 441 ], 442 443 srcs: jemalloc5_testlib_srcs, 444} 445 446//----------------------------------------------------------------------- 447// jemalloc stress tests 448//----------------------------------------------------------------------- 449// All tests are in the same order as in the original jemalloc Makefile 450// to make it easier to track changes. 451stress_tests = [ 452 "test/stress/microbench.c", 453] 454 455cc_test { 456 name: "jemalloc5_stresstests", 457 458 defaults: ["jemalloc5_defaults"], 459 460 gtest: false, 461 462 cflags: common_cflags + [ 463 "-DJEMALLOC_STRESS_TEST", 464 ], 465 466 local_include_dirs: common_c_local_includes + [ 467 "test/include", 468 ], 469 470 srcs: stress_tests, 471 472 static_libs: [ 473 "libjemalloc5", 474 "libjemalloc5_stresstestlib", 475 "libjemalloc5_jet", 476 ], 477 478 test_per_src: true, 479 480 target: { 481 linux_glibc: { 482 // The sanitizer does not work for these tests on the host. 483 sanitize: { 484 never: true, 485 }, 486 }, 487 }, 488} 489