diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
commit | 59203c63bb777a3bacec32fb8830fba33540e809 (patch) | |
tree | 58298e711c0ff0575818c30485b44a2f21bf28a0 /memory | |
parent | Adding upstream version 126.0.1. (diff) | |
download | firefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip |
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'memory')
-rw-r--r-- | memory/build/FdPrintf.cpp | 4 | ||||
-rw-r--r-- | memory/build/FdPrintf.h | 8 | ||||
-rw-r--r-- | memory/build/PHC.cpp | 25 | ||||
-rw-r--r-- | memory/build/mozjemalloc.cpp | 15 | ||||
-rw-r--r-- | memory/build/replace_malloc_bridge.h | 10 | ||||
-rw-r--r-- | memory/gtest/moz.build | 5 | ||||
-rw-r--r-- | memory/replace/logalloc/LogAlloc.cpp | 4 | ||||
-rw-r--r-- | memory/replace/logalloc/replay/Replay.cpp | 8 |
8 files changed, 53 insertions, 26 deletions
diff --git a/memory/build/FdPrintf.cpp b/memory/build/FdPrintf.cpp index 272f3d0db8..ca23c33dc2 100644 --- a/memory/build/FdPrintf.cpp +++ b/memory/build/FdPrintf.cpp @@ -89,7 +89,7 @@ static void WriteDigits(CheckedIncrement<char*>& b, size_t i, } while (x > 0); } -void FdPrintf(intptr_t aFd, const char* aFormat, ...) { +void FdPrintf(platform_handle_t aFd, const char* aFormat, ...) { if (aFd == 0) { return; } @@ -192,7 +192,7 @@ out: #ifdef _WIN32 // See comment in FdPrintf.h as to why WriteFile is used. DWORD written; - WriteFile(reinterpret_cast<HANDLE>(aFd), buf, b - buf, &written, nullptr); + WriteFile(aFd, buf, b - buf, &written, nullptr); #else MOZ_UNUSED(write(aFd, buf, b - buf)); #endif diff --git a/memory/build/FdPrintf.h b/memory/build/FdPrintf.h index 257084243b..ad333c77fd 100644 --- a/memory/build/FdPrintf.h +++ b/memory/build/FdPrintf.h @@ -7,6 +7,12 @@ #ifndef __FdPrintf_h__ #define __FdPrintf_h__ +#ifdef _WIN32 +typedef void* platform_handle_t; +#else +typedef int platform_handle_t; +#endif + /* We can't use libc's (f)printf because it would reenter in replace_malloc, * So use a custom and simplified version. Only %p, %zu, %s and %% are * supported, %zu, %s, support width specifiers. @@ -18,7 +24,7 @@ * APIs is that they don't support O_APPEND in a multi-process-safe way, * while CreateFile does. */ -void FdPrintf(intptr_t aFd, const char* aFormat, ...) +void FdPrintf(platform_handle_t aFd, const char* aFormat, ...) #ifdef __GNUC__ __attribute__((format(printf, 2, 3))) #endif diff --git a/memory/build/PHC.cpp b/memory/build/PHC.cpp index 88c95743eb..8774024bcd 100644 --- a/memory/build/PHC.cpp +++ b/memory/build/PHC.cpp @@ -1395,21 +1395,27 @@ inline void* MozJemallocPHC::calloc(size_t aNum, size_t aReqSize) { // // In summary: realloc doesn't change the allocation kind unless it must. // -MOZ_ALWAYS_INLINE static void* MaybePageRealloc( +// This function may return: +// - Some(pointer) when PHC handled the reallocation. +// - Some(nullptr) when PHC should have handled a page-to-normal transition +// but couldn't because of OOM. +// - Nothing() when PHC is disabled or the original allocation was not +// under PHC. +MOZ_ALWAYS_INLINE static Maybe<void*> MaybePageRealloc( const Maybe<arena_id_t>& aArenaId, void* aOldPtr, size_t aNewSize) { if (!aOldPtr) { // Null pointer. Treat like malloc(aNewSize). - return PageMalloc(aArenaId, aNewSize); + return Some(PageMalloc(aArenaId, aNewSize)); } if (!maybe_init()) { - return nullptr; + return Nothing(); } PtrKind pk = gConst->PtrKind(aOldPtr); if (pk.IsNothing()) { // A normal-to-normal transition. - return nullptr; + return Nothing(); } if (pk.IsGuardPage()) { @@ -1454,7 +1460,7 @@ MOZ_ALWAYS_INLINE static void* MaybePageRealloc( memmove(newPtr, aOldPtr, std::min(oldUsableSize, aNewSize)); gMut->ResizePageInUse(lock, index, aArenaId, newPtr, stack); LOG("PageRealloc-Reuse(%p, %zu) -> %p\n", aOldPtr, aNewSize, newPtr); - return newPtr; + return Some(newPtr); } // A page-to-normal transition (with the new size greater than page-sized). @@ -1469,7 +1475,7 @@ MOZ_ALWAYS_INLINE static void* MaybePageRealloc( : MozJemalloc::malloc(aNewSize)); } if (!newPtr) { - return nullptr; + return Some(nullptr); } Delay reuseDelay = ReuseDelay(lock); @@ -1484,14 +1490,15 @@ MOZ_ALWAYS_INLINE static void* MaybePageRealloc( aOldPtr, index, aNewSize, newPtr, size_t(reuseDelay), size_t(GAtomic::Now()) + reuseDelay); - return newPtr; + return Some(newPtr); } MOZ_ALWAYS_INLINE static void* PageRealloc(const Maybe<arena_id_t>& aArenaId, void* aOldPtr, size_t aNewSize) { - void* ptr = MaybePageRealloc(aArenaId, aOldPtr, aNewSize); + Maybe<void*> ptr = MaybePageRealloc(aArenaId, aOldPtr, aNewSize); - return ptr ? ptr + return ptr.isSome() + ? *ptr : (aArenaId.isSome() ? MozJemalloc::moz_arena_realloc( *aArenaId, aOldPtr, aNewSize) : MozJemalloc::realloc(aOldPtr, aNewSize)); diff --git a/memory/build/mozjemalloc.cpp b/memory/build/mozjemalloc.cpp index 9c63705ce7..27ad60c076 100644 --- a/memory/build/mozjemalloc.cpp +++ b/memory/build/mozjemalloc.cpp @@ -438,7 +438,13 @@ struct arena_chunk_t { // Maximum size of L1 cache line. This is used to avoid cache line aliasing, // so over-estimates are okay (up to a point), but under-estimates will // negatively affect performance. -static const size_t kCacheLineSize = 64; +static const size_t kCacheLineSize = +#if defined(XP_DARWIN) && defined(__aarch64__) + 128 +#else + 64 +#endif + ; // Our size classes are inclusive ranges of memory sizes. By describing the // minimums and how memory is allocated in each range the maximums can be @@ -1518,7 +1524,12 @@ MALLOC_RUNTIME_VAR PoisonType opt_poison = ALL; MALLOC_RUNTIME_VAR PoisonType opt_poison = SOME; #endif -MALLOC_RUNTIME_VAR size_t opt_poison_size = kCacheLineSize * 4; +// Keep this larger than and ideally a multiple of kCacheLineSize; +MALLOC_RUNTIME_VAR size_t opt_poison_size = 256; +#ifndef MALLOC_RUNTIME_CONFIG +static_assert(opt_poison_size >= kCacheLineSize); +static_assert((opt_poison_size % kCacheLineSize) == 0); +#endif static bool opt_randomize_small = true; diff --git a/memory/build/replace_malloc_bridge.h b/memory/build/replace_malloc_bridge.h index 6a0604d896..0e1a9e9f75 100644 --- a/memory/build/replace_malloc_bridge.h +++ b/memory/build/replace_malloc_bridge.h @@ -48,6 +48,12 @@ struct ReplaceMallocBridge; #include "mozilla/Types.h" +#ifdef _WIN32 +typedef void* platform_handle_t; +#else +typedef int platform_handle_t; +#endif + MOZ_BEGIN_EXTERN_C #ifndef REPLACE_MALLOC_IMPL @@ -124,9 +130,9 @@ class AddrInfo; // Callbacks to register debug file handles for Poison IO interpose. // See Mozilla(|Un)RegisterDebugHandle in xpcom/build/PoisonIOInterposer.h struct DebugFdRegistry { - virtual void RegisterHandle(intptr_t aFd); + virtual void RegisterHandle(platform_handle_t aFd); - virtual void UnRegisterHandle(intptr_t aFd); + virtual void UnRegisterHandle(platform_handle_t aFd); }; } // namespace mozilla diff --git a/memory/gtest/moz.build b/memory/gtest/moz.build index 973d0b4dda..dad30f4b63 100644 --- a/memory/gtest/moz.build +++ b/memory/gtest/moz.build @@ -4,10 +4,7 @@ # 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/. -# skip the test on windows10-aarch64 due to perma-crash - bug 1544961 -if CONFIG["OS_TARGET"] != "Android" and not ( - CONFIG["OS_TARGET"] == "WINNT" and CONFIG["TARGET_CPU"] == "aarch64" -): +if CONFIG["OS_TARGET"] != "Android": UNIFIED_SOURCES += [ "TestJemalloc.cpp", ] diff --git a/memory/replace/logalloc/LogAlloc.cpp b/memory/replace/logalloc/LogAlloc.cpp index a976b0c674..d8fe93929b 100644 --- a/memory/replace/logalloc/LogAlloc.cpp +++ b/memory/replace/logalloc/LogAlloc.cpp @@ -21,7 +21,7 @@ #include "Mutex.h" static malloc_table_t sFuncs; -static intptr_t sFd = 0; +static platform_handle_t sFd = 0; static bool sStdoutOrStderr = false; static Mutex sMutex MOZ_UNANNOTATED; @@ -169,7 +169,7 @@ void replace_init(malloc_table_t* aTable, ReplaceMallocBridge** aBridge) { nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); } if (handle != INVALID_HANDLE_VALUE) { - sFd = reinterpret_cast<intptr_t>(handle); + sFd = handle; } #else if (fd == -1) { diff --git a/memory/replace/logalloc/replay/Replay.cpp b/memory/replace/logalloc/replay/Replay.cpp index a1b3217419..191a192bb8 100644 --- a/memory/replace/logalloc/replay/Replay.cpp +++ b/memory/replace/logalloc/replay/Replay.cpp @@ -458,7 +458,7 @@ class Distribution { mTotalRequests++; } - void printDist(intptr_t std_err) { + void printDist(platform_handle_t std_err) { MOZ_ASSERT(mMaxSize); // The translation to turn a slot index into a memory request size. @@ -533,7 +533,7 @@ class SMapsReader : private FdReader { return Some(SMapsReader(FdReader(fd, true))); } - Maybe<MemoryMap> readMap(intptr_t aStdErr) { + Maybe<MemoryMap> readMap(platform_handle_t aStdErr) { // This is not very tolerant of format changes because things like // parseNumber will crash if they get a bad value. TODO: make this // soft-fail. @@ -615,7 +615,7 @@ class Replay { Replay() { #ifdef _WIN32 // See comment in FdPrintf.h as to why native win32 handles are used. - mStdErr = reinterpret_cast<intptr_t>(GetStdHandle(STD_ERROR_HANDLE)); + mStdErr = GetStdHandle(STD_ERROR_HANDLE); #else mStdErr = fileno(stderr); #endif @@ -1044,7 +1044,7 @@ class Replay { } } - intptr_t mStdErr; + platform_handle_t mStdErr; size_t mOps = 0; // The number of slots that have been used. It is used to iterate over slots |