Bug 1436179: Remove redundant entryStorage member. r=mstange
I can't think why would it be needed, if I understand the threading model
correctly this code is effectively equivalent.
MozReview-Commit-ID: IQY4ysB2fIm
--- a/js/public/ProfilingStack.h
+++ b/js/public/ProfilingStack.h
@@ -314,16 +314,17 @@ RegisterContextProfilingEventMarker(JSCo
class PseudoStack final
{
public:
PseudoStack()
: stackPointer(0)
{}
~PseudoStack() {
+ delete[] entries;
// The label macros keep a reference to the PseudoStack to avoid a TLS
// access. If these are somehow not all cleared we will get a
// use-after-free so better to crash now.
MOZ_RELEASE_ASSERT(stackPointer == 0);
}
void pushCppFrame(const char* label, const char* dynamicString, void* sp, uint32_t line,
js::ProfileEntry::Kind kind, js::ProfileEntry::Category category) {
@@ -390,39 +391,37 @@ class PseudoStack final
MOZ_ASSERT(entryCapacity >= stackPointer);
if (stackPointer >= MaxEntries) {
return;
}
// Ensure that entries is always sane here.
if (entryCapacity == stackPointer) {
size_t newCapacity = entryCapacity ? entryCapacity * 2 : kInitialCapacity;
- auto newStorage = mozilla::MakeUnique<js::ProfileEntry[]>(newCapacity);
+ auto* newEntries = new js::ProfileEntry[newCapacity];
for (auto i : mozilla::IntegerRange(entryCapacity)) {
- newStorage[i] = entries[i];
+ newEntries[i] = entries[i];
}
- entries = newStorage.get();
- entryStorage = mozilla::Move(newStorage);
+ js::ProfileEntry* oldEntries = entries;
+ entries = newEntries;
entryCapacity = newCapacity;
+ delete[] oldEntries;
}
cb(entries[stackPointer]);
}
- // The actual storage for the entries, only mutated in the current thread.
- mozilla::UniquePtr<js::ProfileEntry[]> entryStorage;
size_t entryCapacity = 0;
public:
static const uint32_t MaxEntries = 1024;
// The pointer to the stack entries, this is read from the profiler thread and written from the
// current thread.
//
- // This will almost always be a pointer to entryStorage, except during a very short period of
- // time when we're growing it to push a frame.
+ // This is effectively a unique pointer.
mozilla::Atomic<js::ProfileEntry*> entries;
// This may exceed MaxEntries, so instead use the stackSize() method to
// determine the number of valid samples in entries. When this is less
// than MaxEntries, it refers to the first free entry past the top of the
// in-use stack (i.e. entries[stackPointer - 1] is the top stack entry).
//
// WARNING WARNING WARNING