зеркало из https://github.com/mozilla/pjs.git
Bug 702502 - Use an iterator to iterate over compartments (r=igor)
This commit is contained in:
Родитель
36738690e7
Коммит
f9fb4713df
|
@ -585,20 +585,16 @@ js_DestroyContext(JSContext *cx, JSDestroyContextMode mode)
|
|||
*/
|
||||
{
|
||||
AutoLockGC lock(rt);
|
||||
JSCompartment **compartment = rt->compartments.begin();
|
||||
JSCompartment **end = rt->compartments.end();
|
||||
while (compartment < end) {
|
||||
(*compartment)->types.print(cx, false);
|
||||
compartment++;
|
||||
}
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next())
|
||||
c->types.print(cx, false);
|
||||
}
|
||||
|
||||
/* Unpin all common atoms before final GC. */
|
||||
js_FinishCommonAtoms(cx);
|
||||
|
||||
/* Clear debugging state to remove GC roots. */
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); c++)
|
||||
(*c)->clearTraps(cx, NULL);
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next())
|
||||
c->clearTraps(cx, NULL);
|
||||
JS_ClearAllWatchPoints(cx);
|
||||
}
|
||||
|
||||
|
|
|
@ -833,6 +833,32 @@ class ErrorCopier
|
|||
~ErrorCopier();
|
||||
};
|
||||
|
||||
class CompartmentsIter {
|
||||
private:
|
||||
JSCompartment **it, **end;
|
||||
|
||||
public:
|
||||
CompartmentsIter(JSRuntime *rt) {
|
||||
it = rt->compartments.begin();
|
||||
end = rt->compartments.end();
|
||||
}
|
||||
|
||||
bool done() const { return it == end; }
|
||||
|
||||
void next() {
|
||||
JS_ASSERT(!done());
|
||||
it++;
|
||||
}
|
||||
|
||||
JSCompartment *get() const {
|
||||
JS_ASSERT(!done());
|
||||
return *it;
|
||||
}
|
||||
|
||||
operator JSCompartment *() const { return get(); }
|
||||
JSCompartment *operator->() const { return get(); }
|
||||
};
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
#endif /* jscompartment_h___ */
|
||||
|
|
|
@ -1143,8 +1143,8 @@ void
|
|||
js_FinishGC(JSRuntime *rt)
|
||||
{
|
||||
/* Delete all remaining Compartments. */
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c)
|
||||
Foreground::delete_(*c);
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next())
|
||||
Foreground::delete_(c.get());
|
||||
rt->compartments.clear();
|
||||
rt->atomsCompartment = NULL;
|
||||
|
||||
|
@ -2506,8 +2506,8 @@ BeginMarkPhase(JSContext *cx, GCMarker *gcmarker, JSGCInvocationKind gckind)
|
|||
r.front()->bitmap.clear();
|
||||
|
||||
if (rt->gcCurrentCompartment) {
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c)
|
||||
(*c)->markCrossCompartmentWrappers(gcmarker);
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next())
|
||||
c->markCrossCompartmentWrappers(gcmarker);
|
||||
Debugger::markCrossCompartmentDebuggerObjectReferents(gcmarker);
|
||||
}
|
||||
|
||||
|
@ -2545,9 +2545,9 @@ EndMarkPhase(JSContext *cx, GCMarker *gcmarker, JSGCInvocationKind gckind)
|
|||
#ifdef DEBUG
|
||||
/* Make sure that we didn't mark an object in another compartment */
|
||||
if (rt->gcCurrentCompartment) {
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c) {
|
||||
JS_ASSERT_IF(*c != rt->gcCurrentCompartment && *c != rt->atomsCompartment,
|
||||
(*c)->arenas.checkArenaListAllUnmarked());
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next()) {
|
||||
JS_ASSERT_IF(c != rt->gcCurrentCompartment && c != rt->atomsCompartment,
|
||||
c->arenas.checkArenaListAllUnmarked());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -2956,8 +2956,8 @@ GCCycle(JSContext *cx, JSCompartment *comp, JSGCInvocationKind gckind)
|
|||
rt->gcCurrentCompartment = NULL;
|
||||
rt->gcWeakMapList = NULL;
|
||||
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c)
|
||||
(*c)->setGCLastBytes((*c)->gcBytes, gckind);
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next())
|
||||
c->setGCLastBytes(c->gcBytes, gckind);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -3037,13 +3037,13 @@ class AutoCopyFreeListToArenas {
|
|||
public:
|
||||
AutoCopyFreeListToArenas(JSRuntime *rt)
|
||||
: rt(rt) {
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c)
|
||||
(*c)->arenas.copyFreeListsToArenas();
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next())
|
||||
c->arenas.copyFreeListsToArenas();
|
||||
}
|
||||
|
||||
~AutoCopyFreeListToArenas() {
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c)
|
||||
(*c)->arenas.clearFreeListsInArenas();
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next())
|
||||
c->arenas.clearFreeListsInArenas();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -3130,16 +3130,15 @@ IterateCompartmentsArenasCells(JSContext *cx, void *data,
|
|||
AutoUnlockGC unlock(rt);
|
||||
|
||||
AutoCopyFreeListToArenas copy(rt);
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c) {
|
||||
JSCompartment *compartment = *c;
|
||||
(*compartmentCallback)(cx, data, compartment);
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next()) {
|
||||
(*compartmentCallback)(cx, data, c);
|
||||
|
||||
for (size_t thingKind = 0; thingKind != FINALIZE_LIMIT; thingKind++) {
|
||||
JSGCTraceKind traceKind = MapAllocToTraceKind(AllocKind(thingKind));
|
||||
size_t thingSize = Arena::thingSize(AllocKind(thingKind));
|
||||
IterateArenaCallbackOp arenaOp(cx, data, arenaCallback, traceKind, thingSize);
|
||||
IterateCellCallbackOp cellOp(cx, data, cellCallback, traceKind, thingSize);
|
||||
ForEachArenaAndCell(compartment, AllocKind(thingKind), arenaOp, cellOp);
|
||||
ForEachArenaAndCell(c, AllocKind(thingKind), arenaOp, cellOp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3193,8 +3192,8 @@ IterateCells(JSContext *cx, JSCompartment *compartment, AllocKind thingKind,
|
|||
for (CellIterUnderGC i(compartment, thingKind); !i.done(); i.next())
|
||||
cellCallback(cx, data, i.getCell(), traceKind, thingSize);
|
||||
} else {
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c) {
|
||||
for (CellIterUnderGC i(*c, thingKind); !i.done(); i.next())
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next()) {
|
||||
for (CellIterUnderGC i(c, thingKind); !i.done(); i.next())
|
||||
cellCallback(cx, data, i.getCell(), traceKind, thingSize);
|
||||
}
|
||||
}
|
||||
|
@ -3413,10 +3412,10 @@ StartVerifyBarriers(JSContext *cx)
|
|||
* code in the compartment.
|
||||
*/
|
||||
#ifdef JS_METHODJIT
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c) {
|
||||
mjit::ClearAllFrames(*c);
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next()) {
|
||||
mjit::ClearAllFrames(c);
|
||||
|
||||
for (CellIterUnderGC i(*c, FINALIZE_SCRIPT); !i.done(); i.next()) {
|
||||
for (CellIterUnderGC i(c, FINALIZE_SCRIPT); !i.done(); i.next()) {
|
||||
JSScript *script = i.get<JSScript>();
|
||||
mjit::ReleaseScriptCode(cx, script);
|
||||
|
||||
|
@ -3474,9 +3473,9 @@ StartVerifyBarriers(JSContext *cx)
|
|||
|
||||
rt->gcVerifyData = trc;
|
||||
rt->gcIncrementalTracer = &trc->gcmarker;
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c) {
|
||||
(*c)->gcIncrementalTracer = &trc->gcmarker;
|
||||
(*c)->needsBarrier_ = true;
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next()) {
|
||||
c->gcIncrementalTracer = &trc->gcmarker;
|
||||
c->needsBarrier_ = true;
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -3545,9 +3544,9 @@ EndVerifyBarriers(JSContext *cx)
|
|||
|
||||
rt->gcVerifyData = NULL;
|
||||
rt->gcIncrementalTracer = NULL;
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c) {
|
||||
(*c)->gcIncrementalTracer = NULL;
|
||||
(*c)->needsBarrier_ = false;
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next()) {
|
||||
c->gcIncrementalTracer = NULL;
|
||||
c->needsBarrier_ = false;
|
||||
}
|
||||
|
||||
JS_TRACER_INIT(trc, cx, CheckAutorooter);
|
||||
|
|
|
@ -351,14 +351,14 @@ js::PropertyTree::dumpShapes(JSContext *cx)
|
|||
JSRuntime *rt = cx->runtime;
|
||||
fprintf(dumpfp, "rt->gcNumber = %lu", (unsigned long)rt->gcNumber);
|
||||
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c) {
|
||||
if (rt->gcCurrentCompartment != NULL && rt->gcCurrentCompartment != *c)
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next()) {
|
||||
if (rt->gcCurrentCompartment != NULL && rt->gcCurrentCompartment != c)
|
||||
continue;
|
||||
|
||||
fprintf(dumpfp, "*** Compartment %p ***\n", (void *)*c);
|
||||
fprintf(dumpfp, "*** Compartment %p ***\n", (void *)c.get());
|
||||
|
||||
typedef JSCompartment::EmptyShapeSet HS;
|
||||
HS &h = (*c)->emptyShapes;
|
||||
HS &h = c->emptyShapes;
|
||||
for (HS::Range r = h.all(); !r.empty(); r.popFront()) {
|
||||
Shape *empty = r.front();
|
||||
empty->dumpSubtree(cx, 0, dumpfp);
|
||||
|
|
|
@ -184,9 +184,9 @@ WatchpointMap::markAllIteratively(JSTracer *trc)
|
|||
}
|
||||
|
||||
bool mutated = false;
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c) {
|
||||
if ((*c)->watchpointMap)
|
||||
mutated |= (*c)->watchpointMap->markIteratively(trc);
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next()) {
|
||||
if (c->watchpointMap)
|
||||
mutated |= c->watchpointMap->markIteratively(trc);
|
||||
}
|
||||
return mutated;
|
||||
}
|
||||
|
@ -226,8 +226,8 @@ WatchpointMap::sweepAll(JSContext *cx)
|
|||
if (WatchpointMap *wpmap = rt->gcCurrentCompartment->watchpointMap)
|
||||
wpmap->sweep(cx);
|
||||
} else {
|
||||
for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c) {
|
||||
if (WatchpointMap *wpmap = (*c)->watchpointMap)
|
||||
for (CompartmentsIter c(rt); !c.done(); c.next()) {
|
||||
if (WatchpointMap *wpmap = c->watchpointMap)
|
||||
wpmap->sweep(cx);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче