blob: 184209f1bd9051d48bc789ffaf4fe91cf1346efc [file] [log] [blame]
Christopher Ferris5daf4e42014-04-22 18:52:58 -07001#
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
17LOCAL_PATH := $(call my-dir)
18
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +000019jemalloc_common_cflags := \
Alex Naidisf6089842016-11-19 21:03:14 +010020 -std=gnu11 \
Christopher Ferris5daf4e42014-04-22 18:52:58 -070021 -D_REENTRANT \
Alex Naidis98f468a2016-08-19 22:57:27 +020022 -O3 \
23 -funroll-loops \
Christopher Ferris5daf4e42014-04-22 18:52:58 -070024 -fvisibility=hidden \
25 -Wno-unused-parameter \
Colin Cross70274782015-12-29 16:56:11 -080026 -Wno-type-limits \
Christopher Ferris5daf4e42014-04-22 18:52:58 -070027
Christopher Ferrisd4810062014-11-14 12:09:46 -080028# These parameters change the way jemalloc works.
Christopher Ferrisd4810062014-11-14 12:09:46 -080029# ANDROID_MAX_ARENAS=XX
30# The total number of arenas will be less than or equal to this number.
31# The number of arenas will be calculated as 2 * the number of cpus
32# but no larger than XX.
33# ANDROID_TCACHE_NSLOTS_SMALL_MAX=XX
34# The number of small 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 small allocations will take longer to complete.
37# ANDROID_TCACHE_NSLOTS_LARGE=XX
38# The number of large slots held in the tcache. The higher this number
39# is, the higher amount of PSS consumed. If this number is set too low
40# then large allocations will take longer to complete.
41# ANDROID_LG_TCACHE_MAXCLASS_DEFAULT=XX
42# 1 << XX is the maximum sized allocation that will be in the tcache.
Christopher Ferris6f50cbc2015-09-09 12:17:01 -070043# ANDROID_LG_CHUNK_DEFAULT=XX
44# 1 << XX is the default chunk size used by the system. Decreasing this
45# usually decreases the amount of PSS used, but can increase
46# fragmentation.
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +000047jemalloc_common_cflags += \
Christopher Ferrisd4810062014-11-14 12:09:46 -080048 -DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16 \
49
Christopher Ferris08795322016-07-19 14:05:20 -070050ifeq ($(MALLOC_SVELTE),true)
51# Use a single arena on svelte devices to keep the PSS consumption as low
52# as possible.
Josh Gaoc43b70f2016-01-06 16:18:06 -080053jemalloc_common_cflags += \
Christopher Ferris08795322016-07-19 14:05:20 -070054 -DANDROID_MAX_ARENAS=1 \
55
56else
57# Only enable the tcache on non-svelte configurations, to save PSS.
58jemalloc_common_cflags += \
59 -DANDROID_MAX_ARENAS=2 \
60 -DJEMALLOC_TCACHE \
61 -DANDROID_TCACHE_NSLOTS_SMALL_MAX=8 \
62 -DANDROID_TCACHE_NSLOTS_LARGE=16 \
63
Josh Gaoc43b70f2016-01-06 16:18:06 -080064endif
65
Christopher Ferris6f50cbc2015-09-09 12:17:01 -070066# Use a 512K chunk size on 32 bit systems.
67# This keeps the total amount of virtual address space consumed
68# by jemalloc lower.
69jemalloc_common_cflags_32 += \
70 -DANDROID_LG_CHUNK_DEFAULT=19 \
71
72# Use a 2MB chunk size on 64 bit systems.
73# This is the default currently used by 4.0.0.
74jemalloc_common_cflags_64 += \
75 -DANDROID_LG_CHUNK_DEFAULT=21 \
76
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +000077jemalloc_common_c_includes := \
Christopher Ferris5daf4e42014-04-22 18:52:58 -070078 $(LOCAL_PATH)/src \
79 $(LOCAL_PATH)/include \
80
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +000081jemalloc_lib_src_files := \
Christopher Ferris5daf4e42014-04-22 18:52:58 -070082 src/arena.c \
83 src/atomic.c \
84 src/base.c \
85 src/bitmap.c \
86 src/chunk.c \
87 src/chunk_dss.c \
88 src/chunk_mmap.c \
89 src/ckh.c \
90 src/ctl.c \
91 src/extent.c \
92 src/hash.c \
93 src/huge.c \
94 src/jemalloc.c \
95 src/mb.c \
96 src/mutex.c \
Christopher Ferris54d4dfa2016-03-02 16:24:07 -080097 src/nstime.c \
Christopher Ferris6f50cbc2015-09-09 12:17:01 -070098 src/pages.c \
Christopher Ferris54d4dfa2016-03-02 16:24:07 -080099 src/prng.c \
Christopher Ferris5daf4e42014-04-22 18:52:58 -0700100 src/prof.c \
101 src/quarantine.c \
102 src/rtree.c \
103 src/stats.c \
104 src/tcache.c \
Christopher Ferris54d4dfa2016-03-02 16:24:07 -0800105 src/ticker.c \
Christopher Ferris5daf4e42014-04-22 18:52:58 -0700106 src/tsd.c \
107 src/util.c \
108
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700109#-----------------------------------------------------------------------
110# jemalloc static library
111#-----------------------------------------------------------------------
112include $(CLEAR_VARS)
113
114LOCAL_MODULE := libjemalloc
115LOCAL_MODULE_TAGS := optional
116
117LOCAL_ADDITIONAL_DEPENDENCIES := \
118 $(LOCAL_PATH)/Android.mk \
119
120LOCAL_CFLAGS := \
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000121 $(jemalloc_common_cflags) \
122 -include bionic/libc/private/libc_logging.h \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700123
Christopher Ferris6f50cbc2015-09-09 12:17:01 -0700124LOCAL_CFLAGS_32 := $(jemalloc_common_cflags_32)
125LOCAL_CFLAGS_64 := $(jemalloc_common_cflags_64)
126
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700127LOCAL_C_INCLUDES := \
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000128 $(jemalloc_common_c_includes) \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700129
130LOCAL_SRC_FILES := \
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000131 $(jemalloc_lib_src_files) \
Christopher Ferris18ff8412014-05-13 15:22:02 -0700132
Evgenii Stepanov53421a72015-06-11 15:16:33 -0700133# This is linked into libc, which asan runtime library depends on.
134LOCAL_SANITIZE := never
135
Colin Cross55a166e2016-04-07 13:28:20 -0700136LOCAL_CXX_STL := none
137
Christopher Ferris5daf4e42014-04-22 18:52:58 -0700138include $(BUILD_STATIC_LIBRARY)
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700139
140#-----------------------------------------------------------------------
141# jemalloc static jet library
142#-----------------------------------------------------------------------
143include $(CLEAR_VARS)
144
145LOCAL_MODULE := libjemalloc_jet
146LOCAL_MODULE_TAGS := optional
147
148LOCAL_ADDITIONAL_DEPENDENCIES := \
149 $(LOCAL_PATH)/Android.mk \
150
151LOCAL_CFLAGS := \
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000152 $(jemalloc_common_cflags) \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700153 -DJEMALLOC_JET \
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000154 -include $(LOCAL_PATH)/android/include/libc_logging.h \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700155
Christopher Ferris6f50cbc2015-09-09 12:17:01 -0700156LOCAL_CFLAGS_32 := $(jemalloc_common_cflags_32)
157LOCAL_CFLAGS_64 := $(jemalloc_common_cflags_64)
158
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700159LOCAL_C_INCLUDES := \
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000160 $(jemalloc_common_c_includes) \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700161
162LOCAL_SRC_FILES := \
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000163 $(jemalloc_lib_src_files) \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700164
Colin Cross55a166e2016-04-07 13:28:20 -0700165LOCAL_CXX_STL := none
166
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700167include $(BUILD_STATIC_LIBRARY)
168
Christopher Ferris96d58c82015-04-22 06:59:40 +0000169jemalloc_testlib_srcs := \
170 test/src/btalloc.c \
171 test/src/btalloc_0.c \
172 test/src/btalloc_1.c \
173 test/src/math.c \
Christopher Ferris6f50cbc2015-09-09 12:17:01 -0700174 test/src/mq.c \
Christopher Ferris96d58c82015-04-22 06:59:40 +0000175 test/src/mtx.c \
176 test/src/SFMT.c \
177 test/src/test.c \
178 test/src/thd.c \
179 test/src/timer.c \
180
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700181#-----------------------------------------------------------------------
182# jemalloc unit test library
183#-----------------------------------------------------------------------
184include $(CLEAR_VARS)
185
186LOCAL_MODULE := libjemalloc_unittest
187LOCAL_MODULE_TAGS := optional
188
189LOCAL_ADDITIONAL_DEPENDENCIES := \
190 $(LOCAL_PATH)/Android.mk \
191
192LOCAL_CFLAGS := \
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000193 $(jemalloc_common_cflags) \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700194 -DJEMALLOC_UNIT_TEST \
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000195 -include $(LOCAL_PATH)/android/include/libc_logging.h \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700196
Christopher Ferris6f50cbc2015-09-09 12:17:01 -0700197LOCAL_CFLAGS_32 := $(jemalloc_common_cflags_32)
198LOCAL_CFLAGS_64 := $(jemalloc_common_cflags_64)
199
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700200LOCAL_C_INCLUDES := \
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000201 $(jemalloc_common_c_includes) \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700202 $(LOCAL_PATH)/test/src \
203 $(LOCAL_PATH)/test/include \
204
Christopher Ferris96d58c82015-04-22 06:59:40 +0000205LOCAL_SRC_FILES := $(jemalloc_testlib_srcs)
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700206
207LOCAL_WHOLE_STATIC_LIBRARIES := libjemalloc_jet
208
Colin Cross55a166e2016-04-07 13:28:20 -0700209LOCAL_CXX_STL := none
210
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700211include $(BUILD_STATIC_LIBRARY)
Christopher Ferris6f50cbc2015-09-09 12:17:01 -0700212#include $(BUILD_SHARED_LIBRARY)
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700213
214#-----------------------------------------------------------------------
215# jemalloc unit tests
216#-----------------------------------------------------------------------
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000217jemalloc_unit_tests := \
Christopher Ferris9528f3c2014-12-04 19:39:53 -0800218 test/unit/atomic.c \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700219 test/unit/bitmap.c \
220 test/unit/ckh.c \
Christopher Ferris54d4dfa2016-03-02 16:24:07 -0800221 test/unit/decay.c \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700222 test/unit/hash.c \
223 test/unit/junk.c \
Christopher Ferris96d58c82015-04-22 06:59:40 +0000224 test/unit/junk_alloc.c \
225 test/unit/junk_free.c \
226 test/unit/lg_chunk.c \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700227 test/unit/mallctl.c \
228 test/unit/math.c \
229 test/unit/mq.c \
230 test/unit/mtx.c \
Christopher Ferris54d4dfa2016-03-02 16:24:07 -0800231 test/unit/nstime.c \
232 test/unit/prng.c \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700233 test/unit/prof_accum.c \
Christopher Ferris6f50cbc2015-09-09 12:17:01 -0700234 test/unit/prof_active.c \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700235 test/unit/prof_gdump.c \
236 test/unit/prof_idump.c \
Christopher Ferris96d58c82015-04-22 06:59:40 +0000237 test/unit/prof_reset.c \
238 test/unit/prof_thread_name.c \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700239 test/unit/ql.c \
240 test/unit/qr.c \
241 test/unit/quarantine.c \
242 test/unit/rb.c \
243 test/unit/rtree.c \
Christopher Ferris54d4dfa2016-03-02 16:24:07 -0800244 test/unit/run_quantize.c \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700245 test/unit/SFMT.c \
Christopher Ferris35d78ee2015-07-10 10:39:41 -0700246 test/unit/size_classes.c \
Christopher Ferris54d4dfa2016-03-02 16:24:07 -0800247 test/unit/smoothstep.c \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700248 test/unit/stats.c \
Christopher Ferris54d4dfa2016-03-02 16:24:07 -0800249 test/unit/ticker.c \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700250 test/unit/tsd.c \
251 test/unit/util.c \
252 test/unit/zero.c \
253
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000254$(foreach test,$(jemalloc_unit_tests), \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700255 $(eval test_name := $(basename $(notdir $(test)))); \
256 $(eval test_src := $(test)); \
Colin Cross3dd40012015-12-18 14:12:15 -0800257 $(eval test_cflags := -DJEMALLOC_UNIT_TEST); \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700258 $(eval test_libs := libjemalloc_unittest); \
259 $(eval test_path := jemalloc_unittests); \
260 $(eval include $(LOCAL_PATH)/Android.test.mk) \
261)
262
263#-----------------------------------------------------------------------
264# jemalloc integration test library
265#-----------------------------------------------------------------------
266include $(CLEAR_VARS)
267
268LOCAL_MODULE := libjemalloc_integrationtest
269LOCAL_MODULE_TAGS := optional
270
271LOCAL_ADDITIONAL_DEPENDENCIES := \
272 $(LOCAL_PATH)/Android.mk \
273
274LOCAL_CFLAGS := \
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000275 $(jemalloc_common_cflags) \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700276 -DJEMALLOC_INTEGRATION_TEST \
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000277 -include $(LOCAL_PATH)/android/include/libc_logging.h \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700278
Christopher Ferris6f50cbc2015-09-09 12:17:01 -0700279LOCAL_CFLAGS_32 := $(jemalloc_common_cflags_32)
280LOCAL_CFLAGS_64 := $(jemalloc_common_cflags_64)
281
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700282LOCAL_C_INCLUDES := \
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000283 $(jemalloc_common_c_includes) \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700284 $(LOCAL_PATH)/test/src \
285 $(LOCAL_PATH)/test/include \
286
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000287LOCAL_SRC_FILES := \
288 $(jemalloc_testlib_srcs) \
289 $(jemalloc_lib_src_files) \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700290
Colin Cross55a166e2016-04-07 13:28:20 -0700291LOCAL_CXX_STL := none
292
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700293include $(BUILD_STATIC_LIBRARY)
294
295#-----------------------------------------------------------------------
296# jemalloc integration tests
297#-----------------------------------------------------------------------
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000298jemalloc_integration_tests := \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700299 test/integration/aligned_alloc.c \
300 test/integration/allocated.c \
Christopher Ferris6f50cbc2015-09-09 12:17:01 -0700301 test/integration/chunk.c \
Colin Cross368f61e2015-12-29 16:56:53 -0800302 test/integration/iterate.c \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700303 test/integration/MALLOCX_ARENA.c \
Christopher Ferris6f50cbc2015-09-09 12:17:01 -0700304 test/integration/mallocx.c \
305 test/integration/overflow.c \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700306 test/integration/posix_memalign.c \
307 test/integration/rallocx.c \
Christopher Ferris6f50cbc2015-09-09 12:17:01 -0700308 test/integration/sdallocx.c \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700309 test/integration/thread_arena.c \
310 test/integration/thread_tcache_enabled.c \
311 test/integration/xallocx.c \
312
Christopher Ferrisfc0bd6b2015-06-25 17:51:54 +0000313$(foreach test,$(jemalloc_integration_tests), \
Christopher Ferrisc2ad06c2014-07-08 20:56:17 -0700314 $(eval test_name := $(basename $(notdir $(test)))); \
315 $(eval test_src := $(test)); \
316 $(eval test_cflags := -DJEMALLOC_INTEGRATION_TEST); \
317 $(eval test_libs := libjemalloc_integrationtest); \
318 $(eval test_path := jemalloc_integrationtests); \
319 $(eval include $(LOCAL_PATH)/Android.test.mk) \
320)