Bug 961095 - Improve generic callbacks with better typing, and by only adding storebuffer entries when the key is in the nursery r=terrence

This commit is contained in:
Jon Coppeard 2014-01-21 10:44:39 +00:00
parent 1fe5f48357
commit 2bbbec43e9
8 changed files with 30 additions and 29 deletions

View File

@ -943,8 +943,7 @@ nsJSObjWrapper::NP_Construct(NPObject *npobj, const NPVariant *args,
* been finalized if all wrappers have died.
*/
static void
JSObjWrapperKeyMarkCallback(JSTracer *trc, void *key, void *data) {
JSObject *obj = static_cast<JSObject*>(key);
JSObjWrapperKeyMarkCallback(JSTracer *trc, JSObject *obj, void *data) {
NPP npp = static_cast<NPP>(data);
if (!sJSObjWrappers.initialized())
return;

View File

@ -111,9 +111,8 @@ ObjectIdCache::add(JSContext *cx, JSObject *obj, ObjectId id)
* been moved.
*/
/* static */ void
ObjectIdCache::keyMarkCallback(JSTracer *trc, void *keyArg, void *dataArg) {
JSObject *key = static_cast<JSObject*>(keyArg);
ObjectIdTable* table = static_cast<ObjectIdTable*>(dataArg);
ObjectIdCache::keyMarkCallback(JSTracer *trc, JSObject *key, void *data) {
ObjectIdTable* table = static_cast<ObjectIdTable*>(data);
JSObject *prior = key;
JS_CallObjectTracer(trc, &key, "ObjectIdCache::table_ key");
table->rekeyIfMoved(prior, key);

View File

@ -75,7 +75,7 @@ class ObjectIdCache
void remove(JSObject *obj);
private:
static void keyMarkCallback(JSTracer *trc, void *key, void *data);
static void keyMarkCallback(JSTracer *trc, JSObject *key, void *data);
ObjectIdTable *table_;
};

View File

@ -4761,16 +4761,15 @@ StructType::Create(JSContext* cx, unsigned argc, jsval* vp)
}
static void
PostBarrierCallback(JSTracer *trc, void *k, void *d)
PostBarrierCallback(JSTracer *trc, JSString *key, void *data)
{
typedef HashMap<JSFlatString*,
UnbarrieredFieldInfo,
FieldHashPolicy,
SystemAllocPolicy> UnbarrieredFieldInfoHash;
JSString *prior = static_cast<JSString*>(k);
UnbarrieredFieldInfoHash *table = reinterpret_cast<UnbarrieredFieldInfoHash*>(d);
JSString *key = prior;
UnbarrieredFieldInfoHash *table = reinterpret_cast<UnbarrieredFieldInfoHash*>(data);
JSString *prior = key;
JS_CallStringTracer(trc, &key, "CType fieldName");
table->rekeyIfMoved(JS_ASSERT_STRING_IS_FLAT(prior), JS_ASSERT_STRING_IS_FLAT(key));
}

View File

@ -331,12 +331,13 @@ class StoreBuffer
void mark(JSTracer *trc);
};
template <typename Key>
class CallbackRef : public BufferableRef
{
public:
typedef void (*MarkCallback)(JSTracer *trc, void *key, void *data);
typedef void (*MarkCallback)(JSTracer *trc, Key *key, void *data);
CallbackRef(MarkCallback cb, void *k, void *d) : callback(cb), key(k), data(d) {}
CallbackRef(MarkCallback cb, Key *k, void *d) : callback(cb), key(k), data(d) {}
virtual void mark(JSTracer *trc) {
callback(trc, key, data);
@ -344,7 +345,7 @@ class StoreBuffer
private:
MarkCallback callback;
void *key;
Key *key;
void *data;
};
@ -441,8 +442,9 @@ class StoreBuffer
void putGeneric(const T &t) { put(bufferGeneric, t);}
/* Insert or update a callback entry. */
void putCallback(CallbackRef::MarkCallback callback, Cell *key, void *data) {
put(bufferGeneric, CallbackRef(callback, key, data));
template <typename Key>
void putCallback(void (*callback)(JSTracer *trc, Key *key, void *data), Key *key, void *data) {
put(bufferGeneric, CallbackRef<Key>(callback, key, data));
}
/* Mark the source of all edges in the store buffer. */

View File

@ -1227,17 +1227,21 @@ js::IsInRequest(JSContext *cx)
#ifdef JSGC_GENERATIONAL
JS_FRIEND_API(void)
JS_StoreObjectPostBarrierCallback(JSContext* cx,
void (*callback)(JSTracer *trc, void *key, void *data),
void (*callback)(JSTracer *trc, JSObject *key, void *data),
JSObject *key, void *data)
{
cx->runtime()->gcStoreBuffer.putCallback(callback, key, data);
JSRuntime *rt = cx->runtime();
if (IsInsideNursery(rt, key))
rt->gcStoreBuffer.putCallback(callback, key, data);
}
extern JS_FRIEND_API(void)
JS_StoreStringPostBarrierCallback(JSContext* cx,
void (*callback)(JSTracer *trc, void *key, void *data),
void (*callback)(JSTracer *trc, JSString *key, void *data),
JSString *key, void *data)
{
cx->runtime()->gcStoreBuffer.putCallback(callback, key, data);
JSRuntime *rt = cx->runtime();
if (IsInsideNursery(rt, key))
rt->gcStoreBuffer.putCallback(callback, key, data);
}
#endif /* JSGC_GENERATIONAL */

View File

@ -1892,22 +1892,22 @@ js_ReportIsNotFunction(JSContext *cx, JS::HandleValue v);
#ifdef JSGC_GENERATIONAL
extern JS_FRIEND_API(void)
JS_StoreObjectPostBarrierCallback(JSContext* cx,
void (*callback)(JSTracer *trc, void *key, void *data),
void (*callback)(JSTracer *trc, JSObject *key, void *data),
JSObject *key, void *data);
extern JS_FRIEND_API(void)
JS_StoreStringPostBarrierCallback(JSContext* cx,
void (*callback)(JSTracer *trc, void *key, void *data),
void (*callback)(JSTracer *trc, JSString *key, void *data),
JSString *key, void *data);
#else
inline void
JS_StoreObjectPostBarrierCallback(JSContext* cx,
void (*callback)(JSTracer *trc, void *key, void *data),
void (*callback)(JSTracer *trc, JSObject *key, void *data),
JSObject *key, void *data) {}
inline void
JS_StoreStringPostBarrierCallback(JSContext* cx,
void (*callback)(JSTracer *trc, void *key, void *data),
void (*callback)(JSTracer *trc, JSString *key, void *data),
JSString *key, void *data) {}
#endif /* JSGC_GENERATIONAL */

View File

@ -85,9 +85,8 @@ private:
* This function is called during minor GCs for each key in the HashMap that
* has been moved.
*/
static void KeyMarkCallback(JSTracer *trc, void *k, void *d) {
JSObject *key = static_cast<JSObject*>(k);
JSObject2WrappedJSMap* self = static_cast<JSObject2WrappedJSMap*>(d);
static void KeyMarkCallback(JSTracer *trc, JSObject *key, void *data) {
JSObject2WrappedJSMap* self = static_cast<JSObject2WrappedJSMap*>(data);
JSObject *prior = key;
JS_CallObjectTracer(trc, &key, "XPCJSRuntime::mWrappedJSMap key");
self->mTable.rekeyIfMoved(prior, key);
@ -694,7 +693,7 @@ private:
* This function is called during minor GCs for each key in the HashMap that
* has been moved.
*/
static void KeyMarkCallback(JSTracer *trc, void *k, void *d) {
static void KeyMarkCallback(JSTracer *trc, JSObject *key, void *data) {
/*
* To stop the barriers on the values of mTable firing while we are
* marking the store buffer, we cast the table to one that is
@ -702,10 +701,9 @@ private:
*/
typedef js::HashMap<JSObject *, JSObject *, js::PointerHasher<JSObject *, 3>,
js::SystemAllocPolicy> UnbarrieredMap;
JSObject2JSObjectMap *self = static_cast<JSObject2JSObjectMap *>(d);
JSObject2JSObjectMap *self = static_cast<JSObject2JSObjectMap *>(data);
UnbarrieredMap &table = reinterpret_cast<UnbarrieredMap &>(self->mTable);
JSObject *key = static_cast<JSObject*>(k);
JSObject *prior = key;
JS_CallObjectTracer(trc, &key, "XPCWrappedNativeScope::mWaiverWrapperMap key");
table.rekeyIfMoved(prior, key);