Bug 1436179: Remove inline storage, which is now not needed. r?mstange draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 20 Mar 2018 09:43:09 +0100
changeset 769902 e134b7b75cb6322166091aff1fd10e2dc4e9277b
parent 769856 761211f5560a21f8053da4294879b26b32f7be09
push id103252
push userbmo:emilio@crisal.io
push dateTue, 20 Mar 2018 12:06:47 +0000
reviewersmstange
bugs1436179
milestone61.0a1
Bug 1436179: Remove inline storage, which is now not needed. r?mstange MozReview-Commit-ID: I9pS6hqJGTd
js/public/ProfilingStack.h
js/src/perf/ProfilingStack.cpp
--- a/js/public/ProfilingStack.h
+++ b/js/public/ProfilingStack.h
@@ -372,34 +372,29 @@ class PseudoStack final
     // Out of line path for expanding the buffer, since otherwise this would get inlined in every
     // DOM WebIDL call.
     MOZ_COLD MOZ_MUST_USE bool ensureCapacitySlow();
 
     // No copying.
     PseudoStack(const PseudoStack&) = delete;
     void operator=(const PseudoStack&) = delete;
 
-    // No moving either, since we may contain interior pointers to inlineStorage.
+    // No moving either.
     PseudoStack(PseudoStack&&) = delete;
     void operator=(PseudoStack&&) = delete;
 
-    // Reserve capacity for a few frames inline, because this code will run before the SM allocator
-    // is initialized, and we don't want to mess up with malloc / free at that point.
-    static const uint32_t kInlineCapacity = 4;
-
-    uint32_t entryCapacity = kInlineCapacity;
-    js::ProfileEntry inlineStorage[kInlineCapacity];
+    uint32_t entryCapacity = 0;
 
   public:
 
     // The pointer to the stack entries, this is read from the profiler thread and written from the
     // current thread.
     //
     // This is effectively a unique pointer.
-    mozilla::Atomic<js::ProfileEntry*> entries { inlineStorage };
+    mozilla::Atomic<js::ProfileEntry*> entries { nullptr };
 
     // This may exceed the entry capacity, 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
     //
--- a/js/src/perf/ProfilingStack.cpp
+++ b/js/src/perf/ProfilingStack.cpp
@@ -7,47 +7,45 @@
 #include "js/ProfilingStack.h"
 
 #include "mozilla/IntegerRange.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/UniquePtrExtensions.h"
 
 #include <algorithm>
 
-
 using namespace js;
 
 PseudoStack::~PseudoStack()
 {
-    if (entries != inlineStorage)
-        delete[] entries;
+    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);
 }
 
 bool PseudoStack::ensureCapacitySlow()
 {
     MOZ_ASSERT(stackPointer >= entryCapacity);
-    MOZ_ASSERT(entryCapacity > 0);
+    const uint32_t kInitialCapacity = 128;
 
     uint32_t sp = stackPointer;
-    auto newCapacity = std::max(sp + 1, entryCapacity * 2);
+    auto newCapacity = std::max(sp + 1,  entryCapacity ? entryCapacity * 2 : kInitialCapacity);
 
     auto* newEntries =
         new (mozilla::fallible) js::ProfileEntry[newCapacity];
     if (MOZ_UNLIKELY(!newEntries))
         return false;
 
-    // It's important that `entries` / `entryCapacity` / `stackPointer` remain in sync here all
-    // the time.
+    // It's important that `entries` / `entryCapacity` / `stackPointer` remain sane here at all
+    // times.
     for (auto i : mozilla::IntegerRange(entryCapacity))
         newEntries[i] = entries[i];
 
     js::ProfileEntry* oldEntries = entries;
     entries = newEntries;
     entryCapacity = newCapacity;
-    if (oldEntries != inlineStorage)
-        delete[] oldEntries;
+    delete[] oldEntries;
 
     return true;
 }