Bug 1665583 - Report OOM for off-thread buffer allocations r=tcampbell

I don't know why we never did this before.  And I guess it won't be needed when
we stop allocating GC things off-thread.

Differential Revision: https://phabricator.services.mozilla.com/D90701
This commit is contained in:
Jon Coppeard 2020-09-18 14:33:31 +00:00
Родитель 21523543d1
Коммит d0f4cccc5d
2 изменённых файлов: 70 добавлений и 18 удалений

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

@ -128,52 +128,64 @@ template <typename T>
static inline T* ReallocateObjectBuffer(JSContext* cx, JSObject* obj,
T* oldBuffer, uint32_t oldCount,
uint32_t newCount) {
T* buffer;
if (cx->isHelperThreadContext()) {
return obj->zone()->pod_realloc<T>(oldBuffer, oldCount, newCount);
buffer = obj->zone()->pod_realloc<T>(oldBuffer, oldCount, newCount);
} else {
buffer = static_cast<T*>(cx->nursery().reallocateBuffer(
obj->zone(), obj, oldBuffer, oldCount * sizeof(T),
newCount * sizeof(T)));
}
auto* buffer = static_cast<T*>(cx->nursery().reallocateBuffer(
obj->zone(), obj, oldBuffer, oldCount * sizeof(T), newCount * sizeof(T)));
if (!buffer) {
ReportOutOfMemory(cx);
}
return buffer;
}
static inline JS::BigInt::Digit* AllocateBigIntDigits(JSContext* cx,
JS::BigInt* bi,
uint32_t length) {
JS::BigInt::Digit* digits;
if (cx->isHelperThreadContext()) {
return cx->pod_malloc<JS::BigInt::Digit>(length);
digits = cx->pod_malloc<JS::BigInt::Digit>(length);
} else {
size_t nbytes = RoundUp(length * sizeof(JS::BigInt::Digit), sizeof(Value));
digits = static_cast<JS::BigInt::Digit*>(
cx->nursery().allocateBuffer(bi, nbytes));
}
size_t nbytes = RoundUp(length * sizeof(JS::BigInt::Digit), sizeof(Value));
auto* digits =
static_cast<JS::BigInt::Digit*>(cx->nursery().allocateBuffer(bi, nbytes));
if (!digits) {
ReportOutOfMemory(cx);
}
return digits;
}
static inline JS::BigInt::Digit* ReallocateBigIntDigits(
JSContext* cx, JS::BigInt* bi, JS::BigInt::Digit* oldDigits,
uint32_t oldLength, uint32_t newLength) {
JS::BigInt::Digit* digits;
if (cx->isHelperThreadContext()) {
MOZ_ASSERT(!cx->nursery().isInside(oldDigits));
return bi->zone()->pod_realloc<JS::BigInt::Digit>(oldDigits, oldLength,
newLength);
digits = bi->zone()->pod_realloc<JS::BigInt::Digit>(oldDigits, oldLength,
newLength);
} else {
size_t oldBytes =
RoundUp(oldLength * sizeof(JS::BigInt::Digit), sizeof(Value));
size_t newBytes =
RoundUp(newLength * sizeof(JS::BigInt::Digit), sizeof(Value));
digits = static_cast<JS::BigInt::Digit*>(cx->nursery().reallocateBuffer(
bi->zone(), bi, oldDigits, oldBytes, newBytes));
}
size_t oldBytes =
RoundUp(oldLength * sizeof(JS::BigInt::Digit), sizeof(Value));
size_t newBytes =
RoundUp(newLength * sizeof(JS::BigInt::Digit), sizeof(Value));
auto* buffer = static_cast<JS::BigInt::Digit*>(cx->nursery().reallocateBuffer(
bi->zone(), bi, oldDigits, oldBytes, newBytes));
if (!buffer) {
if (!digits) {
ReportOutOfMemory(cx);
}
return buffer;
return digits;
}
} // namespace js

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

@ -0,0 +1,40 @@
// |jit-test| skip-if: !('oomTest' in this)
function parseModule(source) {
offThreadCompileModule(source);
return finishOffThreadModule();
}
function loadFile(lfVarx) {
oomTest(function() {
parseModule(lfVarx);
});
}
loadFile(`
const numberingSystems = {
"adlm": {},
"ahom": {},
"arab": {},
"arabext": {},
"armn": {},
"armnlow": {},
"bali": {},
"beng": {},
"bhks": {},
"brah": {},
"cakm": {},
"cham": {},
"cyrl": {},
"hmnp": {},
"java": {},
"jpan": {},
"jpanfin": {},
"jpanyear": {},
"knda": {},
"lana": {},
"latn": {},
"lepc": {},
"limb": {},
"wcho": {},
"extra1": {}
};
`);