Bug 794365 - Correctly finalize StaticStrings; r=billm
authorTerrence Cole <terrence@mozilla.com>
Wed, 26 Sep 2012 14:17:55 -0700
changeset 108293 898ae4d394b3339269dc93e760db4242b71d36c7
parent 108292 24e6cf3628aebc049380fd95d101b62a1d9eeadc
child 108294 81e6cc2d297ff6a9be09be06f35043f9130e680d
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersbillm
bugs794365
milestone18.0a1
Bug 794365 - Correctly finalize StaticStrings; r=billm The StaticStrings were getting kept alive past the final GC. This did not matter before because we never needed to free external characters. With uninlining this assumption is no longer true.
js/src/jscntxt.cpp
js/src/vm/String.h
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -445,16 +445,19 @@ js::DestroyContext(JSContext *cx, Destro
         /* Unpin all common names before final GC. */
         FinishCommonNames(rt);
 
         /* Clear debugging state to remove GC roots. */
         for (CompartmentsIter c(rt); !c.done(); c.next())
             c->clearTraps(rt->defaultFreeOp());
         JS_ClearAllWatchPoints(cx);
 
+        /* Clear the statics table to remove GC roots. */
+        rt->staticStrings.finish();
+
         PrepareForFullGC(rt);
         GC(rt, GC_NORMAL, gcreason::LAST_CONTEXT);
     } else if (mode == DCM_FORCE_GC) {
         JS_ASSERT(!rt->isHeapBusy());
         PrepareForFullGC(rt);
         GC(rt, GC_NORMAL, gcreason::DESTROY_CONTEXT);
     }
     js_delete(cx);
--- a/js/src/vm/String.h
+++ b/js/src/vm/String.h
@@ -682,29 +682,36 @@ class StaticStrings
     static const size_t SMALL_CHAR_LIMIT    = 128U;
     static const size_t NUM_SMALL_CHARS     = 64U;
 
     static const size_t INT_STATIC_LIMIT    = 256U;
 
     JSAtom *length2StaticTable[NUM_SMALL_CHARS * NUM_SMALL_CHARS];
     JSAtom *intStaticTable[INT_STATIC_LIMIT];
 
+    void clear() {
+        PodArrayZero(unitStaticTable);
+        PodArrayZero(length2StaticTable);
+        PodArrayZero(intStaticTable);
+    }
+
   public:
     /* We keep these public for the methodjit. */
     static const size_t UNIT_STATIC_LIMIT   = 256U;
     JSAtom *unitStaticTable[UNIT_STATIC_LIMIT];
 
     StaticStrings() {
-        PodArrayZero(unitStaticTable);
-        PodArrayZero(length2StaticTable);
-        PodArrayZero(intStaticTable);
+        clear();
     }
 
     bool init(JSContext *cx);
     void trace(JSTracer *trc);
+    void finish() {
+        clear();
+    }
 
     static inline bool hasUint(uint32_t u);
     inline JSAtom *getUint(uint32_t u);
 
     static inline bool hasInt(int32_t i);
     inline JSAtom *getInt(int32_t i);
 
     static inline bool hasUnit(jschar c);