зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1675203 - Backed out changeset 0bcd9a5ae49f (Bug 1667581) for causing memory usage regressions a=backout
Differential Revision: https://phabricator.services.mozilla.com/D96007
This commit is contained in:
Родитель
21e53c53a8
Коммит
07f304d057
|
@ -113,6 +113,43 @@ void nsSegmentedBuffer::Empty() {
|
|||
mFirstSegmentIndex = mLastSegmentIndex = 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void
|
||||
TestSegmentedBuffer()
|
||||
{
|
||||
nsSegmentedBuffer* buf = new nsSegmentedBuffer();
|
||||
NS_ASSERTION(buf, "out of memory");
|
||||
buf->Init(4, 16);
|
||||
char* seg;
|
||||
bool empty;
|
||||
seg = buf->AppendNewSegment();
|
||||
NS_ASSERTION(seg, "AppendNewSegment failed");
|
||||
seg = buf->AppendNewSegment();
|
||||
NS_ASSERTION(seg, "AppendNewSegment failed");
|
||||
seg = buf->AppendNewSegment();
|
||||
NS_ASSERTION(seg, "AppendNewSegment failed");
|
||||
empty = buf->DeleteFirstSegment();
|
||||
NS_ASSERTION(!empty, "DeleteFirstSegment failed");
|
||||
empty = buf->DeleteFirstSegment();
|
||||
NS_ASSERTION(!empty, "DeleteFirstSegment failed");
|
||||
seg = buf->AppendNewSegment();
|
||||
NS_ASSERTION(seg, "AppendNewSegment failed");
|
||||
seg = buf->AppendNewSegment();
|
||||
NS_ASSERTION(seg, "AppendNewSegment failed");
|
||||
seg = buf->AppendNewSegment();
|
||||
NS_ASSERTION(seg, "AppendNewSegment failed");
|
||||
empty = buf->DeleteFirstSegment();
|
||||
NS_ASSERTION(!empty, "DeleteFirstSegment failed");
|
||||
empty = buf->DeleteFirstSegment();
|
||||
NS_ASSERTION(!empty, "DeleteFirstSegment failed");
|
||||
empty = buf->DeleteFirstSegment();
|
||||
NS_ASSERTION(!empty, "DeleteFirstSegment failed");
|
||||
empty = buf->DeleteFirstSegment();
|
||||
NS_ASSERTION(empty, "DeleteFirstSegment failed");
|
||||
delete buf;
|
||||
}
|
||||
#endif
|
||||
|
||||
void nsSegmentedBuffer::FreeOMT(void* aPtr) {
|
||||
if (!NS_IsMainThread()) {
|
||||
free(aPtr);
|
||||
|
@ -122,16 +159,13 @@ void nsSegmentedBuffer::FreeOMT(void* aPtr) {
|
|||
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction("nsSegmentedBuffer::FreeOMT",
|
||||
[aPtr]() { free(aPtr); });
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
if (!mFreeMemoryQueue) {
|
||||
rv = NS_CreateBackgroundTaskQueue("nsSegmentedBuffer::FreeOMT",
|
||||
getter_AddRefs(mFreeMemoryQueue));
|
||||
if (!mIOThread) {
|
||||
mIOThread = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
||||
}
|
||||
|
||||
// During the shutdown we are not able to obtain the thread and/or the
|
||||
// During the shutdown we are not able to obtain the IOThread and/or the
|
||||
// dispatching of runnable fails.
|
||||
if (NS_FAILED(rv) || !mFreeMemoryQueue ||
|
||||
NS_FAILED(mFreeMemoryQueue->Dispatch(r.forget()))) {
|
||||
if (!mIOThread || NS_FAILED(mIOThread->Dispatch(r.forget()))) {
|
||||
free(aPtr);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,8 +84,7 @@ class nsSegmentedBuffer {
|
|||
private:
|
||||
void FreeOMT(void* aPtr);
|
||||
|
||||
// This event queue is used to free segment memory.
|
||||
nsCOMPtr<nsISerialEventTarget> mFreeMemoryQueue;
|
||||
nsCOMPtr<nsIEventTarget> mIOThread;
|
||||
};
|
||||
|
||||
// NS_SEGMENTARRAY_INITIAL_SIZE: This number needs to start out as a
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "../../io/nsSegmentedBuffer.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
TEST(SegmentedBuffer, AppendAndDelete)
|
||||
{
|
||||
auto buf = MakeUnique<nsSegmentedBuffer>();
|
||||
buf->Init(4, 16);
|
||||
char* seg;
|
||||
bool empty;
|
||||
seg = buf->AppendNewSegment();
|
||||
EXPECT_TRUE(seg) << "AppendNewSegment failed";
|
||||
seg = buf->AppendNewSegment();
|
||||
EXPECT_TRUE(seg) << "AppendNewSegment failed";
|
||||
seg = buf->AppendNewSegment();
|
||||
EXPECT_TRUE(seg) << "AppendNewSegment failed";
|
||||
empty = buf->DeleteFirstSegment();
|
||||
EXPECT_TRUE(!empty) << "DeleteFirstSegment failed";
|
||||
empty = buf->DeleteFirstSegment();
|
||||
EXPECT_TRUE(!empty) << "DeleteFirstSegment failed";
|
||||
seg = buf->AppendNewSegment();
|
||||
EXPECT_TRUE(seg) << "AppendNewSegment failed";
|
||||
seg = buf->AppendNewSegment();
|
||||
EXPECT_TRUE(seg) << "AppendNewSegment failed";
|
||||
seg = buf->AppendNewSegment();
|
||||
EXPECT_TRUE(seg) << "AppendNewSegment failed";
|
||||
empty = buf->DeleteFirstSegment();
|
||||
EXPECT_TRUE(!empty) << "DeleteFirstSegment failed";
|
||||
empty = buf->DeleteFirstSegment();
|
||||
EXPECT_TRUE(!empty) << "DeleteFirstSegment failed";
|
||||
empty = buf->DeleteFirstSegment();
|
||||
EXPECT_TRUE(!empty) << "DeleteFirstSegment failed";
|
||||
empty = buf->DeleteFirstSegment();
|
||||
EXPECT_TRUE(empty) << "DeleteFirstSegment failed";
|
||||
}
|
|
@ -40,7 +40,6 @@ UNIFIED_SOURCES += [
|
|||
"TestRacingServiceManager.cpp",
|
||||
"TestRecursiveMutex.cpp",
|
||||
"TestRWLock.cpp",
|
||||
"TestSegmentedBuffer.cpp",
|
||||
"TestSlicedInputStream.cpp",
|
||||
"TestSmallArrayLRUCache.cpp",
|
||||
"TestSnappyStreams.cpp",
|
||||
|
|
Загрузка…
Ссылка в новой задаче