aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Utility/ConstString.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2020-07-31 21:22:58 +0000
committerDimitry Andric <dim@FreeBSD.org>2020-07-31 21:22:58 +0000
commit5ffd83dbcc34f10e07f6d3e968ae6365869615f4 (patch)
tree0e9f5cf729dde39f949698fddef45a34e2bc7f44 /contrib/llvm-project/lldb/source/Utility/ConstString.cpp
parent1799696096df87b52968b8996d00c91e0a5de8d9 (diff)
parentcfca06d7963fa0909f90483b42a6d7d194d01e08 (diff)
downloadsrc-5ffd83dbcc34f10e07f6d3e968ae6365869615f4.tar.gz
src-5ffd83dbcc34f10e07f6d3e968ae6365869615f4.zip
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
master 2e10b7a39b9, the last commit before the llvmorg-12-init tag, from which release/11.x was branched. Note that for now, I rolled back all our local changes to make merging easier, and I will reapply the still-relevant ones after updating to 11.0.0-rc1.
Notes
Notes: svn path=/projects/clang1100-import/; revision=363742
Diffstat (limited to 'contrib/llvm-project/lldb/source/Utility/ConstString.cpp')
-rw-r--r--contrib/llvm-project/lldb/source/Utility/ConstString.cpp48
1 files changed, 44 insertions, 4 deletions
diff --git a/contrib/llvm-project/lldb/source/Utility/ConstString.cpp b/contrib/llvm-project/lldb/source/Utility/ConstString.cpp
index e90bb929bb81..62f79b3df7a5 100644
--- a/contrib/llvm-project/lldb/source/Utility/ConstString.cpp
+++ b/contrib/llvm-project/lldb/source/Utility/ConstString.cpp
@@ -1,4 +1,4 @@
-//===-- ConstString.cpp -----------------------------------------*- C++ -*-===//
+//===-- ConstString.cpp ---------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -29,9 +29,37 @@ using namespace lldb_private;
class Pool {
public:
+ /// The default BumpPtrAllocatorImpl slab size.
+ static const size_t AllocatorSlabSize = 4096;
+ static const size_t SizeThreshold = AllocatorSlabSize;
+ /// Every Pool has its own allocator which receives an equal share of
+ /// the ConstString allocations. This means that when allocating many
+ /// ConstStrings, every allocator sees only its small share of allocations and
+ /// assumes LLDB only allocated a small amount of memory so far. In reality
+ /// LLDB allocated a total memory that is N times as large as what the
+ /// allocator sees (where N is the number of string pools). This causes that
+ /// the BumpPtrAllocator continues a long time to allocate memory in small
+ /// chunks which only makes sense when allocating a small amount of memory
+ /// (which is true from the perspective of a single allocator). On some
+ /// systems doing all these small memory allocations causes LLDB to spend
+ /// a lot of time in malloc, so we need to force all these allocators to
+ /// behave like one allocator in terms of scaling their memory allocations
+ /// with increased demand. To do this we set the growth delay for each single
+ /// allocator to a rate so that our pool of allocators scales their memory
+ /// allocations similar to a single BumpPtrAllocatorImpl.
+ ///
+ /// Currently we have 256 string pools and the normal growth delay of the
+ /// BumpPtrAllocatorImpl is 128 (i.e., the memory allocation size increases
+ /// every 128 full chunks), so by changing the delay to 1 we get a
+ /// total growth delay in our allocator collection of 256/1 = 256. This is
+ /// still only half as fast as a normal allocator but we can't go any faster
+ /// without decreasing the number of string pools.
+ static const size_t AllocatorGrowthDelay = 1;
+ typedef llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, AllocatorSlabSize,
+ SizeThreshold, AllocatorGrowthDelay>
+ Allocator;
typedef const char *StringPoolValueType;
- typedef llvm::StringMap<StringPoolValueType, llvm::BumpPtrAllocator>
- StringPool;
+ typedef llvm::StringMap<StringPoolValueType, Allocator> StringPool;
typedef llvm::StringMapEntry<StringPoolValueType> StringPoolEntryType;
static StringPoolEntryType &
@@ -307,5 +335,17 @@ size_t ConstString::StaticMemorySize() {
void llvm::format_provider<ConstString>::format(const ConstString &CS,
llvm::raw_ostream &OS,
llvm::StringRef Options) {
- format_provider<StringRef>::format(CS.AsCString(), OS, Options);
+ format_provider<StringRef>::format(CS.GetStringRef(), OS, Options);
+}
+
+void llvm::yaml::ScalarTraits<ConstString>::output(const ConstString &Val,
+ void *, raw_ostream &Out) {
+ Out << Val.GetStringRef();
+}
+
+llvm::StringRef
+llvm::yaml::ScalarTraits<ConstString>::input(llvm::StringRef Scalar, void *,
+ ConstString &Val) {
+ Val = ConstString(Scalar);
+ return {};
}