From e853b4f2e42d80156272ebca58a8e92c79d2082a Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Mon, 27 Oct 2014 03:10:27 +0000 Subject: [Sanitizer] Return code that calculates hash for stacktrace back to StackDepot implementation llvm-svn: 220663 --- .../lib/sanitizer_common/sanitizer_stackdepot.cc | 22 ++++++++++++++++++++++ .../sanitizer_common/sanitizer_stackdepotbase.h | 4 ++-- .../lib/sanitizer_common/sanitizer_stacktrace.h | 21 --------------------- 3 files changed, 24 insertions(+), 23 deletions(-) (limited to 'compiler-rt/lib/sanitizer_common') diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc index afd45ddd2e1..f10f1f973fd 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc @@ -47,6 +47,28 @@ 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) { + // murmur2 + const u32 m = 0x5bd1e995; + const u32 seed = 0x9747b28c; + const u32 r = 24; + u32 h = seed ^ (args.size * sizeof(uptr)); + for (uptr i = 0; i < args.size; i++) { + u32 k = args.trace[i]; + k *= m; + k ^= k >> r; + k *= m; + h *= m; + h ^= k; + } + h ^= h >> 13; + h *= m; + h ^= h >> 15; + return h; + } + static bool is_valid(const args_type &args) { + return args.size > 0 && args.trace; + } void store(const args_type &args, u32 hash) { atomic_store(&hash_and_use_count, hash & kHashMask, memory_order_relaxed); size = args.size; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h index d2d3d34980c..5de2e711fe4 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h @@ -97,8 +97,8 @@ typename StackDepotBase::handle_type StackDepotBase::Put(args_type args, bool *inserted) { if (inserted) *inserted = false; - if (!args.is_valid()) return handle_type(); - uptr h = args.hash(); + if (!Node::is_valid(args)) return handle_type(); + uptr h = Node::hash(args); atomic_uintptr_t *p = &tab[h % kTabSize]; uptr v = atomic_load(p, memory_order_consume); Node *s = (Node *)(v & ~1); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h index a3d548804f9..4f613fad164 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h @@ -39,27 +39,6 @@ struct StackTrace { // Prints a symbolized stacktrace, followed by an empty line. void Print() const; - u32 hash() const { - // murmur2 - const u32 m = 0x5bd1e995; - const u32 seed = 0x9747b28c; - const u32 r = 24; - u32 h = seed ^ (size * sizeof(uptr)); - for (uptr i = 0; i < size; i++) { - u32 k = trace[i]; - k *= m; - k ^= k >> r; - k *= m; - h *= m; - h ^= k; - } - h ^= h >> 13; - h *= m; - h ^= h >> 15; - return h; - } - bool is_valid() const { return size > 0 && trace; } - static bool WillUseFastUnwind(bool request_fast_unwind) { // Check if fast unwind is available. Fast unwind is the only option on Mac. // It is also the only option on FreeBSD as the slow unwinding that -- cgit v1.2.3