Bug 1536154 - Make nsStringInputStream always report the full memory size of the backing string r=baku

Give nsIStringStream separate SizeOfIncludingThisIfUnshared and SizeOfIncludingThisEvenIfShared methods. Use the former for memory reporting and the latter for JS engine memory accounting.

Differential Revision: https://phabricator.services.mozilla.com/D29336
This commit is contained in:
Jon Coppeard 2019-04-30 11:53:42 +01:00
Родитель 51a0721c6a
Коммит 0eb4059201
3 изменённых файлов: 17 добавлений и 4 удалений

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

@ -146,7 +146,7 @@ StreamBlobImpl::CollectReports(nsIHandleReportCallback* aHandleReport,
MOZ_COLLECT_REPORT(
"explicit/dom/memory-file-data/stream", KIND_HEAP, UNITS_BYTES,
stringInputStream->SizeOfIncludingThis(MallocSizeOf),
stringInputStream->SizeOfIncludingThisIfUnshared(MallocSizeOf),
"Memory used to back a File/Blob based on an input stream.");
return NS_OK;
@ -159,7 +159,7 @@ size_t StreamBlobImpl::GetAllocationSize() const {
return 0;
}
return stringInputStream->SizeOfIncludingThis(MallocSizeOf);
return stringInputStream->SizeOfIncludingThisEvenIfShared(MallocSizeOf);
}
void StreamBlobImpl::GetBlobImplType(nsAString& aBlobImplType) const {

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

@ -62,5 +62,8 @@ interface nsIStringInputStream : nsIInputStream
[noscript] void shareData(in string data, in long dataLen);
[noscript, notxpcom]
size_t SizeOfIncludingThis(in MallocSizeOf aMallocSizeOf);
size_t SizeOfIncludingThisIfUnshared(in MallocSizeOf aMallocSizeOf);
[noscript, notxpcom]
size_t SizeOfIncludingThisEvenIfShared(in MallocSizeOf aMallocSizeOf);
};

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

@ -196,7 +196,7 @@ nsStringInputStream::ShareData(const char* aData, int32_t aDataLen) {
}
NS_IMETHODIMP_(size_t)
nsStringInputStream::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) {
nsStringInputStream::SizeOfIncludingThisIfUnshared(MallocSizeOf aMallocSizeOf) {
ReentrantMonitorAutoEnter lock(mMon);
size_t n = aMallocSizeOf(this);
@ -204,6 +204,16 @@ nsStringInputStream::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) {
return n;
}
NS_IMETHODIMP_(size_t)
nsStringInputStream::SizeOfIncludingThisEvenIfShared(
MallocSizeOf aMallocSizeOf) {
ReentrantMonitorAutoEnter lock(mMon);
size_t n = aMallocSizeOf(this);
n += mData.SizeOfExcludingThisEvenIfShared(aMallocSizeOf);
return n;
}
/////////
// nsIInputStream implementation
/////////