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
17LOCAL_PATH := $(call my-dir)
18
19jemalloc_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_ALWAYS_PURGE
28#     If defined, always purge immediately when a page is purgeable.
29#   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.
43#   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.
47jemalloc_common_cflags += \
48	-DANDROID_ALWAYS_PURGE \
49	-DANDROID_MAX_ARENAS=2 \
50	-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8 \
51	-DANDROID_TCACHE_NSLOTS_LARGE=16 \
52	-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16 \
53
54# Only enable the tcache on non-svelte configurations, to save PSS.
55ifneq ($(MALLOC_SVELTE),true)
56jemalloc_common_cflags += \
57	-DJEMALLOC_TCACHE
58endif
59
60# Use a 512K chunk size on 32 bit systems.
61# This keeps the total amount of virtual address space consumed
62# by jemalloc lower.
63jemalloc_common_cflags_32 += \
64	-DANDROID_LG_CHUNK_DEFAULT=19 \
65
66# Use a 2MB chunk size on 64 bit systems.
67# This is the default currently used by 4.0.0.
68jemalloc_common_cflags_64 += \
69	-DANDROID_LG_CHUNK_DEFAULT=21 \
70
71jemalloc_common_c_includes := \
72	$(LOCAL_PATH)/src \
73	$(LOCAL_PATH)/include \
74
75jemalloc_lib_src_files := \
76	src/arena.c \
77	src/atomic.c \
78	src/base.c \
79	src/bitmap.c \
80	src/chunk.c \
81	src/chunk_dss.c \
82	src/chunk_mmap.c \
83	src/ckh.c \
84	src/ctl.c \
85	src/extent.c \
86	src/hash.c \
87	src/huge.c \
88	src/jemalloc.c \
89	src/mb.c \
90	src/mutex.c \
91	src/nstime.c \
92	src/pages.c \
93	src/prng.c \
94	src/prof.c \
95	src/quarantine.c \
96	src/rtree.c \
97	src/stats.c \
98	src/tcache.c \
99	src/ticker.c \
100	src/tsd.c \
101	src/util.c \
102
103#-----------------------------------------------------------------------
104# jemalloc static library
105#-----------------------------------------------------------------------
106include $(CLEAR_VARS)
107
108LOCAL_MODULE := libjemalloc
109LOCAL_MODULE_TAGS := optional
110
111LOCAL_ADDITIONAL_DEPENDENCIES := \
112	$(LOCAL_PATH)/Android.mk \
113
114LOCAL_CFLAGS := \
115	$(jemalloc_common_cflags) \
116	-include bionic/libc/private/libc_logging.h \
117
118LOCAL_CFLAGS_32 := $(jemalloc_common_cflags_32)
119LOCAL_CFLAGS_64 := $(jemalloc_common_cflags_64)
120
121LOCAL_C_INCLUDES := \
122	$(jemalloc_common_c_includes) \
123
124LOCAL_SRC_FILES := \
125	$(jemalloc_lib_src_files) \
126
127# This is linked into libc, which asan runtime library depends on.
128LOCAL_SANITIZE := never
129
130include $(BUILD_STATIC_LIBRARY)
131
132#-----------------------------------------------------------------------
133# jemalloc static jet library
134#-----------------------------------------------------------------------
135include $(CLEAR_VARS)
136
137LOCAL_MODULE := libjemalloc_jet
138LOCAL_MODULE_TAGS := optional
139
140LOCAL_ADDITIONAL_DEPENDENCIES := \
141	$(LOCAL_PATH)/Android.mk \
142
143LOCAL_CFLAGS := \
144	$(jemalloc_common_cflags) \
145	-DJEMALLOC_JET \
146	-include $(LOCAL_PATH)/android/include/libc_logging.h \
147
148LOCAL_CFLAGS_32 := $(jemalloc_common_cflags_32)
149LOCAL_CFLAGS_64 := $(jemalloc_common_cflags_64)
150
151LOCAL_C_INCLUDES := \
152	$(jemalloc_common_c_includes) \
153
154LOCAL_SRC_FILES := \
155	$(jemalloc_lib_src_files) \
156
157include $(BUILD_STATIC_LIBRARY)
158
159jemalloc_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# jemalloc unit test library
173#-----------------------------------------------------------------------
174include $(CLEAR_VARS)
175
176LOCAL_MODULE := libjemalloc_unittest
177LOCAL_MODULE_TAGS := optional
178
179LOCAL_ADDITIONAL_DEPENDENCIES := \
180	$(LOCAL_PATH)/Android.mk \
181
182LOCAL_CFLAGS := \
183	$(jemalloc_common_cflags) \
184	-DJEMALLOC_UNIT_TEST \
185	-include $(LOCAL_PATH)/android/include/libc_logging.h \
186
187LOCAL_CFLAGS_32 := $(jemalloc_common_cflags_32)
188LOCAL_CFLAGS_64 := $(jemalloc_common_cflags_64)
189
190LOCAL_C_INCLUDES := \
191	$(jemalloc_common_c_includes) \
192	$(LOCAL_PATH)/test/src \
193	$(LOCAL_PATH)/test/include \
194
195LOCAL_SRC_FILES := $(jemalloc_testlib_srcs)
196
197LOCAL_WHOLE_STATIC_LIBRARIES := libjemalloc_jet
198
199include $(BUILD_STATIC_LIBRARY)
200#include $(BUILD_SHARED_LIBRARY)
201
202#-----------------------------------------------------------------------
203# jemalloc unit tests
204#-----------------------------------------------------------------------
205jemalloc_unit_tests := \
206	test/unit/atomic.c \
207	test/unit/bitmap.c \
208	test/unit/ckh.c \
209	test/unit/decay.c \
210	test/unit/hash.c \
211	test/unit/junk.c \
212	test/unit/junk_alloc.c \
213	test/unit/junk_free.c \
214	test/unit/lg_chunk.c \
215	test/unit/mallctl.c \
216	test/unit/math.c \
217	test/unit/mq.c \
218	test/unit/mtx.c \
219	test/unit/nstime.c \
220	test/unit/prng.c \
221	test/unit/prof_accum.c \
222	test/unit/prof_active.c \
223	test/unit/prof_gdump.c \
224	test/unit/prof_idump.c \
225	test/unit/prof_reset.c \
226	test/unit/prof_thread_name.c \
227	test/unit/ql.c \
228	test/unit/qr.c \
229	test/unit/quarantine.c \
230	test/unit/rb.c \
231	test/unit/rtree.c \
232	test/unit/run_quantize.c \
233	test/unit/SFMT.c \
234	test/unit/size_classes.c \
235	test/unit/smoothstep.c \
236	test/unit/stats.c \
237	test/unit/ticker.c \
238	test/unit/tsd.c \
239	test/unit/util.c \
240	test/unit/zero.c \
241
242$(foreach test,$(jemalloc_unit_tests), \
243  $(eval test_name := $(basename $(notdir $(test)))); \
244  $(eval test_src := $(test)); \
245  $(eval test_cflags := -DJEMALLOC_UNIT_TEST); \
246  $(eval test_libs := libjemalloc_unittest); \
247  $(eval test_path := jemalloc_unittests); \
248  $(eval include $(LOCAL_PATH)/Android.test.mk) \
249)
250
251#-----------------------------------------------------------------------
252# jemalloc integration test library
253#-----------------------------------------------------------------------
254include $(CLEAR_VARS)
255
256LOCAL_MODULE := libjemalloc_integrationtest
257LOCAL_MODULE_TAGS := optional
258
259LOCAL_ADDITIONAL_DEPENDENCIES := \
260	$(LOCAL_PATH)/Android.mk \
261
262LOCAL_CFLAGS := \
263	$(jemalloc_common_cflags) \
264	-DJEMALLOC_INTEGRATION_TEST \
265	-include $(LOCAL_PATH)/android/include/libc_logging.h \
266
267LOCAL_CFLAGS_32 := $(jemalloc_common_cflags_32)
268LOCAL_CFLAGS_64 := $(jemalloc_common_cflags_64)
269
270LOCAL_C_INCLUDES := \
271	$(jemalloc_common_c_includes) \
272	$(LOCAL_PATH)/test/src \
273	$(LOCAL_PATH)/test/include \
274
275LOCAL_SRC_FILES := \
276	$(jemalloc_testlib_srcs) \
277	$(jemalloc_lib_src_files) \
278
279include $(BUILD_STATIC_LIBRARY)
280
281#-----------------------------------------------------------------------
282# jemalloc integration tests
283#-----------------------------------------------------------------------
284jemalloc_integration_tests := \
285	test/integration/aligned_alloc.c \
286	test/integration/allocated.c \
287	test/integration/chunk.c \
288	test/integration/iterate.c \
289	test/integration/MALLOCX_ARENA.c \
290	test/integration/mallocx.c \
291	test/integration/overflow.c \
292	test/integration/posix_memalign.c \
293	test/integration/rallocx.c \
294	test/integration/sdallocx.c \
295	test/integration/thread_arena.c \
296	test/integration/thread_tcache_enabled.c \
297	test/integration/xallocx.c \
298
299$(foreach test,$(jemalloc_integration_tests), \
300  $(eval test_name := $(basename $(notdir $(test)))); \
301  $(eval test_src := $(test)); \
302  $(eval test_cflags := -DJEMALLOC_INTEGRATION_TEST); \
303  $(eval test_libs := libjemalloc_integrationtest); \
304  $(eval test_path := jemalloc_integrationtests); \
305  $(eval include $(LOCAL_PATH)/Android.test.mk) \
306)
307