summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2014-02-25 06:00:10 (GMT)
committerJason Evans <jasone@canonware.com>2014-02-25 06:00:10 (GMT)
commitad47e8996e649ff8b4c920abb937bbacb8b9625e (patch)
tree840badf1ef94819531baa72422e3baa75491711c
parent99b0fbbe6975bf2af1387f75d961ad84fb108276 (diff)
downloadjemalloc-ad47e8996e649ff8b4c920abb937bbacb8b9625e.zip
jemalloc-ad47e8996e649ff8b4c920abb937bbacb8b9625e.tar.gz
jemalloc-ad47e8996e649ff8b4c920abb937bbacb8b9625e.tar.bz2
Break prof_accum into multiple compilation units.
Break prof_accum into multiple compilation units, in order to thwart compiler optimizations such as inlining and tail call optimization that would alter backtraces.
-rw-r--r--Makefile.in15
-rw-r--r--test/unit/prof_accum.c38
-rw-r--r--test/unit/prof_accum.h29
-rw-r--r--test/unit/prof_accum_a.c3
-rw-r--r--test/unit/prof_accum_b.c3
5 files changed, 48 insertions, 40 deletions
diff --git a/Makefile.in b/Makefile.in
index 67c4d5d..7399f27 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -128,6 +128,8 @@ TESTS_UNIT := $(srcroot)test/unit/bitmap.c \
$(srcroot)test/unit/tsd.c \
$(srcroot)test/unit/util.c \
$(srcroot)test/unit/zero.c
+TESTS_UNIT_AUX := $(srcroot)test/unit/prof_accum_a.c \
+ $(srcroot)test/unit/prof_accum_b.c
TESTS_INTEGRATION := $(srcroot)test/integration/aligned_alloc.c \
$(srcroot)test/integration/allocated.c \
$(srcroot)test/integration/mallocx.c \
@@ -155,9 +157,10 @@ C_TESTLIB_STRESS_OBJS := $(C_TESTLIB_SRCS:$(srcroot)%.c=$(objroot)%.stress.$(O))
C_TESTLIB_OBJS := $(C_TESTLIB_UNIT_OBJS) $(C_TESTLIB_INTEGRATION_OBJS) $(C_UTIL_INTEGRATION_OBJS) $(C_TESTLIB_STRESS_OBJS)
TESTS_UNIT_OBJS := $(TESTS_UNIT:$(srcroot)%.c=$(objroot)%.$(O))
+TESTS_UNIT_AUX_OBJS := $(TESTS_UNIT_AUX:$(srcroot)%.c=$(objroot)%.$(O))
TESTS_INTEGRATION_OBJS := $(TESTS_INTEGRATION:$(srcroot)%.c=$(objroot)%.$(O))
TESTS_STRESS_OBJS := $(TESTS_STRESS:$(srcroot)%.c=$(objroot)%.$(O))
-TESTS_OBJS := $(TESTS_UNIT_OBJS) $(TESTS_INTEGRATION_OBJS) $(TESTS_STRESS_OBJS)
+TESTS_OBJS := $(TESTS_UNIT_OBJS) $(TESTS_UNIT_AUX_OBJS) $(TESTS_INTEGRATION_OBJS) $(TESTS_STRESS_OBJS)
.PHONY: all dist build_doc_html build_doc_man build_doc
.PHONY: install_bin install_include install_lib
@@ -206,6 +209,12 @@ $(C_TESTLIB_STRESS_OBJS): $(objroot)test/src/%.stress.$(O): $(srcroot)test/src/%
$(C_TESTLIB_STRESS_OBJS): CPPFLAGS += -DJEMALLOC_STRESS_TEST -DJEMALLOC_STRESS_TESTLIB
$(C_TESTLIB_OBJS): CPPFLAGS += -I$(srcroot)test/include -I$(objroot)test/include
$(TESTS_UNIT_OBJS): CPPFLAGS += -DJEMALLOC_UNIT_TEST
+$(TESTS_UNIT_AUX_OBJS): CPPFLAGS += -DJEMALLOC_UNIT_TEST
+define make-unit-link-dep
+$(1): TESTS_UNIT_LINK_OBJS += $(2)
+$(1): $(2)
+endef
+$(foreach test, $(TESTS_UNIT:$(srcroot)test/unit/%.c=$(objroot)test/unit/%$(EXE)), $(eval $(call make-unit-link-dep,$(test),$(filter $(test:%=%_a.$(O)) $(test:%=%_b.$(O)),$(TESTS_UNIT_AUX_OBJS)))))
$(TESTS_INTEGRATION_OBJS): CPPFLAGS += -DJEMALLOC_INTEGRATION_TEST
$(TESTS_STRESS_OBJS): CPPFLAGS += -DJEMALLOC_STRESS_TEST
$(TESTS_OBJS): $(objroot)test/%.$(O): $(srcroot)test/%.c
@@ -248,7 +257,7 @@ $(STATIC_LIBS):
@mkdir -p $(@D)
$(AR) $(ARFLAGS)@AROUT@ $+
-$(objroot)test/unit/%$(EXE): $(objroot)test/unit/%.$(O) $(C_JET_OBJS) $(C_TESTLIB_UNIT_OBJS)
+$(objroot)test/unit/%$(EXE): $(objroot)test/unit/%.$(O) $(TESTS_UNIT_LINK_OBJS) $(C_JET_OBJS) $(C_TESTLIB_UNIT_OBJS)
@mkdir -p $(@D)
$(CC) $(LDTARGET) $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) $(LDFLAGS) $(filter-out -lm,$(LIBS)) -lm $(EXTRA_LDFLAGS)
@@ -359,7 +368,7 @@ coverage: check
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/src unit $(C_TESTLIB_UNIT_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/src integration $(C_TESTLIB_INTEGRATION_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/src stress $(C_TESTLIB_STRESS_OBJS)
- $(SHELL) $(srcroot)coverage.sh $(srcroot)test/unit unit $(TESTS_UNIT_OBJS)
+ $(SHELL) $(srcroot)coverage.sh $(srcroot)test/unit unit $(TESTS_UNIT_OBJS) $(TESTS_UNIT_AUX_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/integration integration $(TESTS_INTEGRATION_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/stress integration $(TESTS_STRESS_OBJS)
endif
diff --git a/test/unit/prof_accum.c b/test/unit/prof_accum.c
index 08be419..050a8a7 100644
--- a/test/unit/prof_accum.c
+++ b/test/unit/prof_accum.c
@@ -1,9 +1,4 @@
-#include "test/jemalloc_test.h"
-
-#define NTHREADS 4
-#define NALLOCS_PER_THREAD 50
-#define DUMP_INTERVAL 1
-#define BT_COUNT_CHECK_INTERVAL 5
+#include "prof_accum.h"
#ifdef JEMALLOC_PROF
const char *malloc_conf =
@@ -21,37 +16,6 @@ prof_dump_open_intercept(bool propagate_err, const char *filename)
return (fd);
}
-#define alloc_n_proto(n) \
-JEMALLOC_NOINLINE static void *alloc_##n(unsigned bits);
-
-#define alloc_n_gen(n) \
-JEMALLOC_NOINLINE static void * \
-alloc_##n(unsigned bits) \
-{ \
- void *p; \
- \
- if (bits == 0) \
- p = mallocx(1, 0); \
- else { \
- switch (bits & 0x1U) { \
- case 0: \
- p = alloc_0(bits >> 1); \
- break; \
- case 1: \
- p = alloc_1(bits >> 1); \
- break; \
- default: not_reached(); \
- } \
- } \
- /* Intentionally sabotage tail call optimization. */ \
- assert_ptr_not_null(p, "Unexpected mallocx() failure"); \
- return (p); \
-}
-alloc_n_proto(0)
-alloc_n_proto(1)
-alloc_n_gen(0)
-alloc_n_gen(1)
-
static void *
alloc_from_permuted_backtrace(unsigned thd_ind, unsigned iteration)
{
diff --git a/test/unit/prof_accum.h b/test/unit/prof_accum.h
new file mode 100644
index 0000000..de9cfea
--- /dev/null
+++ b/test/unit/prof_accum.h
@@ -0,0 +1,29 @@
+#include "test/jemalloc_test.h"
+
+#define NTHREADS 4
+#define NALLOCS_PER_THREAD 50
+#define DUMP_INTERVAL 1
+#define BT_COUNT_CHECK_INTERVAL 5
+
+#define alloc_n_proto(n) \
+void *alloc_##n(unsigned bits);
+alloc_n_proto(0)
+alloc_n_proto(1)
+
+#define alloc_n_gen(n) \
+void * \
+alloc_##n(unsigned bits) \
+{ \
+ \
+ if (bits == 0) { \
+ void *p = mallocx(1, 0); \
+ assert_ptr_not_null(p, "Unexpected mallocx() failure"); \
+ return (p); \
+ } else { \
+ switch (bits & 0x1U) { \
+ case 0: return (alloc_0(bits >> 1)); \
+ case 1: return (alloc_1(bits >> 1)); \
+ default: not_reached(); \
+ } \
+ } \
+}
diff --git a/test/unit/prof_accum_a.c b/test/unit/prof_accum_a.c
new file mode 100644
index 0000000..42ad521
--- /dev/null
+++ b/test/unit/prof_accum_a.c
@@ -0,0 +1,3 @@
+#include "prof_accum.h"
+
+alloc_n_gen(0)
diff --git a/test/unit/prof_accum_b.c b/test/unit/prof_accum_b.c
new file mode 100644
index 0000000..60d9dab
--- /dev/null
+++ b/test/unit/prof_accum_b.c
@@ -0,0 +1,3 @@
+#include "prof_accum.h"
+
+alloc_n_gen(1)