[PATCH] D47695: [XRay][compiler-rt] Remove reliance on C++ ABI from BufferQueue
Dean Michael Berris via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 4 20:51:13 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL333982: [XRay][compiler-rt] Remove reliance on C++ ABI from BufferQueue (authored by dberris, committed by ).
Herald added a subscriber: delcypher.
Changed prior to commit:
https://reviews.llvm.org/D47695?vs=149899&id=149901#toc
Repository:
rL LLVM
https://reviews.llvm.org/D47695
Files:
compiler-rt/trunk/lib/xray/xray_buffer_queue.cc
compiler-rt/trunk/lib/xray/xray_buffer_queue.h
Index: compiler-rt/trunk/lib/xray/xray_buffer_queue.h
===================================================================
--- compiler-rt/trunk/lib/xray/xray_buffer_queue.h
+++ compiler-rt/trunk/lib/xray/xray_buffer_queue.h
@@ -39,7 +39,6 @@
BufferExtents *Extents;
};
-private:
struct BufferRep {
// The managed buffer.
Buffer Buff;
@@ -49,6 +48,7 @@
bool Used = false;
};
+private:
// This models a ForwardIterator. |T| Must be either a `Buffer` or `const
// Buffer`. Note that we only advance to the "used" buffers, when
// incrementing, so that at dereference we're always at a valid point.
Index: compiler-rt/trunk/lib/xray/xray_buffer_queue.cc
===================================================================
--- compiler-rt/trunk/lib/xray/xray_buffer_queue.cc
+++ compiler-rt/trunk/lib/xray/xray_buffer_queue.cc
@@ -16,14 +16,37 @@
#include "sanitizer_common/sanitizer_allocator_internal.h"
#include "sanitizer_common/sanitizer_common.h"
#include "sanitizer_common/sanitizer_libc.h"
+#include <memory>
using namespace __xray;
using namespace __sanitizer;
+template <class T> static T *initArray(size_t N) {
+ auto A = reinterpret_cast<T *>(
+ InternalAlloc(N * sizeof(T), nullptr, kCacheLineSize));
+ if (A != nullptr)
+ while (N > 0)
+ new (A + (--N)) T();
+ return A;
+}
+
BufferQueue::BufferQueue(size_t B, size_t N, bool &Success)
- : BufferSize(B), Buffers(new BufferRep[N]()), BufferCount(N), Finalizing{0},
- OwnedBuffers(new void *[N]()), Next(Buffers), First(Buffers),
- LiveBuffers(0) {
+ : BufferSize(B), Buffers(initArray<BufferQueue::BufferRep>(N)),
+ BufferCount(N), Finalizing{0}, OwnedBuffers(initArray<void *>(N)),
+ Next(Buffers), First(Buffers), LiveBuffers(0) {
+ if (Buffers == nullptr) {
+ Success = false;
+ return;
+ }
+ if (OwnedBuffers == nullptr) {
+ // Clean up the buffers we've already allocated.
+ for (auto B = Buffers, E = Buffers + BufferCount; B != E; ++B)
+ B->~BufferRep();
+ InternalFree(Buffers);
+ Success = false;
+ return;
+ };
+
for (size_t i = 0; i < N; ++i) {
auto &T = Buffers[i];
void *Tmp = InternalAlloc(BufferSize, nullptr, 64);
@@ -109,6 +132,8 @@
InternalFree(Buf.Data);
InternalFree(Buf.Extents);
}
- delete[] Buffers;
- delete[] OwnedBuffers;
+ for (auto B = Buffers, E = Buffers + BufferCount; B != E; ++B)
+ B->~BufferRep();
+ InternalFree(Buffers);
+ InternalFree(OwnedBuffers);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47695.149901.patch
Type: text/x-patch
Size: 2507 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180605/d3d5775b/attachment.bin>
More information about the llvm-commits
mailing list