vitalybuka updated this revision to Diff 377650.
vitalybuka added a comment.
update a test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D111256/new/
https://reviews.llvm.org/D111256
Files:
clang/docs/tools/clang-formatted-files.txt
compiler-rt/lib/sanitizer_common/CMakeLists.txt
compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.cpp
compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.h
compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp
compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h
compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h
compiler-rt/lib/sanitizer_common/tests/sanitizer_chained_origin_depot_test.cpp
compiler-rt/lib/tsan/go/buildgo.sh
llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn
Index: llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn
===================================================================
--- llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn
+++ llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn
@@ -84,7 +84,6 @@
"sanitizer_mutex.cpp",
"sanitizer_mutex.h",
"sanitizer_netbsd.cpp",
- "sanitizer_persistent_allocator.cpp",
"sanitizer_persistent_allocator.h",
"sanitizer_placement_new.h",
"sanitizer_platform.h",
Index: compiler-rt/lib/tsan/go/buildgo.sh
===================================================================
--- compiler-rt/lib/tsan/go/buildgo.sh
+++ compiler-rt/lib/tsan/go/buildgo.sh
@@ -27,7 +27,6 @@
../../sanitizer_common/sanitizer_flags.cpp
../../sanitizer_common/sanitizer_libc.cpp
../../sanitizer_common/sanitizer_mutex.cpp
- ../../sanitizer_common/sanitizer_persistent_allocator.cpp
../../sanitizer_common/sanitizer_printf.cpp
../../sanitizer_common/sanitizer_suppressions.cpp
../../sanitizer_common/sanitizer_thread_registry.cpp
Index: compiler-rt/lib/sanitizer_common/tests/sanitizer_chained_origin_depot_test.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/tests/sanitizer_chained_origin_depot_test.cpp
+++ compiler-rt/lib/sanitizer_common/tests/sanitizer_chained_origin_depot_test.cpp
@@ -84,7 +84,7 @@
EXPECT_TRUE(chainedOriginDepot.Put(35, 36, &new_id));
StackDepotStats stats3 = chainedOriginDepot.GetStats();
EXPECT_EQ(stats3.n_uniq_ids, stats2.n_uniq_ids + 1);
- EXPECT_GT(stats3.allocated, stats2.allocated);
+ EXPECT_GE(stats3.allocated, stats2.allocated);
}
} // namespace __sanitizer
Index: compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h
@@ -33,7 +33,7 @@
// Retrieves a stored stack trace by the id.
args_type Get(u32 id);
- StackDepotStats GetStats() const { return stats; }
+ StackDepotStats GetStats() const { return {n_uniq_ids, Node::allocated()}; }
void LockAll();
void UnlockAll();
@@ -55,7 +55,7 @@
atomic_uintptr_t tab[kTabSize]; // Hash table of Node's.
atomic_uint32_t seq[kPartCount]; // Unique id generators.
- StackDepotStats stats;
+ uptr n_uniq_ids;
friend class StackDepotReverseMap;
};
@@ -120,14 +120,12 @@
}
uptr part = (h % kTabSize) / kPartSize;
u32 id = atomic_fetch_add(&seq[part], 1, memory_order_relaxed) + 1;
- stats.n_uniq_ids++;
+ n_uniq_ids++;
CHECK_LT(id, kMaxId);
id |= part << kPartShift;
CHECK_NE(id, 0);
CHECK_EQ(id & (((u32)-1) >> kReservedBits), id);
- uptr memsz = Node::storage_size(args);
- s = (Node *)PersistentAlloc(memsz);
- stats.allocated += memsz;
+ s = Node::allocate(args);
s->id = id;
s->store(args, h);
s->link = s2;
Index: compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
@@ -14,10 +14,13 @@
#include "sanitizer_common.h"
#include "sanitizer_hash.h"
+#include "sanitizer_persistent_allocator.h"
#include "sanitizer_stackdepotbase.h"
namespace __sanitizer {
+static PersistentAllocator allocator;
+
struct StackDepotNode {
using hash_type = u64;
hash_type stack_hash;
@@ -36,8 +39,10 @@
bool eq(hash_type hash, const args_type &args) const {
return hash == stack_hash;
}
- static uptr storage_size(const args_type &args) {
- return sizeof(StackDepotNode) + (args.size - 1) * sizeof(uptr);
+ static uptr allocated() { return allocator.total_size(); }
+ static StackDepotNode *allocate(const args_type &args) {
+ uptr alloc_size = sizeof(StackDepotNode) + (args.size - 1) * sizeof(uptr);
+ return (StackDepotNode *)allocator.alloc(alloc_size);
}
static hash_type hash(const args_type &args) {
MurMur2Hash64Builder H(args.size * sizeof(uptr));
Index: compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h
@@ -23,12 +23,14 @@
class PersistentAllocator {
public:
void *alloc(uptr size);
+ uptr total_size() const { return atomic_load_relaxed(&allocated_size); }
private:
void *tryAlloc(uptr size);
StaticSpinMutex mtx; // Protects alloc of new blocks for region allocator.
atomic_uintptr_t region_pos; // Region allocator for Node's.
atomic_uintptr_t region_end;
+ atomic_uintptr_t allocated_size;
};
inline void *PersistentAllocator::tryAlloc(uptr size) {
@@ -56,16 +58,13 @@
uptr allocsz = 64 * 1024;
if (allocsz < size) allocsz = size;
uptr mem = (uptr)MmapOrDie(allocsz, "stack depot");
+ atomic_fetch_add(&allocated_size, allocsz, memory_order_relaxed);
atomic_store(®ion_end, mem + allocsz, memory_order_release);
atomic_store(®ion_pos, mem, memory_order_release);
+ atomic_store(®ion_pos, mem, memory_order_release);
}
}
-extern PersistentAllocator thePersistentAllocator;
-inline void *PersistentAlloc(uptr sz) {
- return thePersistentAllocator.alloc(sz);
-}
-
} // namespace __sanitizer
#endif // SANITIZER_PERSISTENT_ALLOCATOR_H
Index: compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-//===-- sanitizer_persistent_allocator.cpp ----------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is shared between AddressSanitizer and ThreadSanitizer
-// run-time libraries.
-//===----------------------------------------------------------------------===//
-#include "sanitizer_persistent_allocator.h"
-
-namespace __sanitizer {
-
-PersistentAllocator thePersistentAllocator;
-
-} // namespace __sanitizer
Index: compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.h
@@ -53,7 +53,9 @@
bool eq(hash_type hash, const args_type &args) const;
- static uptr storage_size(const args_type &args);
+ static uptr allocated();
+
+ static ChainedOriginDepotNode *allocate(const args_type &args);
static hash_type hash(const args_type &args);
Index: compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_chained_origin_depot.cpp
@@ -13,14 +13,21 @@
namespace __sanitizer {
+static PersistentAllocator allocator;
+
bool ChainedOriginDepot::ChainedOriginDepotNode::eq(
hash_type hash, const args_type &args) const {
return here_id == args.here_id && prev_id == args.prev_id;
}
-uptr ChainedOriginDepot::ChainedOriginDepotNode::storage_size(
- const args_type &args) {
- return sizeof(ChainedOriginDepotNode);
+uptr ChainedOriginDepot::ChainedOriginDepotNode::allocated() {
+ return allocator.total_size();
+}
+
+ChainedOriginDepot::ChainedOriginDepotNode *
+ChainedOriginDepot::ChainedOriginDepotNode::allocate(const args_type &args) {
+ return static_cast<ChainedOriginDepot::ChainedOriginDepotNode *>(
+ allocator.alloc(sizeof(ChainedOriginDepotNode)));
}
/* This is murmur2 hash for the 64->32 bit case.
Index: compiler-rt/lib/sanitizer_common/CMakeLists.txt
===================================================================
--- compiler-rt/lib/sanitizer_common/CMakeLists.txt
+++ compiler-rt/lib/sanitizer_common/CMakeLists.txt
@@ -18,7 +18,6 @@
sanitizer_mac.cpp
sanitizer_mutex.cpp
sanitizer_netbsd.cpp
- sanitizer_persistent_allocator.cpp
sanitizer_platform_limits_freebsd.cpp
sanitizer_platform_limits_linux.cpp
sanitizer_platform_limits_netbsd.cpp
Index: clang/docs/tools/clang-formatted-files.txt
===================================================================
--- clang/docs/tools/clang-formatted-files.txt
+++ clang/docs/tools/clang-formatted-files.txt
@@ -1591,7 +1591,6 @@
compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h
compiler-rt/lib/sanitizer_common/sanitizer_local_address_space_view.h
compiler-rt/lib/sanitizer_common/sanitizer_openbsd.cpp
-compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp
compiler-rt/lib/sanitizer_common/sanitizer_placement_new.h
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_openbsd.cpp
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits