2017-01-20 13:41:41 +08:00
|
|
|
#define JEMALLOC_WITNESS_C_
|
2016-04-14 14:36:15 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_internal.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
witness_init(witness_t *witness, const char *name, witness_rank_t rank,
|
2017-01-16 08:56:30 +08:00
|
|
|
witness_comp_t *comp, void *opaque) {
|
2016-04-14 14:36:15 +08:00
|
|
|
witness->name = name;
|
|
|
|
witness->rank = rank;
|
|
|
|
witness->comp = comp;
|
2016-04-18 03:55:10 +08:00
|
|
|
witness->opaque = opaque;
|
2016-04-14 14:36:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef JEMALLOC_JET
|
|
|
|
#undef witness_lock_error
|
2017-01-20 13:41:41 +08:00
|
|
|
#define witness_lock_error JEMALLOC_N(n_witness_lock_error)
|
2016-04-14 14:36:15 +08:00
|
|
|
#endif
|
2016-05-12 06:33:28 +08:00
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
witness_lock_error(const witness_list_t *witnesses, const witness_t *witness) {
|
2016-04-14 14:36:15 +08:00
|
|
|
witness_t *w;
|
|
|
|
|
|
|
|
malloc_printf("<jemalloc>: Lock rank order reversal:");
|
|
|
|
ql_foreach(w, witnesses, link) {
|
|
|
|
malloc_printf(" %s(%u)", w->name, w->rank);
|
|
|
|
}
|
|
|
|
malloc_printf(" %s(%u)\n", witness->name, witness->rank);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
#ifdef JEMALLOC_JET
|
|
|
|
#undef witness_lock_error
|
2017-01-20 13:41:41 +08:00
|
|
|
#define witness_lock_error JEMALLOC_N(witness_lock_error)
|
2016-05-12 07:14:20 +08:00
|
|
|
witness_lock_error_t *witness_lock_error = JEMALLOC_N(n_witness_lock_error);
|
2016-04-14 14:36:15 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef JEMALLOC_JET
|
|
|
|
#undef witness_owner_error
|
2017-01-20 13:41:41 +08:00
|
|
|
#define witness_owner_error JEMALLOC_N(n_witness_owner_error)
|
2016-04-14 14:36:15 +08:00
|
|
|
#endif
|
2016-05-12 06:33:28 +08:00
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
witness_owner_error(const witness_t *witness) {
|
2016-04-14 14:36:15 +08:00
|
|
|
malloc_printf("<jemalloc>: Should own %s(%u)\n", witness->name,
|
|
|
|
witness->rank);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
#ifdef JEMALLOC_JET
|
|
|
|
#undef witness_owner_error
|
2017-01-20 13:41:41 +08:00
|
|
|
#define witness_owner_error JEMALLOC_N(witness_owner_error)
|
2016-05-12 07:14:20 +08:00
|
|
|
witness_owner_error_t *witness_owner_error = JEMALLOC_N(n_witness_owner_error);
|
2016-04-14 14:36:15 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef JEMALLOC_JET
|
|
|
|
#undef witness_not_owner_error
|
2017-01-20 13:41:41 +08:00
|
|
|
#define witness_not_owner_error JEMALLOC_N(n_witness_not_owner_error)
|
2016-04-14 14:36:15 +08:00
|
|
|
#endif
|
2016-05-12 06:33:28 +08:00
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
witness_not_owner_error(const witness_t *witness) {
|
2016-04-14 14:36:15 +08:00
|
|
|
malloc_printf("<jemalloc>: Should not own %s(%u)\n", witness->name,
|
|
|
|
witness->rank);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
#ifdef JEMALLOC_JET
|
|
|
|
#undef witness_not_owner_error
|
2017-01-20 13:41:41 +08:00
|
|
|
#define witness_not_owner_error JEMALLOC_N(witness_not_owner_error)
|
2016-04-14 14:36:15 +08:00
|
|
|
witness_not_owner_error_t *witness_not_owner_error =
|
2016-05-12 07:14:20 +08:00
|
|
|
JEMALLOC_N(n_witness_not_owner_error);
|
2016-04-14 14:36:15 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef JEMALLOC_JET
|
2017-01-22 07:12:03 +08:00
|
|
|
#undef witness_depth_error
|
|
|
|
#define witness_depth_error JEMALLOC_N(n_witness_depth_error)
|
2016-04-14 14:36:15 +08:00
|
|
|
#endif
|
2016-05-12 06:33:28 +08:00
|
|
|
void
|
2017-01-22 07:12:03 +08:00
|
|
|
witness_depth_error(const witness_list_t *witnesses,
|
|
|
|
witness_rank_t rank_inclusive, unsigned depth) {
|
2016-04-14 14:36:15 +08:00
|
|
|
witness_t *w;
|
|
|
|
|
2017-01-22 07:12:03 +08:00
|
|
|
malloc_printf("<jemalloc>: Should own %u lock%s of rank >= %u:", depth,
|
|
|
|
(depth != 1) ? "s" : "", rank_inclusive);
|
2016-04-14 14:36:15 +08:00
|
|
|
ql_foreach(w, witnesses, link) {
|
|
|
|
malloc_printf(" %s(%u)", w->name, w->rank);
|
|
|
|
}
|
|
|
|
malloc_printf("\n");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
#ifdef JEMALLOC_JET
|
2017-01-22 07:12:03 +08:00
|
|
|
#undef witness_depth_error
|
|
|
|
#define witness_depth_error JEMALLOC_N(witness_depth_error)
|
|
|
|
witness_depth_error_t *witness_depth_error = JEMALLOC_N(n_witness_depth_error);
|
2016-04-14 14:36:15 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
witnesses_cleanup(tsd_t *tsd) {
|
2016-05-11 13:21:10 +08:00
|
|
|
witness_assert_lockless(tsd_tsdn(tsd));
|
2016-04-14 14:36:15 +08:00
|
|
|
|
|
|
|
/* Do nothing. */
|
|
|
|
}
|
2016-04-26 14:14:40 +08:00
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
witness_prefork(tsd_t *tsd) {
|
2016-04-26 14:14:40 +08:00
|
|
|
tsd_witness_fork_set(tsd, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
witness_postfork_parent(tsd_t *tsd) {
|
2016-04-26 14:14:40 +08:00
|
|
|
tsd_witness_fork_set(tsd, false);
|
|
|
|
}
|
2016-04-27 01:47:22 +08:00
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
witness_postfork_child(tsd_t *tsd) {
|
2016-04-27 01:47:22 +08:00
|
|
|
#ifndef JEMALLOC_MUTEX_INIT_CB
|
|
|
|
witness_list_t *witnesses;
|
|
|
|
|
|
|
|
witnesses = tsd_witnessesp_get(tsd);
|
|
|
|
ql_new(witnesses);
|
|
|
|
#endif
|
|
|
|
tsd_witness_fork_set(tsd, false);
|
|
|
|
}
|