forked from OSchip/llvm-project
[NFC][sanitizers] Add StackDepotBase Node::hash_type
Depends on D111177. Differential Revision: https://reviews.llvm.org/D111182
This commit is contained in:
parent
5ae9a3e4bf
commit
3129aa5caf
|
@ -14,7 +14,7 @@
|
|||
namespace __sanitizer {
|
||||
|
||||
bool ChainedOriginDepot::ChainedOriginDepotNode::eq(
|
||||
u32 hash, const args_type &args) const {
|
||||
hash_type hash, const args_type &args) const {
|
||||
return here_id == args.here_id && prev_id == args.prev_id;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,8 @@ uptr ChainedOriginDepot::ChainedOriginDepotNode::storage_size(
|
|||
split, or one of two reserved values (-1) or (-2). Either case can
|
||||
dominate depending on the workload.
|
||||
*/
|
||||
u32 ChainedOriginDepot::ChainedOriginDepotNode::hash(const args_type &args) {
|
||||
ChainedOriginDepot::ChainedOriginDepotNode::hash_type
|
||||
ChainedOriginDepot::ChainedOriginDepotNode::hash(const args_type &args) {
|
||||
const u32 m = 0x5bd1e995;
|
||||
const u32 seed = 0x9747b28c;
|
||||
const u32 r = 24;
|
||||
|
@ -67,7 +68,7 @@ bool ChainedOriginDepot::ChainedOriginDepotNode::is_valid(
|
|||
}
|
||||
|
||||
void ChainedOriginDepot::ChainedOriginDepotNode::store(const args_type &args,
|
||||
u32 other_hash) {
|
||||
hash_type other_hash) {
|
||||
here_id = args.here_id;
|
||||
prev_id = args.prev_id;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ class ChainedOriginDepot {
|
|||
};
|
||||
|
||||
struct ChainedOriginDepotNode {
|
||||
using hash_type = u32;
|
||||
ChainedOriginDepotNode *link;
|
||||
u32 id;
|
||||
u32 here_id;
|
||||
|
@ -50,15 +51,15 @@ class ChainedOriginDepot {
|
|||
|
||||
typedef ChainedOriginDepotDesc args_type;
|
||||
|
||||
bool eq(u32 hash, const args_type &args) const;
|
||||
bool eq(hash_type hash, const args_type &args) const;
|
||||
|
||||
static uptr storage_size(const args_type &args);
|
||||
|
||||
static u32 hash(const args_type &args);
|
||||
static hash_type hash(const args_type &args);
|
||||
|
||||
static bool is_valid(const args_type &args);
|
||||
|
||||
void store(const args_type &args, u32 other_hash);
|
||||
void store(const args_type &args, hash_type other_hash);
|
||||
|
||||
args_type load() const;
|
||||
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
namespace __sanitizer {
|
||||
|
||||
struct StackDepotNode {
|
||||
using hash_type = u32;
|
||||
StackDepotNode *link;
|
||||
u32 id;
|
||||
u32 stack_hash;
|
||||
hash_type stack_hash;
|
||||
u32 size;
|
||||
atomic_uint32_t tag_and_use_count; // tag : 12 high bits; use_count : 20;
|
||||
uptr stack[1]; // [size]
|
||||
|
@ -32,7 +33,7 @@ struct StackDepotNode {
|
|||
static const u32 kUseCountMask = (1 << kUseCountBits) - 1;
|
||||
|
||||
typedef StackTrace args_type;
|
||||
bool eq(u32 hash, const args_type &args) const {
|
||||
bool eq(hash_type hash, const args_type &args) const {
|
||||
u32 tag =
|
||||
atomic_load(&tag_and_use_count, memory_order_relaxed) >> kUseCountBits;
|
||||
if (stack_hash != hash || args.size != size || args.tag != tag)
|
||||
|
@ -46,7 +47,7 @@ struct StackDepotNode {
|
|||
static uptr storage_size(const args_type &args) {
|
||||
return sizeof(StackDepotNode) + (args.size - 1) * sizeof(uptr);
|
||||
}
|
||||
static u32 hash(const args_type &args) {
|
||||
static hash_type hash(const args_type &args) {
|
||||
MurMur2HashBuilder H(args.size * sizeof(uptr));
|
||||
for (uptr i = 0; i < args.size; i++) H.add(args.trace[i]);
|
||||
return H.get();
|
||||
|
@ -54,7 +55,7 @@ struct StackDepotNode {
|
|||
static bool is_valid(const args_type &args) {
|
||||
return args.size > 0 && args.trace;
|
||||
}
|
||||
void store(const args_type &args, u32 hash) {
|
||||
void store(const args_type &args, hash_type hash) {
|
||||
CHECK_EQ(args.tag & (~kUseCountMask >> kUseCountBits), args.tag);
|
||||
atomic_store(&tag_and_use_count, args.tag << kUseCountBits,
|
||||
memory_order_relaxed);
|
||||
|
|
|
@ -27,6 +27,7 @@ class StackDepotBase {
|
|||
public:
|
||||
typedef typename Node::args_type args_type;
|
||||
typedef typename Node::handle_type handle_type;
|
||||
typedef typename Node::hash_type hash_type;
|
||||
// Maps stack trace to an unique id.
|
||||
handle_type Put(args_type args, bool *inserted = nullptr);
|
||||
// Retrieves a stored stack trace by the id.
|
||||
|
@ -39,7 +40,7 @@ class StackDepotBase {
|
|||
void PrintAll();
|
||||
|
||||
private:
|
||||
static Node *find(Node *s, args_type args, u32 hash);
|
||||
static Node *find(Node *s, args_type args, hash_type hash);
|
||||
static Node *lock(atomic_uintptr_t *p);
|
||||
static void unlock(atomic_uintptr_t *p, Node *s);
|
||||
|
||||
|
@ -62,7 +63,7 @@ class StackDepotBase {
|
|||
template <class Node, int kReservedBits, int kTabSizeLog>
|
||||
Node *StackDepotBase<Node, kReservedBits, kTabSizeLog>::find(Node *s,
|
||||
args_type args,
|
||||
u32 hash) {
|
||||
hash_type hash) {
|
||||
// Searches linked list s for the stack, returns its id.
|
||||
for (; s; s = s->link) {
|
||||
if (s->eq(hash, args)) {
|
||||
|
@ -101,7 +102,7 @@ StackDepotBase<Node, kReservedBits, kTabSizeLog>::Put(args_type args,
|
|||
bool *inserted) {
|
||||
if (inserted) *inserted = false;
|
||||
if (!Node::is_valid(args)) return handle_type();
|
||||
uptr h = Node::hash(args);
|
||||
hash_type h = Node::hash(args);
|
||||
atomic_uintptr_t *p = &tab[h % kTabSize];
|
||||
uptr v = atomic_load(p, memory_order_consume);
|
||||
Node *s = (Node *)(v & ~1);
|
||||
|
|
Loading…
Reference in New Issue