Bug 1530412 - Use mozilla::Span for LazyScript tables r=jorendorff

The Span abstraction lets us use range-based iteration and simplifies
changes if we move where the underlying data is stored.

Differential Revision: https://phabricator.services.mozilla.com/D23403

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ted Campbell 2019-04-01 15:08:56 +00:00
Родитель 281b3d9300
Коммит da7ce5d164
4 изменённых файлов: 39 добавлений и 43 удалений

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

@ -992,17 +992,16 @@ void LazyScript::traceChildren(JSTracer* trc) {
}
// We rely on the fact that atoms are always tenured.
JSAtom** closedOverBindings = this->closedOverBindings();
for (auto i : IntegerRange(numClosedOverBindings())) {
if (closedOverBindings[i]) {
TraceManuallyBarrieredEdge(trc, &closedOverBindings[i],
"closedOverBinding");
for (GCPtrAtom& closedOverBinding : closedOverBindings()) {
if (closedOverBinding) {
TraceEdge(trc, &closedOverBinding, "closedOverBinding");
}
}
GCPtrFunction* innerFunctions = this->innerFunctions();
for (auto i : IntegerRange(numInnerFunctions())) {
TraceEdge(trc, &innerFunctions[i], "lazyScriptInnerFunction");
for (GCPtrFunction& innerFunction : innerFunctions()) {
if (innerFunction) {
TraceEdge(trc, &innerFunction, "lazyScriptInnerFunction");
}
}
if (trc->isMarkingTracer()) {
@ -1031,16 +1030,16 @@ inline void js::GCMarker::eagerlyMarkChildren(LazyScript* thing) {
}
// We rely on the fact that atoms are always tenured.
JSAtom** closedOverBindings = thing->closedOverBindings();
for (auto i : IntegerRange(thing->numClosedOverBindings())) {
if (closedOverBindings[i]) {
traverseEdge(thing, static_cast<JSString*>(closedOverBindings[i]));
for (GCPtrAtom& closedOverBinding : thing->closedOverBindings()) {
if (closedOverBinding) {
traverseEdge(thing, static_cast<JSString*>(closedOverBinding));
}
}
GCPtrFunction* innerFunctions = thing->innerFunctions();
for (auto i : IntegerRange(thing->numInnerFunctions())) {
traverseEdge(thing, static_cast<JSObject*>(innerFunctions[i]));
for (GCPtrFunction& innerFunction : thing->innerFunctions()) {
if (innerFunction) {
traverseEdge(thing, static_cast<JSObject*>(innerFunction));
}
}
markImplicitEdges(thing);

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

@ -86,11 +86,7 @@ static void TraverseInnerLazyScriptsForLazyScript(
JSContext* cx, void* data, LazyScript* enclosingLazyScript,
IterateLazyScriptCallback lazyScriptCallback,
const JS::AutoRequireNoGC& nogc) {
GCPtrFunction* innerFunctions = enclosingLazyScript->innerFunctions();
for (size_t i = 0, len = enclosingLazyScript->numInnerFunctions(); i < len;
i++) {
JSFunction* fun = innerFunctions[i];
for (JSFunction* fun : enclosingLazyScript->innerFunctions()) {
// LazyScript::CreateForXDR temporarily initializes innerFunctions with
// its own function, but it should be overwritten with correct
// inner functions before getting inserted into parent's innerFunctions.

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

@ -236,10 +236,10 @@ static XDRResult XDRLazyClosedOverBindings(XDRState<mode>* xdr,
MutableHandle<LazyScript*> lazy) {
JSContext* cx = xdr->cx();
RootedAtom atom(cx);
for (size_t i = 0; i < lazy->numClosedOverBindings(); i++) {
for (GCPtrAtom& elem : lazy->closedOverBindings()) {
uint8_t endOfScopeSentinel;
if (mode == XDR_ENCODE) {
atom = lazy->closedOverBindings()[i];
atom = elem.get();
endOfScopeSentinel = !atom;
}
@ -252,7 +252,7 @@ static XDRResult XDRLazyClosedOverBindings(XDRState<mode>* xdr,
}
if (mode == XDR_DECODE) {
lazy->closedOverBindings()[i] = atom;
elem.init(atom);
}
}
@ -1118,19 +1118,17 @@ XDRResult js::XDRLazyScript(XDRState<mode>* xdr, HandleScope enclosingScope,
// Code inner functions.
{
RootedFunction func(cx);
GCPtrFunction* innerFunctions = lazy->innerFunctions();
size_t numInnerFunctions = lazy->numInnerFunctions();
for (size_t i = 0; i < numInnerFunctions; i++) {
for (GCPtrFunction& elem : lazy->innerFunctions()) {
if (mode == XDR_ENCODE) {
func = innerFunctions[i];
func = elem.get();
}
MOZ_TRY(XDRInterpretedFunction(xdr, nullptr, sourceObject, &func));
if (mode == XDR_DECODE) {
innerFunctions[i] = func;
if (innerFunctions[i]->isInterpretedLazy()) {
innerFunctions[i]->lazyScript()->setEnclosingLazyScript(lazy);
elem.init(func);
if (elem->isInterpretedLazy()) {
elem->lazyScript()->setEnclosingLazyScript(lazy);
}
}
}
@ -4985,12 +4983,12 @@ LazyScript* LazyScript::Create(JSContext* cx, HandleFunction fun,
return nullptr;
}
JSAtom** resClosedOverBindings = res->closedOverBindings();
mozilla::Span<GCPtrAtom> resClosedOverBindings = res->closedOverBindings();
for (size_t i = 0; i < res->numClosedOverBindings(); i++) {
resClosedOverBindings[i] = closedOverBindings[i];
resClosedOverBindings[i].init(closedOverBindings[i]);
}
GCPtrFunction* resInnerFunctions = res->innerFunctions();
mozilla::Span<GCPtrFunction> resInnerFunctions = res->innerFunctions();
for (size_t i = 0; i < res->numInnerFunctions(); i++) {
resInnerFunctions[i].init(innerFunctions[i]);
if (resInnerFunctions[i]->isInterpretedLazy()) {
@ -5026,15 +5024,12 @@ LazyScript* LazyScript::CreateForXDR(
// Fill with dummies, to be GC-safe after the initialization of the free
// variables and inner functions.
size_t i, num;
JSAtom** closedOverBindings = res->closedOverBindings();
for (i = 0, num = res->numClosedOverBindings(); i < num; i++) {
closedOverBindings[i] = dummyAtom;
for (GCPtrAtom& closedOverBinding : res->closedOverBindings()) {
closedOverBinding.init(dummyAtom);
}
GCPtrFunction* functions = res->innerFunctions();
for (i = 0, num = res->numInnerFunctions(); i < num; i++) {
functions[i].init(dummyFun);
for (GCPtrFunction& innerFunction : res->innerFunctions()) {
innerFunction.init(dummyFun);
}
// Set the enclosing scope of the lazy function. This value should only be

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

@ -3115,11 +3115,17 @@ class LazyScript : public gc::TenuredCell {
bool mutedErrors() const { return scriptSource()->mutedErrors(); }
uint32_t numClosedOverBindings() const { return numClosedOverBindings_; }
JSAtom** closedOverBindings() { return (JSAtom**)table_; }
mozilla::Span<GCPtrAtom> closedOverBindings() {
return mozilla::MakeSpan(reinterpret_cast<GCPtrAtom*>(table_),
numClosedOverBindings_);
}
uint32_t numInnerFunctions() const { return numInnerFunctions_; }
GCPtrFunction* innerFunctions() {
return (GCPtrFunction*)&closedOverBindings()[numClosedOverBindings()];
mozilla::Span<GCPtrFunction> innerFunctions() {
uintptr_t base = reinterpret_cast<uintptr_t>(table_);
size_t offset = numClosedOverBindings_ * sizeof(GCPtrAtom);
return mozilla::MakeSpan(reinterpret_cast<GCPtrFunction*>(base + offset),
numInnerFunctions_);
}
GeneratorKind generatorKind() const {