mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 09:45:41 +00:00
Bug 1618995 - Stop storing the Empty Global Scope in the GCThingList r=mgaudet
Differential Revision: https://phabricator.services.mozilla.com/D67101 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
7434f710c9
commit
318f15d93a
@ -13,8 +13,9 @@
|
||||
#include "frontend/SharedContext.h" // FunctionBox
|
||||
#include "frontend/Stencil.h" // ScopeCreationData
|
||||
#include "vm/BytecodeUtil.h" // INDEX_LIMIT, StackUses, StackDefs
|
||||
#include "vm/JSContext.h" // JSContext
|
||||
#include "vm/RegExpObject.h" // RegexpObject
|
||||
#include "vm/GlobalObject.h"
|
||||
#include "vm/JSContext.h" // JSContext
|
||||
#include "vm/RegExpObject.h" // RegexpObject
|
||||
|
||||
using namespace js;
|
||||
using namespace js::frontend;
|
||||
@ -43,6 +44,16 @@ void GCThingList::finishInnerFunctions() {
|
||||
}
|
||||
}
|
||||
|
||||
AbstractScopePtr GCThingList::getScope(size_t index) const {
|
||||
auto& elem = vector[index].get();
|
||||
if (elem.is<JS::GCCellPtr>()) {
|
||||
return AbstractScopePtr(&elem.as<JS::GCCellPtr>().as<Scope>());
|
||||
} else if (elem.is<EmptyGlobalScopeType>()) {
|
||||
return AbstractScopePtr(&compilationInfo.cx->global()->emptyGlobalScope());
|
||||
}
|
||||
return AbstractScopePtr(compilationInfo, elem.as<ScopeIndex>());
|
||||
}
|
||||
|
||||
bool js::frontend::EmitScriptThingsVector(JSContext* cx,
|
||||
CompilationInfo& compilationInfo,
|
||||
const ScriptThingsVector& objects,
|
||||
@ -112,6 +123,12 @@ bool js::frontend::EmitScriptThingsVector(JSContext* cx,
|
||||
output[i] = JS::GCCellPtr(data.as<JSFunction*>());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator()(const EmptyGlobalScopeType& emptyGlobalScope) {
|
||||
Scope* scope = &cx->global()->emptyGlobalScope();
|
||||
output[i] = JS::GCCellPtr(scope);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
for (uint32_t i = 0; i < objects.length(); i++) {
|
||||
|
@ -67,16 +67,6 @@ struct MOZ_STACK_CLASS GCThingList {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
MOZ_MUST_USE bool append(Scope* scope, uint32_t* index) {
|
||||
*index = vector.length();
|
||||
if (!vector.append(mozilla::AsVariant(JS::GCCellPtr(scope)))) {
|
||||
return false;
|
||||
}
|
||||
if (!firstScopeIndex) {
|
||||
firstScopeIndex.emplace(*index);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
MOZ_MUST_USE bool append(BigIntLiteral* literal, uint32_t* index) {
|
||||
*index = vector.length();
|
||||
return vector.append(mozilla::AsVariant(literal->index()));
|
||||
@ -91,19 +81,25 @@ struct MOZ_STACK_CLASS GCThingList {
|
||||
}
|
||||
MOZ_MUST_USE bool append(FunctionBox* funbox, uint32_t* index);
|
||||
|
||||
MOZ_MUST_USE bool appendEmptyGlobalScope(uint32_t* index) {
|
||||
*index = vector.length();
|
||||
EmptyGlobalScopeType emptyGlobalScope;
|
||||
if (!vector.append(mozilla::AsVariant(emptyGlobalScope))) {
|
||||
return false;
|
||||
}
|
||||
if (!firstScopeIndex) {
|
||||
firstScopeIndex.emplace(*index);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t length() const { return vector.length(); }
|
||||
|
||||
const ScriptThingsVector& objects() { return vector; }
|
||||
|
||||
void finishInnerFunctions();
|
||||
|
||||
AbstractScopePtr getScope(size_t index) const {
|
||||
auto& elem = vector[index].get();
|
||||
if (elem.is<JS::GCCellPtr>()) {
|
||||
return AbstractScopePtr(&elem.as<JS::GCCellPtr>().as<Scope>());
|
||||
}
|
||||
return AbstractScopePtr(compilationInfo, elem.as<ScopeIndex>());
|
||||
}
|
||||
AbstractScopePtr getScope(size_t index) const;
|
||||
|
||||
AbstractScopePtr firstScope() const {
|
||||
MOZ_ASSERT(firstScopeIndex.isSome());
|
||||
|
@ -338,7 +338,8 @@ bool EmitterScope::internEmptyGlobalScopeAsBody(BytecodeEmitter* bce) {
|
||||
hasEnvironment_ = scope->hasEnvironment();
|
||||
|
||||
bce->bodyScopeIndex = bce->perScriptData().gcThingList().length();
|
||||
return bce->perScriptData().gcThingList().append(scope, &scopeIndex_);
|
||||
return bce->perScriptData().gcThingList().appendEmptyGlobalScope(
|
||||
&scopeIndex_);
|
||||
}
|
||||
|
||||
template <typename ScopeCreator>
|
||||
|
@ -441,12 +441,15 @@ class ScopeCreationData {
|
||||
}
|
||||
};
|
||||
|
||||
class EmptyGlobalScopeType {};
|
||||
|
||||
// These types all end up being baked into GC things as part of stencil
|
||||
// instantiation. Currently, GCCellPtr is part of this list while we complete
|
||||
// Stencil, but eventually will be removed.
|
||||
using ScriptThingVariant =
|
||||
mozilla::Variant<JS::GCCellPtr, BigIntIndex, ObjLiteralCreationData,
|
||||
RegExpIndex, ScopeIndex, FunctionIndex>;
|
||||
RegExpIndex, ScopeIndex, FunctionIndex,
|
||||
EmptyGlobalScopeType>;
|
||||
|
||||
// A vector of things destined to be converted to GC things.
|
||||
using ScriptThingsVector = GCVector<ScriptThingVariant>;
|
||||
@ -518,5 +521,9 @@ struct GCPolicy<js::frontend::TypedIndex<T>>
|
||||
template <>
|
||||
struct GCPolicy<js::frontend::FunctionIndex>
|
||||
: JS::IgnoreGCPolicy<js::frontend::FunctionIndex> {};
|
||||
|
||||
template <>
|
||||
struct GCPolicy<js::frontend::EmptyGlobalScopeType>
|
||||
: JS::IgnoreGCPolicy<js::frontend::EmptyGlobalScopeType> {};
|
||||
} // namespace JS
|
||||
#endif /* frontend_Stencil_h */
|
||||
|
Loading…
Reference in New Issue
Block a user