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

This commit is contained in:
Terrence Cole
2014-12-01 15:06:38 -08:00
parent c566c89e4c
commit dd1ab48817
5 changed files with 23 additions and 58 deletions

View File

@@ -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;
}
}