Bug 1211031 - Use WeakRef to manage the LazyScript to JSScript back-reference; r=jandem

--HG--
extra : rebase_source : ddc0faeb3fcb3fa0bdaf873ab9cce1e1ffb29cd8
This commit is contained in:
Terrence Cole 2015-10-02 15:29:34 -07:00
Родитель 8302f0688c
Коммит 95cb7b72c9
4 изменённых файлов: 19 добавлений и 14 удалений

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

@ -883,6 +883,9 @@ js::GCMarker::mark(T* thing)
void
LazyScript::traceChildren(JSTracer* trc)
{
if (script_)
TraceWeakEdge(trc, &script_, "script");
if (function_)
TraceEdge(trc, &function_, "function");
@ -906,6 +909,9 @@ LazyScript::traceChildren(JSTracer* trc)
inline void
js::GCMarker::eagerlyMarkChildren(LazyScript *thing)
{
if (thing->script_)
noteWeakEdge(thing->script_.unsafeUnbarrieredForTracing());
if (thing->function_)
traverseEdge(thing, static_cast<JSObject*>(thing->function_));

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

@ -1408,7 +1408,7 @@ JSFunction::createScriptForLazilyInterpretedFunction(JSContext* cx, HandleFuncti
// script together during bytecode compilation. Reset it now on
// error.
fun->initLazyScript(lazy);
if (lazy->maybeScriptUnbarriered())
if (lazy->hasScript())
lazy->resetScript();
return false;
}

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

@ -2964,14 +2964,12 @@ JSScript::finalize(FreeOp* fop)
fop->runtime()->lazyScriptCache.remove(this);
if (lazyScript && lazyScript->maybeScriptUnbarriered() == this) {
// In most cases, our LazyScript's script pointer will reference this
// script. However, because sweeping can be incremental, it's
// possible LazyScript::maybeScript() already null'ed this pointer.
// Furthermore, if we unlazified the LazyScript, it will have a
// completely different JSScript.
lazyScript->resetScript();
}
// In most cases, our LazyScript's script pointer will reference this
// script, and thus be nulled out by normal weakref processing. However, if
// we unlazified the LazyScript during incremental sweeping, it will have a
// completely different JSScript.
MOZ_ASSERT_IF(lazyScript && !IsAboutToBeFinalizedUnbarriered(&lazyScript),
!lazyScript->hasScript() || lazyScript->maybeScriptUnbarriered() != this);
}
static const uint32_t GSN_CACHE_THRESHOLD = 100;
@ -4172,7 +4170,7 @@ LazyScript::Create(ExclusiveContext* cx, HandleFunction fun,
MOZ_ASSERT(!res->sourceObject());
res->setParent(enclosingScope, &sourceObjectScript->scriptSourceUnwrap());
MOZ_ASSERT(!res->maybeScriptUnbarriered());
MOZ_ASSERT(!res->hasScript());
if (script)
res->initScript(script);

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

@ -2071,7 +2071,7 @@ class LazyScript : public gc::TenuredCell
// If non-nullptr, the script has been compiled and this is a forwarding
// pointer to the result. This is a weak pointer: after relazification, we
// can collect the script if there are no other pointers to it.
ReadBarrieredScript script_;
WeakRef<JSScript*> script_;
// Original function with which the lazy script is associated.
HeapPtrFunction function_;
@ -2174,13 +2174,14 @@ class LazyScript : public gc::TenuredCell
void resetScript();
JSScript* maybeScript() {
if (script_.unbarrieredGet() && gc::IsAboutToBeFinalized(&script_))
script_.set(nullptr);
return script_;
}
JSScript* maybeScriptUnbarriered() const {
const JSScript* maybeScriptUnbarriered() const {
return script_.unbarrieredGet();
}
bool hasScript() const {
return bool(script_);
}
JSObject* enclosingScope() const {
return enclosingScope_;