Bug 1405274 - Always update runtime malloc counter too when malloc memory is associated with a zone r=sfink

This commit is contained in:
Jon Coppeard 2017-10-04 13:20:32 +01:00
parent 6e03c7e15b
commit df11828d61
9 changed files with 22 additions and 25 deletions

View File

@ -846,7 +846,7 @@ class GCRuntime
bool isTooMuchMalloc() const { return mallocCounter.isTooMuchMalloc(); }
void resetMallocBytes() { mallocCounter.reset(); }
void setMaxMallocBytes(size_t value);
void updateMallocCounter(JS::Zone* zone, size_t nbytes);
bool updateMallocCounter(size_t nbytes) { return mallocCounter.update(this, nbytes); }
void setGCCallback(JSGCCallback callback, void* data);
void callGCCallback(JSGCStatus status) const;

View File

@ -444,7 +444,10 @@ struct Zone : public JS::shadow::Zone,
void resetGCMallocBytes() { gcMallocCounter.reset(); }
void setGCMaxMallocBytes(size_t value) { gcMallocCounter.setMax(value); }
void updateMallocCounter(size_t nbytes) { gcMallocCounter.update(this, nbytes); }
void updateMallocCounter(size_t nbytes) {
if (!runtime_->gc.updateMallocCounter(nbytes))
gcMallocCounter.update(this, nbytes);
}
size_t GCMaxMallocBytes() const { return gcMallocCounter.maxBytes(); }
size_t GCMallocBytes() const { return gcMallocCounter.bytes(); }

View File

@ -1609,6 +1609,17 @@ JSContext::findVersion()
return runtime()->defaultVersion();
}
void
JSContext::updateMallocCounter(size_t nbytes)
{
if (!zone()) {
runtime()->updateMallocCounter(nbytes);
return;
}
zone()->updateMallocCounter(nbytes);
}
#ifdef DEBUG
JS::AutoCheckRequestDepth::AutoCheckRequestDepth(JSContext* cxArg)

View File

@ -142,9 +142,7 @@ struct JSContext : public JS::RootingContext,
/* Clear the pending exception (if any) due to OOM. */
void recoverFromOutOfMemory();
inline void updateMallocCounter(size_t nbytes) {
runtime()->updateMallocCounter(zone(), nbytes);
}
void updateMallocCounter(size_t nbytes);
void reportAllocationOverflow() {
js::ReportAllocationOverflow(this);

View File

@ -1823,14 +1823,6 @@ GCRuntime::setMaxMallocBytes(size_t value)
zone->setGCMaxMallocBytes(value);
}
void
GCRuntime::updateMallocCounter(JS::Zone* zone, size_t nbytes)
{
bool triggered = mallocCounter.update(this, nbytes);
if (!triggered && zone)
zone->updateMallocCounter(nbytes);
}
double
ZoneHeapThreshold::allocTrigger(bool highFrequencyGC) const
{

View File

@ -756,7 +756,7 @@ ArrayBufferObject::createForWasm(JSContext* cx, uint32_t initialSize,
auto contents = BufferContents::create<WASM>(wasmBuf->dataPointer());
buffer->initialize(initialSize, contents, OwnsData);
cx->zone()->updateMallocCounter(wasmBuf->mappedSize());
cx->updateMallocCounter(wasmBuf->mappedSize());
return buffer;
}
@ -801,7 +801,7 @@ ArrayBufferObject::prepareForAsmJS(JSContext* cx, Handle<ArrayBufferObject*> buf
buffer->changeContents(cx, BufferContents::create<WASM>(data), OwnsData);
buffer->setIsPreparedForAsmJS();
MOZ_ASSERT(data == buffer->dataPointer());
cx->zone()->updateMallocCounter(wasmBuf->mappedSize());
cx->updateMallocCounter(wasmBuf->mappedSize());
return true;
}
@ -1061,7 +1061,7 @@ ArrayBufferObject::create(JSContext* cx, uint32_t nbytes, BufferContents content
nAllocated = JS_ROUNDUP(nbytes, js::gc::SystemPageSize());
else if (contents.kind() == WASM)
nAllocated = contents.wasmBuffer()->allocatedBytes();
cx->zone()->updateMallocCounter(nAllocated);
cx->updateMallocCounter(nAllocated);
}
} else {
MOZ_ASSERT(ownsState == OwnsData);

View File

@ -799,13 +799,7 @@ JSRuntime::forkRandomKeyGenerator()
void
JSRuntime::updateMallocCounter(size_t nbytes)
{
updateMallocCounter(nullptr, nbytes);
}
void
JSRuntime::updateMallocCounter(JS::Zone* zone, size_t nbytes)
{
gc.updateMallocCounter(zone, nbytes);
gc.updateMallocCounter(nbytes);
}
JS_FRIEND_API(void*)

View File

@ -960,7 +960,6 @@ struct JSRuntime : public js::MallocProvider<JSRuntime>
* the caller must ensure that no deadlock possible during OOM reporting.
*/
void updateMallocCounter(size_t nbytes);
void updateMallocCounter(JS::Zone* zone, size_t nbytes);
void reportAllocationOverflow() { js::ReportAllocationOverflow(nullptr); }

View File

@ -92,7 +92,7 @@ FinishStringFlat(JSContext* cx, StringBuffer& sb, Buffer& cb)
* The allocation was made on a TempAllocPolicy, so account for the string
* data on the string's zone.
*/
str->zone()->updateMallocCounter(sizeof(CharT) * len);
cx->updateMallocCounter(sizeof(CharT) * len);
buf.forget();
return str;