Home | History | Annotate | Download | only in jemalloc
      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 LOCAL_PATH := $(call my-dir)
     18 
     19 jemalloc_common_cflags := \
     20 	-std=gnu99 \
     21 	-D_REENTRANT \
     22 	-fvisibility=hidden \
     23 	-Wno-unused-parameter \
     24 	-Wno-type-limits \
     25 
     26 # These parameters change the way jemalloc works.
     27 #   ANDROID_MAX_ARENAS=XX
     28 #     The total number of arenas will be less than or equal to this number.
     29 #     The number of arenas will be calculated as 2 * the number of cpus
     30 #     but no larger than XX.
     31 #   ANDROID_TCACHE_NSLOTS_SMALL_MAX=XX
     32 #     The number of small slots held in the tcache. The higher this number
     33 #     is, the higher amount of PSS consumed. If this number is set too low
     34 #     then small allocations will take longer to complete.
     35 #   ANDROID_TCACHE_NSLOTS_LARGE=XX
     36 #     The number of large slots held in the tcache. The higher this number
     37 #     is, the higher amount of PSS consumed. If this number is set too low
     38 #     then large allocations will take longer to complete.
     39 #   ANDROID_LG_TCACHE_MAXCLASS_DEFAULT=XX
     40 #     1 << XX is the maximum sized allocation that will be in the tcache.
     41 #   ANDROID_LG_CHUNK_DEFAULT=XX
     42 #     1 << XX is the default chunk size used by the system. Decreasing this
     43 #     usually decreases the amount of PSS used, but can increase
     44 #     fragmentation.
     45 jemalloc_common_cflags += \
     46 	-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16 \
     47 
     48 ifeq ($(MALLOC_SVELTE),true)
     49 # Use a single arena on svelte devices to keep the PSS consumption as low
     50 # as possible.
     51 jemalloc_common_cflags += \
     52 	-DANDROID_MAX_ARENAS=1 \
     53 
     54 else
     55 # Only enable the tcache on non-svelte configurations, to save PSS.
     56 jemalloc_common_cflags += \
     57 	-DANDROID_MAX_ARENAS=2 \
     58 	-DJEMALLOC_TCACHE \
     59 	-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8 \
     60 	-DANDROID_TCACHE_NSLOTS_LARGE=16 \
     61 
     62 endif
     63 
     64 # Use a 512K chunk size on 32 bit systems.
     65 # This keeps the total amount of virtual address space consumed
     66 # by jemalloc lower.
     67 jemalloc_common_cflags_32 += \
     68 	-DANDROID_LG_CHUNK_DEFAULT=19 \
     69 
     70 # Use a 2MB chunk size on 64 bit systems.
     71 # This is the default currently used by 4.0.0.
     72 jemalloc_common_cflags_64 += \
     73 	-DANDROID_LG_CHUNK_DEFAULT=21 \
     74 
     75 jemalloc_common_c_includes := \
     76 	$(LOCAL_PATH)/src \
     77 	$(LOCAL_PATH)/include \
     78 
     79 jemalloc_lib_src_files := \
     80 	src/arena.c \
     81 	src/atomic.c \
     82 	src/base.c \
     83 	src/bitmap.c \
     84 	src/chunk.c \
     85 	src/chunk_dss.c \
     86 	src/chunk_mmap.c \
     87 	src/ckh.c \
     88 	src/ctl.c \
     89 	src/extent.c \
     90 	src/hash.c \
     91 	src/huge.c \
     92 	src/jemalloc.c \
     93 	src/mb.c \
     94 	src/mutex.c \
     95 	src/nstime.c \
     96 	src/pages.c \
     97 	src/prng.c \
     98 	src/prof.c \
     99 	src/quarantine.c \
    100 	src/rtree.c \
    101 	src/stats.c \
    102 	src/tcache.c \
    103 	src/ticker.c \
    104 	src/tsd.c \
    105 	src/util.c \
    106 
    107 #-----------------------------------------------------------------------
    108 # jemalloc static library
    109 #-----------------------------------------------------------------------
    110 include $(CLEAR_VARS)
    111 
    112 LOCAL_MODULE := libjemalloc
    113 LOCAL_MODULE_TAGS := optional
    114 
    115 LOCAL_ADDITIONAL_DEPENDENCIES := \
    116 	$(LOCAL_PATH)/Android.mk \
    117 
    118 LOCAL_CFLAGS := \
    119 	$(jemalloc_common_cflags) \
    120 	-include bionic/libc/private/libc_logging.h \
    121 
    122 LOCAL_CFLAGS_32 := $(jemalloc_common_cflags_32)
    123 LOCAL_CFLAGS_64 := $(jemalloc_common_cflags_64)
    124 
    125 LOCAL_C_INCLUDES := \
    126 	$(jemalloc_common_c_includes) \
    127 
    128 LOCAL_SRC_FILES := \
    129 	$(jemalloc_lib_src_files) \
    130 
    131 # This is linked into libc, which asan runtime library depends on.
    132 LOCAL_SANITIZE := never
    133 
    134 include $(BUILD_STATIC_LIBRARY)
    135 
    136 #-----------------------------------------------------------------------
    137 # jemalloc static jet library
    138 #-----------------------------------------------------------------------
    139 include $(CLEAR_VARS)
    140 
    141 LOCAL_MODULE := libjemalloc_jet
    142 LOCAL_MODULE_TAGS := optional
    143 
    144 LOCAL_ADDITIONAL_DEPENDENCIES := \
    145 	$(LOCAL_PATH)/Android.mk \
    146 
    147 LOCAL_CFLAGS := \
    148 	$(jemalloc_common_cflags) \
    149 	-DJEMALLOC_JET \
    150 	-include $(LOCAL_PATH)/android/include/libc_logging.h \
    151 
    152 LOCAL_CFLAGS_32 := $(jemalloc_common_cflags_32)
    153 LOCAL_CFLAGS_64 := $(jemalloc_common_cflags_64)
    154 
    155 LOCAL_C_INCLUDES := \
    156 	$(jemalloc_common_c_includes) \
    157 
    158 LOCAL_SRC_FILES := \
    159 	$(jemalloc_lib_src_files) \
    160 
    161 include $(BUILD_STATIC_LIBRARY)
    162 
    163 jemalloc_testlib_srcs := \
    164 	test/src/btalloc.c \
    165 	test/src/btalloc_0.c \
    166 	test/src/btalloc_1.c \
    167 	test/src/math.c \
    168 	test/src/mq.c \
    169 	test/src/mtx.c \
    170 	test/src/SFMT.c \
    171 	test/src/test.c \
    172 	test/src/thd.c \
    173 	test/src/timer.c \
    174 
    175 #-----------------------------------------------------------------------
    176 # jemalloc unit test library
    177 #-----------------------------------------------------------------------
    178 include $(CLEAR_VARS)
    179 
    180 LOCAL_MODULE := libjemalloc_unittest
    181 LOCAL_MODULE_TAGS := optional
    182 
    183 LOCAL_ADDITIONAL_DEPENDENCIES := \
    184 	$(LOCAL_PATH)/Android.mk \
    185 
    186 LOCAL_CFLAGS := \
    187 	$(jemalloc_common_cflags) \
    188 	-DJEMALLOC_UNIT_TEST \
    189 	-include $(LOCAL_PATH)/android/include/libc_logging.h \
    190 
    191 LOCAL_CFLAGS_32 := $(jemalloc_common_cflags_32)
    192 LOCAL_CFLAGS_64 := $(jemalloc_common_cflags_64)
    193 
    194 LOCAL_C_INCLUDES := \
    195 	$(jemalloc_common_c_includes) \
    196 	$(LOCAL_PATH)/test/src \
    197 	$(LOCAL_PATH)/test/include \
    198 
    199 LOCAL_SRC_FILES := $(jemalloc_testlib_srcs)
    200 
    201 LOCAL_WHOLE_STATIC_LIBRARIES := libjemalloc_jet
    202 
    203 include $(BUILD_STATIC_LIBRARY)
    204 #include $(BUILD_SHARED_LIBRARY)
    205 
    206 #-----------------------------------------------------------------------
    207 # jemalloc unit tests
    208 #-----------------------------------------------------------------------
    209 jemalloc_unit_tests := \
    210 	test/unit/atomic.c \
    211 	test/unit/bitmap.c \
    212 	test/unit/ckh.c \
    213 	test/unit/decay.c \
    214 	test/unit/hash.c \
    215 	test/unit/junk.c \
    216 	test/unit/junk_alloc.c \
    217 	test/unit/junk_free.c \
    218 	test/unit/lg_chunk.c \
    219 	test/unit/mallctl.c \
    220 	test/unit/math.c \
    221 	test/unit/mq.c \
    222 	test/unit/mtx.c \
    223 	test/unit/nstime.c \
    224 	test/unit/prng.c \
    225 	test/unit/prof_accum.c \
    226 	test/unit/prof_active.c \
    227 	test/unit/prof_gdump.c \
    228 	test/unit/prof_idump.c \
    229 	test/unit/prof_reset.c \
    230 	test/unit/prof_thread_name.c \
    231 	test/unit/ql.c \
    232 	test/unit/qr.c \
    233 	test/unit/quarantine.c \
    234 	test/unit/rb.c \
    235 	test/unit/rtree.c \
    236 	test/unit/run_quantize.c \
    237 	test/unit/SFMT.c \
    238 	test/unit/size_classes.c \
    239 	test/unit/smoothstep.c \
    240 	test/unit/stats.c \
    241 	test/unit/ticker.c \
    242 	test/unit/tsd.c \
    243 	test/unit/util.c \
    244 	test/unit/zero.c \
    245 
    246 $(foreach test,$(jemalloc_unit_tests), \
    247   $(eval test_name := $(basename $(notdir $(test)))); \
    248   $(eval test_src := $(test)); \
    249   $(eval test_cflags := -DJEMALLOC_UNIT_TEST); \
    250   $(eval test_libs := libjemalloc_unittest); \
    251   $(eval test_path := jemalloc_unittests); \
    252   $(eval include $(LOCAL_PATH)/Android.test.mk) \
    253 )
    254 
    255 #-----------------------------------------------------------------------
    256 # jemalloc integration test library
    257 #-----------------------------------------------------------------------
    258 include $(CLEAR_VARS)
    259 
    260 LOCAL_MODULE := libjemalloc_integrationtest
    261 LOCAL_MODULE_TAGS := optional
    262 
    263 LOCAL_ADDITIONAL_DEPENDENCIES := \
    264 	$(LOCAL_PATH)/Android.mk \
    265 
    266 LOCAL_CFLAGS := \
    267 	$(jemalloc_common_cflags) \
    268 	-DJEMALLOC_INTEGRATION_TEST \
    269 	-include $(LOCAL_PATH)/android/include/libc_logging.h \
    270 
    271 LOCAL_CFLAGS_32 := $(jemalloc_common_cflags_32)
    272 LOCAL_CFLAGS_64 := $(jemalloc_common_cflags_64)
    273 
    274 LOCAL_C_INCLUDES := \
    275 	$(jemalloc_common_c_includes) \
    276 	$(LOCAL_PATH)/test/src \
    277 	$(LOCAL_PATH)/test/include \
    278 
    279 LOCAL_SRC_FILES := \
    280 	$(jemalloc_testlib_srcs) \
    281 	$(jemalloc_lib_src_files) \
    282 
    283 include $(BUILD_STATIC_LIBRARY)
    284 
    285 #-----------------------------------------------------------------------
    286 # jemalloc integration tests
    287 #-----------------------------------------------------------------------
    288 jemalloc_integration_tests := \
    289 	test/integration/aligned_alloc.c \
    290 	test/integration/allocated.c \
    291 	test/integration/chunk.c \
    292 	test/integration/iterate.c \
    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 
    303 $(foreach test,$(jemalloc_integration_tests), \
    304   $(eval test_name := $(basename $(notdir $(test)))); \
    305   $(eval test_src := $(test)); \
    306   $(eval test_cflags := -DJEMALLOC_INTEGRATION_TEST); \
    307   $(eval test_libs := libjemalloc_integrationtest); \
    308   $(eval test_path := jemalloc_integrationtests); \
    309   $(eval include $(LOCAL_PATH)/Android.test.mk) \
    310 )
    311