From 961f447726346d943c24076f999fd7b1d4df8bf7 Mon Sep 17 00:00:00 2001 From: Steve Fink Date: Mon, 18 Mar 2019 21:37:05 +0000 Subject: [PATCH] Bug 1257982 - root some hashtables r=jonco Differential Revision: https://phabricator.services.mozilla.com/D23620 --HG-- extra : moz-landing-system : lando --- js/src/frontend/ParseContext.h | 23 +++++++++++++++++++---- js/src/vm/Debugger.cpp | 6 +++--- js/src/vm/EnvironmentObject.cpp | 6 +++--- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/js/src/frontend/ParseContext.h b/js/src/frontend/ParseContext.h index b56250ed5b15..6673b61e73ba 100644 --- a/js/src/frontend/ParseContext.h +++ b/js/src/frontend/ParseContext.h @@ -78,6 +78,11 @@ class UsedNameTracker { UsedNameInfo(UsedNameInfo&& other) : uses_(std::move(other.uses_)) {} + UsedNameInfo& operator=(UsedNameInfo&& other) { + uses_ = std::move(other.uses_); + return *this; + } + bool noteUsedInScope(uint32_t scriptId, uint32_t scopeId) { if (uses_.empty() || uses_.back().scopeId < scopeId) { return uses_.append(Use{scriptId, scopeId}); @@ -105,11 +110,13 @@ class UsedNameTracker { } }; - using UsedNameMap = HashMap>; + using UsedNameMap = GCHashMap>; private: - // The map of names to chains of uses. - UsedNameMap map_; + // The map of names to chains of uses. UsedNameTracker is not used in LIFO + // order with Rooteds, so must use PersistentRooted (for the arbitrary + // ordering capability, not for persistence.) + PersistentRooted map_; // Monotonically increasing id for all nested scripts. uint32_t scriptCounter_; @@ -119,7 +126,7 @@ class UsedNameTracker { public: explicit UsedNameTracker(JSContext* cx) - : map_(cx), scriptCounter_(0), scopeCounter_(0) {} + : map_(cx, cx), scriptCounter_(0), scopeCounter_(0) {} uint32_t nextScriptId() { MOZ_ASSERT(scriptCounter_ != UINT32_MAX, @@ -665,4 +672,12 @@ class ParseContext : public Nestable { } // namespace js +namespace JS { + +template <> +struct GCPolicy + : public IgnoreGCPolicy {}; + +} // namespace JS + #endif // frontend_ParseContext_h diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp index 58af14f1d2af..2e11922c14ea 100644 --- a/js/src/vm/Debugger.cpp +++ b/js/src/vm/Debugger.cpp @@ -4538,7 +4538,7 @@ class MOZ_STACK_CLASS Debugger::ScriptQuery : public Debugger::QueryBase { hasLine(false), line(0), innermost(false), - innermostForRealm(cx->zone()), + innermostForRealm(cx, cx->zone()), scriptVector(cx, ScriptVector(cx)), lazyScriptVector(cx, LazyScriptVector(cx)), wasmInstanceVector(cx, WasmInstanceObjectVector(cx)) {} @@ -4806,14 +4806,14 @@ class MOZ_STACK_CLASS Debugger::ScriptQuery : public Debugger::QueryBase { bool innermost; using RealmToScriptMap = - HashMap, ZoneAllocPolicy>; + GCHashMap, ZoneAllocPolicy>; /* * For 'innermost' queries, a map from realms to the innermost script * we've seen so far in that realm. (Template instantiation code size * explosion ho!) */ - RealmToScriptMap innermostForRealm; + Rooted innermostForRealm; /* * Accumulate the scripts in an Rooted and diff --git a/js/src/vm/EnvironmentObject.cpp b/js/src/vm/EnvironmentObject.cpp index 6d3d2e4fe56c..df21feeaacdf 100644 --- a/js/src/vm/EnvironmentObject.cpp +++ b/js/src/vm/EnvironmentObject.cpp @@ -3719,7 +3719,7 @@ bool js::GetFrameEnvironmentAndScope(JSContext* cx, AbstractFramePtr frame, #ifdef DEBUG -typedef HashSet PropertyNameSet; +using PropertyNameSet = GCHashSet; static bool RemoveReferencedNames(JSContext* cx, HandleScript script, PropertyNameSet& remainingNames) { @@ -3797,7 +3797,7 @@ static bool RemoveReferencedNames(JSContext* cx, HandleScript script, static bool AnalyzeEntrainedVariablesInScript(JSContext* cx, HandleScript script, HandleScript innerScript) { - PropertyNameSet remainingNames(cx); + Rooted remainingNames(cx, cx); for (BindingIter bi(script); bi; bi++) { if (bi.closedOver()) { @@ -3809,7 +3809,7 @@ static bool AnalyzeEntrainedVariablesInScript(JSContext* cx, } } - if (!RemoveReferencedNames(cx, innerScript, remainingNames)) { + if (!RemoveReferencedNames(cx, innerScript, remainingNames.get())) { return false; }