Bug 1716727 - patchset #3 [1/1] - Cleanup: remove intermediate function r=glandium

Since mozglue is now aware of Gecko process-types, remove the
configurator for this bug's associated experiment. Instead, use
`GeckoProcessType` directly in mozjemalloc.

This requires a couple of adjustments for non-Firefox uses of
mozjemalloc:

- Since `logalloc-replay` uses mozjemalloc in an odd way, tweak its
  `moz.build` to also include `mozglue/misc/ProcessType.cpp`.
- Since `GeckoProcessType` is not available in standalone SpiderMonkey
  builds, make the mostly-arbitrarily choice to always stall there.

No functional changes.

Differential Revision: https://phabricator.services.mozilla.com/D155300
This commit is contained in:
Ray Kraesig 2022-08-25 14:44:47 +00:00
Родитель 529cf4bac7
Коммит 613c6089f5
4 изменённых файлов: 23 добавлений и 27 удалений

Просмотреть файл

@ -163,6 +163,11 @@
#include "Mutex.h"
#include "Utils.h"
// For GetGeckoProcessType(), when it's used.
#if defined(XP_WIN) && !defined(JS_STANDALONE)
# include "mozilla/ProcessType.h"
#endif
using namespace mozilla;
// On Linux, we use madvise(MADV_DONTNEED) to release memory back to the
@ -1364,15 +1369,10 @@ static inline void ApplyZeroOrJunk(void* aPtr, size_t aSize) {
}
}
// Experiment under bug 1716727. (See ./moz.build for details.)
// On Windows, delay crashing on OOM. Partly experimental. (See bug 1785145 for
// more details.)
#ifdef XP_WIN
// Whether the current process should always stall, or only stall once.
static bool sShouldAlwaysStall = true;
MOZ_JEMALLOC_API void mozjemalloc_win_set_always_stall(bool aVal) {
sShouldAlwaysStall = aVal;
}
// Implementation of VirtualAlloc wrapper (bug 1716727).
namespace MozAllocRetries {
@ -1383,12 +1383,20 @@ constexpr size_t kMaxAttempts = 10;
constexpr size_t kDelayMs = 50;
Atomic<bool> sHasStalled{false};
static bool ShouldStallAndRetry() {
if (sShouldAlwaysStall) {
static inline bool ShouldStallAndRetry() {
# if defined(JS_STANDALONE)
// GetGeckoProcessType() isn't available in this configuration. (SpiderMonkey
// on Windows mostly skips this in favor of directly calling ::VirtualAlloc(),
// though, so it's probably not going to matter whether we stall here or not.)
return true;
# else
// In the main process, always stall.
if (GetGeckoProcessType() == GeckoProcessType::GeckoProcessType_Default) {
return true;
}
// Otherwise, stall at most once.
return sHasStalled.compareExchange(false, true);
# endif
}
// Drop-in wrapper around VirtualAlloc. When out of memory, may attempt to stall
@ -1453,7 +1461,7 @@ static bool ShouldStallAndRetry() {
} // namespace MozAllocRetries
using MozAllocRetries::MozVirtualAlloc;
#endif // XP_WIN
#endif // XP_WIN
// ***************************************************************************

Просмотреть файл

@ -61,11 +61,6 @@ static inline void jemalloc_stats(jemalloc_stats_t* aStats) {
}
# endif
// Configurator for delaying on OOM. See bug 1716727.
# if defined(XP_WIN)
MOZ_JEMALLOC_API void mozjemalloc_win_set_always_stall(bool);
# endif
#endif // MOZ_MEMORY
#define NOTHROW_MALLOC_DECL(name, return_type, ...) \

Просмотреть файл

@ -16,6 +16,11 @@ SOURCES += [
"Replay.cpp",
]
if CONFIG["OS_TARGET"] == "WINNT":
SOURCES += [
"/mozglue/misc/ProcessType.cpp",
]
if CONFIG["OS_TARGET"] == "Linux":
LDFLAGS += ["-static-libstdc++"]

Просмотреть файл

@ -5,7 +5,6 @@
#include "mozilla/DebugOnly.h"
#include "nsXULAppAPI.h"
#include "mozmemory.h"
#include <stdlib.h>
#if defined(MOZ_WIDGET_GTK)
@ -266,17 +265,6 @@ void XRE_SetAndroidChildFds(JNIEnv* env, const XRE_AndroidChildFds& fds) {
void XRE_SetProcessType(const char* aProcessTypeString) {
SetGeckoProcessType(aProcessTypeString);
#if defined(MOZ_MEMORY) && defined(XP_WIN)
GeckoProcessType const processType = GetGeckoProcessType();
// For the parent process, we're probably willing to accept an apparent
// lockup in preference to a crash. Always stall and retry.
//
// For child processes, an obvious OOM-crash may be preferable to slow
// performance. Retry at most once per process, then give up.
mozjemalloc_win_set_always_stall(processType == GeckoProcessType_Default);
#endif
}
#if defined(XP_WIN)