Bug 1517823 - Part 2: Pass arena to MallocProvider client. r=sfink

This commit is contained in:
André Bargull 2019-01-07 05:47:09 -08:00
Родитель cd2bf34a4f
Коммит 039d42cd5a
8 изменённых файлов: 32 добавлений и 24 удалений

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

@ -3420,8 +3420,8 @@ static bool ThrowOutOfMemory(JSContext* cx, unsigned argc, Value* vp) {
static bool ReportLargeAllocationFailure(JSContext* cx, unsigned argc,
Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
void* buf = cx->runtime()->onOutOfMemoryCanGC(AllocFunction::Malloc,
JSRuntime::LARGE_ALLOCATION);
void* buf = cx->runtime()->onOutOfMemoryCanGC(
AllocFunction::Malloc, js::MallocArena, JSRuntime::LARGE_ALLOCATION);
js_free(buf);
args.rval().setUndefined();
return true;

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

@ -352,7 +352,8 @@ void Zone::notifyObservingDebuggers() {
for (GlobalObject::DebuggerVector::Range r = dbgs->all(); !r.empty();
r.popFront()) {
if (!r.front().unbarrieredGet()->debuggeeIsBeingCollected(rt->gc.majorGCCount())) {
if (!r.front().unbarrieredGet()->debuggeeIsBeingCollected(
rt->gc.majorGCCount())) {
#ifdef DEBUG
fprintf(stderr,
"OOM while notifying observing Debuggers of a GC: The "
@ -463,12 +464,13 @@ void Zone::traceAtomCache(JSTracer* trc) {
}
}
void* Zone::onOutOfMemory(js::AllocFunction allocFunc, size_t nbytes,
void* reallocPtr) {
void* Zone::onOutOfMemory(js::AllocFunction allocFunc, arena_id_t arena,
size_t nbytes, void* reallocPtr) {
if (!js::CurrentThreadCanAccessRuntime(runtime_)) {
return nullptr;
}
return runtimeFromMainThread()->onOutOfMemory(allocFunc, nbytes, reallocPtr);
return runtimeFromMainThread()->onOutOfMemory(allocFunc, arena, nbytes,
reallocPtr);
}
void Zone::reportAllocationOverflow() { js::ReportAllocationOverflow(nullptr); }

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

@ -206,7 +206,8 @@ class Zone : public JS::shadow::Zone,
std::forward<Args>(args)...);
}
MOZ_MUST_USE void* onOutOfMemory(js::AllocFunction allocFunc, size_t nbytes,
MOZ_MUST_USE void* onOutOfMemory(js::AllocFunction allocFunc,
arena_id_t arena, size_t nbytes,
void* reallocPtr = nullptr);
void reportAllocationOverflow();

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

@ -12,7 +12,7 @@ using namespace js;
void* TempAllocPolicy::onOutOfMemory(AllocFunction allocFunc, size_t nbytes,
void* reallocPtr) {
return cx_->onOutOfMemory(allocFunc, nbytes, reallocPtr);
return cx_->onOutOfMemory(allocFunc, js::MallocArena, nbytes, reallocPtr);
}
void TempAllocPolicy::reportAllocOverflow() const {

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

@ -165,12 +165,12 @@ struct JSContext : public JS::RootingContext,
}
void* onOutOfMemory(js::AllocFunction allocFunc, size_t nbytes,
void* reallocPtr = nullptr) {
arena_id_t arena, void* reallocPtr = nullptr) {
if (helperThread()) {
addPendingOutOfMemory();
return nullptr;
}
return runtime_->onOutOfMemory(allocFunc, nbytes, reallocPtr, this);
return runtime_->onOutOfMemory(allocFunc, arena, nbytes, reallocPtr, this);
}
/* Clear the pending exception (if any) due to OOM. */
@ -192,7 +192,7 @@ struct JSContext : public JS::RootingContext,
return nullptr;
}
p = static_cast<T*>(
runtime()->onOutOfMemoryCanGC(js::AllocFunction::Calloc, bytes));
runtime()->onOutOfMemoryCanGC(js::AllocFunction::Calloc, arena, bytes));
if (!p) {
return nullptr;
}

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

@ -95,7 +95,7 @@ struct MallocProvider {
client()->reportAllocationOverflow();
return nullptr;
}
p = (T*)client()->onOutOfMemory(AllocFunction::Malloc, bytes);
p = (T*)client()->onOutOfMemory(AllocFunction::Malloc, arena, bytes);
if (p) {
client()->updateMallocCounter(bytes);
}
@ -114,7 +114,8 @@ struct MallocProvider {
client()->updateMallocCounter(bytes);
return p;
}
p = (T*)client()->onOutOfMemory(AllocFunction::Malloc, bytes);
p = (T*)client()->onOutOfMemory(AllocFunction::Malloc, js::MallocArena,
bytes);
if (p) {
client()->updateMallocCounter(bytes);
}
@ -137,7 +138,7 @@ struct MallocProvider {
client()->reportAllocationOverflow();
return nullptr;
}
p = (T*)client()->onOutOfMemory(AllocFunction::Calloc, bytes);
p = (T*)client()->onOutOfMemory(AllocFunction::Calloc, arena, bytes);
if (p) {
client()->updateMallocCounter(bytes);
}
@ -156,7 +157,8 @@ struct MallocProvider {
client()->updateMallocCounter(bytes);
return p;
}
p = (T*)client()->onOutOfMemory(AllocFunction::Calloc, bytes);
p = (T*)client()->onOutOfMemory(AllocFunction::Calloc, js::MallocArena,
bytes);
if (p) {
client()->updateMallocCounter(bytes);
}
@ -179,7 +181,8 @@ struct MallocProvider {
client()->reportAllocationOverflow();
return nullptr;
}
p = (T*)client()->onOutOfMemory(AllocFunction::Realloc, bytes, prior);
p = (T*)client()->onOutOfMemory(AllocFunction::Realloc, js::MallocArena,
bytes, prior);
if (p && newSize > oldSize) {
client()->updateMallocCounter((newSize - oldSize) * sizeof(T));
}

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

@ -690,7 +690,8 @@ void JSRuntime::updateMallocCounter(size_t nbytes) {
}
JS_FRIEND_API void* JSRuntime::onOutOfMemory(AllocFunction allocFunc,
size_t nbytes, void* reallocPtr,
arena_id_t arena, size_t nbytes,
void* reallocPtr,
JSContext* maybecx) {
MOZ_ASSERT_IF(allocFunc != AllocFunction::Realloc, !reallocPtr);
@ -707,10 +708,10 @@ JS_FRIEND_API void* JSRuntime::onOutOfMemory(AllocFunction allocFunc,
void* p;
switch (allocFunc) {
case AllocFunction::Malloc:
p = js_malloc(nbytes);
p = js_arena_malloc(arena, nbytes);
break;
case AllocFunction::Calloc:
p = js_calloc(nbytes);
p = js_arena_calloc(arena, nbytes, 1);
break;
case AllocFunction::Realloc:
p = js_realloc(reallocPtr, nbytes);
@ -729,12 +730,12 @@ JS_FRIEND_API void* JSRuntime::onOutOfMemory(AllocFunction allocFunc,
return nullptr;
}
void* JSRuntime::onOutOfMemoryCanGC(AllocFunction allocFunc, size_t bytes,
void* reallocPtr) {
void* JSRuntime::onOutOfMemoryCanGC(AllocFunction allocFunc, arena_id_t arena,
size_t bytes, void* reallocPtr) {
if (OnLargeAllocationFailure && bytes >= LARGE_ALLOCATION) {
OnLargeAllocationFailure();
}
return onOutOfMemory(allocFunc, bytes, reallocPtr);
return onOutOfMemory(allocFunc, arena, bytes, reallocPtr);
}
bool JSRuntime::activeGCInAtomsZone() {

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

@ -834,13 +834,14 @@ struct JSRuntime : public js::MallocProvider<JSRuntime> {
*
* The function must be called outside the GC lock.
*/
JS_FRIEND_API void* onOutOfMemory(js::AllocFunction allocator, size_t nbytes,
JS_FRIEND_API void* onOutOfMemory(js::AllocFunction allocator,
arena_id_t arena, size_t nbytes,
void* reallocPtr = nullptr,
JSContext* maybecx = nullptr);
/* onOutOfMemory but can call OnLargeAllocationFailure. */
JS_FRIEND_API void* onOutOfMemoryCanGC(js::AllocFunction allocator,
size_t nbytes,
arena_id_t arena, size_t nbytes,
void* reallocPtr = nullptr);
static const unsigned LARGE_ALLOCATION = 25 * 1024 * 1024;