[compiler-rt] r220663 - [Sanitizer] Return code that calculates hash for stacktrace back to StackDepot implementation

Alexey Samsonov vonosmas at gmail.com
Sun Oct 26 20:10:27 PDT 2014


Author: samsonov
Date: Sun Oct 26 22:10:27 2014
New Revision: 220663

URL: http://llvm.org/viewvc/llvm-project?rev=220663&view=rev
Log:
[Sanitizer] Return code that calculates hash for stacktrace back to StackDepot implementation

Modified:
    compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepotbase.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h

Modified: compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cc?rev=220663&r1=220662&r2=220663&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cc Sun Oct 26 22:10:27 2014
@@ -19,6 +19,21 @@ namespace __msan {
 struct ChainedOriginDepotDesc {
   u32 here_id;
   u32 prev_id;
+};
+
+struct ChainedOriginDepotNode {
+  ChainedOriginDepotNode *link;
+  u32 id;
+  u32 here_id;
+  u32 prev_id;
+
+  typedef ChainedOriginDepotDesc args_type;
+  bool eq(u32 hash, const args_type &args) const {
+    return here_id == args.here_id && prev_id == args.prev_id;
+  }
+  static uptr storage_size(const args_type &args) {
+    return sizeof(ChainedOriginDepotNode);
+  }
   /* This is murmur2 hash for the 64->32 bit case.
      It does not behave all that well because the keys have a very biased
      distribution (I've seen 7-element buckets with the table only 14% full).
@@ -32,19 +47,19 @@ struct ChainedOriginDepotDesc {
      split, or one of two reserved values (-1) or (-2). Either case can
      dominate depending on the workload.
   */
-  u32 hash() const {
+  static u32 hash(const args_type &args) {
     const u32 m = 0x5bd1e995;
     const u32 seed = 0x9747b28c;
     const u32 r = 24;
     u32 h = seed;
-    u32 k = here_id;
+    u32 k = args.here_id;
     k *= m;
     k ^= k >> r;
     k *= m;
     h *= m;
     h ^= k;
 
-    k = prev_id;
+    k = args.prev_id;
     k *= m;
     k ^= k >> r;
     k *= m;
@@ -56,22 +71,7 @@ struct ChainedOriginDepotDesc {
     h ^= h >> 15;
     return h;
   }
-  bool is_valid() { return true; }
-};
-
-struct ChainedOriginDepotNode {
-  ChainedOriginDepotNode *link;
-  u32 id;
-  u32 here_id;
-  u32 prev_id;
-
-  typedef ChainedOriginDepotDesc args_type;
-  bool eq(u32 hash, const args_type &args) const {
-    return here_id == args.here_id && prev_id == args.prev_id;
-  }
-  static uptr storage_size(const args_type &args) {
-    return sizeof(ChainedOriginDepotNode);
-  }
+  static bool is_valid(const args_type &args) { return true; }
   void store(const args_type &args, u32 other_hash) {
     here_id = args.here_id;
     prev_id = args.prev_id;

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc?rev=220663&r1=220662&r2=220663&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc Sun Oct 26 22:10:27 2014
@@ -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;

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepotbase.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepotbase.h?rev=220663&r1=220662&r2=220663&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepotbase.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepotbase.h Sun Oct 26 22:10:27 2014
@@ -97,8 +97,8 @@ typename StackDepotBase<Node, kReservedB
 StackDepotBase<Node, kReservedBits, kTabSizeLog>::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);

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h?rev=220663&r1=220662&r2=220663&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h Sun Oct 26 22:10:27 2014
@@ -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





More information about the llvm-commits mailing list