summaryrefslogtreecommitdiffstats
path: root/memory/build/PHC.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
commit8dd16259287f58f9273002717ec4d27e97127719 (patch)
tree3863e62a53829a84037444beab3abd4ed9dfc7d0 /memory/build/PHC.cpp
parentReleasing progress-linux version 126.0.1-1~progress7.99u1. (diff)
downloadfirefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz
firefox-8dd16259287f58f9273002717ec4d27e97127719.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'memory/build/PHC.cpp')
-rw-r--r--memory/build/PHC.cpp25
1 files changed, 16 insertions, 9 deletions
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));