summaryrefslogtreecommitdiffstats
path: root/memory/build
diff options
context:
space:
mode:
Diffstat (limited to 'memory/build')
-rw-r--r--memory/build/FdPrintf.cpp4
-rw-r--r--memory/build/FdPrintf.h8
-rw-r--r--memory/build/PHC.cpp25
-rw-r--r--memory/build/mozjemalloc.cpp15
-rw-r--r--memory/build/replace_malloc_bridge.h10
5 files changed, 46 insertions, 16 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