mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 964803 - Cleanup the JS OOM testing code. r=jandem
This commit is contained in:
parent
4ab362e7fb
commit
1df9de4ac2
@ -71,61 +71,24 @@ extern JS_PUBLIC_API(void) JS_Abort(void);
|
||||
extern JS_PUBLIC_DATA(uint32_t) OOM_maxAllocations; /* set in builtins/TestingFunctions.cpp */
|
||||
extern JS_PUBLIC_DATA(uint32_t) OOM_counter; /* data race, who cares. */
|
||||
|
||||
#ifdef JS_OOM_DO_BACKTRACES
|
||||
#define JS_OOM_BACKTRACE_SIZE 32
|
||||
static MOZ_ALWAYS_INLINE void
|
||||
PrintBacktrace()
|
||||
{
|
||||
void* OOM_trace[JS_OOM_BACKTRACE_SIZE];
|
||||
char** OOM_traceSymbols = nullptr;
|
||||
int32_t OOM_traceSize = 0;
|
||||
int32_t OOM_traceIdx = 0;
|
||||
OOM_traceSize = backtrace(OOM_trace, JS_OOM_BACKTRACE_SIZE);
|
||||
OOM_traceSymbols = backtrace_symbols(OOM_trace, OOM_traceSize);
|
||||
|
||||
if (!OOM_traceSymbols)
|
||||
return;
|
||||
|
||||
for (OOM_traceIdx = 0; OOM_traceIdx < OOM_traceSize; ++OOM_traceIdx) {
|
||||
fprintf(stderr, "#%d %s\n", OOM_traceIdx, OOM_traceSymbols[OOM_traceIdx]);
|
||||
}
|
||||
|
||||
// This must be free(), not js_free(), because backtrace_symbols()
|
||||
// allocates with malloc().
|
||||
free(OOM_traceSymbols);
|
||||
}
|
||||
|
||||
#define JS_OOM_EMIT_BACKTRACE() \
|
||||
do {\
|
||||
fprintf(stderr, "Forcing artificial memory allocation function failure:\n");\
|
||||
PrintBacktrace();\
|
||||
} while (0)
|
||||
# else
|
||||
# define JS_OOM_EMIT_BACKTRACE() do {} while(0)
|
||||
#endif /* JS_OOM_DO_BACKTRACES */
|
||||
#ifdef JS_OOM_BREAKPOINT
|
||||
static MOZ_NEVER_INLINE void js_failedAllocBreakpoint() { asm(""); }
|
||||
#define JS_OOM_CALL_BP_FUNC() js_failedAllocBreakpoint()
|
||||
#else
|
||||
#define JS_OOM_CALL_BP_FUNC() do {} while(0)
|
||||
#endif
|
||||
|
||||
# define JS_OOM_POSSIBLY_FAIL() \
|
||||
do \
|
||||
{ \
|
||||
if (++OOM_counter > OOM_maxAllocations) { \
|
||||
JS_OOM_EMIT_BACKTRACE();\
|
||||
JS_OOM_CALL_BP_FUNC();\
|
||||
return nullptr; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) \
|
||||
do \
|
||||
{ \
|
||||
if (++OOM_counter > OOM_maxAllocations) { \
|
||||
JS_OOM_EMIT_BACKTRACE();\
|
||||
js_ReportOutOfMemory(cx);\
|
||||
return false; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
# else
|
||||
# define JS_OOM_POSSIBLY_FAIL() do {} while(0)
|
||||
# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) do {} while(0)
|
||||
# endif /* JS_DEBUG */
|
||||
|
||||
static inline void* js_malloc(size_t bytes)
|
||||
|
@ -3456,15 +3456,15 @@ if test -n "$JS_MORE_DETERMINISTIC"; then
|
||||
fi
|
||||
|
||||
dnl ========================================================
|
||||
dnl Enable output of backtraces on artificial OOMs
|
||||
dnl Enable breakpoint for artificial OOMs
|
||||
dnl ========================================================
|
||||
MOZ_ARG_ENABLE_BOOL(oom-backtrace,
|
||||
[ --enable-oom-backtrace
|
||||
Enable output of backtraces on artificial OOMs (-A)],
|
||||
JS_OOM_DO_BACKTRACES=1,
|
||||
JS_OOM_DO_BACKTRACES= )
|
||||
if test -n "$JS_OOM_DO_BACKTRACES"; then
|
||||
AC_DEFINE(JS_OOM_DO_BACKTRACES)
|
||||
MOZ_ARG_ENABLE_BOOL(oom-breakpoint,
|
||||
[ --enable-oom-breakpoint
|
||||
Enable a breakpoint function for artificial OOMs],
|
||||
JS_OOM_BREAKPOINT=1,
|
||||
JS_OOM_BREAKPOINT= )
|
||||
if test -n "$JS_OOM_BREAKPOINT"; then
|
||||
AC_DEFINE(JS_OOM_BREAKPOINT)
|
||||
fi
|
||||
|
||||
MOZ_CHECK_CCACHE
|
||||
|
@ -424,7 +424,7 @@ CheckAllocatorState(ThreadSafeContext *cx, AllocKind kind)
|
||||
#endif
|
||||
|
||||
// For testing out of memory conditions
|
||||
JS_OOM_POSSIBLY_FAIL_REPORT(ncx);
|
||||
JS_OOM_POSSIBLY_FAIL();
|
||||
|
||||
if (allowGC) {
|
||||
#ifdef JS_GC_ZEAL
|
||||
|
Loading…
Reference in New Issue
Block a user