Verified Commit efee8978 authored by Jon Coppeard's avatar Jon Coppeard Committed by ma1
Browse files

Bug 1828024 - Require the helper thread lock in the GC helper thread count getter r=sfink

This makes us take a lock to read this state (we already lock when writing it).

Also it adds a release assert in case something goes wrong with the thread
count calculations, as a crash is preferable to the potential deadlock.

Differential Revision: https://phabricator.services.mozilla.com/D181257
parent 30d19aa0
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -1331,6 +1331,11 @@ void GCRuntime::assertNoMarkingWork() const {
}
#endif

static size_t GetGCParallelThreadCount() {
  AutoLockHelperThreadState lock;
  return HelperThreadState().getGCParallelThreadCount(lock);
}

bool GCRuntime::updateMarkersVector() {
  MOZ_ASSERT(helperThreadCount >= 1,
             "There must always be at least one mark task");
@@ -1339,8 +1344,8 @@ bool GCRuntime::updateMarkersVector() {

  // Limit worker count to number of GC parallel tasks that can run
  // concurrently, otherwise one thread can deadlock waiting on another.
  size_t targetCount = std::min(markingWorkerCount(),
                                HelperThreadState().getGCParallelThreadCount());
  size_t targetCount =
      std::min(markingWorkerCount(), GetGCParallelThreadCount());

  if (markers.length() > targetCount) {
    return markers.resize(targetCount);
+4 −0
Original line number Diff line number Diff line
@@ -103,6 +103,10 @@ bool ParallelMarker::markOneColor(MarkColor color, SliceBudget& sliceBudget) {
  {
    AutoLockHelperThreadState lock;

    // There should always be enough parallel tasks to run our marking work.
    MOZ_RELEASE_ASSERT(HelperThreadState().getGCParallelThreadCount(lock) >=
                       workerCount());

    for (size_t i = 0; i < workerCount(); i++) {
      gc->startTask(*tasks[i], lock);
    }
+4 −2
Original line number Diff line number Diff line
@@ -333,9 +333,11 @@ class GlobalHelperThreadState {

  GCParallelTaskList& gcParallelWorklist() { return gcParallelWorklist_; }

  size_t getGCParallelThreadCount() const { return gcParallelThreadCount; }
  size_t getGCParallelThreadCount(const AutoLockHelperThreadState& lock) const {
    return gcParallelThreadCount;
  }
  void setGCParallelThreadCount(size_t count,
                                const AutoLockHelperThreadState&) {
                                const AutoLockHelperThreadState& lock) {
    MOZ_ASSERT(count >= 1);
    MOZ_ASSERT(count <= threadCount);
    gcParallelThreadCount = count;