Bug 888338 - 2 - give post barrier callback function an extra data argument r=terrence
authorJon Coppeard <jcoppeard@mozilla.com>
Tue, 23 Jul 2013 10:58:26 +0100
changeset 139577 03f30c353078636ea84409ba42c3cc041d898427
parent 139576 a80f35bdbaa0e86fb4e758176a683c57cc902993
child 139578 7a1ecc3941348d54101c03b0b6b0c0d098b5b1fa
push id24998
push userryanvm@gmail.com
push dateWed, 24 Jul 2013 00:38:35 +0000
treeherdermozilla-central@2983ca6d4d1a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs888338
milestone25.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 888338 - 2 - give post barrier callback function an extra data argument r=terrence
js/src/gc/StoreBuffer.h
js/src/jsfriendapi.cpp
js/src/jsfriendapi.h
js/xpconnect/src/XPCMaps.h
--- a/js/src/gc/StoreBuffer.h
+++ b/js/src/gc/StoreBuffer.h
@@ -351,27 +351,28 @@ class StoreBuffer
         bool isNullEdge() const { return false; }
 
         void mark(JSTracer *trc);
     };
 
     class CallbackRef : public BufferableRef
     {
       public:
-        typedef void (*MarkCallback)(JSTracer *trc, void *key);
+        typedef void (*MarkCallback)(JSTracer *trc, void *key, void *data);
 
-        CallbackRef(MarkCallback cb, void *k) : callback(cb), key(k) {}
+        CallbackRef(MarkCallback cb, void *k, void *d) : callback(cb), key(k), data(d) {}
 
         virtual void mark(JSTracer *trc) {
-            callback(trc, key);
+            callback(trc, key, data);
         }
 
       private:
         MarkCallback callback;
         void *key;
+        void *data;
     };
 
     MonoTypeBuffer<ValueEdge> bufferVal;
     MonoTypeBuffer<CellPtrEdge> bufferCell;
     MonoTypeBuffer<SlotEdge> bufferSlot;
     MonoTypeBuffer<WholeCellEdges> bufferWholeCell;
     RelocatableMonoTypeBuffer<ValueEdge> bufferRelocVal;
     RelocatableMonoTypeBuffer<CellPtrEdge> bufferRelocCell;
@@ -446,18 +447,19 @@ class StoreBuffer
 
     /* Insert an entry into the generic buffer. */
     template <typename T>
     void putGeneric(const T &t) {
         bufferGeneric.put(t);
     }
 
     /* Insert or update a callback entry. */
-    void putCallback(CallbackRef::MarkCallback callback, void *key) {
-        bufferGeneric.put(CallbackRef(callback, key));
+    void putCallback(CallbackRef::MarkCallback callback, Cell *key, void *data) {
+        if (!key->isTenured())
+            bufferGeneric.put(CallbackRef(callback, key, data));
     }
 
     /* Mark the source of all edges in the store buffer. */
     void mark(JSTracer *trc);
 
     /* We cannot call InParallelSection directly because of a circular dependency. */
     bool inParallelSection() const;
 
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -1116,13 +1116,23 @@ js::IsInRequest(JSContext *cx)
 #else
     return true;
 #endif
 }
 #endif
 
 #ifdef JSGC_GENERATIONAL
 JS_FRIEND_API(void)
-JS_StorePostBarrierCallback(JSContext* cx, void (*callback)(JSTracer *trc, void *key), void *key)
+JS_StoreObjectPostBarrierCallback(JSContext* cx,
+                                  void (*callback)(JSTracer *trc, void *key, void *data),
+                                  JSObject *key, void *data)
 {
-    cx->runtime()->gcStoreBuffer.putCallback(callback, key);
+    cx->runtime()->gcStoreBuffer.putCallback(callback, key, data);
+}
+
+extern JS_FRIEND_API(void)
+JS_StoreStringPostBarrierCallback(JSContext* cx,
+                                  void (*callback)(JSTracer *trc, void *key, void *data),
+                                  JSString *key, void *data)
+{
+    cx->runtime()->gcStoreBuffer.putCallback(callback, key, data);
 }
 #endif /* JSGC_GENERATIONAL */
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -1789,15 +1789,29 @@ extern JS_FRIEND_API(JSBool)
 js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg,
                      const js::PropertyDescriptor& descriptor, JSBool *bp);
 
 extern JS_FRIEND_API(JSBool)
 js_ReportIsNotFunction(JSContext *cx, const JS::Value& v);
 
 #ifdef JSGC_GENERATIONAL
 extern JS_FRIEND_API(void)
-JS_StorePostBarrierCallback(JSContext* cx, void (*callback)(JSTracer *trc, void *key), void *key);
+JS_StoreObjectPostBarrierCallback(JSContext* cx,
+                                  void (*callback)(JSTracer *trc, void *key, void *data),
+                                  JSObject *key, void *data);
+
+extern JS_FRIEND_API(void)
+JS_StoreStringPostBarrierCallback(JSContext* cx,
+                                  void (*callback)(JSTracer *trc, void *key, void *data),
+                                  JSString *key, void *data);
 #else
 inline void
-JS_StorePostBarrierCallback(JSContext* cx, void (*callback)(JSTracer *trc, void *key), void *key) {}
+JS_StoreObjectPostBarrierCallback(JSContext* cx,
+                                  void (*callback)(JSTracer *trc, void *key, void *data),
+                                  JSObject *key, void *data) {}
+
+inline void
+JS_StoreStringPostBarrierCallback(JSContext* cx,
+                                  void (*callback)(JSTracer *trc, void *key, void *data),
+                                  JSString *key, void *data) {}
 #endif /* JSGC_GENERATIONAL */
 
 #endif /* jsfriendapi_h */
--- a/js/xpconnect/src/XPCMaps.h
+++ b/js/xpconnect/src/XPCMaps.h
@@ -49,17 +49,17 @@ public:
     inline nsXPCWrappedJS* Add(JSContext* cx, nsXPCWrappedJS* wrapper) {
         NS_PRECONDITION(wrapper,"bad param");
         JSObject* obj = wrapper->GetJSObjectPreserveColor();
         Map::AddPtr p = mTable.lookupForAdd(obj);
         if (p)
             return p->value;
         if (!mTable.add(p, obj, wrapper))
             return nullptr;
-        JS_StorePostBarrierCallback(cx, KeyMarkCallback, obj);
+        JS_StoreObjectPostBarrierCallback(cx, KeyMarkCallback, obj, this);
         return wrapper;
     }
 
     inline void Remove(nsXPCWrappedJS* wrapper) {
         NS_PRECONDITION(wrapper,"bad param");
         mTable.remove(wrapper->GetJSObjectPreserveColor());
     }
 
@@ -82,22 +82,21 @@ public:
 
 private:
     JSObject2WrappedJSMap() {}
 
     /*
      * This function is called during minor GCs for each key in the HashMap that
      * has been moved.
      */
-    static void KeyMarkCallback(JSTracer *trc, void *k) {
+    static void KeyMarkCallback(JSTracer *trc, void *k, void *d) {
         JSObject *key = static_cast<JSObject*>(k);
+        JSObject2WrappedJSMap* self = static_cast<JSObject2WrappedJSMap*>(d);
         JSObject *prior = key;
         JS_CallObjectTracer(trc, &key, "XPCJSRuntime::mWrappedJSMap key");
-        XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
-        JSObject2WrappedJSMap* self = rt->GetWrappedJSMap();
         self->mTable.rekey(prior, key);
     }
 
     Map mTable;
 };
 
 /*************************/
 
@@ -645,17 +644,17 @@ public:
     inline JSObject* Add(JSContext *cx, JSObject *key, JSObject *value) {
         NS_PRECONDITION(key,"bad param");
         Map::AddPtr p = mTable.lookupForAdd(key);
         if (p)
             return p->value;
         if (!mTable.add(p, key, value))
             return nullptr;
         MOZ_ASSERT(xpc::GetObjectScope(key)->mWaiverWrapperMap == this);
-        JS_StorePostBarrierCallback(cx, KeyMarkCallback, key);
+        JS_StoreObjectPostBarrierCallback(cx, KeyMarkCallback, key, this);
         return value;
     }
 
     inline void Remove(JSObject* key) {
         NS_PRECONDITION(key,"bad param");
         mTable.remove(key);
     }
 
@@ -692,20 +691,20 @@ public:
 
 private:
     JSObject2JSObjectMap() {}
 
     /*
      * This function is called during minor GCs for each key in the HashMap that
      * has been moved.
      */
-    static void KeyMarkCallback(JSTracer *trc, void *k) {
+    static void KeyMarkCallback(JSTracer *trc, void *k, void *d) {
         JSObject *key = static_cast<JSObject*>(k);
+        JSObject2JSObjectMap *self = static_cast<JSObject2JSObjectMap *>(d);
         JSObject *prior = key;
         JS_CallObjectTracer(trc, &key, "XPCWrappedNativeScope::mWaiverWrapperMap key");
-        JSObject2JSObjectMap *self = xpc::GetObjectScope(key)->mWaiverWrapperMap;
         self->mTable.rekey(prior, key);
     }
 
     Map mTable;
 };
 
 #endif /* xpcmaps_h___ */