From 9c8baec0a310f7bbd00c7dc76cfbf663dd9c14ce Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Wed, 22 Jan 2014 13:08:47 -0800 Subject: Fix a typo. --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c5e4198..5c2b1ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,7 +16,7 @@ found in the git revision history: API. The *allocx() functions are slightly simpler to use because they have fewer parameters, they directly return the results of primary interest, and mallocx()/rallocx() avoid the strict aliasing pitfall that - allocm()/rallocx() share with posix_memalign(). Note that *allocm() is + allocm()/rallocm() share with posix_memalign(). Note that *allocm() is slated for removal in the next non-bugfix release. - Add support for LinuxThreads. -- cgit v0.12 From 2b51a3e9e9bfebf081d25dfa92f3cd89e4a8ed73 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 28 Jan 2014 17:22:06 -0800 Subject: Fix mallctl argument size mismatches (size_t vs. uint64_t). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported by İsmail Dönmez. --- test/unit/stats.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/test/unit/stats.c b/test/unit/stats.c index 6cd9773..03a55c7 100644 --- a/test/unit/stats.c +++ b/test/unit/stats.c @@ -31,21 +31,25 @@ TEST_END TEST_BEGIN(test_stats_chunks) { - size_t current, total, high; - size_t sz = sizeof(size_t); + size_t current, high; + uint64_t total; + size_t sz; int expected = config_stats ? 0 : ENOENT; + sz = sizeof(size_t); assert_d_eq(mallctl("stats.chunks.current", ¤t, &sz, NULL, 0), expected, "Unexpected mallctl() result"); + sz = sizeof(uint64_t); assert_d_eq(mallctl("stats.chunks.total", &total, &sz, NULL, 0), expected, "Unexpected mallctl() result"); + sz = sizeof(size_t); assert_d_eq(mallctl("stats.chunks.high", &high, &sz, NULL, 0), expected, "Unexpected mallctl() result"); if (config_stats) { assert_zu_le(current, high, "current should be no larger than high"); - assert_zu_le(high, total, + assert_u64_le((uint64_t)high, total, "high should be no larger than total"); } } @@ -247,9 +251,9 @@ TEST_BEGIN(test_stats_arenas_bins) { unsigned arena; void *p; - size_t sz, allocated; + size_t sz, allocated, curruns; uint64_t epoch, nmalloc, ndalloc, nrequests, nfills, nflushes; - uint64_t nruns, nreruns, curruns; + uint64_t nruns, nreruns; int expected = config_stats ? 0 : ENOENT; arena = 0; @@ -287,6 +291,7 @@ TEST_BEGIN(test_stats_arenas_bins) NULL, 0), expected, "Unexpected mallctl() result"); assert_d_eq(mallctl("stats.arenas.0.bins.0.nreruns", &nreruns, &sz, NULL, 0), expected, "Unexpected mallctl() result"); + sz = sizeof(size_t); assert_d_eq(mallctl("stats.arenas.0.bins.0.curruns", &curruns, &sz, NULL, 0), expected, "Unexpected mallctl() result"); @@ -307,7 +312,7 @@ TEST_BEGIN(test_stats_arenas_bins) } assert_u64_gt(nruns, 0, "At least one run should have been allocated"); - assert_u64_gt(curruns, 0, + assert_zu_gt(curruns, 0, "At least one run should be currently allocated"); } @@ -319,8 +324,8 @@ TEST_BEGIN(test_stats_arenas_lruns) { unsigned arena; void *p; - uint64_t epoch, nmalloc, ndalloc, nrequests, curruns; - size_t sz = sizeof(uint64_t); + uint64_t epoch, nmalloc, ndalloc, nrequests; + size_t curruns, sz; int expected = config_stats ? 0 : ENOENT; arena = 0; @@ -333,12 +338,14 @@ TEST_BEGIN(test_stats_arenas_lruns) assert_d_eq(mallctl("epoch", NULL, NULL, &epoch, sizeof(epoch)), 0, "Unexpected mallctl() failure"); + sz = sizeof(uint64_t); assert_d_eq(mallctl("stats.arenas.0.lruns.0.nmalloc", &nmalloc, &sz, NULL, 0), expected, "Unexpected mallctl() result"); assert_d_eq(mallctl("stats.arenas.0.lruns.0.ndalloc", &ndalloc, &sz, NULL, 0), expected, "Unexpected mallctl() result"); assert_d_eq(mallctl("stats.arenas.0.lruns.0.nrequests", &nrequests, &sz, NULL, 0), expected, "Unexpected mallctl() result"); + sz = sizeof(size_t); assert_d_eq(mallctl("stats.arenas.0.lruns.0.curruns", &curruns, &sz, NULL, 0), expected, "Unexpected mallctl() result"); -- cgit v0.12 From a184d3fcdecfaaf694029fb375d023882aea444e Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 28 Jan 2014 18:02:07 -0800 Subject: Fix/remove flawed alignment-related overflow tests. Fix/remove three related flawed tests that attempted to cause OOM due to large request size and alignment constraint. Although these tests "passed" on 64-bit systems due to the virtual memory hole, they could pass on some 32-bit systems. --- test/integration/aligned_alloc.c | 4 ++-- test/integration/mallocx.c | 21 --------------------- test/integration/posix_memalign.c | 4 ++-- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/test/integration/aligned_alloc.c b/test/integration/aligned_alloc.c index 17c2151..6090014 100644 --- a/test/integration/aligned_alloc.c +++ b/test/integration/aligned_alloc.c @@ -47,10 +47,10 @@ TEST_BEGIN(test_oom_errors) #if LG_SIZEOF_PTR == 3 alignment = UINT64_C(0x4000000000000000); - size = UINT64_C(0x8400000000000001); + size = UINT64_C(0xc000000000000001); #else alignment = 0x40000000LU; - size = 0x84000001LU; + size = 0xc0000001LU; #endif set_errno(0); p = aligned_alloc(alignment, size); diff --git a/test/integration/mallocx.c b/test/integration/mallocx.c index c26f6c5..f37a74b 100644 --- a/test/integration/mallocx.c +++ b/test/integration/mallocx.c @@ -34,26 +34,6 @@ TEST_BEGIN(test_basic) } TEST_END -TEST_BEGIN(test_alignment_errors) -{ - void *p; - size_t nsz, sz, alignment; - -#if LG_SIZEOF_PTR == 3 - alignment = UINT64_C(0x4000000000000000); - sz = UINT64_C(0x8400000000000001); -#else - alignment = 0x40000000LU; - sz = 0x84000001LU; -#endif - nsz = nallocx(sz, MALLOCX_ALIGN(alignment)); - assert_zu_ne(nsz, 0, "Unexpected nallocx() error"); - p = mallocx(sz, MALLOCX_ALIGN(alignment)); - assert_ptr_null(p, "Expected error for mallocx(%zu, %#x)", sz, - MALLOCX_ALIGN(alignment)); -} -TEST_END - TEST_BEGIN(test_alignment_and_size) { size_t nsz, rsz, sz, alignment, total; @@ -114,6 +94,5 @@ main(void) return (test( test_basic, - test_alignment_errors, test_alignment_and_size)); } diff --git a/test/integration/posix_memalign.c b/test/integration/posix_memalign.c index c88a4dc..19741c6 100644 --- a/test/integration/posix_memalign.c +++ b/test/integration/posix_memalign.c @@ -43,10 +43,10 @@ TEST_BEGIN(test_oom_errors) #if LG_SIZEOF_PTR == 3 alignment = UINT64_C(0x4000000000000000); - size = UINT64_C(0x8400000000000001); + size = UINT64_C(0xc000000000000001); #else alignment = 0x40000000LU; - size = 0x84000001LU; + size = 0xc0000001LU; #endif assert_d_ne(posix_memalign(&p, alignment, size), 0, "Expected error for posix_memalign(&p, %zu, %zu)", -- cgit v0.12 From 5f60afa01eb2cf7d44024d162a1ecc6cceedcca1 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 28 Jan 2014 23:04:02 -0800 Subject: Avoid a compiler warning. Avoid copying "jeprof" to a 1-byte buffer within prof_boot0() when heap profiling is disabled. Although this is dead code under such conditions, the compiler doesn't figure that part out. Reported by Eduardo Silva. --- include/jemalloc/internal/prof.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/jemalloc/internal/prof.h b/include/jemalloc/internal/prof.h index db056fc..6f162d2 100644 --- a/include/jemalloc/internal/prof.h +++ b/include/jemalloc/internal/prof.h @@ -8,7 +8,11 @@ typedef struct prof_ctx_s prof_ctx_t; typedef struct prof_tdata_s prof_tdata_t; /* Option defaults. */ -#define PROF_PREFIX_DEFAULT "jeprof" +#ifdef JEMALLOC_PROF +# define PROF_PREFIX_DEFAULT "jeprof" +#else +# define PROF_PREFIX_DEFAULT "" +#endif #define LG_PROF_SAMPLE_DEFAULT 19 #define LG_PROF_INTERVAL_DEFAULT -1 -- cgit v0.12 From 2850e90d0d42d0e2b54864949bfa41c59c3a8dc9 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Wed, 29 Jan 2014 10:54:18 -0800 Subject: Remove flawed alignment-related overflow test. Remove the allocm() test equivalent to the mallocx() test removed in the previous commit. The flawed test attempted to cause OOM due to large request size and alignment constraint. Although this test "passed" on 64-bit systems due to the virtual memory hole, it could pass on some 32-bit systems. --- test/integration/allocm.c | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/test/integration/allocm.c b/test/integration/allocm.c index bd7a3ca..66ecf86 100644 --- a/test/integration/allocm.c +++ b/test/integration/allocm.c @@ -39,28 +39,6 @@ TEST_BEGIN(test_basic) } TEST_END -TEST_BEGIN(test_alignment_errors) -{ - void *p; - size_t nsz, rsz, sz, alignment; - -#if LG_SIZEOF_PTR == 3 - alignment = UINT64_C(0x4000000000000000); - sz = UINT64_C(0x8400000000000001); -#else - alignment = 0x40000000LU; - sz = 0x84000001LU; -#endif - nsz = 0; - assert_d_eq(nallocm(&nsz, sz, ALLOCM_ALIGN(alignment)), ALLOCM_SUCCESS, - "Unexpected nallocm() error"); - rsz = 0; - assert_d_ne(allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment)), - ALLOCM_SUCCESS, "Expected error for allocm(&p, %zu, %#x)", - sz, ALLOCM_ALIGN(alignment)); -} -TEST_END - TEST_BEGIN(test_alignment_and_size) { int r; @@ -126,6 +104,5 @@ main(void) return (test( test_basic, - test_alignment_errors, test_alignment_and_size)); } -- cgit v0.12 From 526e4a59a2fe39e4f8bdf1ec0c0d2a5a557c3f62 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Wed, 29 Jan 2014 10:56:51 -0800 Subject: Prevent inlining of backtraced test functions. Inlining of alloc_0() and alloc_1() would prevent generation of unique backtraces, upon which the test code relies. --- test/unit/prof_accum.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/prof_accum.c b/test/unit/prof_accum.c index cf3f287..08be419 100644 --- a/test/unit/prof_accum.c +++ b/test/unit/prof_accum.c @@ -22,10 +22,10 @@ prof_dump_open_intercept(bool propagate_err, const char *filename) } #define alloc_n_proto(n) \ -static void *alloc_##n(unsigned bits); +JEMALLOC_NOINLINE static void *alloc_##n(unsigned bits); #define alloc_n_gen(n) \ -static void * \ +JEMALLOC_NOINLINE static void * \ alloc_##n(unsigned bits) \ { \ void *p; \ -- cgit v0.12 From ddd6bd4e99e62feb3e377624b93e8cf88080fca4 Mon Sep 17 00:00:00 2001 From: George Kola Date: Wed, 12 Feb 2014 23:05:45 +0000 Subject: Using MADV_FREE on Solaris/Illumos --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 61fd868..a80c05d 100644 --- a/configure.ac +++ b/configure.ac @@ -296,6 +296,7 @@ case "${host}" in *-*-solaris2*) CFLAGS="$CFLAGS" abi="elf" + AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ]) RPATH='-Wl,-R,$(1)' dnl Solaris needs this for sigwait(). CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS" -- cgit v0.12 From 69e9fbb9c143e0d60670c68e29076a5c5c76ca3c Mon Sep 17 00:00:00 2001 From: Erwan Legrand Date: Fri, 14 Feb 2014 12:48:58 +0100 Subject: Fix typo --- src/arena.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/arena.c b/src/arena.c index 4da6d50..390ab0f 100644 --- a/src/arena.c +++ b/src/arena.c @@ -2476,7 +2476,6 @@ bin_info_run_size_calc(arena_bin_info_t *bin_info, size_t min_run_size) bin_info->reg_interval) - pad_size; } while (try_hdr_size > try_redzone0_offset); } while (try_run_size <= arena_maxclass - && try_run_size <= arena_maxclass && RUN_MAX_OVRHD * (bin_info->reg_interval << 3) > RUN_MAX_OVRHD_RELAX && (try_redzone0_offset << RUN_BFP) > RUN_MAX_OVRHD * try_run_size -- cgit v0.12 From 99b0fbbe6975bf2af1387f75d961ad84fb108276 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Mon, 24 Feb 2014 16:08:38 -0800 Subject: Add workaround for missing 'restrict' keyword. Add a cpp #define that removes 'restrict' keyword usage unless the compiler definitely supports C99. As written, 'restrict' is only enabled if the compiler supports the -std=gnu99 option (e.g. gcc and llvm). Reported by Tobias Hieta. --- configure.ac | 5 +++++ include/jemalloc/internal/jemalloc_internal_defs.h.in | 3 +++ include/jemalloc/internal/jemalloc_internal_macros.h | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/configure.ac b/configure.ac index a80c05d..938c019 100644 --- a/configure.ac +++ b/configure.ac @@ -19,7 +19,9 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM( ]], [[ return 0; ]])], + [je_cv_cflags_appended=$1] AC_MSG_RESULT([yes]), + [je_cv_cflags_appended=] AC_MSG_RESULT([no]) [CFLAGS="${TCFLAGS}"] ) @@ -128,6 +130,9 @@ if test "x$CFLAGS" = "x" ; then no_CFLAGS="yes" if test "x$GCC" = "xyes" ; then JE_CFLAGS_APPEND([-std=gnu99]) + if test "x$je_cv_cflags_appended" = "x-std=gnu99" ; then + AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT]) + fi JE_CFLAGS_APPEND([-Wall]) JE_CFLAGS_APPEND([-pipe]) JE_CFLAGS_APPEND([-g3]) diff --git a/include/jemalloc/internal/jemalloc_internal_defs.h.in b/include/jemalloc/internal/jemalloc_internal_defs.h.in index 752bb10..e3758e4 100644 --- a/include/jemalloc/internal/jemalloc_internal_defs.h.in +++ b/include/jemalloc/internal/jemalloc_internal_defs.h.in @@ -187,6 +187,9 @@ */ #undef JEMALLOC_HAS_ALLOCA_H +/* C99 restrict keyword supported. */ +#undef JEMALLOC_HAS_RESTRICT + /* sizeof(int) == 2^LG_SIZEOF_INT. */ #undef LG_SIZEOF_INT diff --git a/include/jemalloc/internal/jemalloc_internal_macros.h b/include/jemalloc/internal/jemalloc_internal_macros.h index 70602ee..4e23923 100644 --- a/include/jemalloc/internal/jemalloc_internal_macros.h +++ b/include/jemalloc/internal/jemalloc_internal_macros.h @@ -45,3 +45,7 @@ #ifndef __DECONST # define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) #endif + +#ifndef JEMALLOC_HAS_RESTRICT +# define restrict +#endif -- cgit v0.12 From ad47e8996e649ff8b4c920abb937bbacb8b9625e Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Mon, 24 Feb 2014 22:00:10 -0800 Subject: 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. --- Makefile.in | 15 ++++++++++++--- test/unit/prof_accum.c | 38 +------------------------------------- test/unit/prof_accum.h | 29 +++++++++++++++++++++++++++++ test/unit/prof_accum_a.c | 3 +++ test/unit/prof_accum_b.c | 3 +++ 5 files changed, 48 insertions(+), 40 deletions(-) create mode 100644 test/unit/prof_accum.h create mode 100644 test/unit/prof_accum_a.c create mode 100644 test/unit/prof_accum_b.c 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) -- cgit v0.12 From cb657e3170349a27e753cdf6316513f56550205e Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 25 Feb 2014 11:21:41 -0800 Subject: Add configure test to verify SSE2 code compiles. Make sure that emmintrin.h can be #include'd without causing a compilation error, rather than blindly defining HAVE_SSE2 based on architecture. Attempts to force SSE2 compilation on a 32-bit Ubuntu 13.10 system running as a VMware guest resulted in a no-win choice without any obvious explanation besides toolchain misconfiguration/bug: - Suffer compilation failure due to __MMX__, __SSE__, and __SSE2__ not being defined, even if -mmmx, -msse, and -msse2 are manually specified (note that they appear to be enabled by default). - Manually define __MMX__, __SSE__, and __SSE2__, and suffer compiler warnings that they are already automatically defined. This results in successful compilation and execution, but the noise is intolerable. --- configure.ac | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 938c019..3837a78 100644 --- a/configure.ac +++ b/configure.ac @@ -198,21 +198,21 @@ CPU_SPINWAIT="" case "${host_cpu}" in i[[345]]86) ;; - i686) - JE_COMPILABLE([__asm__], [], [[__asm__ volatile("pause"); return 0;]], - [je_cv_asm]) - if test "x${je_cv_asm}" = "xyes" ; then + i686|x86_64) + JE_COMPILABLE([pause instruction], [], + [[__asm__ volatile("pause"); return 0;]], + [je_cv_pause]) + if test "x${je_cv_pause}" = "xyes" ; then CPU_SPINWAIT='__asm__ volatile("pause")' fi - AC_DEFINE_UNQUOTED([HAVE_SSE2], [ ]) - ;; - x86_64) - JE_COMPILABLE([__asm__ syntax], [], - [[__asm__ volatile("pause"); return 0;]], [je_cv_asm]) - if test "x${je_cv_asm}" = "xyes" ; then - CPU_SPINWAIT='__asm__ volatile("pause")' + dnl emmintrin.h fails to compile unless MMX, SSE, and SSE2 are + dnl supported. + JE_COMPILABLE([SSE2 intrinsics], [ +#include +], [], [je_cv_sse2]) + if test "x${je_cv_sse2}" = "xyes" ; then + AC_DEFINE_UNQUOTED([HAVE_SSE2], [ ]) fi - AC_DEFINE_UNQUOTED([HAVE_SSE2], [ ]) ;; powerpc) AC_DEFINE_UNQUOTED([HAVE_ALTIVEC], [ ]) -- cgit v0.12 From 940fdfd5eef45f5425f9124e250fddde5c5c48bf Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 25 Feb 2014 11:58:50 -0800 Subject: Fix junk filling for mremap(2)-based huge reallocation. If mremap(2) is used for huge reallocation, physical pages are mapped to new virtual addresses rather than data being copied to new pages. This bypasses the normal junk filling that would happen during allocation, so add junk filling that is specific to this case. --- src/huge.c | 10 ++++++++++ test/unit/junk.c | 9 ++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/huge.c b/src/huge.c index cecaf2d..6d86aed 100644 --- a/src/huge.c +++ b/src/huge.c @@ -171,6 +171,16 @@ huge_ralloc(void *ptr, size_t oldsize, size_t size, size_t extra, abort(); memcpy(ret, ptr, copysize); chunk_dealloc_mmap(ptr, oldsize); + } else if (config_fill && zero == false && opt_junk && oldsize + < newsize) { + /* + * mremap(2) clobbers the original mapping, so + * junk/zero filling is not preserved. There is no + * need to zero fill here, since any trailing + * uninititialized memory is demand-zeroed by the + * kernel, but junk filling must be redone. + */ + memset(ret + oldsize, 0xa5, newsize - oldsize); } } else #endif diff --git a/test/unit/junk.c b/test/unit/junk.c index e27db2f..ef8f9c1 100644 --- a/test/unit/junk.c +++ b/test/unit/junk.c @@ -92,9 +92,12 @@ test_junk(size_t sz_min, size_t sz_max) s = (char *)rallocx(s, sz+1, 0); assert_ptr_not_null((void *)s, "Unexpected rallocx() failure"); - assert_ptr_eq(most_recently_junked, junked, - "Expected region of size %zu to be junk-filled", - sz); + if (!config_mremap || sz+1 <= arena_maxclass) { + assert_ptr_eq(most_recently_junked, junked, + "Expected region of size %zu to be " + "junk-filled", + sz); + } } } -- cgit v0.12 From b037a55f365471002bac024ffa1a8392ddcd578f Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 25 Feb 2014 16:11:15 -0800 Subject: Restore tail call optimization subversion. Restore the essence of 898960247a8b2e6534738b7a3a244855f379faf9, which sabotages tail call optimization. This is necessary even when the mutually recursive functions are in separate compilation units. --- test/unit/prof_accum.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/test/unit/prof_accum.h b/test/unit/prof_accum.h index de9cfea..109d86b 100644 --- a/test/unit/prof_accum.h +++ b/test/unit/prof_accum.h @@ -14,16 +14,22 @@ alloc_n_proto(1) void * \ alloc_##n(unsigned bits) \ { \ + void *p; \ \ - if (bits == 0) { \ - void *p = mallocx(1, 0); \ - assert_ptr_not_null(p, "Unexpected mallocx() failure"); \ - return (p); \ - } else { \ + if (bits == 0) \ + p = mallocx(1, 0); \ + else { \ switch (bits & 0x1U) { \ - case 0: return (alloc_0(bits >> 1)); \ - case 1: return (alloc_1(bits >> 1)); \ + 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); \ } -- cgit v0.12 From b9ec5c9a004a9c2f63951c476a6ff9f4c27f7b6f Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 25 Feb 2014 16:43:51 -0800 Subject: Update ChangeLog for 3.5.1. --- ChangeLog | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c2b1ee..c0ca338 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,8 +3,26 @@ bug fixes are all mentioned, but internal enhancements are omitted here for brevity (even though they are more fun to write about). Much more detail can be found in the git revision history: - http://www.canonware.com/cgi-bin/gitweb.cgi?p=jemalloc.git - git://canonware.com/jemalloc.git + https://github.com/jemalloc/jemalloc + +* 3.5.1 (February 25, 2014) + + This version primarily addresses minor bugs in test code. + + Bug fixes: + - Configure Solaris/Illumos to use MADV_FREE. + - Fix junk filling for mremap(2)-based huge reallocation. This is only + relevant if configuring with the --enable-mremap option specified. + - Avoid compilation failure if 'restrict' C99 keyword is not supported by the + compiler. + - Add a configure test for SSE2 rather than assuming it is usable on i686 + systems. This fixes test compilation errors, especially on 32-bit Linux + systems. + - Fix mallctl argument size mismatches (size_t vs. uint64_t) in the stats unit + test. + - Fix/remove flawed alignment-related overflow tests. + - Prevent compiler optimizations that could change backtraces in the + prof_accum unit test. * 3.5.0 (January 22, 2014) -- cgit v0.12