Bug 1436179: Remove redundant entryStorage member. r=mstange draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sun, 18 Mar 2018 17:23:02 +0100
changeset 769855 03538a2496fc87ec88d2bfae2c583e88e835b992
parent 769854 57b476d4fa77e28d38fc11c423f00db0ba063eb5
child 769856 761211f5560a21f8053da4294879b26b32f7be09
push id103235
push userbmo:emilio@crisal.io
push dateTue, 20 Mar 2018 08:48:29 +0000
reviewersmstange
bugs1436179
milestone61.0a1
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
js/public/ProfilingStack.h
--- 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