From 6d490604c692ce83ba801ed7b3b0a9baa4f6931b Mon Sep 17 00:00:00 2001 From: Stanca Serban Date: Tue, 12 Sep 2023 07:54:18 +0300 Subject: [PATCH] Backed out 2 changesets (bug 1814798) for multiple phc related failures. Backed out changeset 50b72ab948b2 (bug 1814798) Backed out changeset bf7d386ad43a (bug 1814798) --- memory/build/replace_malloc_bridge.h | 27 +----------------- memory/replace/phc/PHC.cpp | 29 +------------------- modules/libpref/init/StaticPrefList.yaml | 13 --------- modules/libpref/moz.build | 4 --- xpcom/base/PHCManager.cpp | 35 ------------------------ xpcom/base/PHCManager.h | 18 ------------ xpcom/base/moz.build | 12 -------- xpcom/build/XPCOMInit.cpp | 9 ------ xpcom/build/moz.build | 3 -- 9 files changed, 2 insertions(+), 148 deletions(-) delete mode 100644 xpcom/base/PHCManager.cpp delete mode 100644 xpcom/base/PHCManager.h diff --git a/memory/build/replace_malloc_bridge.h b/memory/build/replace_malloc_bridge.h index f47b14218e0c..20683c85df05 100644 --- a/memory/build/replace_malloc_bridge.h +++ b/memory/build/replace_malloc_bridge.h @@ -116,19 +116,6 @@ struct DMDFuncs; } // namespace dmd namespace phc { - -// PHC has three different states: -// * Not compiled in -// * OnlyFree - The memory allocator is hooked but new allocations -// requests will be forwarded to mozjemalloc, free() will -// correctly free any PHC allocations and realloc() will -// "move" PHC allocations to mozjemalloc allocations. -// * Enabled - Full use. -enum PHCState { - OnlyFree, - Enabled, -}; - class AddrInfo; struct MemoryUsage { @@ -152,7 +139,7 @@ struct DebugFdRegistry { } // namespace mozilla struct ReplaceMallocBridge { - ReplaceMallocBridge() : mVersion(6) {} + ReplaceMallocBridge() : mVersion(5) {} // This method was added in version 1 of the bridge. virtual mozilla::dmd::DMDFuncs* GetDMDFuncs() { return nullptr; } @@ -208,11 +195,6 @@ struct ReplaceMallocBridge { // This method was added in version 5 of the bridge. virtual void PHCMemoryUsage(mozilla::phc::MemoryUsage& aMemoryUsage) {} - // Set PHC's state. See the comments above on `PHCState` for the meaning of - // each state. - // This method was added in version 6 of the bridge. - virtual void SetPHCState(mozilla::phc::PHCState aState) {} - # ifndef REPLACE_MALLOC_IMPL // Returns the replace-malloc bridge if its version is at least the // requested one. @@ -287,13 +269,6 @@ struct ReplaceMalloc { singleton->PHCMemoryUsage(aMemoryUsage); } } - - static void SetPHCState(mozilla::phc::PHCState aPHCState) { - auto singleton = ReplaceMallocBridge::Get(/* minimumVersion */ 6); - if (singleton) { - singleton->SetPHCState(aPHCState); - } - } }; # endif diff --git a/memory/replace/phc/PHC.cpp b/memory/replace/phc/PHC.cpp index e5f24c3e029b..ad1b3a49faca 100644 --- a/memory/replace/phc/PHC.cpp +++ b/memory/replace/phc/PHC.cpp @@ -323,9 +323,6 @@ static const size_t kAllPagesSize = kNumAllPages * kPageSize; // AllocAllPages() for more information. static const size_t kAllPagesJemallocSize = kAllPagesSize - kPageSize; -// The default state for PHC. Either Enabled or OnlyFree. -#define DEFAULT_STATE mozilla::phc::OnlyFree - // The junk value used to fill new allocation in debug builds. It's same value // as the one used by mozjemalloc. PHC applies it unconditionally in debug // builds. Unlike mozjemalloc, PHC doesn't consult the MALLOC_OPTIONS @@ -877,14 +874,6 @@ class GMut { } #endif - // Should we make new PHC allocations? - bool ShouldMakeNewAllocations() const { - return mPhcState == mozilla::phc::Enabled; - } - - using PHCState = mozilla::phc::PHCState; - void SetState(PHCState aState) { mPhcState = aState; } - private: template uint64_t RandomSeed() { @@ -944,11 +933,6 @@ class GMut { size_t mPageAllocHits = 0; size_t mPageAllocMisses = 0; #endif - - // This will only ever be updated from one thread. The other threads should - // eventually get the update. - Atomic mPhcState = - Atomic(DEFAULT_STATE); }; Mutex GMut::sMutex; @@ -1090,11 +1074,6 @@ static void* MaybePageAlloc(const Maybe& aArenaId, size_t aReqSize, return nullptr; } - MOZ_ASSERT(gMut); - if (!gMut->ShouldMakeNewAllocations()) { - return nullptr; - } - GAtomic::IncrementNow(); // Decrement the delay. If it's zero, we do a page allocation and reset the @@ -1365,7 +1344,7 @@ MOZ_ALWAYS_INLINE static void* PageRealloc(const Maybe& aArenaId, // Check for realloc() of a freed block. gMut->EnsureValidAndInUse(lock, aOldPtr, index); - if (aNewSize <= kPageSize && gMut->ShouldMakeNewAllocations()) { + if (aNewSize <= kPageSize) { // A page-to-page transition. Just keep using the page allocation. We do // this even if the thread is disabled, because it doesn't create a new // page allocation. Note that ResizePageInUse() checks aArenaId. @@ -1708,12 +1687,6 @@ class PHCBridge : public ReplaceMallocBridge { aMemoryUsage.mFragmentationBytes = 0; } } - - // Enable or Disable PHC at runtime. If PHC is disabled it will still trap - // bad uses of previous allocations, but won't track any new allocations. - virtual void SetPHCState(mozilla::phc::PHCState aState) override { - gMut->SetState(aState); - } }; // WARNING: this function runs *very* early -- before all static initializers diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index e5b45a92ef10..902a91ac8abb 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -11010,19 +11010,6 @@ mirror: always #endif -#--------------------------------------------------------------------------- -# Prefs starting with "memory." -#--------------------------------------------------------------------------- - -- name: memory.phc.enabled - type: bool -#if defined(MOZ_PHC) - value: true -#else - value: false -#endif - mirror: always - #--------------------------------------------------------------------------- # Prefs starting with "midi." #--------------------------------------------------------------------------- diff --git a/modules/libpref/moz.build b/modules/libpref/moz.build index 5a258b61b22e..e8f8b97170d3 100644 --- a/modules/libpref/moz.build +++ b/modules/libpref/moz.build @@ -62,7 +62,6 @@ pref_groups = [ "layout", "mathml", "media", - "memory", "midi", "mousewheel", "mozilla", @@ -173,6 +172,3 @@ else: FINAL_TARGET_PP_FILES += [ "greprefs.js", ] - -if CONFIG["MOZ_PHC"]: - DEFINES["MOZ_PHC"] = True diff --git a/xpcom/base/PHCManager.cpp b/xpcom/base/PHCManager.cpp deleted file mode 100644 index 15c011792508..000000000000 --- a/xpcom/base/PHCManager.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* 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 "PHCManager.h" - -#include "replace_malloc_bridge.h" -#include "mozilla/Preferences.h" -#include "mozilla/StaticPrefs_memory.h" - -namespace mozilla { - -using namespace phc; - -static const char kPHCPref[] = "memory.phc.enabled"; - -static PHCState GetPHCStateFromPref() { - return StaticPrefs::memory_phc_enabled() ? Enabled : OnlyFree; -} - -static void PrefChangeCallback(const char* aPrefName, void* aNull) { - MOZ_ASSERT(0 == strcmp(aPrefName, kPHCPref)); - - ReplaceMalloc::SetPHCState(GetPHCStateFromPref()); -} - -void InitPHCState() { - ReplaceMalloc::SetPHCState(GetPHCStateFromPref()); - - Preferences::RegisterCallback(PrefChangeCallback, kPHCPref); -} - -}; // namespace mozilla diff --git a/xpcom/base/PHCManager.h b/xpcom/base/PHCManager.h deleted file mode 100644 index 066406208094..000000000000 --- a/xpcom/base/PHCManager.h +++ /dev/null @@ -1,18 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* 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 mozilla_PHCManager_h -#define mozilla_PHCManager_h - -namespace mozilla { - -// Read the PHC pref and potentially initialise PHC. Also register a -// callback for the pref to update PHC as the pref changes. -void InitPHCState(); - -}; // namespace mozilla - -#endif // mozilla_PHCManager_h diff --git a/xpcom/base/moz.build b/xpcom/base/moz.build index 1ac409ed04ec..fa7653b31f77 100644 --- a/xpcom/base/moz.build +++ b/xpcom/base/moz.build @@ -257,15 +257,3 @@ LOCAL_INCLUDES += [ if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk": CXXFLAGS += CONFIG["MOZ_GTK3_CFLAGS"] - -if CONFIG["MOZ_PHC"]: - EXPORTS.mozilla += [ - "PHCManager.h", - ] - - DEFINES["MOZ_PHC"] = 1 - - UNIFIED_SOURCES += ["PHCManager.cpp"] - -with Files("PHCManager.*"): - BUG_COMPONENT = ("Core", "Memory Allocator") diff --git a/xpcom/build/XPCOMInit.cpp b/xpcom/build/XPCOMInit.cpp index 9253283ec320..3bd2d2b86ffd 100644 --- a/xpcom/build/XPCOMInit.cpp +++ b/xpcom/build/XPCOMInit.cpp @@ -89,9 +89,6 @@ #include "mozilla/AvailableMemoryTracker.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/CountingAllocatorBase.h" -#ifdef MOZ_PHC -# include "mozilla/PHCManager.h" -#endif #include "mozilla/UniquePtr.h" #include "mozilla/ServoStyleConsts.h" @@ -451,12 +448,6 @@ NS_InitXPCOM(nsIServiceManager** aResult, nsIFile* aBinDirectory, NS_ADDREF(*aResult = nsComponentManagerImpl::gComponentManager); } -#ifdef MOZ_PHC - // This is the earliest possible moment we can start PHC while still being - // able to read prefs. - mozilla::InitPHCState(); -#endif - // After autoreg, but before we actually instantiate any components, // add any services listed in the "xpcom-directory-providers" category // to the directory service. diff --git a/xpcom/build/moz.build b/xpcom/build/moz.build index 232da98ae295..8d08e73978c1 100644 --- a/xpcom/build/moz.build +++ b/xpcom/build/moz.build @@ -103,6 +103,3 @@ if CONFIG["MOZ_VPX"]: LOCAL_INCLUDES += [ "/media/libvpx", ] - -if CONFIG["MOZ_PHC"]: - DEFINES["MOZ_PHC"] = 1