diff --git a/tools/profiler/core/ProfileBufferEntry.cpp b/tools/profiler/core/ProfileBufferEntry.cpp index 3e745bb8779b..f92cfc0e0ce5 100644 --- a/tools/profiler/core/ProfileBufferEntry.cpp +++ b/tools/profiler/core/ProfileBufferEntry.cpp @@ -233,6 +233,23 @@ UniqueStacks::StackKey UniqueStacks::BeginStack(const FrameKey& aFrame) { return StackKey(GetOrAddFrameIndex(aFrame)); } +Vector&& +JITFrameInfo::MoveRangesWithNewFailureLatch(FailureLatch& aFailureLatch) && { + aFailureLatch.SetFailureFrom(mLocalFailureLatchSource); + return std::move(mRanges); +} + +UniquePtr&& +JITFrameInfo::MoveUniqueStringsWithNewFailureLatch( + FailureLatch& aFailureLatch) && { + if (mUniqueStrings) { + mUniqueStrings->ChangeFailureLatchAndForwardState(aFailureLatch); + } else { + aFailureLatch.SetFailureFrom(mLocalFailureLatchSource); + } + return std::move(mUniqueStrings); +} + UniqueStacks::StackKey UniqueStacks::AppendFrame(const StackKey& aStack, const FrameKey& aFrame) { return StackKey(aStack, GetOrAddStackIndex(aStack), @@ -299,13 +316,15 @@ bool UniqueStacks::FrameKey::JITFrameData::operator==( // JIT frame info's string table, so our string table needs to have the same // strings at the same indices. UniqueStacks::UniqueStacks( - JITFrameInfo&& aJITFrameInfo, + FailureLatch& aFailureLatch, JITFrameInfo&& aJITFrameInfo, ProfilerCodeAddressService* aCodeAddressService /* = nullptr */) - : mUniqueStrings(std::move(aJITFrameInfo).MoveUniqueStrings()), + : mUniqueStrings(std::move(aJITFrameInfo) + .MoveUniqueStringsWithNewFailureLatch(aFailureLatch)), mCodeAddressService(aCodeAddressService), - mFrameTableWriter(FailureLatchInfallibleSource::Singleton()), - mStackTableWriter(FailureLatchInfallibleSource::Singleton()), - mJITInfoRanges(std::move(aJITFrameInfo).MoveRanges()) { + mFrameTableWriter(aFailureLatch), + mStackTableWriter(aFailureLatch), + mJITInfoRanges(std::move(aJITFrameInfo) + .MoveRangesWithNewFailureLatch(aFailureLatch)) { mFrameTableWriter.StartBareList(); mStackTableWriter.StartBareList(); } diff --git a/tools/profiler/core/ProfileBufferEntry.h b/tools/profiler/core/ProfileBufferEntry.h index a511a30c83c0..8beec4121e09 100644 --- a/tools/profiler/core/ProfileBufferEntry.h +++ b/tools/profiler/core/ProfileBufferEntry.h @@ -178,12 +178,12 @@ class JITFrameInfo final { return mLocalFailureLatchSource; } - mozilla::Vector&& MoveRanges() && { - return std::move(mRanges); - } - mozilla::UniquePtr&& MoveUniqueStrings() && { - return std::move(mUniqueStrings); - } + // The encapsulated data points at the local FailureLatch, so on the way out + // they must be given a new external FailureLatch to start using instead. + mozilla::Vector&& MoveRangesWithNewFailureLatch( + mozilla::FailureLatch& aFailureLatch) &&; + mozilla::UniquePtr&& MoveUniqueStringsWithNewFailureLatch( + mozilla::FailureLatch& aFailureLatch) &&; private: // JITFrameInfo's may exist during profiling, so it carries its own fallible @@ -202,7 +202,7 @@ class JITFrameInfo final { mozilla::UniquePtr mUniqueStrings; }; -class UniqueStacks { +class UniqueStacks final : public mozilla::FailureLatch { public: struct FrameKey { explicit FrameKey(const char* aLocation) @@ -332,9 +332,9 @@ class UniqueStacks { } }; - explicit UniqueStacks( - JITFrameInfo&& aJITFrameInfo, - ProfilerCodeAddressService* aCodeAddressService = nullptr); + UniqueStacks(mozilla::FailureLatch& aFailureLatch, + JITFrameInfo&& aJITFrameInfo, + ProfilerCodeAddressService* aCodeAddressService = nullptr); // Return a StackKey for aFrame as the stack's root frame (no prefix). [[nodiscard]] StackKey BeginStack(const FrameKey& aFrame); @@ -367,6 +367,8 @@ class UniqueStacks { // provided), otherwise just stringify that PC. [[nodiscard]] nsAutoCString FunctionNameOrAddress(void* aPC); + FAILURELATCH_IMPL_PROXY(mFrameTableWriter) + private: void StreamNonJITFrame(const FrameKey& aFrame); void StreamStack(const StackKey& aStack); diff --git a/tools/profiler/core/ProfiledThreadData.cpp b/tools/profiler/core/ProfiledThreadData.cpp index 0c7504a65062..515b4a7f72fa 100644 --- a/tools/profiler/core/ProfiledThreadData.cpp +++ b/tools/profiler/core/ProfiledThreadData.cpp @@ -125,7 +125,7 @@ ProfiledThreadData::PrepareUniqueStacks( } return mozilla::MakeNotNull>( - std::move(jitFrameInfo), aService); + aFailureLatch, std::move(jitFrameInfo), aService); } void ProfiledThreadData::StreamJSON(