Bug 1225298 - Use GCHashSet for atoms table, r=terrence
authorSteve Fink <sfink@mozilla.com>
Mon, 16 Nov 2015 21:56:36 -0800
changeset 309217 caec8d45e0e85e58c9dbec964407bca292fbeedf
parent 309216 df5c30c74fef10f92f0d10ba233a8050ce8124d5
child 309218 4cedcf1506cba07d3c72a3843f25b2c1c29eb1cf
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs1225298
milestone45.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 1225298 - Use GCHashSet for atoms table, r=terrence
js/src/jsatom.cpp
js/src/jsatom.h
--- a/js/src/jsatom.cpp
+++ b/js/src/jsatom.cpp
@@ -240,30 +240,18 @@ js::MarkWellKnownSymbols(JSTracer* trc)
         for (size_t i = 0; i < JS::WellKnownSymbolLimit; i++)
             TraceProcessGlobalRoot(trc, wks->get(i).get(), "well_known_symbol");
     }
 }
 
 void
 JSRuntime::sweepAtoms()
 {
-    if (!atoms_)
-        return;
-
-    for (AtomSet::Enum e(*atoms_); !e.empty(); e.popFront()) {
-        AtomStateEntry entry = e.front();
-        JSAtom* atom = entry.asPtrUnbarriered();
-        bool isDying = IsAboutToBeFinalizedUnbarriered(&atom);
-
-        /* Pinned or interned key cannot be finalized. */
-        MOZ_ASSERT_IF(hasContexts() && entry.isPinned(), !isDying);
-
-        if (isDying)
-            e.removeFront();
-    }
+    if (atoms_)
+        atoms_->sweep();
 }
 
 bool
 JSRuntime::transformToPermanentAtoms(JSContext* cx)
 {
     MOZ_ASSERT(!parentRuntime);
 
     // All static strings were created as permanent atoms, now move the contents
--- a/js/src/jsatom.h
+++ b/js/src/jsatom.h
@@ -7,18 +7,20 @@
 #ifndef jsatom_h
 #define jsatom_h
 
 #include "mozilla/HashFunctions.h"
 
 #include "jsalloc.h"
 
 #include "gc/Barrier.h"
+#include "gc/Marking.h"
 #include "gc/Rooting.h"
 #include "js/GCAPI.h"
+#include "js/GCHashTable.h"
 #include "vm/CommonPropertyNames.h"
 
 class JSAtom;
 class JSAutoByteString;
 
 namespace js {
 
 JS_STATIC_ASSERT(sizeof(HashNumber) == 4);
@@ -71,16 +73,21 @@ class AtomStateEntry
      * the hash function doesn't consider the tag to be a portion of the key.
      */
     void setPinned(bool pinned) const {
         const_cast<AtomStateEntry*>(this)->bits |= uintptr_t(pinned);
     }
 
     JSAtom* asPtr() const;
     JSAtom* asPtrUnbarriered() const;
+
+    bool needsSweep() {
+        JSAtom* atom = asPtrUnbarriered();
+        return gc::IsAboutToBeFinalizedUnbarriered(&atom);
+    }
 };
 
 struct AtomHasher
 {
     struct Lookup
     {
         union {
             const JS::Latin1Char* latin1Chars;
@@ -106,17 +113,17 @@ struct AtomHasher
         inline explicit Lookup(const JSAtom* atom);
     };
 
     static HashNumber hash(const Lookup& l) { return l.hash; }
     static inline bool match(const AtomStateEntry& entry, const Lookup& lookup);
     static void rekey(AtomStateEntry& k, const AtomStateEntry& newKey) { k = newKey; }
 };
 
-typedef HashSet<AtomStateEntry, AtomHasher, SystemAllocPolicy> AtomSet;
+using AtomSet = js::GCHashSet<AtomStateEntry, AtomHasher, SystemAllocPolicy>;
 
 // This class is a wrapper for AtomSet that is used to ensure the AtomSet is
 // not modified. It should only expose read-only methods from AtomSet.
 // Note however that the atoms within the table can be marked during GC.
 class FrozenAtomSet
 {
     AtomSet* mSet;