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
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.
42jemalloc_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
49jemalloc_common_c_includes := \
50	$(LOCAL_PATH)/src \
51	$(LOCAL_PATH)/include \
52
53jemalloc_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#-----------------------------------------------------------------------
80include $(CLEAR_VARS)
81
82# Temporarily disable clang build for this project:
83#   mips and arm64 do not compile with clang
84LOCAL_CLANG_arm64 := false
85LOCAL_CLANG_mips := false
86
87LOCAL_MODULE := libjemalloc
88LOCAL_MODULE_TAGS := optional
89
90LOCAL_ADDITIONAL_DEPENDENCIES := \
91	$(LOCAL_PATH)/Android.mk \
92
93LOCAL_CFLAGS := \
94	$(jemalloc_common_cflags) \
95	-include bionic/libc/private/libc_logging.h \
96
97LOCAL_C_INCLUDES := \
98	$(jemalloc_common_c_includes) \
99
100LOCAL_SRC_FILES := \
101	$(jemalloc_lib_src_files) \
102
103include $(BUILD_STATIC_LIBRARY)
104
105#-----------------------------------------------------------------------
106# jemalloc static jet library
107#-----------------------------------------------------------------------
108include $(CLEAR_VARS)
109
110LOCAL_CLANG_arm64 := false
111LOCAL_CLANG_mips := false
112
113LOCAL_MODULE := libjemalloc_jet
114LOCAL_MODULE_TAGS := optional
115
116LOCAL_ADDITIONAL_DEPENDENCIES := \
117	$(LOCAL_PATH)/Android.mk \
118
119LOCAL_CFLAGS := \
120	$(jemalloc_common_cflags) \
121	-DJEMALLOC_JET \
122	-include $(LOCAL_PATH)/android/include/libc_logging.h \
123
124LOCAL_C_INCLUDES := \
125	$(jemalloc_common_c_includes) \
126
127LOCAL_SRC_FILES := \
128	$(jemalloc_lib_src_files) \
129
130include $(BUILD_STATIC_LIBRARY)
131
132jemalloc_testlib_srcs := \
133	test/src/btalloc.c \
134	test/src/btalloc_0.c \
135	test/src/btalloc_1.c \
136	test/src/math.c \
137	test/src/mtx.c \
138	test/src/SFMT.c \
139	test/src/test.c \
140	test/src/thd.c \
141	test/src/timer.c \
142
143#-----------------------------------------------------------------------
144# jemalloc unit test library
145#-----------------------------------------------------------------------
146include $(CLEAR_VARS)
147
148LOCAL_CLANG_arm64 := false
149LOCAL_CLANG_mips := false
150
151LOCAL_MODULE := libjemalloc_unittest
152LOCAL_MODULE_TAGS := optional
153
154LOCAL_ADDITIONAL_DEPENDENCIES := \
155	$(LOCAL_PATH)/Android.mk \
156
157LOCAL_CFLAGS := \
158	$(jemalloc_common_cflags) \
159	-DJEMALLOC_UNIT_TEST \
160	-include $(LOCAL_PATH)/android/include/libc_logging.h \
161
162LOCAL_C_INCLUDES := \
163	$(jemalloc_common_c_includes) \
164	$(LOCAL_PATH)/test/src \
165	$(LOCAL_PATH)/test/include \
166
167LOCAL_SRC_FILES := $(jemalloc_testlib_srcs)
168
169LOCAL_WHOLE_STATIC_LIBRARIES := libjemalloc_jet
170
171include $(BUILD_STATIC_LIBRARY)
172
173#-----------------------------------------------------------------------
174# jemalloc unit tests
175#-----------------------------------------------------------------------
176jemalloc_unit_tests := \
177	test/unit/atomic.c \
178	test/unit/bitmap.c \
179	test/unit/ckh.c \
180	test/unit/hash.c \
181	test/unit/junk.c \
182	test/unit/junk_alloc.c \
183	test/unit/junk_free.c \
184	test/unit/lg_chunk.c \
185	test/unit/mallctl.c \
186	test/unit/math.c \
187	test/unit/mq.c \
188	test/unit/mtx.c \
189	test/unit/prof_accum.c \
190	test/unit/prof_gdump.c \
191	test/unit/prof_idump.c \
192	test/unit/prof_reset.c \
193	test/unit/prof_thread_name.c \
194	test/unit/ql.c \
195	test/unit/qr.c \
196	test/unit/quarantine.c \
197	test/unit/rb.c \
198	test/unit/rtree.c \
199	test/unit/SFMT.c \
200	test/unit/size_classes.c \
201	test/unit/stats.c \
202	test/unit/tsd.c \
203	test/unit/util.c \
204	test/unit/zero.c \
205
206$(foreach test,$(jemalloc_unit_tests), \
207  $(eval test_name := $(basename $(notdir $(test)))); \
208  $(eval test_src := $(test)); \
209  $(eval test_cflags := -DJEMALLOC_UNIT_TEST); \
210  $(eval test_libs := libjemalloc_unittest); \
211  $(eval test_path := jemalloc_unittests); \
212  $(eval include $(LOCAL_PATH)/Android.test.mk) \
213)
214
215#-----------------------------------------------------------------------
216# jemalloc integration test library
217#-----------------------------------------------------------------------
218include $(CLEAR_VARS)
219
220LOCAL_CLANG_arm64 := false
221LOCAL_CLANG_mips := false
222
223LOCAL_MODULE := libjemalloc_integrationtest
224LOCAL_MODULE_TAGS := optional
225
226LOCAL_ADDITIONAL_DEPENDENCIES := \
227	$(LOCAL_PATH)/Android.mk \
228
229LOCAL_CFLAGS := \
230	$(jemalloc_common_cflags) \
231	-DJEMALLOC_INTEGRATION_TEST \
232	-include $(LOCAL_PATH)/android/include/libc_logging.h \
233
234LOCAL_C_INCLUDES := \
235	$(jemalloc_common_c_includes) \
236	$(LOCAL_PATH)/test/src \
237	$(LOCAL_PATH)/test/include \
238
239LOCAL_SRC_FILES := \
240	$(jemalloc_testlib_srcs) \
241	$(jemalloc_lib_src_files) \
242
243include $(BUILD_STATIC_LIBRARY)
244
245#-----------------------------------------------------------------------
246# jemalloc integration tests
247#-----------------------------------------------------------------------
248jemalloc_integration_tests := \
249	test/integration/aligned_alloc.c \
250	test/integration/allocated.c \
251	test/integration/sdallocx.c \
252	test/integration/mallocx.c \
253	test/integration/MALLOCX_ARENA.c \
254	test/integration/posix_memalign.c \
255	test/integration/rallocx.c \
256	test/integration/thread_arena.c \
257	test/integration/thread_tcache_enabled.c \
258	test/integration/xallocx.c \
259	test/integration/chunk.c \
260
261$(foreach test,$(jemalloc_integration_tests), \
262  $(eval test_name := $(basename $(notdir $(test)))); \
263  $(eval test_src := $(test)); \
264  $(eval test_cflags := -DJEMALLOC_INTEGRATION_TEST); \
265  $(eval test_libs := libjemalloc_integrationtest); \
266  $(eval test_path := jemalloc_integrationtests); \
267  $(eval include $(LOCAL_PATH)/Android.test.mk) \
268)
269