Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 77f350b

Browse files
author
Jason Evans
committed
Improve backtracing-related configuration.
Clean up configuration for backtracing when profiling is enabled, and document the configuration logic in INSTALL. Disable libgcc-based backtracing except on x64 (where it is known to work). Add the --disable-prof-gcc option.
1 parent b602daa commit 77f350b

File tree

4 files changed

+140
-83
lines changed

4 files changed

+140
-83
lines changed

jemalloc/INSTALL

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,23 @@ any of the following arguments (not a definitive list) to 'configure':
6262

6363
--enable-prof
6464
Enable heap profiling and leak detection functionality. See the "opt.prof"
65-
option documentation for usage details.
65+
option documentation for usage details. When enabled, there are several
66+
approaches to backtracing, and the configure script chooses the first one
67+
in the following list that appears to function correctly:
6668

67-
--disable-prof-libgcc
68-
Disable the use of libgcc's backtracing functionality. Ordinarily, libgcc's
69-
backtracing functionality is superior to the alternatives, but it may fail
70-
to capture backtraces on some systems.
69+
+ libunwind (requires --enable-prof-libunwind)
70+
+ libgcc (unless --disable-prof-libgcc)
71+
+ gcc intrinsics (unless --disable-prof-gcc)
7172

7273
--enable-prof-libunwind
7374
Use the libunwind library (http://www.nongnu.org/libunwind/) for stack
74-
backtracing. libunwind is quite slow, but it tends to work across a wider
75-
variety of system configurations than the default backtracing code, which is
76-
based on libgcc functionality or gcc intrinsics.
75+
backtracing.
76+
77+
--disable-prof-libgcc
78+
Disable the use of libgcc's backtracing functionality.
79+
80+
--disable-prof-gcc
81+
Disable the use of gcc intrinsics for backtracing.
7782

7883
--with-static-libunwind=<libunwind.a>
7984
Statically link against the specified libunwind.a rather than dynamically

jemalloc/configure.ac

Lines changed: 84 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,12 @@ fi
404404
],
405405
[enable_prof="0"]
406406
)
407-
AC_ARG_ENABLE([prof-libgcc],
408-
[AS_HELP_STRING([--disable-prof-libgcc],
409-
[Do not use libgcc for backtracing])],
410-
[if test "x$enable_prof_libgcc" = "xno" ; then
411-
enable_prof_libgcc="0"
407+
if test "x$enable_prof" = "x1" ; then
408+
backtrace_method=""
412409
else
413-
enable_prof_libgcc="1"
410+
backtrace_method="N/A"
414411
fi
415-
],
416-
[enable_prof_libgcc="1"]
417-
)
412+
418413
AC_ARG_ENABLE([prof-libunwind],
419414
[AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
420415
[if test "x$enable_prof_libunwind" = "xno" ; then
@@ -438,39 +433,90 @@ else
438433
fi,
439434
LUNWIND="-lunwind"
440435
)
441-
if test "x$enable_prof" = "x1" ; then
442-
LIBS="$LIBS -lm"
443-
AC_DEFINE([JEMALLOC_PROF], [ ])
444-
if test "x$enable_prof_libunwind" = "x1" ; then
445-
AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
446-
if test "x$LUNWIND" = "x-lunwind" ; then
447-
AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
448-
[enable_prof_libunwind="0"])
449-
else
450-
LIBS="$LIBS $LUNWIND"
451-
fi
452-
if test "x${enable_prof_libunwind}" = "x1" ; then
453-
AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
454-
fi
436+
if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
437+
AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
438+
if test "x$LUNWIND" = "x-lunwind" ; then
439+
AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
440+
[enable_prof_libunwind="0"])
441+
else
442+
LIBS="$LIBS $LUNWIND"
443+
fi
444+
if test "x${enable_prof_libunwind}" = "x1" ; then
445+
backtrace_method="libunwind"
446+
AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
455447
fi
456448
fi
457-
AC_SUBST([enable_prof])
458449

459-
dnl If libunwind isn't enabled, try to use libgcc rather than gcc intrinsics
460-
dnl for backtracing.
461-
if test "x$enable_prof" = "x1" -a "x$enable_prof_libgcc" = "x1" ; then
462-
if test "x$enable_prof_libunwind" = "x0" -a "x$GCC" = "xyes" ; then
463-
enable_prof_libgcc="1"
464-
AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
465-
AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
466-
if test "x${enable_prof_libgcc}" = "x1" ; then
467-
AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
468-
fi
469-
else
470-
enable_prof_libgcc="0"
450+
AC_ARG_ENABLE([prof-libgcc],
451+
[AS_HELP_STRING([--disable-prof-libgcc],
452+
[Do not use libgcc for backtracing])],
453+
[if test "x$enable_prof_libgcc" = "xno" ; then
454+
enable_prof_libgcc="0"
455+
else
456+
enable_prof_libgcc="1"
457+
fi
458+
],
459+
[enable_prof_libgcc="1"]
460+
)
461+
if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
462+
-a "x$GCC" = "xyes" ; then
463+
AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
464+
AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
465+
dnl The following is conservative, in that it only has entries for CPUs on
466+
dnl which jemalloc has been tested.
467+
AC_MSG_CHECKING([libgcc-based backtracing reliability on ${host_cpu}])
468+
case "${host_cpu}" in
469+
i[[3456]]86)
470+
AC_MSG_RESULT([unreliable])
471+
enable_prof_libgcc="0";
472+
;;
473+
x86_64)
474+
AC_MSG_RESULT([reliable])
475+
;;
476+
*)
477+
AC_MSG_RESULT([unreliable])
478+
enable_prof_libgcc="0";
479+
;;
480+
esac
481+
if test "x${enable_prof_libgcc}" = "x1" ; then
482+
backtrace_method="libgcc"
483+
AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
471484
fi
485+
else
486+
enable_prof_libgcc="0"
487+
fi
488+
489+
AC_ARG_ENABLE([prof-gcc],
490+
[AS_HELP_STRING([--disable-prof-gcc],
491+
[Do not use gcc intrinsics for backtracing])],
492+
[if test "x$enable_prof_gcc" = "xno" ; then
493+
enable_prof_gcc="0"
494+
else
495+
enable_prof_gcc="1"
496+
fi
497+
],
498+
[enable_prof_gcc="1"]
499+
)
500+
if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
501+
-a "x$GCC" = "xyes" ; then
502+
backtrace_method="gcc intrinsics"
503+
AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
504+
else
505+
enable_prof_gcc="0"
472506
fi
473507

508+
if test "x$backtrace_method" = "x" ; then
509+
backtrace_method="none (disabling profiling)"
510+
enable_prof="0"
511+
fi
512+
AC_MSG_CHECKING([configured backtracing method])
513+
AC_MSG_RESULT([$backtrace_method])
514+
if test "x$enable_prof" = "x1" ; then
515+
LIBS="$LIBS -lm"
516+
AC_DEFINE([JEMALLOC_PROF], [ ])
517+
fi
518+
AC_SUBST([enable_prof])
519+
474520
dnl Enable tiny allocations by default.
475521
AC_ARG_ENABLE([tiny],
476522
[AS_HELP_STRING([--disable-tiny], [Disable tiny (sub-quantum) allocations])],
@@ -810,8 +856,9 @@ AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
810856
AC_MSG_RESULT([debug : ${enable_debug}])
811857
AC_MSG_RESULT([stats : ${enable_stats}])
812858
AC_MSG_RESULT([prof : ${enable_prof}])
813-
AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
814859
AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
860+
AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
861+
AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
815862
AC_MSG_RESULT([tiny : ${enable_tiny}])
816863
AC_MSG_RESULT([tcache : ${enable_tcache}])
817864
AC_MSG_RESULT([fill : ${enable_fill}])

jemalloc/include/jemalloc/jemalloc_defs.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
/* Use libgcc for profile backtracing if defined. */
5454
#undef JEMALLOC_PROF_LIBGCC
5555

56+
/* Use gcc intrinsics for profile backtracing if defined. */
57+
#undef JEMALLOC_PROF_GCC
58+
5659
/*
5760
* JEMALLOC_TINY enables support for tiny objects, which are smaller than one
5861
* quantum.

jemalloc/src/prof.c

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
#ifdef JEMALLOC_PROF
44
/******************************************************************************/
55

6-
#ifdef JEMALLOC_PROF_LIBGCC
7-
#include <unwind.h>
8-
#endif
9-
106
#ifdef JEMALLOC_PROF_LIBUNWIND
117
#define UNW_LOCAL_ONLY
128
#include <libunwind.h>
139
#endif
1410

11+
#ifdef JEMALLOC_PROF_LIBGCC
12+
#include <unwind.h>
13+
#endif
14+
1515
/******************************************************************************/
1616
/* Data. */
1717

@@ -169,39 +169,7 @@ prof_leave(void)
169169
prof_gdump();
170170
}
171171

172-
#ifdef JEMALLOC_PROF_LIBGCC
173-
static _Unwind_Reason_Code
174-
prof_unwind_init_callback(struct _Unwind_Context *context, void *arg)
175-
{
176-
177-
return (_URC_NO_REASON);
178-
}
179-
180-
static _Unwind_Reason_Code
181-
prof_unwind_callback(struct _Unwind_Context *context, void *arg)
182-
{
183-
prof_unwind_data_t *data = (prof_unwind_data_t *)arg;
184-
185-
if (data->nignore > 0)
186-
data->nignore--;
187-
else {
188-
data->bt->vec[data->bt->len] = (void *)_Unwind_GetIP(context);
189-
data->bt->len++;
190-
if (data->bt->len == data->max)
191-
return (_URC_END_OF_STACK);
192-
}
193-
194-
return (_URC_NO_REASON);
195-
}
196-
197-
void
198-
prof_backtrace(prof_bt_t *bt, unsigned nignore, unsigned max)
199-
{
200-
prof_unwind_data_t data = {bt, nignore, max};
201-
202-
_Unwind_Backtrace(prof_unwind_callback, &data);
203-
}
204-
#elif defined(JEMALLOC_PROF_LIBUNWIND)
172+
#ifdef JEMALLOC_PROF_LIBUNWIND
205173
void
206174
prof_backtrace(prof_bt_t *bt, unsigned nignore, unsigned max)
207175
{
@@ -236,7 +204,41 @@ prof_backtrace(prof_bt_t *bt, unsigned nignore, unsigned max)
236204
break;
237205
}
238206
}
239-
#else
207+
#endif
208+
#ifdef JEMALLOC_PROF_LIBGCC
209+
static _Unwind_Reason_Code
210+
prof_unwind_init_callback(struct _Unwind_Context *context, void *arg)
211+
{
212+
213+
return (_URC_NO_REASON);
214+
}
215+
216+
static _Unwind_Reason_Code
217+
prof_unwind_callback(struct _Unwind_Context *context, void *arg)
218+
{
219+
prof_unwind_data_t *data = (prof_unwind_data_t *)arg;
220+
221+
if (data->nignore > 0)
222+
data->nignore--;
223+
else {
224+
data->bt->vec[data->bt->len] = (void *)_Unwind_GetIP(context);
225+
data->bt->len++;
226+
if (data->bt->len == data->max)
227+
return (_URC_END_OF_STACK);
228+
}
229+
230+
return (_URC_NO_REASON);
231+
}
232+
233+
void
234+
prof_backtrace(prof_bt_t *bt, unsigned nignore, unsigned max)
235+
{
236+
prof_unwind_data_t data = {bt, nignore, max};
237+
238+
_Unwind_Backtrace(prof_unwind_callback, &data);
239+
}
240+
#endif
241+
#ifdef JEMALLOC_PROF_GCC
240242
void
241243
prof_backtrace(prof_bt_t *bt, unsigned nignore, unsigned max)
242244
{

0 commit comments

Comments
 (0)