Bug 1641202 - Part 2: Rewind CompilationInfo.{funcData,functions}. r=tcampbell

Differential Revision: https://phabricator.services.mozilla.com/D81148
This commit is contained in:
Tooru Fujisawa 2020-07-08 19:15:24 +00:00
parent 2694f1a293
commit 01471d3b5b
4 changed files with 12 additions and 1 deletions

View File

@ -67,6 +67,7 @@ class GCVector {
bool initCapacity(size_t cap) { return vector.initCapacity(cap); }
MOZ_MUST_USE bool reserve(size_t req) { return vector.reserve(req); }
void shrinkBy(size_t amount) { return vector.shrinkBy(amount); }
void shrinkTo(size_t newLen) { return vector.shrinkTo(newLen); }
MOZ_MUST_USE bool growBy(size_t amount) { return vector.growBy(amount); }
MOZ_MUST_USE bool resize(size_t newLen) { return vector.resize(newLen); }

View File

@ -137,6 +137,7 @@ struct MOZ_RAII CompilationInfo : public JS::CustomAutoRooter {
// encounter discarded frontend state.
struct RewindToken {
FunctionBox* funbox = nullptr;
size_t funcDataLength = 0;
};
RewindToken getRewindToken();

View File

@ -11394,11 +11394,14 @@ template class Parser<FullParseHandler, char16_t>;
template class Parser<SyntaxParseHandler, char16_t>;
CompilationInfo::RewindToken CompilationInfo::getRewindToken() {
return RewindToken{traceListHead};
MOZ_ASSERT(funcData.length() == functions.length());
return RewindToken{traceListHead, funcData.length()};
}
void CompilationInfo::rewind(const CompilationInfo::RewindToken& pos) {
traceListHead = pos.funbox;
funcData.get().shrinkTo(pos.funcDataLength);
functions.get().shrinkTo(pos.funcDataLength);
}
} // namespace js::frontend

View File

@ -380,16 +380,22 @@ class MOZ_STACK_CLASS ParserBase : public ParserSharedBase,
friend class ParserBase;
LifoAlloc::Mark mark;
FunctionBox* traceListHead;
size_t funcDataLength;
};
Mark mark() const {
Mark m;
m.mark = alloc_.mark();
m.traceListHead = compilationInfo_.traceListHead;
MOZ_ASSERT(compilationInfo_.funcData.length() ==
compilationInfo_.functions.length());
m.funcDataLength = compilationInfo_.funcData.length();
return m;
}
void release(Mark m) {
alloc_.release(m.mark);
compilationInfo_.traceListHead = m.traceListHead;
compilationInfo_.funcData.get().shrinkTo(m.funcDataLength);
compilationInfo_.functions.get().shrinkTo(m.funcDataLength);
}
public: