summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Goldblatt <davidgoldblatt@fb.com>2019-03-19 23:04:35 (GMT)
committerDavid Goldblatt <davidtgoldblatt@gmail.com>2019-04-15 23:48:12 (GMT)
commitf4d24f05e1f270c43bc4129c0d18d673b8ac85b8 (patch)
tree4e3e0d1ae1f5c496a889ec13691bc6c090d7f8fb
parent7f7935cf7805036d42fb510592ab8b40bcfb0690 (diff)
downloadjemalloc-f4d24f05e1f270c43bc4129c0d18d673b8ac85b8.zip
jemalloc-f4d24f05e1f270c43bc4129c0d18d673b8ac85b8.tar.gz
jemalloc-f4d24f05e1f270c43bc4129c0d18d673b8ac85b8.tar.bz2
Move extra size checks behind a config flag.
This will let us turn that flag into a generic "turn on runtime checks" flag that guards other functionality we have planned.
-rw-r--r--configure.ac22
-rw-r--r--include/jemalloc/internal/jemalloc_internal_defs.h.in4
-rw-r--r--include/jemalloc/internal/jemalloc_preamble.h.in19
-rw-r--r--src/tcache.c17
4 files changed, 40 insertions, 22 deletions
diff --git a/configure.ac b/configure.ac
index 9cc2a6b..7a83a1a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1418,22 +1418,22 @@ if test "x$enable_readlinkat" = "x1" ; then
fi
AC_SUBST([enable_readlinkat])
-dnl Avoid the extra size checking by default
-AC_ARG_ENABLE([extra-size-check],
- [AS_HELP_STRING([--enable-extra-size-check],
- [Perform additonal size related sanity checks])],
-[if test "x$enable_extra_size_check" = "xno" ; then
- enable_extra_size_check="0"
+dnl Avoid extra safety checks by default
+AC_ARG_ENABLE([opt-safety-checks],
+ [AS_HELP_STRING([--enable-opt-safety-checks],
+ [Perform certain low-overhead checks, even in opt mode])],
+[if test "x$enable_opt_safety_checks" = "xno" ; then
+ enable_opt_safety_checks="0"
else
- enable_extra_size_check="1"
+ enable_opt_safety_checks="1"
fi
],
-[enable_extra_size_check="0"]
+[enable_opt_safety_checks="0"]
)
-if test "x$enable_extra_size_check" = "x1" ; then
- AC_DEFINE([JEMALLOC_EXTRA_SIZE_CHECK], [ ])
+if test "x$enable_opt_safety_checks" = "x1" ; then
+ AC_DEFINE([JEMALLOC_OPT_SAFETY_CHECKS], [ ])
fi
-AC_SUBST([enable_extra_size_check])
+AC_SUBST([enable_opt_safety_checks])
JE_COMPILABLE([a program using __builtin_unreachable], [
void foo (void) {
diff --git a/include/jemalloc/internal/jemalloc_internal_defs.h.in b/include/jemalloc/internal/jemalloc_internal_defs.h.in
index 21b6514..c442a21 100644
--- a/include/jemalloc/internal/jemalloc_internal_defs.h.in
+++ b/include/jemalloc/internal/jemalloc_internal_defs.h.in
@@ -360,7 +360,7 @@
*/
#undef JEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE
-/* Performs additional size-matching sanity checks when defined. */
-#undef JEMALLOC_EXTRA_SIZE_CHECK
+/* Performs additional safety checks when defined. */
+#undef JEMALLOC_OPT_SAFETY_CHECKS
#endif /* JEMALLOC_INTERNAL_DEFS_H_ */
diff --git a/include/jemalloc/internal/jemalloc_preamble.h.in b/include/jemalloc/internal/jemalloc_preamble.h.in
index 4bfdb32..9fd2a7f 100644
--- a/include/jemalloc/internal/jemalloc_preamble.h.in
+++ b/include/jemalloc/internal/jemalloc_preamble.h.in
@@ -161,6 +161,25 @@ static const bool config_log =
false
#endif
;
+/*
+ * Are extra safety checks enabled; things like checking the size of sized
+ * deallocations, double-frees, etc.
+ */
+static const bool config_opt_safety_checks =
+#if defined(JEMALLOC_EXTRA_SAFETY_CHECKS)
+ true
+#elif defined(JEMALLOC_DEBUG)
+ /*
+ * This lets us only guard safety checks by one flag instead of two; fast
+ * checks can guard solely by config_opt_safety_checks and run in debug mode
+ * too.
+ */
+ true
+#else
+ false
+#endif
+ ;
+
#if defined(_WIN32) || defined(JEMALLOC_HAVE_SCHED_GETCPU)
/* Currently percpu_arena depends on sched_getcpu. */
#define JEMALLOC_PERCPU_ARENA
diff --git a/src/tcache.c b/src/tcache.c
index e7b970d..160b0b7 100644
--- a/src/tcache.c
+++ b/src/tcache.c
@@ -101,7 +101,6 @@ tcache_alloc_small_hard(tsdn_t *tsdn, arena_t *arena, tcache_t *tcache,
}
/* Enabled with --enable-extra-size-check. */
-#ifdef JEMALLOC_EXTRA_SIZE_CHECK
static void
tbin_extents_lookup_size_check(tsdn_t *tsdn, cache_bin_t *tbin, szind_t binind,
size_t nflush, extent_t **extents){
@@ -129,7 +128,6 @@ tbin_extents_lookup_size_check(tsdn_t *tsdn, cache_bin_t *tbin, szind_t binind,
abort();
}
}
-#endif
void
tcache_bin_flush_small(tsd_t *tsd, tcache_t *tcache, cache_bin_t *tbin,
@@ -144,15 +142,16 @@ tcache_bin_flush_small(tsd_t *tsd, tcache_t *tcache, cache_bin_t *tbin,
unsigned nflush = tbin->ncached - rem;
VARIABLE_ARRAY(extent_t *, item_extent, nflush);
-#ifndef JEMALLOC_EXTRA_SIZE_CHECK
/* Look up extent once per item. */
- for (unsigned i = 0 ; i < nflush; i++) {
- item_extent[i] = iealloc(tsd_tsdn(tsd), *(tbin->avail - 1 - i));
+ if (config_opt_safety_checks) {
+ tbin_extents_lookup_size_check(tsd_tsdn(tsd), tbin, binind,
+ nflush, item_extent);
+ } else {
+ for (unsigned i = 0 ; i < nflush; i++) {
+ item_extent[i] = iealloc(tsd_tsdn(tsd),
+ *(tbin->avail - 1 - i));
+ }
}
-#else
- tbin_extents_lookup_size_check(tsd_tsdn(tsd), tbin, binind, nflush,
- item_extent);
-#endif
while (nflush > 0) {
/* Lock the arena bin associated with the first object. */
extent_t *extent = item_extent[0];