Bug 848395 - GC: Move Rooted to JS namespace - Move js::Rooted to JS namespace r=terrence
authorJon Coppeard <jcoppeard@mozilla.com>
Wed, 06 Mar 2013 16:41:38 +0000
changeset 124134 fc80038cf2ef412222daca08db2308f99f2d08b0
parent 124133 577f5474a1b7c9cb49ba335809332185e9ccbb4f
child 124135 e9dca222d6c3aa1f4311dbac73769c3e9bd1be90
push id1408
push userjwalker@mozilla.com
push dateFri, 08 Mar 2013 16:48:59 +0000
treeherderfx-team@af5f267cd6a1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs848395
milestone22.0a1
Bug 848395 - GC: Move Rooted to JS namespace - Move js::Rooted to JS namespace r=terrence
CLOBBER
js/src/gc/Root.h
js/src/jspubtd.h
js/src/vm/String.h
--- a/CLOBBER
+++ b/CLOBBER
@@ -10,9 +10,9 @@
 #                  O   <-- Users coming from both parents need to Clobber
 #               /     \
 #          O               O
 #          |               |
 #          O <-- Clobber   O  <-- Clobber
 #
 # Note: The description below will be part of the error message shown to users.
 #
-Bug 784841 pretty much changed how the build system works. It's best to clobber.
+Bug 848395 resulted in Windows test failures when landed without clobber
--- a/js/src/gc/Root.h
+++ b/js/src/gc/Root.h
@@ -112,34 +112,34 @@
  * only for the purpose of bootstrapping exact rooting and will be removed in
  * the future (Bug 817164).
  */
 
 namespace js {
 
 class Module;
 
-template <typename T> class Rooted;
-
 template <typename T>
 struct RootMethods {};
 
 template <typename T>
 class RootedBase {};
 
 template <typename T>
 class HandleBase {};
 
 template <typename T>
 class MutableHandleBase {};
 
 } /* namespace js */
 
 namespace JS {
 
+template <typename T> class Rooted;
+
 class AutoAssertNoGC;
 
 template <typename T> class Handle;
 template <typename T> class MutableHandle;
 
 JS_FRIEND_API(void) EnterAssertNoGCScope();
 JS_FRIEND_API(void) LeaveAssertNoGCScope();
 
@@ -210,17 +210,17 @@ class Handle : public js::HandleBase<T>
     }
 
     /*
      * Construct a handle from an explicitly rooted location. This is the
      * normal way to create a handle, and normally happens implicitly.
      */
     template <typename S>
     inline
-    Handle(js::Rooted<S> &root,
+    Handle(Rooted<S> &root,
            typename mozilla::EnableIf<mozilla::IsConvertible<S, T>::value, int>::Type dummy = 0);
 
     /* Construct a read only handle from a mutable handle. */
     template <typename S>
     inline
     Handle(MutableHandle<S> &root,
            typename mozilla::EnableIf<mozilla::IsConvertible<S, T>::value, int>::Type dummy = 0);
 
@@ -257,17 +257,17 @@ typedef Handle<Value>        HandleValue
  * If you want to add additional methods to MutableHandle for a specific
  * specialization, define a MutableHandleBase<T> specialization containing
  * them.
  */
 template <typename T>
 class MutableHandle : public js::MutableHandleBase<T>
 {
   public:
-    inline MutableHandle(js::Rooted<T> *root);
+    inline MutableHandle(Rooted<T> *root);
 
     void set(T v) {
         JS_ASSERT(!js::RootMethods<T>::poisoned(v));
         *ptr = v;
     }
 
     /*
      * This may be called only if the location of the T is guaranteed
@@ -403,67 +403,71 @@ struct RootKind<T *>
 template <typename T>
 struct RootMethods<T *>
 {
     static T *initial() { return NULL; }
     static ThingRootKind kind() { return RootKind<T *>::rootKind(); }
     static bool poisoned(T *v) { return IsPoisonedPtr(v); }
 };
 
+} /* namespace js */
+
+namespace JS {
+
 /*
  * Local variable of type T whose value is always rooted. This is typically
  * used for local variables, or for non-rooted values being passed to a
  * function that requires a handle, e.g. Foo(Root<T>(cx, x)).
  *
  * If you want to add additional methods to Rooted for a specific
  * specialization, define a RootedBase<T> specialization containing them.
  */
 template <typename T>
-class Rooted : public RootedBase<T>
+class Rooted : public js::RootedBase<T>
 {
     void init(JSContext *cxArg) {
 #if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)
-        ContextFriendFields *cx = ContextFriendFields::get(cxArg);
+        js::ContextFriendFields *cx = js::ContextFriendFields::get(cxArg);
         commonInit(cx->thingGCRooters);
 #endif
     }
 
-    void init(PerThreadData *ptArg) {
+    void init(js::PerThreadData *ptArg) {
 #if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)
-        PerThreadDataFriendFields *pt = PerThreadDataFriendFields::get(ptArg);
+        js::PerThreadDataFriendFields *pt = js::PerThreadDataFriendFields::get(ptArg);
         commonInit(pt->thingGCRooters);
 #endif
     }
 
   public:
     Rooted(JSContext *cx
            MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
-      : ptr(RootMethods<T>::initial())
+      : ptr(js::RootMethods<T>::initial())
     {
         MOZ_GUARD_OBJECT_NOTIFIER_INIT;
         init(cx);
     }
 
     Rooted(JSContext *cx, T initial
            MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
       : ptr(initial)
     {
         MOZ_GUARD_OBJECT_NOTIFIER_INIT;
         init(cx);
     }
 
-    Rooted(PerThreadData *pt
+    Rooted(js::PerThreadData *pt
            MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
-      : ptr(RootMethods<T>::initial())
+      : ptr(js::RootMethods<T>::initial())
     {
         MOZ_GUARD_OBJECT_NOTIFIER_INIT;
         init(pt);
     }
 
-    Rooted(PerThreadData *pt, T initial
+    Rooted(js::PerThreadData *pt, T initial
            MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
       : ptr(initial)
     {
         MOZ_GUARD_OBJECT_NOTIFIER_INIT;
         init(pt);
     }
 
     ~Rooted() {
@@ -480,38 +484,38 @@ class Rooted : public RootedBase<T>
     operator T() const { return ptr; }
     T operator->() const { return ptr; }
     T *address() { return &ptr; }
     const T *address() const { return &ptr; }
     T &get() { return ptr; }
     const T &get() const { return ptr; }
 
     T &operator=(T value) {
-        JS_ASSERT(!RootMethods<T>::poisoned(value));
+        JS_ASSERT(!js::RootMethods<T>::poisoned(value));
         ptr = value;
         return ptr;
     }
 
     T &operator=(const Rooted &value) {
         ptr = value;
         return ptr;
     }
 
     bool operator!=(const T &other) { return ptr != other; }
     bool operator==(const T &other) { return ptr == other; }
 
   private:
     void commonInit(Rooted<void*> **thingGCRooters) {
 #if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)
-        ThingRootKind kind = RootMethods<T>::kind();
+        js::ThingRootKind kind = js::RootMethods<T>::kind();
         this->stack = &thingGCRooters[kind];
         this->prev = *stack;
         *stack = reinterpret_cast<Rooted<void*>*>(this);
 
-        JS_ASSERT(!RootMethods<T>::poisoned(ptr));
+        JS_ASSERT(!js::RootMethods<T>::poisoned(ptr));
 #endif
     }
 
 #if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)
     Rooted<void*> **stack, *prev;
 #endif
 
 #if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
@@ -540,16 +544,20 @@ class Rooted<JSStableString *>;
 typedef Rooted<JSObject*>    RootedObject;
 typedef Rooted<js::Module*>  RootedModule;
 typedef Rooted<JSFunction*>  RootedFunction;
 typedef Rooted<JSScript*>    RootedScript;
 typedef Rooted<JSString*>    RootedString;
 typedef Rooted<jsid>         RootedId;
 typedef Rooted<JS::Value>    RootedValue;
 
+} /* namespace JS */
+
+namespace js {
+
 /*
  * Mark a stack location as a root for the rooting analysis, without actually
  * rooting it in release builds. This should only be used for stack locations
  * of GC things that cannot be relocated by a garbage collection, and that
  * are definitely reachable via another path.
  */
 class SkipRoot
 {
@@ -748,33 +756,33 @@ template <typename T> class MaybeRooted<
 };
 
 } /* namespace js */
 
 namespace JS {
 
 template <typename T> template <typename S>
 inline
-Handle<T>::Handle(js::Rooted<S> &root,
+Handle<T>::Handle(Rooted<S> &root,
                   typename mozilla::EnableIf<mozilla::IsConvertible<S, T>::value, int>::Type dummy)
 {
     ptr = reinterpret_cast<const T *>(root.address());
 }
 
 template <typename T> template <typename S>
 inline
 Handle<T>::Handle(MutableHandle<S> &root,
                   typename mozilla::EnableIf<mozilla::IsConvertible<S, T>::value, int>::Type dummy)
 {
     ptr = reinterpret_cast<const T *>(root.address());
 }
 
 template <typename T>
 inline
-MutableHandle<T>::MutableHandle(js::Rooted<T> *root)
+MutableHandle<T>::MutableHandle(Rooted<T> *root)
 {
     ptr = root->address();
 }
 
 /*
  * The scoped guard object AutoAssertNoGC forces the GC to assert if a GC is
  * attempted while the guard object is live.  If you have a GC-unsafe operation
  * to perform, use this guard object to protect your operation.
--- a/js/src/jspubtd.h
+++ b/js/src/jspubtd.h
@@ -9,23 +9,32 @@
 
 /*
  * JS public API typedefs.
  */
 
 #include "jsprototypes.h"
 #include "jstypes.h"
 
+#ifdef __cplusplus
+
+namespace JS {
+
 /*
  * Allow headers to reference JS::Value without #including the whole jsapi.h.
  * Unfortunately, typedefs (hence jsval) cannot be declared.
  */
-#ifdef __cplusplus
-namespace JS { class Value; }
-#endif
+class Value;
+
+template <typename T>
+class Rooted;
+
+} /* namespace JS */
+
+#endif /* __cplusplus */
 
 /*
  * In release builds, jsid is defined to be an integral type. This
  * prevents many bugs from being caught at compile time. E.g.:
  *
  *  jsid id = ...
  *  if (id == JS_TRUE)  // error
  *    ...
@@ -205,19 +214,16 @@ typedef JSBool                   JSCallO
 typedef JSBool                 (*JSInitCallback)(void);
 
 #ifdef __cplusplus
 
 namespace js {
 
 class Allocator;
 
-template <typename T>
-class Rooted;
-
 class SkipRoot;
 
 enum ThingRootKind
 {
     THING_ROOT_OBJECT,
     THING_ROOT_SHAPE,
     THING_ROOT_BASE_SHAPE,
     THING_ROOT_TYPE_OBJECT,
@@ -270,17 +276,17 @@ struct ContextFriendFields {
         return reinterpret_cast<ContextFriendFields *>(cx);
     }
 
 #if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)
     /*
      * Stack allocated GC roots for stack GC heap pointers, which may be
      * overwritten if moved during a GC.
      */
-    Rooted<void*> *thingGCRooters[THING_ROOT_LIMIT];
+    JS::Rooted<void*> *thingGCRooters[THING_ROOT_LIMIT];
 #endif
 
 #if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
     /*
      * Stack allocated list of stack locations which hold non-relocatable
      * GC heap pointers (where the target is rooted somewhere else) or integer
      * values which may be confused for GC heap pointers. These are used to
      * suppress false positives which occur when a rooting analysis treats the
@@ -329,17 +335,17 @@ struct PerThreadDataFriendFields
 
     PerThreadDataFriendFields();
 
 #if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)
     /*
      * Stack allocated GC roots for stack GC heap pointers, which may be
      * overwritten if moved during a GC.
      */
-    Rooted<void*> *thingGCRooters[THING_ROOT_LIMIT];
+    JS::Rooted<void*> *thingGCRooters[THING_ROOT_LIMIT];
 #endif
 
 #if defined(DEBUG) && defined(JS_GC_ZEAL) && defined(JSGC_ROOT_ANALYSIS) && !defined(JS_THREADSAFE)
     /*
      * Stack allocated list of stack locations which hold non-relocatable
      * GC heap pointers (where the target is rooted somewhere else) or integer
      * values which may be confused for GC heap pointers. These are used to
      * suppress false positives which occur when a rooting analysis treats the
--- a/js/src/vm/String.h
+++ b/js/src/vm/String.h
@@ -573,17 +573,17 @@ class JSStableString : public JSFlatStri
         JS_ASSERT(!JSString::isInline());
         return JS::StableTwoByteChars(d.u1.chars, length());
     }
 };
 
 JS_STATIC_ASSERT(sizeof(JSStableString) == sizeof(JSString));
 
 #if !(defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING))
-namespace js {
+namespace JS {
 /*
  * Specialization of Rooted<T> to explicitly root the string rather than
  * relying on conservative stack scanning.
  *
  * In exact-gc builds, Rooted<T> already keeps the T reachable, so this hack is
  * ifdef'd out. In non-exact-gc builds, conservative scanning would ordinarily
  * pick up the slack. However in the case where the Rooted pointer is no longer
  * used, but some subobject or malloc'd memory with the same lifetime may be
@@ -611,17 +611,17 @@ class Rooted<JSStableString *>
     JSStableString ** address() { return reinterpret_cast<JSStableString **>(rooter.addr()); }
     JSStableString * const * address() const {
         return reinterpret_cast<JSStableString * const *>(rooter.addr());
     }
     JSStableString * get() const { return static_cast<JSStableString *>(rooter.string()); }
 
     Rooted & operator =(JSStableString *value)
     {
-        JS_ASSERT(!RootMethods<JSStableString *>::poisoned(value));
+        JS_ASSERT(!js::RootMethods<JSStableString *>::poisoned(value));
         rooter.setString(value);
         return *this;
     }
 
     Rooted & operator =(const Rooted &value)
     {
         rooter.setString(value.get());
         return *this;