Bug 968616 - "Implement" AutoIgnoreRootingHazards, r=terrence
authorSteve Fink <sfink@mozilla.com>
Tue, 18 Feb 2014 14:45:21 -0800
changeset 169972 7f6f5e970345d4ec0bfd45d5f9145bceee007ee6
parent 169971 892751e80036a9c04fd361ca3fb8c348d809693a
child 169973 6609365ee797da12a7789db922ab4237ba375d6b
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersterrence
bugs968616
milestone30.0a1
Bug 968616 - "Implement" AutoIgnoreRootingHazards, r=terrence
js/src/devtools/rootAnalysis/annotations.js
js/src/jsapi-tests/testGCStoreBufferRemoval.cpp
--- a/js/src/devtools/rootAnalysis/annotations.js
+++ b/js/src/devtools/rootAnalysis/annotations.js
@@ -220,19 +220,20 @@ function isRootedPointerTypeName(name)
     if (name.startsWith('MaybeRooted<'))
         return /\(js::AllowGC\)1u>::RootType/.test(name);
 
     return name.startsWith('Rooted') || name.startsWith('PersistentRooted');
 }
 
 function isSuppressConstructor(name)
 {
-    return /::AutoSuppressGC/.test(name)
-        || /::AutoEnterAnalysis/.test(name)
-        || /::AutoAssertNoGC/.test(name);
+    return name.indexOf("::AutoSuppressGC") != -1
+        || name.indexOf("::AutoEnterAnalysis") != -1
+        || name.indexOf("::AutoAssertNoGC") != -1
+        || name.indexOf("::AutoIgnoreRootingHazards") != -1;
 }
 
 // nsISupports subclasses' methods may be scriptable (or overridden
 // via binary XPCOM), and so may GC. But some fields just aren't going
 // to get overridden with something that can GC.
 function isOverridableField(initialCSU, csu, field)
 {
     if (csu != 'nsISupports')
--- a/js/src/jsapi-tests/testGCStoreBufferRemoval.cpp
+++ b/js/src/jsapi-tests/testGCStoreBufferRemoval.cpp
@@ -8,33 +8,41 @@
 #ifdef JSGC_GENERATIONAL
 
 #include "gc/Barrier.h"
 #include "jsapi-tests/tests.h"
 
 using namespace JS;
 using namespace js;
 
+struct AutoIgnoreRootingHazards {
+    // Force a nontrivial destructor so the compiler sees the whole RAII scope
+    static volatile int depth;
+    AutoIgnoreRootingHazards() { depth++; }
+    ~AutoIgnoreRootingHazards() { depth--; }
+};
+volatile int AutoIgnoreRootingHazards::depth = 0;
+
 BEGIN_TEST(testGCStoreBufferRemoval)
 {
     // Sanity check - objects start in the nursery and then become tenured.
     JS_GC(cx->runtime());
     JS::RootedObject obj(cx, NurseryObject());
     CHECK(js::gc::IsInsideNursery(rt, obj.get()));
     JS_GC(cx->runtime());
     CHECK(!js::gc::IsInsideNursery(rt, obj.get()));
     JS::RootedObject tenuredObject(cx, obj);
 
     // Hide the horrors herein from the static rooting analysis.
-    typedef JSObject *ObjectPtr;
+    AutoIgnoreRootingHazards ignore;
 
     // Test removal of store buffer entries added by RelocatablePtr<T>.
     {
-        ObjectPtr badObject = reinterpret_cast<JSObject*>(1);
-        ObjectPtr punnedPtr = nullptr;
+        JSObject *badObject = reinterpret_cast<JSObject*>(1);
+        JSObject *punnedPtr = nullptr;
         RelocatablePtrObject* relocPtr =
             reinterpret_cast<RelocatablePtrObject*>(&punnedPtr);
         new (relocPtr) RelocatablePtrObject;
         *relocPtr = NurseryObject();
         relocPtr->~RelocatablePtrObject();
         punnedPtr = badObject;
         JS_GC(cx->runtime());
 
@@ -75,18 +83,18 @@ BEGIN_TEST(testGCStoreBufferRemoval)
         *relocValue = NullValue();
         relocValue->~RelocatableValue();
         punnedValue = ObjectValueCrashOnTouch();
         JS_GC(cx->runtime());
     }
 
     // Test removal of store buffer entries added by Heap<T>.
     {
-        ObjectPtr badObject = reinterpret_cast<JSObject*>(1);
-        ObjectPtr punnedPtr = nullptr;
+        JSObject *badObject = reinterpret_cast<JSObject*>(1);
+        JSObject *punnedPtr = nullptr;
         Heap<JSObject*>* heapPtr =
             reinterpret_cast<Heap<JSObject*>*>(&punnedPtr);
         new (heapPtr) Heap<JSObject*>;
         *heapPtr = NurseryObject();
         heapPtr->~Heap<JSObject*>();
         punnedPtr = badObject;
         JS_GC(cx->runtime());