2017-01-20 13:41:41 +08:00
|
|
|
#define JEMALLOC_WITNESS_C_
|
2017-04-11 09:17:55 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_preamble.h"
|
|
|
|
#include "jemalloc/internal/jemalloc_internal_includes.h"
|
2016-04-14 14:36:15 +08:00
|
|
|
|
2017-04-12 05:43:12 +08:00
|
|
|
#include "jemalloc/internal/assert.h"
|
2017-04-12 04:06:31 +08:00
|
|
|
#include "jemalloc/internal/malloc_io.h"
|
|
|
|
|
2016-04-14 14:36:15 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-05-02 14:10:42 +08:00
|
|
|
static void
|
|
|
|
witness_lock_error_impl(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();
|
|
|
|
}
|
2017-05-02 14:10:42 +08:00
|
|
|
witness_lock_error_t *JET_MUTABLE witness_lock_error = witness_lock_error_impl;
|
2016-04-14 14:36:15 +08:00
|
|
|
|
2017-05-02 14:10:42 +08:00
|
|
|
static void
|
|
|
|
witness_owner_error_impl(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();
|
|
|
|
}
|
2017-05-02 14:10:42 +08:00
|
|
|
witness_owner_error_t *JET_MUTABLE witness_owner_error =
|
|
|
|
witness_owner_error_impl;
|
2016-04-14 14:36:15 +08:00
|
|
|
|
2017-05-02 14:10:42 +08:00
|
|
|
static void
|
|
|
|
witness_not_owner_error_impl(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();
|
|
|
|
}
|
2017-05-02 14:10:42 +08:00
|
|
|
witness_not_owner_error_t *JET_MUTABLE witness_not_owner_error =
|
|
|
|
witness_not_owner_error_impl;
|
2016-04-14 14:36:15 +08:00
|
|
|
|
2017-05-02 14:10:42 +08:00
|
|
|
static void
|
|
|
|
witness_depth_error_impl(const witness_list_t *witnesses,
|
2017-01-22 07:12:03 +08:00
|
|
|
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();
|
|
|
|
}
|
2017-05-02 14:10:42 +08:00
|
|
|
witness_depth_error_t *JET_MUTABLE witness_depth_error =
|
|
|
|
witness_depth_error_impl;
|
2016-04-14 14:36:15 +08:00
|
|
|
|
|
|
|
void
|
2017-05-23 10:32:04 +08:00
|
|
|
witnesses_cleanup(witness_tsd_t *witness_tsd) {
|
|
|
|
witness_assert_lockless(witness_tsd_tsdn(witness_tsd));
|
2016-04-14 14:36:15 +08:00
|
|
|
|
|
|
|
/* Do nothing. */
|
|
|
|
}
|
2016-04-26 14:14:40 +08:00
|
|
|
|
|
|
|
void
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_prefork(witness_tsd_t *witness_tsd) {
|
2017-04-06 13:04:12 +08:00
|
|
|
if (!config_debug) {
|
|
|
|
return;
|
|
|
|
}
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_tsd->forking = true;
|
2016-04-26 14:14:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_postfork_parent(witness_tsd_t *witness_tsd) {
|
2017-04-06 13:04:12 +08:00
|
|
|
if (!config_debug) {
|
|
|
|
return;
|
|
|
|
}
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_tsd->forking = false;
|
2016-04-26 14:14:40 +08:00
|
|
|
}
|
2016-04-27 01:47:22 +08:00
|
|
|
|
|
|
|
void
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_postfork_child(witness_tsd_t *witness_tsd) {
|
2017-04-06 13:04:12 +08:00
|
|
|
if (!config_debug) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-27 01:47:22 +08:00
|
|
|
#ifndef JEMALLOC_MUTEX_INIT_CB
|
|
|
|
witness_list_t *witnesses;
|
|
|
|
|
2017-05-23 10:32:04 +08:00
|
|
|
witnesses = &witness_tsd->witnesses;
|
2016-04-27 01:47:22 +08:00
|
|
|
ql_new(witnesses);
|
|
|
|
#endif
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_tsd->forking = false;
|
2016-04-27 01:47:22 +08:00
|
|
|
}
|