[compiler-rt] r331617 - [sanitizer] Remove reserving constructor from InternalMmapVector
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Sun May 6 22:56:24 PDT 2018
Author: vitalybuka
Date: Sun May 6 22:56:24 2018
New Revision: 331617
URL: http://llvm.org/viewvc/llvm-project?rev=331617&view=rev
Log:
[sanitizer] Remove reserving constructor from InternalMmapVector
Modified:
compiler-rt/trunk/lib/asan/asan_debugging.cc
compiler-rt/trunk/lib/asan/asan_descriptions.cc
compiler-rt/trunk/lib/asan/asan_globals.cc
compiler-rt/trunk/lib/asan/asan_memory_profile.cc
compiler-rt/trunk/lib/lsan/lsan_common.cc
compiler-rt/trunk/lib/lsan/lsan_common.h
compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_deadlock_detector2.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc
Modified: compiler-rt/trunk/lib/asan/asan_debugging.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_debugging.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_debugging.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_debugging.cc Sun May 6 22:56:24 2018
@@ -27,7 +27,8 @@ using namespace __asan;
static void FindInfoForStackVar(uptr addr, const char *frame_descr, uptr offset,
char *name, uptr name_size,
uptr ®ion_address, uptr ®ion_size) {
- InternalMmapVector<StackVarDescr> vars(16);
+ InternalMmapVector<StackVarDescr> vars;
+ vars.reserve(16);
if (!ParseFrameDescription(frame_descr, &vars)) {
return;
}
Modified: compiler-rt/trunk/lib/asan/asan_descriptions.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_descriptions.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_descriptions.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_descriptions.cc Sun May 6 22:56:24 2018
@@ -380,7 +380,8 @@ void StackAddressDescription::Print() co
StackTrace alloca_stack(&frame_pc, 1);
alloca_stack.Print();
- InternalMmapVector<StackVarDescr> vars(16);
+ InternalMmapVector<StackVarDescr> vars;
+ vars.reserve(16);
if (!ParseFrameDescription(frame_descr, &vars)) {
Printf(
"AddressSanitizer can't parse the stack frame "
Modified: compiler-rt/trunk/lib/asan/asan_globals.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_globals.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_globals.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_globals.cc Sun May 6 22:56:24 2018
@@ -224,8 +224,9 @@ static void RegisterGlobal(const Global
list_of_all_globals = l;
if (g->has_dynamic_init) {
if (!dynamic_init_globals) {
- dynamic_init_globals = new(allocator_for_globals)
- VectorOfGlobals(kDynamicInitGlobalsInitialCapacity);
+ dynamic_init_globals =
+ new (allocator_for_globals) VectorOfGlobals; // NOLINT
+ dynamic_init_globals->reserve(kDynamicInitGlobalsInitialCapacity);
}
DynInitGlobal dyn_global = { *g, false };
dynamic_init_globals->push_back(dyn_global);
@@ -358,9 +359,11 @@ void __asan_register_globals(__asan_glob
GET_STACK_TRACE_MALLOC;
u32 stack_id = StackDepotPut(stack);
BlockingMutexLock lock(&mu_for_globals);
- if (!global_registration_site_vector)
+ if (!global_registration_site_vector) {
global_registration_site_vector =
- new(allocator_for_globals) GlobalRegistrationSiteVector(128);
+ new (allocator_for_globals) GlobalRegistrationSiteVector; // NOLINT
+ global_registration_site_vector->reserve(128);
+ }
GlobalRegistrationSite site = {stack_id, &globals[0], &globals[n - 1]};
global_registration_site_vector->push_back(site);
if (flags()->report_globals >= 2) {
Modified: compiler-rt/trunk/lib/asan/asan_memory_profile.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_memory_profile.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_memory_profile.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_memory_profile.cc Sun May 6 22:56:24 2018
@@ -31,9 +31,9 @@ struct AllocationSite {
class HeapProfile {
public:
- HeapProfile() : allocations_(1024) {}
+ HeapProfile() { allocations_.reserve(1024); }
- void ProcessChunk(const AsanChunkView& cv) {
+ void ProcessChunk(const AsanChunkView &cv) {
if (cv.IsAllocated()) {
total_allocated_user_size_ += cv.UsedSize();
total_allocated_count_++;
Modified: compiler-rt/trunk/lib/lsan/lsan_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.cc Sun May 6 22:56:24 2018
@@ -104,7 +104,7 @@ InternalMmapVector<RootRegion> const *Ge
void InitializeRootRegions() {
CHECK(!root_regions);
ALIGNED(64) static char placeholder[sizeof(InternalMmapVector<RootRegion>)];
- root_regions = new(placeholder) InternalMmapVector<RootRegion>(1);
+ root_regions = new (placeholder) InternalMmapVector<RootRegion>(); // NOLINT
}
const char *MaybeCallLsanDefaultOptions() {
@@ -445,7 +445,7 @@ void ProcessPC(Frontier *frontier) {
// Sets the appropriate tag on each chunk.
static void ClassifyAllChunks(SuspendedThreadsList const &suspended_threads) {
// Holds the flood fill frontier.
- Frontier frontier(1);
+ Frontier frontier;
ForEachChunk(CollectIgnoredCb, &frontier);
ProcessGlobalRegions(&frontier);
@@ -507,7 +507,7 @@ static void CollectLeaksCb(uptr chunk, v
}
static void PrintMatchedSuppressions() {
- InternalMmapVector<Suppression *> matched(1);
+ InternalMmapVector<Suppression *> matched;
GetSuppressionContext()->GetMatched(&matched);
if (!matched.size())
return;
Modified: compiler-rt/trunk/lib/lsan/lsan_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.h?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.h (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.h Sun May 6 22:56:24 2018
@@ -95,7 +95,7 @@ struct LeakedObject {
// Aggregates leaks by stack trace prefix.
class LeakReport {
public:
- LeakReport() : next_id_(0), leaks_(1), leaked_objects_(1) {}
+ LeakReport() {}
void AddLeakedChunk(uptr chunk, u32 stack_trace_id, uptr leaked_size,
ChunkTag tag);
void ReportTopLeaks(uptr max_leaks);
@@ -103,12 +103,11 @@ class LeakReport {
void ApplySuppressions();
uptr UnsuppressedLeakCount();
-
private:
void PrintReportForLeak(uptr index);
void PrintLeakedObjectsForLeak(uptr index);
- u32 next_id_;
+ u32 next_id_ = 0;
InternalMmapVector<Leak> leaks_;
InternalMmapVector<LeakedObject> leaked_objects_;
};
Modified: compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common_mac.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common_mac.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common_mac.cc Sun May 6 22:56:24 2018
@@ -119,7 +119,8 @@ void ProcessGlobalRegions(Frontier *fron
for (auto name : kSkippedSecNames) CHECK(ARRAY_SIZE(name) < kMaxSegName);
MemoryMappingLayout memory_mapping(false);
- InternalMmapVector<LoadedModule> modules(/*initial_capacity*/ 128);
+ InternalMmapVector<LoadedModule> modules;
+ modules.reserve(128);
memory_mapping.DumpListOfModules(&modules);
for (uptr i = 0; i < modules.size(); ++i) {
// Even when global scanning is disabled, we still need to scan
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Sun May 6 22:56:24 2018
@@ -482,6 +482,10 @@ class InternalMmapVectorNoCtor {
uptr capacity() const {
return capacity_;
}
+ void reserve(uptr new_size) {
+ if (new_size >= size()) return;
+ Resize(new_size);
+ }
void resize(uptr new_size) {
Resize(new_size);
if (new_size > size_) {
@@ -527,9 +531,7 @@ class InternalMmapVectorNoCtor {
template<typename T>
class InternalMmapVector : public InternalMmapVectorNoCtor<T> {
public:
- explicit InternalMmapVector(uptr initial_capacity) {
- InternalMmapVectorNoCtor<T>::Initialize(initial_capacity);
- }
+ InternalMmapVector() { InternalMmapVectorNoCtor<T>::Initialize(1); }
~InternalMmapVector() { InternalMmapVectorNoCtor<T>::Destroy(); }
// Disallow copies and moves.
InternalMmapVector(const InternalMmapVector &) = delete;
@@ -545,7 +547,7 @@ class InternalMmapVector : public Intern
template <typename T>
class InternalScopedBuffer : public InternalMmapVector<T> {
public:
- explicit InternalScopedBuffer(uptr cnt) : InternalMmapVector<T>(cnt) {
+ explicit InternalScopedBuffer(uptr cnt) : InternalMmapVector<T>() {
this->resize(cnt);
}
};
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_deadlock_detector2.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_deadlock_detector2.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_deadlock_detector2.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_deadlock_detector2.cc Sun May 6 22:56:24 2018
@@ -111,7 +111,7 @@ struct DD : public DDetector {
SpinMutex mtx;
InternalMmapVector<u32> free_id;
- int id_gen;
+ int id_gen = 0;
};
DDetector *DDetector::Create(const DDFlags *flags) {
@@ -120,11 +120,7 @@ DDetector *DDetector::Create(const DDFla
return new(mem) DD(flags);
}
-DD::DD(const DDFlags *flags)
- : flags(*flags)
- , free_id(1024) {
- id_gen = 0;
-}
+DD::DD(const DDFlags *flags) : flags(*flags) { free_id.reserve(1024); }
DDPhysicalThread* DD::CreatePhysicalThread() {
DDPhysicalThread *pt = (DDPhysicalThread*)MmapOrDie(sizeof(DDPhysicalThread),
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Sun May 6 22:56:24 2018
@@ -1032,7 +1032,8 @@ void FormatUUID(char *out, uptr size, co
void PrintModuleMap() {
Printf("Process module map:\n");
MemoryMappingLayout memory_mapping(false);
- InternalMmapVector<LoadedModule> modules(/*initial_capacity*/ 128);
+ InternalMmapVector<LoadedModule> modules;
+ modules.reserve(128);
memory_mapping.DumpListOfModules(&modules);
InternalSort(&modules, modules.size(), CompareBaseAddress);
for (uptr i = 0; i < modules.size(); ++i) {
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=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc Sun May 6 22:56:24 2018
@@ -135,8 +135,8 @@ bool StackDepotReverseMap::IdDescPair::I
return a.id < b.id;
}
-StackDepotReverseMap::StackDepotReverseMap()
- : map_(StackDepotGetStats()->n_uniq_ids + 100) {
+StackDepotReverseMap::StackDepotReverseMap() {
+ map_.reserve(StackDepotGetStats()->n_uniq_ids + 100);
for (int idx = 0; idx < StackDepot::kTabSize; idx++) {
atomic_uintptr_t *p = &theDepot.tab[idx];
uptr v = atomic_load(p, memory_order_consume);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc Sun May 6 22:56:24 2018
@@ -88,7 +88,7 @@ namespace __sanitizer {
class SuspendedThreadsListLinux : public SuspendedThreadsList {
public:
- SuspendedThreadsListLinux() : thread_ids_(1024) {}
+ SuspendedThreadsListLinux() { thread_ids_.reserve(1024); }
tid_t GetThreadID(uptr index) const;
uptr ThreadCount() const;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_suppressions.cc Sun May 6 22:56:24 2018
@@ -25,7 +25,7 @@ namespace __sanitizer {
SuppressionContext::SuppressionContext(const char *suppression_types[],
int suppression_types_num)
: suppression_types_(suppression_types),
- suppression_types_num_(suppression_types_num), suppressions_(1),
+ suppression_types_num_(suppression_types_num),
can_parse_(true) {
CHECK_LE(suppression_types_num_, kMaxSuppressionTypes);
internal_memset(has_suppression_type_, 0, suppression_types_num_);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h Sun May 6 22:56:24 2018
@@ -132,8 +132,9 @@ class Symbolizer final {
class ModuleNameOwner {
public:
explicit ModuleNameOwner(BlockingMutex *synchronized_by)
- : storage_(kInitialCapacity), last_match_(nullptr),
- mu_(synchronized_by) {}
+ : last_match_(nullptr), mu_(synchronized_by) {
+ storage_.reserve(kInitialCapacity);
+ }
const char *GetOwnedCopy(const char *str);
private:
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc Sun May 6 22:56:24 2018
@@ -315,8 +315,9 @@ class Addr2LinePool : public SymbolizerT
public:
explicit Addr2LinePool(const char *addr2line_path,
LowLevelAllocator *allocator)
- : addr2line_path_(addr2line_path), allocator_(allocator),
- addr2line_pool_(16) {}
+ : addr2line_path_(addr2line_path), allocator_(allocator) {
+ addr2line_pool_.reserve(16);
+ }
bool SymbolizePC(uptr addr, SymbolizedStack *stack) override {
if (const char *buf =
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc Sun May 6 22:56:24 2018
@@ -89,7 +89,7 @@ TEST(SanitizerCommon, MmapAlignedOrDieOn
}
TEST(SanitizerCommon, InternalMmapVector) {
- InternalMmapVector<uptr> vector(1);
+ InternalMmapVector<uptr> vector;
for (uptr i = 0; i < 100; i++) {
EXPECT_EQ(i, vector.size());
vector.push_back(i);
@@ -102,7 +102,7 @@ TEST(SanitizerCommon, InternalMmapVector
vector.pop_back();
EXPECT_EQ((uptr)i, vector.size());
}
- InternalMmapVector<uptr> empty_vector(0);
+ InternalMmapVector<uptr> empty_vector;
CHECK_GT(empty_vector.capacity(), 0U);
CHECK_EQ(0U, empty_vector.size());
}
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc Sun May 6 22:56:24 2018
@@ -37,7 +37,8 @@ TEST(MemoryMappingLayout, DumpListOfModu
const char *binary_name = last_slash ? last_slash + 1 : argv0;
MemoryMappingLayout memory_mapping(false);
const uptr kMaxModules = 100;
- InternalMmapVector<LoadedModule> modules(kMaxModules);
+ InternalMmapVector<LoadedModule> modules;
+ modules.reserve(kMaxModules);
memory_mapping.DumpListOfModules(&modules);
EXPECT_GT(modules.size(), 0U);
bool found = false;
@@ -56,7 +57,8 @@ TEST(MemoryMapping, LoadedModuleArchAndU
if (SANITIZER_MAC) {
MemoryMappingLayout memory_mapping(false);
const uptr kMaxModules = 100;
- InternalMmapVector<LoadedModule> modules(kMaxModules);
+ InternalMmapVector<LoadedModule> modules;
+ modules.reserve(kMaxModules);
memory_mapping.DumpListOfModules(&modules);
for (uptr i = 0; i < modules.size(); ++i) {
ModuleArch arch = modules[i].arch();
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Sun May 6 22:56:24 2018
@@ -105,8 +105,8 @@ Context::Context()
, racy_stacks()
, racy_addresses()
, fired_suppressions_mtx(MutexTypeFired, StatMtxFired)
- , fired_suppressions(8)
, clock_alloc("clock allocator") {
+ fired_suppressions.reserve(8);
}
// The objects are allocated in TLS, so one may rely on zero-initialization.
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc?rev=331617&r1=331616&r2=331617&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc Sun May 6 22:56:24 2018
@@ -152,7 +152,7 @@ uptr IsSuppressed(ReportType typ, const
}
void PrintMatchedSuppressions() {
- InternalMmapVector<Suppression *> matched(1);
+ InternalMmapVector<Suppression *> matched;
CHECK(suppression_ctx);
suppression_ctx->GetMatched(&matched);
if (!matched.size())
More information about the llvm-commits
mailing list