Bug 1189112 - Part 2: simplify rooting of ScriptsAndCountsVector with PersistentRooted; r=nbp
authorTerrence Cole <terrence@mozilla.com>
Wed, 29 Jul 2015 14:59:49 -0700
changeset 287608 027800a23ccb63ac3b0b1f493de197e8cfefbd3b
parent 287607 abc018892155463bfee51a1cc3d72454904a0bf0
child 287609 5ba973a43c12931c3538803459de5cb71e4c1d81
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnbp
bugs1189112
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1189112 - Part 2: simplify rooting of ScriptsAndCountsVector with PersistentRooted; r=nbp
js/public/TraceableVector.h
js/src/gc/RootMarking.cpp
js/src/jsopcode.cpp
js/src/vm/Runtime.h
--- a/js/public/TraceableVector.h
+++ b/js/public/TraceableVector.h
@@ -130,51 +130,68 @@ class MutableTraceableVectorOperations
     T popCopy() { return vec().podCopy(); }
     template<typename U> T* insert(T* aP, U&& aVal) {
         return vec().insert(aP, mozilla::Forward<U>(aVal));
     }
     void erase(T* aT) { vec().erase(aT); }
     void erase(T* aBegin, T* aEnd) { vec().erase(aBegin, aEnd); }
 };
 
-template <typename A, size_t B, typename C, typename D>
-class RootedBase<TraceableVector<A,B,C,D>>
-  : public MutableTraceableVectorOperations<JS::Rooted<TraceableVector<A,B,C,D>>, A,B,C,D>
+template <typename T, size_t N, typename AP, typename TP>
+class RootedBase<TraceableVector<T,N,AP,TP>>
+  : public MutableTraceableVectorOperations<JS::Rooted<TraceableVector<T,N,AP,TP>>, T,N,AP,TP>
 {
-    using Vec = TraceableVector<A,B,C,D>;
+    using Vec = TraceableVector<T,N,AP,TP>;
 
-    friend class TraceableVectorOperations<JS::Rooted<Vec>, A,B,C,D>;
+    friend class TraceableVectorOperations<JS::Rooted<Vec>, T,N,AP,TP>;
     const Vec& extract() const { return *static_cast<const JS::Rooted<Vec>*>(this)->address(); }
 
-    friend class MutableTraceableVectorOperations<JS::Rooted<Vec>, A,B,C,D>;
+    friend class MutableTraceableVectorOperations<JS::Rooted<Vec>, T,N,AP,TP>;
     Vec& extract() { return *static_cast<JS::Rooted<Vec>*>(this)->address(); }
 };
 
-template <typename A, size_t B, typename C, typename D>
-class MutableHandleBase<TraceableVector<A,B,C,D>>
-  : public MutableTraceableVectorOperations<JS::MutableHandle<TraceableVector<A,B,C,D>>, A,B,C,D>
+template <typename T, size_t N, typename AP, typename TP>
+class MutableHandleBase<TraceableVector<T,N,AP,TP>>
+  : public MutableTraceableVectorOperations<JS::MutableHandle<TraceableVector<T,N,AP,TP>>,
+                                            T,N,AP,TP>
 {
-    using Vec = TraceableVector<A,B,C,D>;
+    using Vec = TraceableVector<T,N,AP,TP>;
 
-    friend class TraceableVectorOperations<JS::MutableHandle<Vec>, A,B,C,D>;
+    friend class TraceableVectorOperations<JS::MutableHandle<Vec>, T,N,AP,TP>;
     const Vec& extract() const {
         return *static_cast<const JS::MutableHandle<Vec>*>(this)->address();
     }
 
-    friend class MutableTraceableVectorOperations<JS::MutableHandle<Vec>, A,B,C,D>;
+    friend class MutableTraceableVectorOperations<JS::MutableHandle<Vec>, T,N,AP,TP>;
     Vec& extract() { return *static_cast<JS::MutableHandle<Vec>*>(this)->address(); }
 };
 
-template <typename A, size_t B, typename C, typename D>
-class HandleBase<TraceableVector<A,B,C,D>>
-  : public TraceableVectorOperations<JS::Handle<TraceableVector<A,B,C,D>>, A,B,C,D>
+template <typename T, size_t N, typename AP, typename TP>
+class HandleBase<TraceableVector<T,N,AP,TP>>
+  : public TraceableVectorOperations<JS::Handle<TraceableVector<T,N,AP,TP>>, T,N,AP,TP>
 {
-    using Vec = TraceableVector<A,B,C,D>;
+    using Vec = TraceableVector<T,N,AP,TP>;
 
-    friend class TraceableVectorOperations<JS::Handle<Vec>, A,B,C,D>;
+    friend class TraceableVectorOperations<JS::Handle<Vec>, T,N,AP,TP>;
     const Vec& extract() const {
         return *static_cast<const JS::Handle<Vec>*>(this)->address();
     }
 };
 
+template <typename T, size_t N, typename AP, typename TP>
+class PersistentRootedBase<TraceableVector<T,N,AP,TP>>
+  : public MutableTraceableVectorOperations<JS::PersistentRooted<TraceableVector<T,N,AP,TP>>,
+                                            T,N,AP,TP>
+{
+    using Vec = TraceableVector<T,N,AP,TP>;
+
+    friend class TraceableVectorOperations<JS::PersistentRooted<Vec>, T,N,AP,TP>;
+    const Vec& extract() const {
+        return *static_cast<const JS::PersistentRooted<Vec>*>(this)->address();
+    }
+
+    friend class MutableTraceableVectorOperations<JS::PersistentRooted<Vec>, T,N,AP,TP>;
+    Vec& extract() { return *static_cast<JS::PersistentRooted<Vec>*>(this)->address(); }
+};
+
 } // namespace js
 
 #endif // js_TraceableVector_h
--- a/js/src/gc/RootMarking.cpp
+++ b/js/src/gc/RootMarking.cpp
@@ -360,19 +360,16 @@ js::gc::GCRuntime::markRuntime(JSTracer*
         for (RootRange r = rootsHash.all(); !r.empty(); r.popFront()) {
             const RootEntry& entry = r.front();
             TraceRoot(trc, entry.key(), entry.value());
         }
 
         MarkPersistentRootedChains(trc);
     }
 
-    if (rt->scriptAndCountsVector)
-        rt->scriptAndCountsVector->trace(trc);
-
     if (!rt->isBeingDestroyed() && !rt->isHeapMinorCollecting()) {
         gcstats::AutoPhase ap(stats, gcstats::PHASE_MARK_RUNTIME_DATA);
 
         if (traceOrMark == TraceRuntime || rt->atomsCompartment()->zone()->isCollecting()) {
             MarkPermanentAtoms(trc);
             MarkAtoms(trc);
             MarkWellKnownSymbols(trc);
             jit::JitRuntime::Mark(trc);
--- a/js/src/jsopcode.cpp
+++ b/js/src/jsopcode.cpp
@@ -1601,17 +1601,17 @@ js::IsValidBytecodeOffset(JSContext* cx,
  */
 
 static void
 ReleaseScriptCounts(FreeOp* fop)
 {
     JSRuntime* rt = fop->runtime();
     MOZ_ASSERT(rt->scriptAndCountsVector);
 
-    ScriptAndCountsVector& vec = *rt->scriptAndCountsVector;
+    ScriptAndCountsVector& vec = rt->scriptAndCountsVector->get();
 
     for (size_t i = 0; i < vec.length(); i++)
         vec[i].scriptCounts.destroy(fop);
 
     fop->delete_(rt->scriptAndCountsVector);
     rt->scriptAndCountsVector = nullptr;
 }
 
@@ -1637,17 +1637,18 @@ js::StopPCCountProfiling(JSContext* cx)
     JSRuntime* rt = cx->runtime();
 
     if (!rt->profilingScripts)
         return;
     MOZ_ASSERT(!rt->scriptAndCountsVector);
 
     ReleaseAllJITCode(rt->defaultFreeOp());
 
-    ScriptAndCountsVector* vec = cx->new_<ScriptAndCountsVector>(SystemAllocPolicy());
+    auto* vec = cx->new_<PersistentRooted<ScriptAndCountsVector>>(cx,
+        ScriptAndCountsVector(SystemAllocPolicy()));
     if (!vec)
         return;
 
     for (ZonesIter zone(rt, SkipAtoms); !zone.done(); zone.next()) {
         for (ZoneCellIter i(zone, AllocKind::SCRIPT); !i.done(); i.next()) {
             JSScript* script = i.get<JSScript>();
             if (script->hasScriptCounts() && script->types()) {
                 ScriptAndCounts sac;
--- a/js/src/vm/Runtime.h
+++ b/js/src/vm/Runtime.h
@@ -1047,17 +1047,17 @@ struct JSRuntime : public JS::shadow::Ru
 
   public:
 #ifdef JS_SIMULATOR
     js::jit::Simulator* simulator() const;
     uintptr_t* addressOfSimulatorStackLimit();
 #endif
 
     /* Strong references on scripts held for PCCount profiling API. */
-    js::ScriptAndCountsVector* scriptAndCountsVector;
+    JS::PersistentRooted<js::ScriptAndCountsVector>* scriptAndCountsVector;
 
     /* Well-known numbers held for use by this runtime's contexts. */
     const js::Value     NaNValue;
     const js::Value     negativeInfinityValue;
     const js::Value     positiveInfinityValue;
 
     js::PropertyName*   emptyString;