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 common_cflags := \ 20 -std=gnu99 \ 21 -D_REENTRANT \ 22 -fvisibility=hidden \ 23 -Wno-unused-parameter \ 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 common_cflags += \ 43 -DANDROID_ALWAYS_PURGE \ 44 -DANDROID_MAX_ARENAS=2 \ 45 -DANDROID_TCACHE_NSLOTS_SMALL_MAX=8 \ 46 -DANDROID_TCACHE_NSLOTS_LARGE=16 \ 47 -DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16 \ 48 49 common_c_includes := \ 50 $(LOCAL_PATH)/src \ 51 $(LOCAL_PATH)/include \ 52 53 lib_src_files := \ 54 src/arena.c \ 55 src/atomic.c \ 56 src/base.c \ 57 src/bitmap.c \ 58 src/chunk.c \ 59 src/chunk_dss.c \ 60 src/chunk_mmap.c \ 61 src/ckh.c \ 62 src/ctl.c \ 63 src/extent.c \ 64 src/hash.c \ 65 src/huge.c \ 66 src/jemalloc.c \ 67 src/mb.c \ 68 src/mutex.c \ 69 src/prof.c \ 70 src/quarantine.c \ 71 src/rtree.c \ 72 src/stats.c \ 73 src/tcache.c \ 74 src/tsd.c \ 75 src/util.c \ 76 77 #----------------------------------------------------------------------- 78 # jemalloc static library 79 #----------------------------------------------------------------------- 80 include $(CLEAR_VARS) 81 82 LOCAL_MODULE := libjemalloc 83 LOCAL_MODULE_TAGS := optional 84 85 LOCAL_ADDITIONAL_DEPENDENCIES := \ 86 $(LOCAL_PATH)/Android.mk \ 87 88 LOCAL_CFLAGS := \ 89 $(common_cflags) \ 90 91 LOCAL_C_INCLUDES := \ 92 $(common_c_includes) \ 93 94 LOCAL_SRC_FILES := \ 95 $(lib_src_files) \ 96 android/src/je_mallinfo.c 97 98 include $(BUILD_STATIC_LIBRARY) 99 100 #----------------------------------------------------------------------- 101 # jemalloc static jet library 102 #----------------------------------------------------------------------- 103 include $(CLEAR_VARS) 104 105 LOCAL_MODULE := libjemalloc_jet 106 LOCAL_MODULE_TAGS := optional 107 108 LOCAL_ADDITIONAL_DEPENDENCIES := \ 109 $(LOCAL_PATH)/Android.mk \ 110 111 LOCAL_CFLAGS := \ 112 $(common_cflags) \ 113 -DJEMALLOC_JET \ 114 115 LOCAL_C_INCLUDES := \ 116 $(common_c_includes) \ 117 118 LOCAL_SRC_FILES := \ 119 $(lib_src_files) \ 120 121 include $(BUILD_STATIC_LIBRARY) 122 123 #----------------------------------------------------------------------- 124 # jemalloc unit test library 125 #----------------------------------------------------------------------- 126 include $(CLEAR_VARS) 127 128 LOCAL_MODULE := libjemalloc_unittest 129 LOCAL_MODULE_TAGS := optional 130 131 LOCAL_ADDITIONAL_DEPENDENCIES := \ 132 $(LOCAL_PATH)/Android.mk \ 133 134 LOCAL_CFLAGS := \ 135 $(common_cflags) \ 136 -DJEMALLOC_UNIT_TEST \ 137 138 LOCAL_C_INCLUDES := \ 139 $(common_c_includes) \ 140 $(LOCAL_PATH)/test/src \ 141 $(LOCAL_PATH)/test/include \ 142 143 LOCAL_SRC_FILES := \ 144 test/src/math.c \ 145 test/src/mtx.c \ 146 test/src/SFMT.c \ 147 test/src/test.c \ 148 test/src/thd.c \ 149 150 LOCAL_WHOLE_STATIC_LIBRARIES := libjemalloc_jet 151 152 include $(BUILD_STATIC_LIBRARY) 153 154 #----------------------------------------------------------------------- 155 # jemalloc unit tests 156 #----------------------------------------------------------------------- 157 unit_tests := \ 158 test/unit/bitmap.c \ 159 test/unit/ckh.c \ 160 test/unit/hash.c \ 161 test/unit/junk.c \ 162 test/unit/mallctl.c \ 163 test/unit/math.c \ 164 test/unit/mq.c \ 165 test/unit/mtx.c \ 166 test/unit/prof_accum.c \ 167 test/unit/prof_gdump.c \ 168 test/unit/prof_idump.c \ 169 test/unit/ql.c \ 170 test/unit/qr.c \ 171 test/unit/quarantine.c \ 172 test/unit/rb.c \ 173 test/unit/rtree.c \ 174 test/unit/SFMT.c \ 175 test/unit/stats.c \ 176 test/unit/tsd.c \ 177 test/unit/util.c \ 178 test/unit/zero.c \ 179 180 $(foreach test,$(unit_tests), \ 181 $(eval test_name := $(basename $(notdir $(test)))); \ 182 $(eval test_src := $(test)); \ 183 $(eval test_cflags := -DJEMALLOC_UNIT_TEST); \ 184 $(eval test_libs := libjemalloc_unittest); \ 185 $(eval test_path := jemalloc_unittests); \ 186 $(eval include $(LOCAL_PATH)/Android.test.mk) \ 187 ) 188 189 #----------------------------------------------------------------------- 190 # jemalloc integration test library 191 #----------------------------------------------------------------------- 192 include $(CLEAR_VARS) 193 194 LOCAL_MODULE := libjemalloc_integrationtest 195 LOCAL_MODULE_TAGS := optional 196 197 LOCAL_ADDITIONAL_DEPENDENCIES := \ 198 $(LOCAL_PATH)/Android.mk \ 199 200 LOCAL_CFLAGS := \ 201 $(common_cflags) \ 202 -DJEMALLOC_INTEGRATION_TEST \ 203 204 LOCAL_C_INCLUDES := \ 205 $(common_c_includes) \ 206 $(LOCAL_PATH)/test/src \ 207 $(LOCAL_PATH)/test/include \ 208 209 LOCAL_SRC_FILES := \ 210 test/src/math.c \ 211 test/src/mtx.c \ 212 test/src/SFMT.c \ 213 test/src/test.c \ 214 test/src/thd.c \ 215 216 LOCAL_WHOLE_STATIC_LIBRARIES := libjemalloc 217 218 include $(BUILD_STATIC_LIBRARY) 219 220 #----------------------------------------------------------------------- 221 # jemalloc integration tests 222 #----------------------------------------------------------------------- 223 integration_tests := \ 224 test/integration/aligned_alloc.c \ 225 test/integration/allocated.c \ 226 test/integration/chunk.c \ 227 test/integration/mallocx.c \ 228 test/integration/MALLOCX_ARENA.c \ 229 test/integration/posix_memalign.c \ 230 test/integration/rallocx.c \ 231 test/integration/thread_arena.c \ 232 test/integration/thread_tcache_enabled.c \ 233 test/integration/xallocx.c \ 234 235 $(foreach test,$(integration_tests), \ 236 $(eval test_name := $(basename $(notdir $(test)))); \ 237 $(eval test_src := $(test)); \ 238 $(eval test_cflags := -DJEMALLOC_INTEGRATION_TEST); \ 239 $(eval test_libs := libjemalloc_integrationtest); \ 240 $(eval test_path := jemalloc_integrationtests); \ 241 $(eval include $(LOCAL_PATH)/Android.test.mk) \ 242 ) 243