зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset bbb1c8c9858b (bug 1401827
)
This commit is contained in:
Родитель
6142626b8c
Коммит
aa5d8773e4
|
@ -46,11 +46,19 @@ class Fifo
|
|||
|
||||
private:
|
||||
// Maintain invariants after adding or removing entries.
|
||||
void fixup() {
|
||||
if (front_.empty() && !rear_.empty()) {
|
||||
front_.swap(rear_);
|
||||
Reverse(front_.begin(), front_.end());
|
||||
bool fixup() {
|
||||
if (!front_.empty())
|
||||
return true;
|
||||
|
||||
if (!front_.reserve(rear_.length()))
|
||||
return false;
|
||||
|
||||
while (!rear_.empty()) {
|
||||
front_.infallibleAppend(mozilla::Move(rear_.back()));
|
||||
rear_.popBack();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -90,7 +98,10 @@ class Fifo
|
|||
MOZ_MUST_USE bool pushBack(U&& u) {
|
||||
if (!rear_.append(mozilla::Forward<U>(u)))
|
||||
return false;
|
||||
fixup();
|
||||
if (!fixup()) {
|
||||
rear_.popBack();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -99,7 +110,10 @@ class Fifo
|
|||
MOZ_MUST_USE bool emplaceBack(Args&&... args) {
|
||||
if (!rear_.emplaceBack(mozilla::Forward<Args>(args)...))
|
||||
return false;
|
||||
fixup();
|
||||
if (!fixup()) {
|
||||
rear_.popBack();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -114,10 +128,20 @@ class Fifo
|
|||
}
|
||||
|
||||
// Remove the front element from the queue.
|
||||
void popFront() {
|
||||
MOZ_MUST_USE bool popFront() {
|
||||
MOZ_ASSERT(!empty());
|
||||
T t(mozilla::Move(front()));
|
||||
front_.popBack();
|
||||
fixup();
|
||||
if (!fixup()) {
|
||||
// Attempt to remain in a valid state by reinserting the element
|
||||
// back at the front. If we can't remain in a valid state in the
|
||||
// face of OOMs, crash.
|
||||
AutoEnterOOMUnsafeRegion oomUnsafe;
|
||||
if (!front_.append(mozilla::Move(t)))
|
||||
oomUnsafe.crash("js::Fifo::popFront");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Clear all elements from the queue.
|
||||
|
|
|
@ -79,7 +79,7 @@ class MutableWrappedPtrOperations<TraceableFifo<T, Capacity, AllocPolicy>, Wrapp
|
|||
return fifo().emplaceBack(mozilla::Forward<Args...>(args...));
|
||||
}
|
||||
|
||||
void popFront() { fifo().popFront(); }
|
||||
bool popFront() { return fifo().popFront(); }
|
||||
void clear() { fifo().clear(); }
|
||||
};
|
||||
|
||||
|
|
|
@ -323,7 +323,7 @@ BEGIN_TEST(testTraceableFifo)
|
|||
bool match;
|
||||
CHECK(JS_StringEqualsAscii(cx, JSID_TO_STRING(shapes.front()->propid()), buffer, &match));
|
||||
CHECK(match);
|
||||
shapes.popFront();
|
||||
CHECK(shapes.popFront());
|
||||
}
|
||||
|
||||
CHECK(shapes.empty());
|
||||
|
|
|
@ -2298,7 +2298,10 @@ Debugger::appendAllocationSite(JSContext* cx, HandleObject obj, HandleSavedFrame
|
|||
}
|
||||
|
||||
if (allocationsLog.length() > maxAllocationsLogLength) {
|
||||
allocationsLog.popFront();
|
||||
if (!allocationsLog.popFront()) {
|
||||
ReportOutOfMemory(cx);
|
||||
return false;
|
||||
}
|
||||
MOZ_ASSERT(allocationsLog.length() == maxAllocationsLogLength);
|
||||
allocationsLogOverflowed = true;
|
||||
}
|
||||
|
|
|
@ -238,7 +238,10 @@ DebuggerMemory::drainAllocationsLog(JSContext* cx, unsigned argc, Value* vp)
|
|||
// Pop the front queue entry, and delete it immediately, so that the GC
|
||||
// sees the AllocationsLogEntry's HeapPtr barriers run atomically with
|
||||
// the change to the graph (the queue link).
|
||||
dbg->allocationsLog.popFront();
|
||||
if (!dbg->allocationsLog.popFront()) {
|
||||
ReportOutOfMemory(cx);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
dbg->allocationsLogOverflowed = false;
|
||||
|
@ -275,8 +278,12 @@ DebuggerMemory::setMaxAllocationsLogLength(JSContext* cx, unsigned argc, Value*
|
|||
Debugger* dbg = memory->getDebugger();
|
||||
dbg->maxAllocationsLogLength = max;
|
||||
|
||||
while (dbg->allocationsLog.length() > dbg->maxAllocationsLogLength)
|
||||
dbg->allocationsLog.popFront();
|
||||
while (dbg->allocationsLog.length() > dbg->maxAllocationsLogLength) {
|
||||
if (!dbg->allocationsLog.popFront()) {
|
||||
ReportOutOfMemory(cx);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
|
|
Загрузка…
Ссылка в новой задаче