Commit c2306345 authored by Nicholas Nethercote's avatar Nicholas Nethercote
Browse files

Bug 1297658 - Avoid unnecessary checking in memory reporters. r=erahm.

This patch removes checking of all the callback calls in memory reporter
CollectReport() functions, because it's not useful.

The patch also does some associated clean-up.

- Replaces some uses of nsIMemoryReporterCallback with the preferred
  nsIHandleReportCallback typedef.

- Replaces aCallback/aCb/aClosure with aHandleRepor/aData for CollectReports()
  parameter names, for consistency.

- Adds MOZ_MUST_USE/[must_use] in a few places in nsIMemoryReporter.idl.

- Uses the MOZ_COLLECT_REPORT macro in all suitable places.

Overall the patch reduces code size by ~300 lines and reduces the size of
libxul by about 37 KiB on my Linux64 builds.

--HG--
extra : rebase_source : e94323614bd10463a0c5134a7276238a7ca1cf23
parent 412407ac
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -1081,8 +1081,8 @@ class BlobImplMemoryDataOwnerMemoryReporter final
public:
  NS_DECL_THREADSAFE_ISUPPORTS

  NS_IMETHOD CollectReports(nsIMemoryReporterCallback *aCallback,
                            nsISupports *aClosure, bool aAnonymize) override
  NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
                            nsISupports* aData, bool aAnonymize) override
  {
    typedef BlobImplMemory::DataOwner DataOwner;

@@ -1113,7 +1113,7 @@ public:
          digestString.AppendPrintf("%02x", digest[i]);
        }

        nsresult rv = aCallback->Callback(
        aHandleReport->Callback(
          /* process */ NS_LITERAL_CSTRING(""),
          nsPrintfCString(
            "explicit/dom/memory-file-data/large/file(length=%llu, sha1=%s)",
@@ -1126,13 +1126,12 @@ public:
            "that is, an N-byte memory file may take up more than N bytes of "
            "memory.",
            owner->mLength, digestString.get()),
          aClosure);
        NS_ENSURE_SUCCESS(rv, rv);
          aData);
      }
    }

    if (smallObjectsTotal > 0) {
      nsresult rv = aCallback->Callback(
      aHandleReport->Callback(
        /* process */ NS_LITERAL_CSTRING(""),
        NS_LITERAL_CSTRING("explicit/dom/memory-file-data/small"),
        KIND_HEAP, UNITS_BYTES, smallObjectsTotal,
@@ -1141,8 +1140,7 @@ public:
          "Note that the allocator may round up a memory file's length -- "
          "that is, an N-byte memory file may take up more than N bytes of "
          "memory."),
        aClosure);
      NS_ENSURE_SUCCESS(rv, rv);
        aData);
    }

    return NS_OK;
+3 −1
Original line number Diff line number Diff line
@@ -396,10 +396,12 @@ public:
                       MallocSizeOf)
                   : 0;

    return MOZ_COLLECT_REPORT(
    MOZ_COLLECT_REPORT(
      "explicit/dom/event-listener-managers-hash", KIND_HEAP, UNITS_BYTES,
      amount,
      "Memory used by the event listener manager's hash table.");

    return NS_OK;
  }
};

+15 −24
Original line number Diff line number Diff line
@@ -1578,20 +1578,18 @@ MessageManagerReporter::CountReferents(nsFrameMessageManager* aMessageManager,
  }
}

static nsresult
static void
ReportReferentCount(const char* aManagerType,
                    const MessageManagerReferentCount& aReferentCount,
                    nsIMemoryReporterCallback* aCb,
                    nsISupports* aClosure)
                    nsIHandleReportCallback* aHandleReport,
                    nsISupports* aData)
{
#define REPORT(_path, _amount, _desc) \
    do { \
      nsresult rv;                                                            \
      rv = aCb->Callback(EmptyCString(), _path,                               \
      aHandleReport->Callback(EmptyCString(), _path, \
                              nsIMemoryReporter::KIND_OTHER, \
                              nsIMemoryReporter::UNITS_COUNT, _amount, \
                         _desc, aClosure);                                    \
      NS_ENSURE_SUCCESS(rv, rv);                                              \
                              _desc, aData); \
    } while (0)

  REPORT(nsPrintfCString("message-manager/referent/%s/strong", aManagerType),
@@ -1622,16 +1620,12 @@ ReportReferentCount(const char* aManagerType,
  }

#undef REPORT

  return NS_OK;
}

NS_IMETHODIMP
MessageManagerReporter::CollectReports(nsIMemoryReporterCallback* aCb,
                                       nsISupports* aClosure, bool aAnonymize)
MessageManagerReporter::CollectReports(nsIHandleReportCallback* aHandleReport,
                                       nsISupports* aData, bool aAnonymize)
{
  nsresult rv;

  if (XRE_IsParentProcess()) {
    nsCOMPtr<nsIMessageBroadcaster> globalmm =
      do_GetService("@mozilla.org/globalmessagemanager;1");
@@ -1640,23 +1634,20 @@ MessageManagerReporter::CollectReports(nsIMemoryReporterCallback* aCb,
        static_cast<nsFrameMessageManager*>(globalmm.get());
      MessageManagerReferentCount count;
      CountReferents(mm, &count);
      rv = ReportReferentCount("global-manager", count, aCb, aClosure);
      NS_ENSURE_SUCCESS(rv, rv);
      ReportReferentCount("global-manager", count, aHandleReport, aData);
    }
  }

  if (nsFrameMessageManager::sParentProcessManager) {
    MessageManagerReferentCount count;
    CountReferents(nsFrameMessageManager::sParentProcessManager, &count);
    rv = ReportReferentCount("parent-process-manager", count, aCb, aClosure);
    NS_ENSURE_SUCCESS(rv, rv);
    ReportReferentCount("parent-process-manager", count, aHandleReport, aData);
  }

  if (nsFrameMessageManager::sChildProcessManager) {
    MessageManagerReferentCount count;
    CountReferents(nsFrameMessageManager::sChildProcessManager, &count);
    rv = ReportReferentCount("child-process-manager", count, aCb, aClosure);
    NS_ENSURE_SUCCESS(rv, rv);
    ReportReferentCount("child-process-manager", count, aHandleReport, aData);
  }

  return NS_OK;
+3 −1
Original line number Diff line number Diff line
@@ -169,11 +169,13 @@ class HostObjectURLsReporter final : public nsIMemoryReporter
  NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
                            nsISupports* aData, bool aAnonymize) override
  {
    return MOZ_COLLECT_REPORT(
    MOZ_COLLECT_REPORT(
      "host-object-urls", KIND_OTHER, UNITS_COUNT,
      gDataTable ? gDataTable->Count() : 0,
      "The number of host objects stored for access via URLs "
      "(e.g. blobs passed to URL.createObjectURL).");

    return NS_OK;
  }
};

+3 −1
Original line number Diff line number Diff line
@@ -412,10 +412,12 @@ NS_IMETHODIMP
nsScriptNameSpaceManager::CollectReports(
  nsIHandleReportCallback* aHandleReport, nsISupports* aData, bool aAnonymize)
{
  return MOZ_COLLECT_REPORT(
  MOZ_COLLECT_REPORT(
    "explicit/script-namespace-manager", KIND_HEAP, UNITS_BYTES,
    SizeOfIncludingThis(ScriptNameSpaceManagerMallocSizeOf),
    "Memory used for the script namespace manager.");

  return NS_OK;
}

size_t
Loading