Bug 1144931 - Move gray buffering code to RootMarking.cpp; r=jonco

--HG--
extra : rebase_source : 684ef52c0ee78ab9d8a77199af461e32a044b9bc
This commit is contained in:
Terrence Cole 2015-03-19 13:38:11 -07:00
parent b7c1bdf80d
commit f174c824a1
3 changed files with 59 additions and 61 deletions

View File

@ -1038,7 +1038,6 @@ class GCRuntime
// accumulate these roots in each zone's gcGrayRoots vector and then mark
// them later, after black marking is complete for each compartment. This
// accumulation can fail, but in that case we switch to non-incremental GC.
friend class js::GCMarker;
enum class GrayBufferState {
Unused,
Okay,

View File

@ -574,3 +574,62 @@ js::gc::GCRuntime::bufferGrayRoots()
grayBufferState = GrayBufferState::Okay;
}
}
void
BufferGrayRootsTracer::appendGrayRoot(void *thing, JSGCTraceKind kind)
{
MOZ_ASSERT(runtime()->isHeapBusy());
if (bufferingGrayRootsFailed)
return;
GrayRoot root(thing, kind);
#ifdef DEBUG
root.debugPrinter = debugPrinter();
root.debugPrintArg = debugPrintArg();
root.debugPrintIndex = debugPrintIndex();
#endif
Zone *zone = TenuredCell::fromPointer(thing)->zone();
if (zone->isCollecting()) {
// See the comment on SetMaybeAliveFlag to see why we only do this for
// objects and scripts. We rely on gray root buffering for this to work,
// but we only need to worry about uncollected dead compartments during
// incremental GCs (when we do gray root buffering).
switch (kind) {
case JSTRACE_OBJECT:
static_cast<JSObject *>(thing)->compartment()->maybeAlive = true;
break;
case JSTRACE_SCRIPT:
static_cast<JSScript *>(thing)->compartment()->maybeAlive = true;
break;
default:
break;
}
if (!zone->gcGrayRoots.append(root))
bufferingGrayRootsFailed = true;
}
}
void
GCRuntime::markBufferedGrayRoots(JS::Zone *zone)
{
MOZ_ASSERT(grayBufferState == GrayBufferState::Okay);
MOZ_ASSERT(zone->isGCMarkingGray() || zone->isGCCompacting());
for (GrayRoot *elem = zone->gcGrayRoots.begin(); elem != zone->gcGrayRoots.end(); elem++) {
#ifdef DEBUG
marker.setTracingDetails(elem->debugPrinter, elem->debugPrintArg, elem->debugPrintIndex);
#endif
MarkKind(&marker, &elem->thing, elem->kind);
}
}
void
GCRuntime::resetBufferedGrayRoots() const
{
MOZ_ASSERT(grayBufferState != GrayBufferState::Okay,
"Do not clear the gray buffers unless we are Failed or becoming Unused");
for (GCZonesIter zone(rt); !zone.done(); zone.next())
zone->gcGrayRoots.clearAndFree();
}

View File

@ -643,65 +643,6 @@ GCMarker::checkZone(void *p)
}
#endif
void
GCRuntime::resetBufferedGrayRoots() const
{
MOZ_ASSERT(grayBufferState != GrayBufferState::Okay,
"Do not clear the gray buffers unless we are Failed or becoming Unused");
for (GCZonesIter zone(rt); !zone.done(); zone.next())
zone->gcGrayRoots.clearAndFree();
}
void
GCRuntime::markBufferedGrayRoots(JS::Zone *zone)
{
MOZ_ASSERT(grayBufferState == GrayBufferState::Okay);
MOZ_ASSERT(zone->isGCMarkingGray() || zone->isGCCompacting());
for (GrayRoot *elem = zone->gcGrayRoots.begin(); elem != zone->gcGrayRoots.end(); elem++) {
#ifdef DEBUG
marker.setTracingDetails(elem->debugPrinter, elem->debugPrintArg, elem->debugPrintIndex);
#endif
MarkKind(&marker, &elem->thing, elem->kind);
}
}
void
BufferGrayRootsTracer::appendGrayRoot(void *thing, JSGCTraceKind kind)
{
MOZ_ASSERT(runtime()->isHeapBusy());
if (bufferingGrayRootsFailed)
return;
GrayRoot root(thing, kind);
#ifdef DEBUG
root.debugPrinter = debugPrinter();
root.debugPrintArg = debugPrintArg();
root.debugPrintIndex = debugPrintIndex();
#endif
Zone *zone = TenuredCell::fromPointer(thing)->zone();
if (zone->isCollecting()) {
// See the comment on SetMaybeAliveFlag to see why we only do this for
// objects and scripts. We rely on gray root buffering for this to work,
// but we only need to worry about uncollected dead compartments during
// incremental GCs (when we do gray root buffering).
switch (kind) {
case JSTRACE_OBJECT:
static_cast<JSObject *>(thing)->compartment()->maybeAlive = true;
break;
case JSTRACE_SCRIPT:
static_cast<JSScript *>(thing)->compartment()->maybeAlive = true;
break;
default:
break;
}
if (!zone->gcGrayRoots.append(root))
bufferingGrayRootsFailed = true;
}
}
size_t
GCMarker::sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const
{
@ -716,4 +657,3 @@ js::SetMarkStackLimit(JSRuntime *rt, size_t limit)
{
rt->gc.setMarkStackLimit(limit);
}