Backed out 4 changesets (bug 1875768) for causing cppunittest-1proc failures CLOSED TREE

Backed out changeset add6151e17ee (bug 1875768)
Backed out changeset 01fa7e793e87 (bug 1875768)
Backed out changeset 99f0bce25b22 (bug 1875768)
Backed out changeset f6847957c1cc (bug 1875768)
This commit is contained in:
Sandor Molnar 2024-06-07 08:18:50 +03:00
parent 9c113718ee
commit 10e7fbf7a5
3 changed files with 12 additions and 47 deletions

View file

@ -153,13 +153,9 @@ typedef Mutex StaticMutex;
#ifdef XP_WIN #ifdef XP_WIN
typedef DWORD ThreadId; typedef DWORD ThreadId;
inline ThreadId GetThreadId() { return GetCurrentThreadId(); } inline ThreadId GetThreadId() { return GetCurrentThreadId(); }
inline bool ThreadIdEqual(ThreadId a, ThreadId b) { return a == b; }
#else #else
typedef pthread_t ThreadId; typedef pthread_t ThreadId;
inline ThreadId GetThreadId() { return pthread_self(); } inline ThreadId GetThreadId() { return pthread_self(); }
inline bool ThreadIdEqual(ThreadId a, ThreadId b) {
return pthread_equal(a, b);
}
#endif #endif
class MOZ_CAPABILITY("mutex") MaybeMutex : public Mutex { class MOZ_CAPABILITY("mutex") MaybeMutex : public Mutex {
@ -216,7 +212,7 @@ class MOZ_CAPABILITY("mutex") MaybeMutex : public Mutex {
// protected resource. // protected resource.
#ifdef MOZ_DEBUG #ifdef MOZ_DEBUG
bool SafeOnThisThread() const { bool SafeOnThisThread() const {
return mDoLock == MUST_LOCK || ThreadIdEqual(GetThreadId(), mThreadId); return mDoLock == MUST_LOCK || GetThreadId() == mThreadId;
} }
#endif #endif
@ -232,7 +228,7 @@ class MOZ_CAPABILITY("mutex") MaybeMutex : public Mutex {
return true; return true;
} }
MOZ_ASSERT(ThreadIdEqual(GetThreadId(), mThreadId)); MOZ_ASSERT(GetThreadId() == mThreadId);
return false; return false;
} }

View file

@ -1392,8 +1392,7 @@ class ArenaCollection {
// We're running on the main thread which is set by a call to SetMainThread(). // We're running on the main thread which is set by a call to SetMainThread().
bool IsOnMainThread() const { bool IsOnMainThread() const {
return mMainThreadId.isSome() && return mMainThreadId.isSome() && mMainThreadId.value() == GetThreadId();
ThreadIdEqual(mMainThreadId.value(), GetThreadId());
} }
// We're running on the main thread or SetMainThread() has never been called. // We're running on the main thread or SetMainThread() has never been called.
@ -1402,10 +1401,11 @@ class ArenaCollection {
} }
// After a fork set the new thread ID in the child. // After a fork set the new thread ID in the child.
void ResetMainThread() { void PostForkFixMainThread() {
// The post fork handler in the child can run from a MacOS worker thread, if (mMainThreadId.isSome()) {
// so we can't set our main thread to it here. Instead we have to clear it. // Only if the main thread has been defined.
mMainThreadId = Nothing(); mMainThreadId = Some(GetThreadId());
}
} }
void SetMainThread() { void SetMainThread() {
@ -1550,9 +1550,6 @@ static bool malloc_init_hard();
FORK_HOOK void _malloc_prefork(void); FORK_HOOK void _malloc_prefork(void);
FORK_HOOK void _malloc_postfork_parent(void); FORK_HOOK void _malloc_postfork_parent(void);
FORK_HOOK void _malloc_postfork_child(void); FORK_HOOK void _malloc_postfork_child(void);
# ifdef XP_DARWIN
FORK_HOOK void _malloc_postfork(void);
# endif
#endif #endif
// End forward declarations. // End forward declarations.
@ -5181,23 +5178,13 @@ inline void MozJemalloc::moz_set_max_dirty_page_modifier(int32_t aModifier) {
// state for the child is if fork is called from the main thread only. Or the // state for the child is if fork is called from the main thread only. Or the
// child must not use them, eg it should call exec(). We attempt to prevent the // child must not use them, eg it should call exec(). We attempt to prevent the
// child for accessing these arenas by refusing to re-initialise them. // child for accessing these arenas by refusing to re-initialise them.
//
// This is only accessed in the fork handlers while gArenas.mLock is held.
static pthread_t gForkingThread; static pthread_t gForkingThread;
# ifdef XP_DARWIN
// This is only accessed in the fork handlers while gArenas.mLock is held.
static mach_port_t gForkingProcess;
# endif
FORK_HOOK FORK_HOOK
void _malloc_prefork(void) MOZ_NO_THREAD_SAFETY_ANALYSIS { void _malloc_prefork(void) MOZ_NO_THREAD_SAFETY_ANALYSIS {
// Acquire all mutexes in a safe order. // Acquire all mutexes in a safe order.
gArenas.mLock.Lock(); gArenas.mLock.Lock();
gForkingThread = pthread_self(); gForkingThread = pthread_self();
# ifdef XP_DARWIN
gForkingProcess = mach_task_self();
# endif
for (auto arena : gArenas.iter()) { for (auto arena : gArenas.iter()) {
if (arena->mLock.LockIsEnabled()) { if (arena->mLock.LockIsEnabled()) {
@ -5228,9 +5215,6 @@ void _malloc_postfork_parent(void) MOZ_NO_THREAD_SAFETY_ANALYSIS {
FORK_HOOK FORK_HOOK
void _malloc_postfork_child(void) { void _malloc_postfork_child(void) {
// Do this before iterating over the arenas.
gArenas.ResetMainThread();
// Reinitialize all mutexes, now that fork() has completed. // Reinitialize all mutexes, now that fork() has completed.
huge_mtx.Init(); huge_mtx.Init();
@ -5240,24 +5224,10 @@ void _malloc_postfork_child(void) {
arena->mLock.Reinit(gForkingThread); arena->mLock.Reinit(gForkingThread);
} }
gArenas.PostForkFixMainThread();
gArenas.mLock.Init(); gArenas.mLock.Init();
} }
#endif // XP_WIN
# ifdef XP_DARWIN
FORK_HOOK
void _malloc_postfork(void) {
// On MacOS we need to check if this is running in the parent or child
// process.
bool is_in_parent = mach_task_self() == gForkingProcess;
gForkingProcess = 0;
if (is_in_parent) {
_malloc_postfork_parent();
} else {
_malloc_postfork_child();
}
}
# endif // XP_DARWIN
#endif // ! XP_WIN
// End library-private functions. // End library-private functions.
// *************************************************************************** // ***************************************************************************

View file

@ -232,9 +232,8 @@ static void zone_print(malloc_zone_t* zone, boolean_t verbose) {}
static void zone_log(malloc_zone_t* zone, void* address) {} static void zone_log(malloc_zone_t* zone, void* address) {}
// On Darwin the postfork handler is called in both the parent and the child.
extern void _malloc_prefork(void); extern void _malloc_prefork(void);
extern void _malloc_postfork(void); extern void _malloc_postfork_child(void);
static void zone_force_lock(malloc_zone_t* zone) { static void zone_force_lock(malloc_zone_t* zone) {
// /!\ This calls into mozjemalloc. It works because we're linked in the // /!\ This calls into mozjemalloc. It works because we're linked in the
@ -245,7 +244,7 @@ static void zone_force_lock(malloc_zone_t* zone) {
static void zone_force_unlock(malloc_zone_t* zone) { static void zone_force_unlock(malloc_zone_t* zone) {
// /!\ This calls into mozjemalloc. It works because we're linked in the // /!\ This calls into mozjemalloc. It works because we're linked in the
// same library. // same library.
_malloc_postfork(); _malloc_postfork_child();
} }
static void zone_statistics(malloc_zone_t* zone, malloc_statistics_t* stats) { static void zone_statistics(malloc_zone_t* zone, malloc_statistics_t* stats) {