Bug 1874022 - pt 14. Seperate arena and non-arena code paths in PHC r=glandium

The Arena ID is wrapped in a Maybe, the construction of Nothing() shows up
in profiles.  By testing the maybe we show the compiler that it can optimise
away the construction of Nothing when inlining this code.

Differential Revision: https://phabricator.services.mozilla.com/D207680
This commit is contained in:
Paul Bone 2024-06-26 02:06:42 +00:00
parent 29a4b0695d
commit 065f8db2ee

View File

@ -1469,7 +1469,10 @@ static void FreePage(PHCLock aLock, uintptr_t aIndex,
MOZ_ALWAYS_INLINE static void* PageMalloc(const Maybe<arena_id_t>& aArenaId,
size_t aReqSize) {
void* ptr = ShouldPageAllocHot(aReqSize)
? MaybePageAlloc(aArenaId, aReqSize, /* aAlignment */ 1,
// The test on aArenaId here helps the compiler optimise away
// the construction of Nothing() in the caller.
? MaybePageAlloc(aArenaId.isSome() ? aArenaId : Nothing(),
aReqSize, /* aAlignment */ 1,
/* aZero */ false)
: nullptr;
return ptr ? ptr
@ -1496,11 +1499,13 @@ MOZ_ALWAYS_INLINE static void* PageCalloc(const Maybe<arena_id_t>& aArenaId,
return nullptr;
}
void* ptr =
ShouldPageAllocHot(checkedSize.value())
? MaybePageAlloc(aArenaId, checkedSize.value(), /* aAlignment */ 1,
/* aZero */ true)
: nullptr;
void* ptr = ShouldPageAllocHot(checkedSize.value())
// The test on aArenaId here helps the compiler optimise away
// the construction of Nothing() in the caller.
? MaybePageAlloc(aArenaId.isSome() ? aArenaId : Nothing(),
checkedSize.value(), /* aAlignment */ 1,
/* aZero */ true)
: nullptr;
return ptr ? ptr
: (aArenaId.isSome()
? MozJemalloc::moz_arena_calloc(*aArenaId, aNum, aReqSize)
@ -1700,7 +1705,9 @@ MOZ_ALWAYS_INLINE static bool FastIsPHCPtr(void* aPtr) {
MOZ_ALWAYS_INLINE static void PageFree(const Maybe<arena_id_t>& aArenaId,
void* aPtr) {
if (MOZ_UNLIKELY(FastIsPHCPtr(aPtr))) {
DoPageFree(aArenaId, aPtr);
// The tenery expression here helps the compiler optimise away the
// construction of Nothing() in the caller.
DoPageFree(aArenaId.isSome() ? aArenaId : Nothing(), aPtr);
return;
}
@ -1720,7 +1727,10 @@ MOZ_ALWAYS_INLINE static void* PageMemalign(const Maybe<arena_id_t>& aArenaId,
// mozjemalloc in that case.
void* ptr = nullptr;
if (ShouldPageAllocHot(aReqSize) && aAlignment <= kPageSize) {
ptr = MaybePageAlloc(aArenaId, aReqSize, aAlignment, /* aZero */ false);
// The test on aArenaId here helps the compiler optimise away
// the construction of Nothing() in the caller.
ptr = MaybePageAlloc(aArenaId.isSome() ? aArenaId : Nothing(), aReqSize,
aAlignment, /* aZero */ false);
}
return ptr ? ptr
: (aArenaId.isSome()