diff options
author | Dean Michael Berris <dberris@google.com> | 2018-10-22 02:11:27 +0000 |
---|---|---|
committer | Dean Michael Berris <dberris@google.com> | 2018-10-22 02:11:27 +0000 |
commit | ebfbf89000f7b698e502dcb8a8a5d8bd2ec2742f (patch) | |
tree | e1b8bc89d23cbea9d17dd2637f7e1f262409d53d /compiler-rt/lib/xray/xray_segmented_array.h | |
parent | dbabdfaca5c9a82d706fcc1111cac36a3f04699f (diff) | |
download | bcm5719-llvm-ebfbf89000f7b698e502dcb8a8a5d8bd2ec2742f.tar.gz bcm5719-llvm-ebfbf89000f7b698e502dcb8a8a5d8bd2ec2742f.zip |
[XRay] Handle allocator exhaustion in segmented array
Summary:
This change allows us to handle allocator exhaustion properly in the
segmented array implementation. Before this change, we relied on the
caller of the `trim` function to provide a valid number of elements to
trim. This change allows us to do the right thing in case the elements
to trim is greater than the size of the container.
Reviewers: mboerger, eizan
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D53484
llvm-svn: 344880
Diffstat (limited to 'compiler-rt/lib/xray/xray_segmented_array.h')
-rw-r--r-- | compiler-rt/lib/xray/xray_segmented_array.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/compiler-rt/lib/xray/xray_segmented_array.h b/compiler-rt/lib/xray/xray_segmented_array.h index c723c7de083..42f53be1e01 100644 --- a/compiler-rt/lib/xray/xray_segmented_array.h +++ b/compiler-rt/lib/xray/xray_segmented_array.h @@ -78,6 +78,8 @@ public: static SegmentBase SentinelSegment; + using size_type = size_t; + private: AllocatorType *Alloc; SegmentBase *Head = &SentinelSegment; @@ -334,9 +336,8 @@ public: if (Elements == 0) return; - DCHECK_LE(Elements, Size); - DCHECK_GT(Size, 0); auto OldSize = Size; + Elements = Elements >= Size ? Size : Elements; Size -= Elements; DCHECK_NE(Head, &SentinelSegment); @@ -346,8 +347,11 @@ public: nearest_boundary(Size, ElementsPerSegment)) / ElementsPerSegment; SegmentsToTrim > 0; --SegmentsToTrim) { - DCHECK_NE(Head, &SentinelSegment); - DCHECK_NE(Tail, &SentinelSegment); + + // We want to short-circuit if the trace is already empty. + if (Head == &SentinelSegment && Head == Tail) + return; + // Put the tail into the Freelist. auto *FreeSegment = Tail; Tail = Tail->Prev; |