summaryrefslogtreecommitdiff
path: root/deps/jemalloc/include/jemalloc/internal/witness.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/jemalloc/include/jemalloc/internal/witness.h')
-rw-r--r--deps/jemalloc/include/jemalloc/internal/witness.h183
1 files changed, 107 insertions, 76 deletions
diff --git a/deps/jemalloc/include/jemalloc/internal/witness.h b/deps/jemalloc/include/jemalloc/internal/witness.h
index fff9e98cb..e81b9a006 100644
--- a/deps/jemalloc/include/jemalloc/internal/witness.h
+++ b/deps/jemalloc/include/jemalloc/internal/witness.h
@@ -7,60 +7,76 @@
/* LOCK RANKS */
/******************************************************************************/
-/*
- * Witnesses with rank WITNESS_RANK_OMIT are completely ignored by the witness
- * machinery.
- */
-
-#define WITNESS_RANK_OMIT 0U
-
-#define WITNESS_RANK_MIN 1U
-
-#define WITNESS_RANK_INIT 1U
-#define WITNESS_RANK_CTL 1U
-#define WITNESS_RANK_TCACHES 2U
-#define WITNESS_RANK_ARENAS 3U
-
-#define WITNESS_RANK_BACKGROUND_THREAD_GLOBAL 4U
-
-#define WITNESS_RANK_PROF_DUMP 5U
-#define WITNESS_RANK_PROF_BT2GCTX 6U
-#define WITNESS_RANK_PROF_TDATAS 7U
-#define WITNESS_RANK_PROF_TDATA 8U
-#define WITNESS_RANK_PROF_LOG 9U
-#define WITNESS_RANK_PROF_GCTX 10U
-#define WITNESS_RANK_BACKGROUND_THREAD 11U
-
-/*
- * Used as an argument to witness_assert_depth_to_rank() in order to validate
- * depth excluding non-core locks with lower ranks. Since the rank argument to
- * witness_assert_depth_to_rank() is inclusive rather than exclusive, this
- * definition can have the same value as the minimally ranked core lock.
- */
-#define WITNESS_RANK_CORE 12U
-
-#define WITNESS_RANK_DECAY 12U
-#define WITNESS_RANK_TCACHE_QL 13U
-#define WITNESS_RANK_EXTENT_GROW 14U
-#define WITNESS_RANK_EXTENTS 15U
-#define WITNESS_RANK_EXTENT_AVAIL 16U
-
-#define WITNESS_RANK_EXTENT_POOL 17U
-#define WITNESS_RANK_RTREE 18U
-#define WITNESS_RANK_BASE 19U
-#define WITNESS_RANK_ARENA_LARGE 20U
-#define WITNESS_RANK_HOOK 21U
-
-#define WITNESS_RANK_LEAF 0xffffffffU
-#define WITNESS_RANK_BIN WITNESS_RANK_LEAF
-#define WITNESS_RANK_ARENA_STATS WITNESS_RANK_LEAF
-#define WITNESS_RANK_DSS WITNESS_RANK_LEAF
-#define WITNESS_RANK_PROF_ACTIVE WITNESS_RANK_LEAF
-#define WITNESS_RANK_PROF_ACCUM WITNESS_RANK_LEAF
-#define WITNESS_RANK_PROF_DUMP_SEQ WITNESS_RANK_LEAF
-#define WITNESS_RANK_PROF_GDUMP WITNESS_RANK_LEAF
-#define WITNESS_RANK_PROF_NEXT_THR_UID WITNESS_RANK_LEAF
-#define WITNESS_RANK_PROF_THREAD_ACTIVE_INIT WITNESS_RANK_LEAF
+enum witness_rank_e {
+ /*
+ * Order matters within this enum listing -- higher valued locks can
+ * only be acquired after lower-valued ones. We use the
+ * auto-incrementing-ness of enum values to enforce this.
+ */
+
+ /*
+ * Witnesses with rank WITNESS_RANK_OMIT are completely ignored by the
+ * witness machinery.
+ */
+ WITNESS_RANK_OMIT,
+ WITNESS_RANK_MIN,
+ WITNESS_RANK_INIT = WITNESS_RANK_MIN,
+ WITNESS_RANK_CTL,
+ WITNESS_RANK_TCACHES,
+ WITNESS_RANK_ARENAS,
+ WITNESS_RANK_BACKGROUND_THREAD_GLOBAL,
+ WITNESS_RANK_PROF_DUMP,
+ WITNESS_RANK_PROF_BT2GCTX,
+ WITNESS_RANK_PROF_TDATAS,
+ WITNESS_RANK_PROF_TDATA,
+ WITNESS_RANK_PROF_LOG,
+ WITNESS_RANK_PROF_GCTX,
+ WITNESS_RANK_PROF_RECENT_DUMP,
+ WITNESS_RANK_BACKGROUND_THREAD,
+ /*
+ * Used as an argument to witness_assert_depth_to_rank() in order to
+ * validate depth excluding non-core locks with lower ranks. Since the
+ * rank argument to witness_assert_depth_to_rank() is inclusive rather
+ * than exclusive, this definition can have the same value as the
+ * minimally ranked core lock.
+ */
+ WITNESS_RANK_CORE,
+ WITNESS_RANK_DECAY = WITNESS_RANK_CORE,
+ WITNESS_RANK_TCACHE_QL,
+
+ WITNESS_RANK_SEC_SHARD,
+
+ WITNESS_RANK_EXTENT_GROW,
+ WITNESS_RANK_HPA_SHARD_GROW = WITNESS_RANK_EXTENT_GROW,
+ WITNESS_RANK_SAN_BUMP_ALLOC = WITNESS_RANK_EXTENT_GROW,
+
+ WITNESS_RANK_EXTENTS,
+ WITNESS_RANK_HPA_SHARD = WITNESS_RANK_EXTENTS,
+
+ WITNESS_RANK_HPA_CENTRAL_GROW,
+ WITNESS_RANK_HPA_CENTRAL,
+
+ WITNESS_RANK_EDATA_CACHE,
+
+ WITNESS_RANK_RTREE,
+ WITNESS_RANK_BASE,
+ WITNESS_RANK_ARENA_LARGE,
+ WITNESS_RANK_HOOK,
+
+ WITNESS_RANK_LEAF=0x1000,
+ WITNESS_RANK_BIN = WITNESS_RANK_LEAF,
+ WITNESS_RANK_ARENA_STATS = WITNESS_RANK_LEAF,
+ WITNESS_RANK_COUNTER_ACCUM = WITNESS_RANK_LEAF,
+ WITNESS_RANK_DSS = WITNESS_RANK_LEAF,
+ WITNESS_RANK_PROF_ACTIVE = WITNESS_RANK_LEAF,
+ WITNESS_RANK_PROF_DUMP_FILENAME = WITNESS_RANK_LEAF,
+ WITNESS_RANK_PROF_GDUMP = WITNESS_RANK_LEAF,
+ WITNESS_RANK_PROF_NEXT_THR_UID = WITNESS_RANK_LEAF,
+ WITNESS_RANK_PROF_RECENT_ALLOC = WITNESS_RANK_LEAF,
+ WITNESS_RANK_PROF_STATS = WITNESS_RANK_LEAF,
+ WITNESS_RANK_PROF_THREAD_ACTIVE_INIT = WITNESS_RANK_LEAF,
+};
+typedef enum witness_rank_e witness_rank_t;
/******************************************************************************/
/* PER-WITNESS DATA */
@@ -72,7 +88,6 @@
#endif
typedef struct witness_s witness_t;
-typedef unsigned witness_rank_t;
typedef ql_head(witness_t) witness_list_t;
typedef int witness_comp_t (const witness_t *, void *, const witness_t *,
void *);
@@ -82,8 +97,8 @@ struct witness_s {
const char *name;
/*
- * Witness rank, where 0 is lowest and UINT_MAX is highest. Witnesses
- * must be acquired in order of increasing rank.
+ * Witness rank, where 0 is lowest and WITNESS_RANK_LEAF is highest.
+ * Witnesses must be acquired in order of increasing rank.
*/
witness_rank_t rank;
@@ -228,26 +243,13 @@ witness_assert_not_owner(witness_tsdn_t *witness_tsdn,
}
}
-static inline void
-witness_assert_depth_to_rank(witness_tsdn_t *witness_tsdn,
- witness_rank_t rank_inclusive, unsigned depth) {
- witness_tsd_t *witness_tsd;
- unsigned d;
- witness_list_t *witnesses;
- witness_t *w;
-
- if (!config_debug) {
- return;
- }
+/* Returns depth. Not intended for direct use. */
+static inline unsigned
+witness_depth_to_rank(witness_list_t *witnesses, witness_rank_t rank_inclusive)
+{
+ unsigned d = 0;
+ witness_t *w = ql_last(witnesses, link);
- if (witness_tsdn_null(witness_tsdn)) {
- return;
- }
- witness_tsd = witness_tsdn_tsd(witness_tsdn);
-
- d = 0;
- witnesses = &witness_tsd->witnesses;
- w = ql_last(witnesses, link);
if (w != NULL) {
ql_reverse_foreach(w, witnesses, link) {
if (w->rank < rank_inclusive) {
@@ -256,6 +258,20 @@ witness_assert_depth_to_rank(witness_tsdn_t *witness_tsdn,
d++;
}
}
+
+ return d;
+}
+
+static inline void
+witness_assert_depth_to_rank(witness_tsdn_t *witness_tsdn,
+ witness_rank_t rank_inclusive, unsigned depth) {
+ if (!config_debug || witness_tsdn_null(witness_tsdn)) {
+ return;
+ }
+
+ witness_list_t *witnesses = &witness_tsdn_tsd(witness_tsdn)->witnesses;
+ unsigned d = witness_depth_to_rank(witnesses, rank_inclusive);
+
if (d != depth) {
witness_depth_error(witnesses, rank_inclusive, depth);
}
@@ -272,6 +288,21 @@ witness_assert_lockless(witness_tsdn_t *witness_tsdn) {
}
static inline void
+witness_assert_positive_depth_to_rank(witness_tsdn_t *witness_tsdn,
+ witness_rank_t rank_inclusive) {
+ if (!config_debug || witness_tsdn_null(witness_tsdn)) {
+ return;
+ }
+
+ witness_list_t *witnesses = &witness_tsdn_tsd(witness_tsdn)->witnesses;
+ unsigned d = witness_depth_to_rank(witnesses, rank_inclusive);
+
+ if (d == 0) {
+ witness_depth_error(witnesses, rank_inclusive, 1);
+ }
+}
+
+static inline void
witness_lock(witness_tsdn_t *witness_tsdn, witness_t *witness) {
witness_tsd_t *witness_tsd;
witness_list_t *witnesses;