Jason Evans | c0cc5db | 2017-01-19 21:41:41 -0800 | [diff] [blame] | 1 | #define JEMALLOC_WITNESS_C_ |
David Goldblatt | 743d940 | 2017-04-10 18:17:55 -0700 | [diff] [blame] | 2 | #include "jemalloc/internal/jemalloc_preamble.h" |
| 3 | #include "jemalloc/internal/jemalloc_internal_includes.h" |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 4 | |
David Goldblatt | d9ec36e | 2017-04-11 14:43:12 -0700 | [diff] [blame] | 5 | #include "jemalloc/internal/assert.h" |
David Goldblatt | 54373be | 2017-04-11 13:06:31 -0700 | [diff] [blame] | 6 | #include "jemalloc/internal/malloc_io.h" |
| 7 | |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 8 | void |
| 9 | witness_init(witness_t *witness, const char *name, witness_rank_t rank, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 10 | witness_comp_t *comp, void *opaque) { |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 11 | witness->name = name; |
| 12 | witness->rank = rank; |
| 13 | witness->comp = comp; |
Jason Evans | e75e9be | 2016-04-17 12:55:10 -0700 | [diff] [blame] | 14 | witness->opaque = opaque; |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 15 | } |
| 16 | |
Jason Evans | a268af5 | 2017-05-01 23:10:42 -0700 | [diff] [blame^] | 17 | static void |
| 18 | witness_lock_error_impl(const witness_list_t *witnesses, |
| 19 | const witness_t *witness) { |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 20 | witness_t *w; |
| 21 | |
| 22 | malloc_printf("<jemalloc>: Lock rank order reversal:"); |
| 23 | ql_foreach(w, witnesses, link) { |
| 24 | malloc_printf(" %s(%u)", w->name, w->rank); |
| 25 | } |
| 26 | malloc_printf(" %s(%u)\n", witness->name, witness->rank); |
| 27 | abort(); |
| 28 | } |
Jason Evans | a268af5 | 2017-05-01 23:10:42 -0700 | [diff] [blame^] | 29 | witness_lock_error_t *JET_MUTABLE witness_lock_error = witness_lock_error_impl; |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 30 | |
Jason Evans | a268af5 | 2017-05-01 23:10:42 -0700 | [diff] [blame^] | 31 | static void |
| 32 | witness_owner_error_impl(const witness_t *witness) { |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 33 | malloc_printf("<jemalloc>: Should own %s(%u)\n", witness->name, |
| 34 | witness->rank); |
| 35 | abort(); |
| 36 | } |
Jason Evans | a268af5 | 2017-05-01 23:10:42 -0700 | [diff] [blame^] | 37 | witness_owner_error_t *JET_MUTABLE witness_owner_error = |
| 38 | witness_owner_error_impl; |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 39 | |
Jason Evans | a268af5 | 2017-05-01 23:10:42 -0700 | [diff] [blame^] | 40 | static void |
| 41 | witness_not_owner_error_impl(const witness_t *witness) { |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 42 | malloc_printf("<jemalloc>: Should not own %s(%u)\n", witness->name, |
| 43 | witness->rank); |
| 44 | abort(); |
| 45 | } |
Jason Evans | a268af5 | 2017-05-01 23:10:42 -0700 | [diff] [blame^] | 46 | witness_not_owner_error_t *JET_MUTABLE witness_not_owner_error = |
| 47 | witness_not_owner_error_impl; |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 48 | |
Jason Evans | a268af5 | 2017-05-01 23:10:42 -0700 | [diff] [blame^] | 49 | static void |
| 50 | witness_depth_error_impl(const witness_list_t *witnesses, |
Jason Evans | d0e93ad | 2017-01-21 15:12:03 -0800 | [diff] [blame] | 51 | witness_rank_t rank_inclusive, unsigned depth) { |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 52 | witness_t *w; |
| 53 | |
Jason Evans | d0e93ad | 2017-01-21 15:12:03 -0800 | [diff] [blame] | 54 | malloc_printf("<jemalloc>: Should own %u lock%s of rank >= %u:", depth, |
| 55 | (depth != 1) ? "s" : "", rank_inclusive); |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 56 | ql_foreach(w, witnesses, link) { |
| 57 | malloc_printf(" %s(%u)", w->name, w->rank); |
| 58 | } |
| 59 | malloc_printf("\n"); |
| 60 | abort(); |
| 61 | } |
Jason Evans | a268af5 | 2017-05-01 23:10:42 -0700 | [diff] [blame^] | 62 | witness_depth_error_t *JET_MUTABLE witness_depth_error = |
| 63 | witness_depth_error_impl; |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 64 | |
| 65 | void |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 66 | witnesses_cleanup(tsd_t *tsd) { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 67 | witness_assert_lockless(tsd_tsdn(tsd)); |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 68 | |
| 69 | /* Do nothing. */ |
| 70 | } |
Jason Evans | 174c0c3 | 2016-04-25 23:14:40 -0700 | [diff] [blame] | 71 | |
| 72 | void |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 73 | witness_prefork(tsd_t *tsd) { |
Qi Wang | 4dec507 | 2017-04-05 22:04:12 -0700 | [diff] [blame] | 74 | if (!config_debug) { |
| 75 | return; |
| 76 | } |
Jason Evans | 174c0c3 | 2016-04-25 23:14:40 -0700 | [diff] [blame] | 77 | tsd_witness_fork_set(tsd, true); |
| 78 | } |
| 79 | |
| 80 | void |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 81 | witness_postfork_parent(tsd_t *tsd) { |
Qi Wang | 4dec507 | 2017-04-05 22:04:12 -0700 | [diff] [blame] | 82 | if (!config_debug) { |
| 83 | return; |
| 84 | } |
Jason Evans | 174c0c3 | 2016-04-25 23:14:40 -0700 | [diff] [blame] | 85 | tsd_witness_fork_set(tsd, false); |
| 86 | } |
Jason Evans | 108c4a1 | 2016-04-26 10:47:22 -0700 | [diff] [blame] | 87 | |
| 88 | void |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 89 | witness_postfork_child(tsd_t *tsd) { |
Qi Wang | 4dec507 | 2017-04-05 22:04:12 -0700 | [diff] [blame] | 90 | if (!config_debug) { |
| 91 | return; |
| 92 | } |
Jason Evans | 108c4a1 | 2016-04-26 10:47:22 -0700 | [diff] [blame] | 93 | #ifndef JEMALLOC_MUTEX_INIT_CB |
| 94 | witness_list_t *witnesses; |
| 95 | |
| 96 | witnesses = tsd_witnessesp_get(tsd); |
| 97 | ql_new(witnesses); |
| 98 | #endif |
| 99 | tsd_witness_fork_set(tsd, false); |
| 100 | } |