Bug 1105069 - Part 7: Convert WeakMapTracer to use GCCellPtr; r=jonco, r=mccr8

--HG--
extra : rebase_source : d61c5f00a86472581bedd833fd4fbaf1f6700a0a
This commit is contained in:
Terrence Cole 2014-12-01 15:06:38 -08:00
Родитель dcf7f9a22d
Коммит 6eb606db7f
5 изменённых файлов: 23 добавлений и 58 удалений

Просмотреть файл

@ -405,36 +405,6 @@ ToMarkable(Cell *cell)
return cell;
}
inline JSGCTraceKind
TraceKind(const Value &v)
{
MOZ_ASSERT(v.isMarkable());
if (v.isObject())
return JSTRACE_OBJECT;
if (v.isString())
return JSTRACE_STRING;
MOZ_ASSERT(v.isSymbol());
return JSTRACE_SYMBOL;
}
inline JSGCTraceKind
TraceKind(JSObject *obj)
{
return JSTRACE_OBJECT;
}
inline JSGCTraceKind
TraceKind(JSScript *script)
{
return JSTRACE_SCRIPT;
}
inline JSGCTraceKind
TraceKind(LazyScript *lazy)
{
return JSTRACE_LAZY_SCRIPT;
}
} /* namespace gc */
void

Просмотреть файл

@ -493,9 +493,7 @@ struct WeakMapTracer;
* m will be nullptr if the weak map is not contained in a JS Object.
*/
typedef void
(* WeakMapTraceCallback)(WeakMapTracer *trc, JSObject *m,
void *k, JSGCTraceKind kkind,
void *v, JSGCTraceKind vkind);
(* WeakMapTraceCallback)(WeakMapTracer *trc, JSObject *m, JS::GCCellPtr key, JS::GCCellPtr value);
struct WeakMapTracer {
JSRuntime *runtime;

Просмотреть файл

@ -246,7 +246,7 @@ WatchpointMap::trace(WeakMapTracer *trc)
for (Map::Range r = map.all(); !r.empty(); r.popFront()) {
Map::Entry &entry = r.front();
trc->callback(trc, nullptr,
entry.key().object.get(), JSTRACE_OBJECT,
entry.value().closure.get(), JSTRACE_OBJECT);
JS::GCCellPtr(entry.key().object.get()),
JS::GCCellPtr(entry.value().closure.get()));
}
}

Просмотреть файл

@ -251,8 +251,8 @@ class WeakMap : public HashMap<Key, Value, HashPolicy, RuntimeAllocPolicy>, publ
gc::Cell *value = gc::ToMarkable(r.front().value());
if (key && value) {
tracer->callback(tracer, memberOf,
key, gc::TraceKind(r.front().key()),
value, gc::TraceKind(r.front().value()));
JS::GCCellPtr(r.front().key()),
JS::GCCellPtr(r.front().value()));
}
}
}

Просмотреть файл

@ -180,8 +180,7 @@ struct NoteWeakMapsTracer : public js::WeakMapTracer
static void
TraceWeakMapping(js::WeakMapTracer* aTrc, JSObject* aMap,
void* aKey, JSGCTraceKind aKeyKind,
void* aValue, JSGCTraceKind aValueKind)
JS::GCCellPtr aKey, JS::GCCellPtr aValue)
{
MOZ_ASSERT(aTrc->callback == TraceWeakMapping);
NoteWeakMapsTracer* tracer = static_cast<NoteWeakMapsTracer*>(aTrc);
@ -189,8 +188,7 @@ TraceWeakMapping(js::WeakMapTracer* aTrc, JSObject* aMap,
// If nothing that could be held alive by this entry is marked gray, return.
if ((!aKey || !xpc_IsGrayGCThing(aKey)) &&
MOZ_LIKELY(!tracer->mCb.WantAllTraces())) {
if (!aValue || !xpc_IsGrayGCThing(aValue) ||
aValueKind == JSTRACE_STRING) {
if (!aValue || !xpc_IsGrayGCThing(aValue) || aValue.isString()) {
return;
}
}
@ -199,22 +197,22 @@ TraceWeakMapping(js::WeakMapTracer* aTrc, JSObject* aMap,
// reason about the liveness of their keys, which in turn requires that
// the key can be represented in the cycle collector graph. All existing
// uses of weak maps use either objects or scripts as keys, which are okay.
MOZ_ASSERT(AddToCCKind(aKeyKind));
MOZ_ASSERT(AddToCCKind(aKey.kind()));
// As an emergency fallback for non-debug builds, if the key is not
// representable in the cycle collector graph, we treat it as marked. This
// can cause leaks, but is preferable to ignoring the binding, which could
// cause the cycle collector to free live objects.
if (!AddToCCKind(aKeyKind)) {
aKey = nullptr;
if (!AddToCCKind(aKey.kind())) {
aKey = JS::GCCellPtr::NullPtr();
}
JSObject* kdelegate = nullptr;
if (aKey && aKeyKind == JSTRACE_OBJECT) {
kdelegate = js::GetWeakmapKeyDelegate((JSObject*)aKey);
if (aKey.isObject()) {
kdelegate = js::GetWeakmapKeyDelegate(aKey.toObject());
}
if (AddToCCKind(aValueKind)) {
if (AddToCCKind(aValue.kind())) {
tracer->mCb.NoteWeakMapping(aMap, aKey, kdelegate, aValue);
} else {
tracer->mChildTracer.mTracedAny = false;
@ -222,8 +220,8 @@ TraceWeakMapping(js::WeakMapTracer* aTrc, JSObject* aMap,
tracer->mChildTracer.mKey = aKey;
tracer->mChildTracer.mKeyDelegate = kdelegate;
if (aValue && aValueKind != JSTRACE_STRING) {
JS_TraceChildren(&tracer->mChildTracer, aValue, aValueKind);
if (aValue.isString()) {
JS_TraceChildren(&tracer->mChildTracer, aValue, aValue.kind());
}
// The delegate could hold alive the key, so report something to the CC
@ -256,8 +254,7 @@ private:
static void
FixWeakMappingGrayBits(js::WeakMapTracer* aTrc, JSObject* aMap,
void* aKey, JSGCTraceKind aKeyKind,
void* aValue, JSGCTraceKind aValueKind)
JS::GCCellPtr aKey, JS::GCCellPtr aValue)
{
FixWeakMappingGrayBitsTracer* tracer =
static_cast<FixWeakMappingGrayBitsTracer*>(aTrc);
@ -265,17 +262,17 @@ private:
// If nothing that could be held alive by this entry is marked gray, return.
bool delegateMightNeedMarking = aKey && xpc_IsGrayGCThing(aKey);
bool valueMightNeedMarking = aValue && xpc_IsGrayGCThing(aValue) &&
aValueKind != JSTRACE_STRING;
aValue.kind() != JSTRACE_STRING;
if (!delegateMightNeedMarking && !valueMightNeedMarking) {
return;
}
if (!AddToCCKind(aKeyKind)) {
aKey = nullptr;
if (!AddToCCKind(aKey.kind())) {
aKey = JS::GCCellPtr::NullPtr();
}
if (delegateMightNeedMarking && aKeyKind == JSTRACE_OBJECT) {
JSObject* kdelegate = js::GetWeakmapKeyDelegate((JSObject*)aKey);
if (delegateMightNeedMarking && aKey.isObject()) {
JSObject* kdelegate = js::GetWeakmapKeyDelegate(aKey.toObject());
if (kdelegate && !xpc_IsGrayGCThing(kdelegate)) {
if (JS::UnmarkGrayGCThingRecursively(aKey, JSTRACE_OBJECT)) {
tracer->mAnyMarked = true;
@ -286,8 +283,8 @@ private:
if (aValue && xpc_IsGrayGCThing(aValue) &&
(!aKey || !xpc_IsGrayGCThing(aKey)) &&
(!aMap || !xpc_IsGrayGCThing(aMap)) &&
aValueKind != JSTRACE_SHAPE) {
if (JS::UnmarkGrayGCThingRecursively(aValue, aValueKind)) {
aValue.kind() != JSTRACE_SHAPE) {
if (JS::UnmarkGrayGCThingRecursively(aValue, aValue.kind())) {
tracer->mAnyMarked = true;
}
}