From 2cbcf465b5f9df99ddafd6c3988c56f493108312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 7 May 2024 07:44:15 +0000 Subject: [PATCH] Bug 1895346 - Drop nsStringStats. r=nika,xpcom-reviewers As per the discussion in D208771, they don't bring much value so seems worth doing this first. Differential Revision: https://phabricator.services.mozilla.com/D209580 --- xpcom/string/moz.build | 3 -- xpcom/string/nsStringBuffer.cpp | 7 ---- xpcom/string/nsStringStats.cpp | 68 --------------------------------- xpcom/string/nsStringStats.h | 35 ----------------- xpcom/string/nsTSubstring.cpp | 4 -- 5 files changed, 117 deletions(-) delete mode 100644 xpcom/string/nsStringStats.cpp delete mode 100644 xpcom/string/nsStringStats.h diff --git a/xpcom/string/moz.build b/xpcom/string/moz.build index c0f8091b8fbc..1220a16bc8c2 100644 --- a/xpcom/string/moz.build +++ b/xpcom/string/moz.build @@ -56,7 +56,4 @@ UNIFIED_SOURCES += [ "RustStringAPI.cpp", ] -if CONFIG["MOZ_DEBUG"]: - UNIFIED_SOURCES += ["nsStringStats.cpp"] - FINAL_LIBRARY = "xul" diff --git a/xpcom/string/nsStringBuffer.cpp b/xpcom/string/nsStringBuffer.cpp index 8a59f9f0c251..196630dd53a9 100644 --- a/xpcom/string/nsStringBuffer.cpp +++ b/xpcom/string/nsStringBuffer.cpp @@ -9,7 +9,6 @@ #include "mozilla/MemoryReporting.h" #include "nsISupportsImpl.h" #include "nsString.h" -#include "nsStringStats.h" void nsStringBuffer::AddRef() { // Memory synchronization is not required when incrementing a @@ -28,7 +27,6 @@ void nsStringBuffer::AddRef() { + 1 #endif ; - STRING_STAT_INCREMENT(Share); NS_LOG_ADDREF(this, count, "nsStringBuffer", sizeof(*this)); } @@ -46,7 +44,6 @@ void nsStringBuffer::Release() { // writes prior to that release are now visible on this thread. count = mRefCount.load(std::memory_order_acquire); - STRING_STAT_INCREMENT(Free); free(this); // we were allocated with |malloc| } } @@ -62,8 +59,6 @@ already_AddRefed nsStringBuffer::Alloc(size_t aSize) { auto* hdr = (nsStringBuffer*)malloc(sizeof(nsStringBuffer) + aSize); if (hdr) { - STRING_STAT_INCREMENT(Alloc); - hdr->mRefCount = 1; hdr->mStorageSize = aSize; NS_LOG_ADDREF(hdr, 1, "nsStringBuffer", sizeof(*hdr)); @@ -96,8 +91,6 @@ already_AddRefed nsStringBuffer::Create(const char16_t* aData, } nsStringBuffer* nsStringBuffer::Realloc(nsStringBuffer* aHdr, size_t aSize) { - STRING_STAT_INCREMENT(Realloc); - NS_ASSERTION(aSize != 0, "zero capacity allocation not allowed"); NS_ASSERTION(sizeof(nsStringBuffer) + aSize <= size_t(uint32_t(-1)) && sizeof(nsStringBuffer) + aSize > aSize, diff --git a/xpcom/string/nsStringStats.cpp b/xpcom/string/nsStringStats.cpp deleted file mode 100644 index 9766021b69eb..000000000000 --- a/xpcom/string/nsStringStats.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsStringStats.h" - -#ifdef DEBUG -# include "mozilla/IntegerPrintfMacros.h" -# include "mozilla/MemoryReporting.h" -# include "nsString.h" - -# include -# include - -# ifdef XP_WIN -# include -# include -# else -# include -# include -# endif - -nsStringStats gStringStats; - -nsStringStats::~nsStringStats() { - // this is a hack to suppress duplicate string stats printing - // in seamonkey as a result of the string code being linked - // into seamonkey and libxpcom! :-( - if (!mAllocCount && !mAdoptCount) { - return; - } - - // Only print the stats if we detect a leak. - if (mAllocCount <= mFreeCount && mAdoptCount <= mAdoptFreeCount) { - return; - } - - printf("nsStringStats\n"); - printf(" => mAllocCount: % 10d\n", int(mAllocCount)); - printf(" => mReallocCount: % 10d\n", int(mReallocCount)); - printf(" => mFreeCount: % 10d", int(mFreeCount)); - if (mAllocCount > mFreeCount) { - printf(" -- LEAKED %d !!!\n", mAllocCount - mFreeCount); - } else { - printf("\n"); - } - printf(" => mShareCount: % 10d\n", int(mShareCount)); - printf(" => mAdoptCount: % 10d\n", int(mAdoptCount)); - printf(" => mAdoptFreeCount: % 10d", int(mAdoptFreeCount)); - if (mAdoptCount > mAdoptFreeCount) { - printf(" -- LEAKED %d !!!\n", mAdoptCount - mAdoptFreeCount); - } else { - printf("\n"); - } - -# ifdef XP_WIN - auto pid = uintptr_t(_getpid()); - auto tid = uintptr_t(GetCurrentThreadId()); -# else - auto pid = uintptr_t(getpid()); - auto tid = uintptr_t(pthread_self()); -# endif - - printf(" => Process ID: %" PRIuPTR ", Thread ID: %" PRIuPTR "\n", pid, tid); -} -#endif diff --git a/xpcom/string/nsStringStats.h b/xpcom/string/nsStringStats.h deleted file mode 100644 index 24523f5bf08b..000000000000 --- a/xpcom/string/nsStringStats.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef nsStringStats_h -#define nsStringStats_h - -#ifdef DEBUG -# include "mozilla/Atomics.h" - -class nsStringStats { - public: - nsStringStats() = default; - - ~nsStringStats(); - - using AtomicInt = mozilla::Atomic; - - AtomicInt mAllocCount{0}; - AtomicInt mReallocCount{0}; - AtomicInt mFreeCount{0}; - AtomicInt mShareCount{0}; - AtomicInt mAdoptCount{0}; - AtomicInt mAdoptFreeCount{0}; -}; - -extern nsStringStats gStringStats; -# define STRING_STAT_INCREMENT(_s) (gStringStats.m##_s##Count)++ -#else -# define STRING_STAT_INCREMENT(_s) -#endif - -#endif // nsStringStats_h diff --git a/xpcom/string/nsTSubstring.cpp b/xpcom/string/nsTSubstring.cpp index 412465188ad6..fdad8c492c9d 100644 --- a/xpcom/string/nsTSubstring.cpp +++ b/xpcom/string/nsTSubstring.cpp @@ -16,7 +16,6 @@ #include "nsISupports.h" #include "nsString.h" #include "nsTArray.h" -#include "nsStringStats.h" // It's not worthwhile to reallocate the buffer and memcpy the // contents over when the size difference isn't large. With @@ -58,7 +57,6 @@ static void ReleaseData(void* aData, nsAString::DataFlags aFlags) { MOZ_LOG_DTOR(aData, "StringAdopt", 1); free(aData); - STRING_STAT_INCREMENT(AdoptFree); } // otherwise, nothing to do. } @@ -74,7 +72,6 @@ nsTSubstring::nsTSubstring(char_type* aData, size_type aLength, AssertValid(); if (aDataFlags & DataFlags::OWNED) { - STRING_STAT_INCREMENT(Adopt); MOZ_LOG_CTOR(this->mData, "StringAdopt", 1); } } @@ -626,7 +623,6 @@ void nsTSubstring::Adopt(char_type* aData, size_type aLength) { SetData(aData, aLength, DataFlags::TERMINATED | DataFlags::OWNED); - STRING_STAT_INCREMENT(Adopt); // Treat this as construction of a "StringAdopt" object for leak // tracking purposes. MOZ_LOG_CTOR(this->mData, "StringAdopt", 1);