Bug 1786451 - Part 1: Export MozVirtualAlloc as part of the jemalloc API r=glandium

This will allow this function to be used by the JS engine too.

Differential Revision: https://phabricator.services.mozilla.com/D226462
This commit is contained in:
Jon Coppeard
2024-10-31 09:52:34 +00:00
parent 1e0acc349a
commit dfadfa4ba9
3 changed files with 20 additions and 9 deletions

View File

@@ -1665,14 +1665,24 @@ static inline StallSpecs GetStallSpecs() {
# endif
}
} // namespace MozAllocRetries
namespace mozilla {
StallSpecs GetAllocatorStallSpecs() {
return ::MozAllocRetries::GetStallSpecs();
}
// Drop-in wrapper around VirtualAlloc. When out of memory, may attempt to stall
// and retry rather than returning immediately, in hopes that the page file is
// about to be expanded by Windows.
//
// Ref:
// https://docs.microsoft.com/en-us/troubleshoot/windows-client/performance/slow-page-file-growth-memory-allocation-errors
[[nodiscard]] void* MozVirtualAlloc(LPVOID lpAddress, SIZE_T dwSize,
DWORD flAllocationType, DWORD flProtect) {
void* MozVirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType,
DWORD flProtect) {
using namespace MozAllocRetries;
DWORD const lastError = ::GetLastError();
constexpr auto IsOOMError = [] {
@@ -1727,14 +1737,7 @@ static inline StallSpecs GetStallSpecs() {
return ret.value_or(nullptr);
}
} // namespace MozAllocRetries
using MozAllocRetries::MozVirtualAlloc;
namespace mozilla {
MOZ_JEMALLOC_API StallSpecs GetAllocatorStallSpecs() {
return ::MozAllocRetries::GetStallSpecs();
}
} // namespace mozilla
#endif // XP_WIN

View File

@@ -11,6 +11,7 @@
#include <type_traits>
#if defined(MOZ_MEMORY) && defined(XP_WIN)
# include <wtypes.h>
# include "mozmemory_wrap.h"
#endif
@@ -68,6 +69,10 @@ struct StallSpecs {
#if defined(MOZ_MEMORY) && defined(XP_WIN)
MOZ_JEMALLOC_API StallSpecs GetAllocatorStallSpecs();
MOZ_JEMALLOC_API_NODISCARD void* MozVirtualAlloc(LPVOID lpAddress,
SIZE_T dwSize,
DWORD flAllocationType,
DWORD flProtect);
#endif
} // namespace mozilla

View File

@@ -106,6 +106,7 @@
#ifdef MOZ_MEMORY_IMPL
# define MOZ_JEMALLOC_API MOZ_EXTERN_C MFBT_API
# define MOZ_JEMALLOC_API_NODISCARD MOZ_EXTERN_C [[nodiscard]] MFBT_API
# if defined(XP_WIN)
# define mozmem_malloc_impl(a) je_##a
# else
@@ -119,6 +120,7 @@
#if !defined(MOZ_MEMORY_IMPL)
# define MOZ_MEMORY_API MOZ_EXTERN_C MFBT_API
# define MOZ_JEMALLOC_API MOZ_EXTERN_C MFBT_API
# define MOZ_JEMALLOC_API_NODISCARD MOZ_EXTERN_C [[nodiscard]] MFBT_API
#endif
#ifndef MOZ_MEMORY_API
@@ -126,6 +128,7 @@
#endif
#ifndef MOZ_JEMALLOC_API
# define MOZ_JEMALLOC_API MOZ_EXTERN_C
# define MOZ_JEMALLOC_API_NODISCARD MOZ_EXTERN_C [[nodiscard]]
#endif
#ifndef mozmem_malloc_impl