зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1143042 - Switch AllocKind iteration over to range-based for loops. r=terrence
--HG-- extra : rebase_source : 301622627350bf423f8e4dcae0b882f1f9b2bde5
This commit is contained in:
Родитель
ea3c8574a4
Коммит
15f33e4bda
|
@ -99,7 +99,7 @@ js::gc::InitTrace(GCRuntime &gc)
|
|||
TraceEvent(TraceEventInit, 0, TraceFormatVersion);
|
||||
|
||||
/* Trace information about thing sizes. */
|
||||
for (ALL_ALLOC_KINDS(kind))
|
||||
for (auto kind : AllAllocKinds())
|
||||
TraceEvent(TraceEventThingSize, Arena::thingSize(kind));
|
||||
|
||||
return true;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/EnumeratedArray.h"
|
||||
#include "mozilla/EnumeratedRange.h"
|
||||
#include "mozilla/PodOperations.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
@ -112,11 +113,17 @@ enum class AllocKind {
|
|||
static_assert(uint8_t(AllocKind::OBJECT0) == 0, "Please check AllocKind iterations and comparisons"
|
||||
" of the form |kind <= AllocKind::OBJECT_LAST| to ensure their range is still valid!");
|
||||
|
||||
#define ALL_ALLOC_KINDS(i) AllocKind i = AllocKind::FIRST;\
|
||||
i < AllocKind::LIMIT; i = AllocKind(uint8_t(i) + 1)
|
||||
inline decltype(mozilla::MakeEnumeratedRange<int>(AllocKind::FIRST, AllocKind::LIMIT))
|
||||
AllAllocKinds()
|
||||
{
|
||||
return mozilla::MakeEnumeratedRange<int>(AllocKind::FIRST, AllocKind::LIMIT);
|
||||
}
|
||||
|
||||
#define OBJECT_ALLOC_KINDS(i) AllocKind i = AllocKind::OBJECT0;\
|
||||
i < AllocKind::OBJECT_LIMIT; i = AllocKind(uint8_t(i) + 1)
|
||||
inline decltype(mozilla::MakeEnumeratedRange<int>(AllocKind::OBJECT0, AllocKind::OBJECT_LIMIT))
|
||||
ObjectAllocKinds()
|
||||
{
|
||||
return mozilla::MakeEnumeratedRange<int>(AllocKind::OBJECT0, AllocKind::OBJECT_LIMIT);
|
||||
}
|
||||
|
||||
template<typename ValueType> using AllAllocKindArray =
|
||||
mozilla::EnumeratedArray<AllocKind, AllocKind::LIMIT, ValueType>;
|
||||
|
|
|
@ -38,7 +38,7 @@ IterateCompartmentsArenasCells(JSRuntime *rt, Zone *zone, void *data,
|
|||
for (CompartmentsInZoneIter comp(zone); !comp.done(); comp.next())
|
||||
(*compartmentCallback)(rt, data, comp);
|
||||
|
||||
for (ALL_ALLOC_KINDS(thingKind)) {
|
||||
for (auto thingKind : AllAllocKinds()) {
|
||||
JSGCTraceKind traceKind = MapAllocToTraceKind(thingKind);
|
||||
size_t thingSize = Arena::thingSize(thingKind);
|
||||
|
||||
|
@ -117,7 +117,7 @@ js::IterateGrayObjects(Zone *zone, GCThingCallback cellCallback, void *data)
|
|||
zone->runtimeFromMainThread()->gc.evictNursery();
|
||||
AutoPrepareForTracing prep(zone->runtimeFromMainThread(), SkipAtoms);
|
||||
|
||||
for (OBJECT_ALLOC_KINDS(thingKind)) {
|
||||
for (auto thingKind : ObjectAllocKinds()) {
|
||||
for (ZoneCellIterUnderGC i(zone, thingKind); !i.done(); i.next()) {
|
||||
JSObject *obj = i.get<JSObject>();
|
||||
if (obj->asTenured().isMarked(GRAY))
|
||||
|
|
|
@ -501,7 +501,7 @@ js::gc::GCRuntime::endVerifyPostBarriers()
|
|||
/* Walk the heap to find any edges not the the |edges| set. */
|
||||
trc->setTraceCallback(PostVerifierVisitEdge);
|
||||
for (GCZoneGroupIter zone(rt); !zone.done(); zone.next()) {
|
||||
for (ALL_ALLOC_KINDS(kind)) {
|
||||
for (auto kind : AllAllocKinds()) {
|
||||
for (ZoneCellIterUnderGC cells(zone, kind); !cells.done(); cells.next()) {
|
||||
Cell *src = cells.getCell();
|
||||
JS_TraceChildren(trc, src, MapAllocToTraceKind(kind));
|
||||
|
|
|
@ -1770,7 +1770,7 @@ GCMarker::delayMarkingChildren(const void *thing)
|
|||
inline void
|
||||
ArenaLists::prepareForIncrementalGC(JSRuntime *rt)
|
||||
{
|
||||
for (ALL_ALLOC_KINDS(i)) {
|
||||
for (auto i : AllAllocKinds()) {
|
||||
FreeList *freeList = &freeLists[i];
|
||||
if (!freeList->isEmpty()) {
|
||||
ArenaHeader *aheader = freeList->arenaHeader();
|
||||
|
@ -2088,7 +2088,7 @@ ArenaLists::relocateArenas(ArenaHeader *&relocatedListOut, JS::gcreason::Reason
|
|||
checkEmptyFreeLists();
|
||||
|
||||
if (ShouldRelocateAllArenas(reason)) {
|
||||
for (ALL_ALLOC_KINDS(i)) {
|
||||
for (auto i : AllAllocKinds()) {
|
||||
if (CanRelocateAllocKind(i)) {
|
||||
ArenaList &al = arenaLists[i];
|
||||
ArenaHeader *allArenas = al.head();
|
||||
|
@ -2101,7 +2101,7 @@ ArenaLists::relocateArenas(ArenaHeader *&relocatedListOut, JS::gcreason::Reason
|
|||
size_t relocCount = 0;
|
||||
AllAllocKindArray<ArenaHeader **> toRelocate;
|
||||
|
||||
for (ALL_ALLOC_KINDS(i)) {
|
||||
for (auto i : AllAllocKinds()) {
|
||||
toRelocate[i] = nullptr;
|
||||
if (CanRelocateAllocKind(i))
|
||||
toRelocate[i] = arenaLists[i].pickArenasToRelocate(arenaCount, relocCount);
|
||||
|
@ -2110,7 +2110,7 @@ ArenaLists::relocateArenas(ArenaHeader *&relocatedListOut, JS::gcreason::Reason
|
|||
if (!ShouldRelocateZone(arenaCount, relocCount, reason))
|
||||
return false;
|
||||
|
||||
for (ALL_ALLOC_KINDS(i)) {
|
||||
for (auto i : AllAllocKinds()) {
|
||||
if (toRelocate[i]) {
|
||||
ArenaList &al = arenaLists[i];
|
||||
ArenaHeader *arenas = al.removeRemainingArenas(toRelocate[i]);
|
||||
|
@ -2145,7 +2145,7 @@ GCRuntime::relocateArenas(Zone *zone, JS::gcreason::Reason reason, SliceBudget &
|
|||
#ifdef DEBUG
|
||||
// Check that we did as much compaction as we should have. There
|
||||
// should always be less than one arena's worth of free cells.
|
||||
for (ALL_ALLOC_KINDS(i)) {
|
||||
for (auto i : AllAllocKinds()) {
|
||||
size_t thingsPerArena = Arena::thingsPerArena(Arena::thingSize(i));
|
||||
if (CanRelocateAllocKind(i)) {
|
||||
ArenaList &al = zone->arenas.arenaLists[i];
|
||||
|
@ -2688,7 +2688,7 @@ ArenaLists::~ArenaLists()
|
|||
{
|
||||
AutoLockGC lock(runtime_);
|
||||
|
||||
for (ALL_ALLOC_KINDS(i)) {
|
||||
for (auto i : AllAllocKinds()) {
|
||||
/*
|
||||
* We can only call this during the shutdown after the last GC when
|
||||
* the background finalization is disabled.
|
||||
|
@ -2698,7 +2698,7 @@ ArenaLists::~ArenaLists()
|
|||
}
|
||||
ReleaseArenaList(runtime_, incrementalSweptArenas.head(), lock);
|
||||
|
||||
for (OBJECT_ALLOC_KINDS(i))
|
||||
for (auto i : ObjectAllocKinds())
|
||||
ReleaseArenaList(runtime_, savedObjectArenas[i].head(), lock);
|
||||
ReleaseArenaList(runtime_, savedEmptyObjectArenas, lock);
|
||||
}
|
||||
|
@ -2840,8 +2840,9 @@ ArenaLists::queueForegroundObjectsForSweep(FreeOp *fop)
|
|||
gcstats::AutoPhase ap(fop->runtime()->gc.stats, gcstats::PHASE_SWEEP_OBJECT);
|
||||
|
||||
#ifdef DEBUG
|
||||
for (OBJECT_ALLOC_KINDS(i))
|
||||
for (auto i : ObjectAllocKinds()) { // Braces needed to appease MSVC 2013.
|
||||
MOZ_ASSERT(savedObjectArenas[i].isEmpty());
|
||||
}
|
||||
MOZ_ASSERT(savedEmptyObjectArenas == nullptr);
|
||||
#endif
|
||||
|
||||
|
@ -3234,7 +3235,7 @@ GCRuntime::assertBackgroundSweepingFinished()
|
|||
#ifdef DEBUG
|
||||
MOZ_ASSERT(backgroundSweepZones.isEmpty());
|
||||
for (ZonesIter zone(rt, WithAtoms); !zone.done(); zone.next()) {
|
||||
for (ALL_ALLOC_KINDS(i)) {
|
||||
for (auto i : AllAllocKinds()) {
|
||||
MOZ_ASSERT(!zone->arenas.arenaListsToSweep[i]);
|
||||
MOZ_ASSERT(zone->arenas.doneBackgroundFinalize(i));
|
||||
}
|
||||
|
@ -3706,7 +3707,7 @@ GCRuntime::checkForCompartmentMismatches()
|
|||
CompartmentCheckTracer trc(rt, CheckCompartmentCallback);
|
||||
for (ZonesIter zone(rt, SkipAtoms); !zone.done(); zone.next()) {
|
||||
trc.zone = zone;
|
||||
for (ALL_ALLOC_KINDS(thingKind)) {
|
||||
for (auto thingKind : AllAllocKinds()) {
|
||||
for (ZoneCellIterUnderGC i(zone, thingKind); !i.done(); i.next()) {
|
||||
trc.src = i.getCell();
|
||||
trc.srcKind = MapAllocToTraceKind(thingKind);
|
||||
|
@ -3735,8 +3736,11 @@ GCRuntime::beginMarkPhase(JS::gcreason::Reason reason)
|
|||
/* Assert that zone state is as we expect */
|
||||
MOZ_ASSERT(!zone->isCollecting());
|
||||
MOZ_ASSERT(!zone->compartments.empty());
|
||||
for (ALL_ALLOC_KINDS(i))
|
||||
#ifdef DEBUG
|
||||
for (auto i : AllAllocKinds()) { // Braces needed to appease MSVC 2013.
|
||||
MOZ_ASSERT(!zone->arenas.arenaListsToSweep[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set up which zones will be collected. */
|
||||
if (zone->isGCScheduled()) {
|
||||
|
@ -5295,7 +5299,7 @@ GCRuntime::endSweepPhase(bool destroyingRuntime)
|
|||
|
||||
#ifdef DEBUG
|
||||
for (ZonesIter zone(rt, WithAtoms); !zone.done(); zone.next()) {
|
||||
for (ALL_ALLOC_KINDS(i)) {
|
||||
for (auto i : AllAllocKinds()) {
|
||||
MOZ_ASSERT_IF(!IsBackgroundFinalized(i) ||
|
||||
!sweepOnBackgroundThread,
|
||||
!zone->arenas.arenaListsToSweep[i]);
|
||||
|
@ -6470,7 +6474,7 @@ gc::MergeCompartments(JSCompartment *source, JSCompartment *target)
|
|||
|
||||
// Fixup zone pointers in source's zone to refer to target's zone.
|
||||
|
||||
for (ALL_ALLOC_KINDS(thingKind)) {
|
||||
for (auto thingKind : AllAllocKinds()) {
|
||||
for (ArenaIter aiter(source->zone(), thingKind); !aiter.done(); aiter.next()) {
|
||||
ArenaHeader *aheader = aiter.get();
|
||||
aheader->zone = target->zone();
|
||||
|
@ -6666,7 +6670,7 @@ ArenaLists::adoptArenas(JSRuntime *rt, ArenaLists *fromArenaLists)
|
|||
|
||||
fromArenaLists->purge();
|
||||
|
||||
for (ALL_ALLOC_KINDS(thingKind)) {
|
||||
for (auto thingKind : AllAllocKinds()) {
|
||||
// When we enter a parallel section, we join the background
|
||||
// thread, and we do not run GC while in the parallel section,
|
||||
// so no finalizer should be active!
|
||||
|
|
|
@ -618,11 +618,11 @@ class ArenaLists
|
|||
|
||||
public:
|
||||
explicit ArenaLists(JSRuntime *rt) : runtime_(rt) {
|
||||
for (ALL_ALLOC_KINDS(i))
|
||||
for (auto i : AllAllocKinds())
|
||||
freeLists[i].initAsEmpty();
|
||||
for (ALL_ALLOC_KINDS(i))
|
||||
for (auto i : AllAllocKinds())
|
||||
backgroundFinalizeState[i] = BFS_DONE;
|
||||
for (ALL_ALLOC_KINDS(i))
|
||||
for (auto i : AllAllocKinds())
|
||||
arenaListsToSweep[i] = nullptr;
|
||||
incrementalSweptArenaKind = AllocKind::LIMIT;
|
||||
gcShapeArenasToUpdate = nullptr;
|
||||
|
@ -662,7 +662,7 @@ class ArenaLists
|
|||
}
|
||||
|
||||
bool arenaListsAreEmpty() const {
|
||||
for (ALL_ALLOC_KINDS(i)) {
|
||||
for (auto i : AllAllocKinds()) {
|
||||
/*
|
||||
* The arena cannot be empty if the background finalization is not yet
|
||||
* done.
|
||||
|
@ -676,7 +676,7 @@ class ArenaLists
|
|||
}
|
||||
|
||||
void unmarkAll() {
|
||||
for (ALL_ALLOC_KINDS(i)) {
|
||||
for (auto i : AllAllocKinds()) {
|
||||
/* The background finalization must have stopped at this point. */
|
||||
MOZ_ASSERT(backgroundFinalizeState[i] == BFS_DONE);
|
||||
for (ArenaHeader *aheader = arenaLists[i].head(); aheader; aheader = aheader->next)
|
||||
|
@ -697,7 +697,7 @@ class ArenaLists
|
|||
* run the finalizers over unitialized bytes from free things.
|
||||
*/
|
||||
void purge() {
|
||||
for (ALL_ALLOC_KINDS(i))
|
||||
for (auto i : AllAllocKinds())
|
||||
purge(i);
|
||||
}
|
||||
|
||||
|
@ -718,7 +718,7 @@ class ArenaLists
|
|||
* outside the GC.
|
||||
*/
|
||||
void copyFreeListsToArenas() {
|
||||
for (ALL_ALLOC_KINDS(i))
|
||||
for (auto i : AllAllocKinds())
|
||||
copyFreeListToArena(i);
|
||||
}
|
||||
|
||||
|
@ -736,7 +736,7 @@ class ArenaLists
|
|||
* copyToArenas.
|
||||
*/
|
||||
void clearFreeListsInArenas() {
|
||||
for (ALL_ALLOC_KINDS(i))
|
||||
for (auto i : AllAllocKinds())
|
||||
clearFreeListInArena(i);
|
||||
}
|
||||
|
||||
|
@ -792,7 +792,7 @@ class ArenaLists
|
|||
|
||||
void checkEmptyFreeLists() {
|
||||
#ifdef DEBUG
|
||||
for (ALL_ALLOC_KINDS(i))
|
||||
for (auto i : AllAllocKinds())
|
||||
checkEmptyFreeList(i);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -298,7 +298,7 @@ js::DumpCompartmentPCCounts(JSContext *cx)
|
|||
}
|
||||
}
|
||||
|
||||
for (OBJECT_ALLOC_KINDS(thingKind)) {
|
||||
for (auto thingKind : ObjectAllocKinds()) {
|
||||
for (ZoneCellIter i(cx->zone(), thingKind); !i.done(); i.next()) {
|
||||
JSObject *obj = i.get<JSObject>();
|
||||
if (obj->compartment() != cx->compartment())
|
||||
|
|
Загрузка…
Ссылка в новой задаче