Commit ca8279e2 authored by Gerald Squelart's avatar Gerald Squelart
Browse files

Bug 1716959 - Remove compulsory proof-of-lock in DoNativeBacktrace and DoSyncSample - r=canaltinova

Since these functions don't need to access profiler functions requiring a lock, they themselves don't need that lock anymore.

Differential Revision: https://phabricator.services.mozilla.com/D122088
parent e8f70d89
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -2263,7 +2263,7 @@ static void DoNativeBacktrace(
// The grammar for entry sequences is in a comment above
// ProfileBuffer::StreamSamplesToJSON.
static inline void DoSharedSample(
    PSLockRef aLock, bool aIsSynchronous, uint32_t aFeatures,
    bool aIsSynchronous, uint32_t aFeatures,
    const ThreadRegistration::UnlockedReaderAndAtomicRWOnThread& aThreadData,
    JsFrame* aJsFrames, const Registers& aRegs, uint64_t aSamplePos,
    uint64_t aBufferRangeStart, ProfileBuffer& aBuffer,
@@ -2273,8 +2273,6 @@ static inline void DoSharedSample(
  MOZ_ASSERT(!aBuffer.IsThreadSafe(),
             "Mutexes cannot be used inside this critical section");

  MOZ_RELEASE_ASSERT(ActivePS::Exists(aLock));

  ProfileBufferCollector collector(aBuffer, aSamplePos, aBufferRangeStart);
  StackWalkControl* stackWalkControlIfSupported = nullptr;
#if defined(HAVE_NATIVE_UNWIND)
@@ -2315,7 +2313,7 @@ static inline void DoSharedSample(

// Writes the components of a synchronous sample to the given ProfileBuffer.
static void DoSyncSample(
    PSLockRef aLock, uint32_t aFeatures,
    uint32_t aFeatures,
    const ThreadRegistration::UnlockedReaderAndAtomicRWOnThread& aThreadData,
    const TimeStamp& aNow, const Registers& aRegs, ProfileBuffer& aBuffer,
    StackCaptureOptions aCaptureOptions) {
@@ -2332,7 +2330,7 @@ static void DoSyncSample(
  TimeDuration delta = aNow - CorePS::ProcessStartTime();
  aBuffer.AddEntry(ProfileBufferEntry::Time(delta.ToMilliseconds()));

  DoSharedSample(aLock, /* aIsSynchronous = */ true, aFeatures, aThreadData,
  DoSharedSample(/* aIsSynchronous = */ true, aFeatures, aThreadData,
                 aThreadData.GetJsFrameBuffer(), aRegs, samplePos,
                 bufferRangeStart, aBuffer, aCaptureOptions);
}
@@ -2347,8 +2345,10 @@ static inline void DoPeriodicSample(
    ProfileBuffer& aBuffer) {
  // WARNING: this function runs within the profiler's "critical section".

  MOZ_RELEASE_ASSERT(ActivePS::Exists(aLock));

  JsFrameBuffer& jsFrames = CorePS::JsFrames(aLock);
  DoSharedSample(aLock, /* aIsSynchronous = */ false, ActivePS::Features(aLock),
  DoSharedSample(/* aIsSynchronous = */ false, ActivePS::Features(aLock),
                 aThreadData, jsFrames, aRegs, aSamplePos, aBufferRangeStart,
                 aBuffer);
}
@@ -5514,7 +5514,7 @@ bool profiler_capture_backtrace_into(ProfileChunkedBuffer& aChunkedBuffer,

  PSAutoLock lock;

  if (!ActivePS::Exists(lock) ||
  if (!profiler_is_active() ||
      aCaptureOptions == StackCaptureOptions::NoStack) {
    return false;
  }
@@ -5536,7 +5536,7 @@ bool profiler_capture_backtrace_into(ProfileChunkedBuffer& aChunkedBuffer,
        regs.Clear();
#endif

        DoSyncSample(lock, *maybeFeatures,
        DoSyncSample(*maybeFeatures,
                     aOnThreadRef.UnlockedReaderAndAtomicRWOnThreadCRef(),
                     TimeStamp::Now(), regs, profileBuffer, aCaptureOptions);