1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * GC-internal iterators for various data structures.
11 #ifndef gc_PrivateIterators_inl_h
12 #define gc_PrivateIterators_inl_h
14 #include "gc/PublicIterators.h"
16 #include "gc/GC-inl.h"
20 class ArenaCellIterUnderGC
: public ArenaCellIter
{
22 explicit ArenaCellIterUnderGC(Arena
* arena
) : ArenaCellIter(arena
) {
23 MOZ_ASSERT(CurrentThreadIsPerformingGC());
27 class ArenaCellIterUnderFinalize
: public ArenaCellIter
{
29 explicit ArenaCellIterUnderFinalize(Arena
* arena
) : ArenaCellIter(arena
) {
30 MOZ_ASSERT(CurrentThreadIsGCFinalizing());
34 class GrayObjectIter
: public ZoneAllCellIter
<js::gc::TenuredCell
> {
36 explicit GrayObjectIter(JS::Zone
* zone
, AllocKind kind
)
37 : ZoneAllCellIter
<js::gc::TenuredCell
>() {
38 initForTenuredIteration(zone
, kind
);
41 JSObject
* get() const {
42 return ZoneAllCellIter
<js::gc::TenuredCell
>::get
<JSObject
>();
44 operator JSObject
*() const { return get(); }
45 JSObject
* operator->() const { return get(); }
52 explicit GCZonesIter(GCRuntime
* gc
) : zone(gc
) {
53 MOZ_ASSERT(gc
->heapState() != JS::HeapState::Idle
);
54 if (!done() && !zone
->wasGCStarted()) {
58 explicit GCZonesIter(JSRuntime
* rt
) : GCZonesIter(&rt
->gc
) {}
60 bool done() const { return zone
.done(); }
66 } while (!zone
.done() && !zone
->wasGCStarted());
69 JS::Zone
* get() const {
74 operator JS::Zone
*() const { return get(); }
75 JS::Zone
* operator->() const { return get(); }
78 using GCCompartmentsIter
=
79 CompartmentsOrRealmsIterT
<GCZonesIter
, CompartmentsInZoneIter
>;
80 using GCRealmsIter
= CompartmentsOrRealmsIterT
<GCZonesIter
, RealmsInZoneIter
>;
82 /* Iterates over all zones in the current sweep group. */
83 class SweepGroupZonesIter
{
87 explicit SweepGroupZonesIter(GCRuntime
* gc
)
88 : current(gc
->getCurrentSweepGroup()) {
89 MOZ_ASSERT(CurrentThreadIsPerformingGC());
91 explicit SweepGroupZonesIter(JSRuntime
* rt
) : SweepGroupZonesIter(&rt
->gc
) {}
93 bool done() const { return !current
; }
97 current
= current
->nextNodeInGroup();
100 JS::Zone
* get() const {
105 operator JS::Zone
*() const { return get(); }
106 JS::Zone
* operator->() const { return get(); }
109 using SweepGroupCompartmentsIter
=
110 CompartmentsOrRealmsIterT
<SweepGroupZonesIter
, CompartmentsInZoneIter
>;
111 using SweepGroupRealmsIter
=
112 CompartmentsOrRealmsIterT
<SweepGroupZonesIter
, RealmsInZoneIter
>;
114 // Iterate the free cells in an arena. See also ArenaCellIter which iterates
115 // the allocated cells.
116 class ArenaFreeCellIter
{
123 explicit ArenaFreeCellIter(Arena
* arena
)
125 thingSize(arena
->getThingSize()),
126 span(*arena
->getFirstFreeSpan()),
129 MOZ_ASSERT(thing
< ArenaSize
);
133 MOZ_ASSERT(thing
< ArenaSize
);
137 TenuredCell
* get() const {
139 return reinterpret_cast<TenuredCell
*>(uintptr_t(arena
) + thing
);
144 MOZ_ASSERT(thing
>= span
.first
&& thing
<= span
.last
);
146 if (thing
== span
.last
) {
147 span
= *span
.nextSpan(arena
);
153 MOZ_ASSERT(thing
< ArenaSize
);
156 operator TenuredCell
*() const { return get(); }
157 TenuredCell
* operator->() const { return get(); }
160 } // namespace js::gc
162 #endif // gc_PrivateIterators_inl_h