Bug 1429904 - Put mUniqueStrings into a UniquePtr. r?njn draft
authorMarkus Stange <mstange@themasta.com>
Sat, 17 Feb 2018 15:50:43 -0500
changeset 762108 053e5491c5b0abd9a4f62982ddbc2ff6b17f085f
parent 762107 a9da8a4acb143bb5821af85b0de2bc1bbf41dd49
child 762109 c6b5aa2d7edd7d667d7a4563578ef7614a6d58e8
push id101088
push userbmo:mstange@themasta.com
push dateThu, 01 Mar 2018 20:52:26 +0000
reviewersnjn
bugs1429904
milestone60.0a1
Bug 1429904 - Put mUniqueStrings into a UniquePtr. r?njn In an upcoming patch we'll want to initialize mUniqueStrings by stealing another object's UniqueJSONStrings, but UniqueJSONStrings itself is not move-constructible. But UniquePtr is. Making UniqueJSONStrings itself move-constructible would be a bit tricky because it has a SpliceableChunkedJSONWriter which is not move-constructible; and making SpliceableChunkedJSONWriter move-constructible is hard because there's no obvious "empty but valid" state that we could leave a moved-out-of SpliceableChunkedJSONWriter in; for example, it expects to have a non-null WriteFunc at all times. MozReview-Commit-ID: Q6o61HFTiD
tools/profiler/core/ProfileBufferEntry.cpp
tools/profiler/core/ProfileBufferEntry.h
tools/profiler/core/ProfiledThreadData.cpp
tools/profiler/core/ProfilerMarker.h
--- a/tools/profiler/core/ProfileBufferEntry.cpp
+++ b/tools/profiler/core/ProfileBufferEntry.cpp
@@ -335,16 +335,17 @@ UniqueStacks::FrameKey::Hash() const
     const JITFrameData& data = mData.as<JITFrameData>();
     hash = AddToHash(hash, data.mAddress.Hash());
     hash = AddToHash(hash, data.mDepth);
   }
   return hash;
 }
 
 UniqueStacks::UniqueStacks()
+  : mUniqueStrings(MakeUnique<UniqueJSONStrings>())
 {
   mFrameTableWriter.StartBareList();
   mStackTableWriter.StartBareList();
 }
 
 uint32_t UniqueStacks::GetOrAddStackIndex(const StackKey& aStack)
 {
   uint32_t index;
@@ -429,17 +430,17 @@ void UniqueStacks::SpliceStackTableEleme
 
 void UniqueStacks::StreamStack(const StackKey& aStack)
 {
   enum Schema : uint32_t {
     PREFIX = 0,
     FRAME = 1
   };
 
-  AutoArraySchemaWriter writer(mStackTableWriter, mUniqueStrings);
+  AutoArraySchemaWriter writer(mStackTableWriter, *mUniqueStrings);
   if (aStack.mPrefixStackIndex.isSome()) {
     writer.IntElement(PREFIX, *aStack.mPrefixStackIndex);
   }
   writer.IntElement(FRAME, aStack.mFrameIndex);
 }
 
 void
 UniqueStacks::StreamNonJITFrame(const FrameKey& aFrame)
@@ -449,17 +450,17 @@ UniqueStacks::StreamNonJITFrame(const Fr
   enum Schema : uint32_t {
     LOCATION = 0,
     IMPLEMENTATION = 1,
     OPTIMIZATIONS = 2,
     LINE = 3,
     CATEGORY = 4
   };
 
-  AutoArraySchemaWriter writer(mFrameTableWriter, mUniqueStrings);
+  AutoArraySchemaWriter writer(mFrameTableWriter, *mUniqueStrings);
 
   const NormalFrameData& data = aFrame.mData.as<NormalFrameData>();
   writer.StringElement(LOCATION, data.mLocation.get());
   if (data.mLine.isSome()) {
     writer.IntElement(LINE, *data.mLine);
   }
   if (data.mCategory.isSome()) {
     writer.IntElement(CATEGORY, *data.mCategory);
@@ -566,17 +567,17 @@ UniqueStacks::StreamJITFrame(JSContext* 
   enum Schema : uint32_t {
     LOCATION = 0,
     IMPLEMENTATION = 1,
     OPTIMIZATIONS = 2,
     LINE = 3,
     CATEGORY = 4
   };
 
-  AutoArraySchemaWriter writer(mFrameTableWriter, mUniqueStrings);
+  AutoArraySchemaWriter writer(mFrameTableWriter, *mUniqueStrings);
 
   writer.StringElement(LOCATION, aJITFrame.label());
 
   JS::ProfilingFrameIterator::FrameKind frameKind = aJITFrame.frameKind();
   MOZ_ASSERT(frameKind == JS::ProfilingFrameIterator::Frame_Ion ||
               frameKind == JS::ProfilingFrameIterator::Frame_Baseline);
   writer.StringElement(IMPLEMENTATION,
                         frameKind == JS::ProfilingFrameIterator::Frame_Ion
@@ -954,17 +955,17 @@ ProfileBuffer::StreamSamplesToJSON(Splic
       e.Next();
     }
 
     if (e.Has() && e.Get().IsUnsharedMemory()) {
       sample.mUSS = Some(e.Get().u.mDouble);
       e.Next();
     }
 
-    WriteSample(aWriter, aUniqueStacks.mUniqueStrings, sample);
+    WriteSample(aWriter, *aUniqueStacks.mUniqueStrings, sample);
     haveSamples = true;
   }
 
   return haveSamples;
   #undef ERROR_AND_CONTINUE
 }
 
 // This method returns true if it wrote anything to the writer.
--- a/tools/profiler/core/ProfileBufferEntry.h
+++ b/tools/profiler/core/ProfileBufferEntry.h
@@ -268,17 +268,17 @@ private:
                              const JS::ProfiledFrameHandle& aJITFrame);
 
   void StreamNonJITFrame(const FrameKey& aFrame);
   void StreamJITFrame(JSContext* aContext,
                       const JS::ProfiledFrameHandle& aJITFrame);
   void StreamStack(const StackKey& aStack);
 
 public:
-  UniqueJSONStrings mUniqueStrings;
+  mozilla::UniquePtr<UniqueJSONStrings> mUniqueStrings;
 
 private:
   // To avoid incurring JitcodeGlobalTable lookup costs for every JIT frame,
   // we cache the frame keys of frames keyed by JIT code address. All FrameKeys
   // in mAddressToJITFrameKeysMap are guaranteed to be in mFrameToIndexMap.
   nsClassHashtable<nsGenericHashKey<JITAddress>, nsTArray<FrameKey>> mAddressToJITFrameKeysMap;
 
   SpliceableChunkedJSONWriter mFrameTableWriter;
--- a/tools/profiler/core/ProfiledThreadData.cpp
+++ b/tools/profiler/core/ProfiledThreadData.cpp
@@ -93,17 +93,17 @@ ProfiledThreadData::StreamJSON(const Pro
         uniqueStacks->SpliceFrameTableElements(aWriter);
       }
       aWriter.EndArray();
     }
     aWriter.EndObject();
 
     aWriter.StartArrayProperty("stringTable");
     {
-      uniqueStacks->mUniqueStrings.SpliceStringTableElements(aWriter);
+      uniqueStacks->mUniqueStrings->SpliceStringTableElements(aWriter);
     }
     aWriter.EndArray();
   }
 
   aWriter.End();
 }
 
 void
--- a/tools/profiler/core/ProfilerMarker.h
+++ b/tools/profiler/core/ProfilerMarker.h
@@ -49,17 +49,17 @@ public:
                   const mozilla::TimeStamp& aProcessStartTime,
                   UniqueStacks& aUniqueStacks) const
   {
     // Schema:
     //   [name, time, data]
 
     aWriter.StartArrayElement();
     {
-      aUniqueStacks.mUniqueStrings.WriteElement(aWriter, mMarkerName.get());
+      aUniqueStacks.mUniqueStrings->WriteElement(aWriter, mMarkerName.get());
       aWriter.DoubleElement(mTime);
       // TODO: Store the callsite for this marker if available:
       // if have location data
       //   b.NameValue(marker, "location", ...);
       if (mPayload) {
         aWriter.StartObjectElement(SpliceableJSONWriter::SingleLineStyle);
         {
           mPayload->StreamPayload(aWriter, aProcessStartTime, aUniqueStacks);