|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
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/. */ |
|
6 |
|
7 #include "jscompartment.h" |
|
8 #include "jsgc.h" |
|
9 |
|
10 #include "gc/GCInternals.h" |
|
11 #include "js/HashTable.h" |
|
12 #include "vm/Runtime.h" |
|
13 |
|
14 #include "jscntxtinlines.h" |
|
15 #include "jsgcinlines.h" |
|
16 |
|
17 using namespace js; |
|
18 using namespace js::gc; |
|
19 |
|
20 void |
|
21 js::TraceRuntime(JSTracer *trc) |
|
22 { |
|
23 JS_ASSERT(!IS_GC_MARKING_TRACER(trc)); |
|
24 |
|
25 MinorGC(trc->runtime(), JS::gcreason::EVICT_NURSERY); |
|
26 AutoPrepareForTracing prep(trc->runtime(), WithAtoms); |
|
27 MarkRuntime(trc); |
|
28 } |
|
29 |
|
30 static void |
|
31 IterateCompartmentsArenasCells(JSRuntime *rt, Zone *zone, void *data, |
|
32 JSIterateCompartmentCallback compartmentCallback, |
|
33 IterateArenaCallback arenaCallback, |
|
34 IterateCellCallback cellCallback) |
|
35 { |
|
36 for (CompartmentsInZoneIter comp(zone); !comp.done(); comp.next()) |
|
37 (*compartmentCallback)(rt, data, comp); |
|
38 |
|
39 for (size_t thingKind = 0; thingKind != FINALIZE_LIMIT; thingKind++) { |
|
40 JSGCTraceKind traceKind = MapAllocToTraceKind(AllocKind(thingKind)); |
|
41 size_t thingSize = Arena::thingSize(AllocKind(thingKind)); |
|
42 |
|
43 for (ArenaIter aiter(zone, AllocKind(thingKind)); !aiter.done(); aiter.next()) { |
|
44 ArenaHeader *aheader = aiter.get(); |
|
45 (*arenaCallback)(rt, data, aheader->getArena(), traceKind, thingSize); |
|
46 for (CellIterUnderGC iter(aheader); !iter.done(); iter.next()) |
|
47 (*cellCallback)(rt, data, iter.getCell(), traceKind, thingSize); |
|
48 } |
|
49 } |
|
50 } |
|
51 |
|
52 void |
|
53 js::IterateZonesCompartmentsArenasCells(JSRuntime *rt, void *data, |
|
54 IterateZoneCallback zoneCallback, |
|
55 JSIterateCompartmentCallback compartmentCallback, |
|
56 IterateArenaCallback arenaCallback, |
|
57 IterateCellCallback cellCallback) |
|
58 { |
|
59 AutoPrepareForTracing prop(rt, WithAtoms); |
|
60 |
|
61 for (ZonesIter zone(rt, WithAtoms); !zone.done(); zone.next()) { |
|
62 (*zoneCallback)(rt, data, zone); |
|
63 IterateCompartmentsArenasCells(rt, zone, data, |
|
64 compartmentCallback, arenaCallback, cellCallback); |
|
65 } |
|
66 } |
|
67 |
|
68 void |
|
69 js::IterateZoneCompartmentsArenasCells(JSRuntime *rt, Zone *zone, void *data, |
|
70 IterateZoneCallback zoneCallback, |
|
71 JSIterateCompartmentCallback compartmentCallback, |
|
72 IterateArenaCallback arenaCallback, |
|
73 IterateCellCallback cellCallback) |
|
74 { |
|
75 AutoPrepareForTracing prop(rt, WithAtoms); |
|
76 |
|
77 (*zoneCallback)(rt, data, zone); |
|
78 IterateCompartmentsArenasCells(rt, zone, data, |
|
79 compartmentCallback, arenaCallback, cellCallback); |
|
80 } |
|
81 |
|
82 void |
|
83 js::IterateChunks(JSRuntime *rt, void *data, IterateChunkCallback chunkCallback) |
|
84 { |
|
85 AutoPrepareForTracing prep(rt, SkipAtoms); |
|
86 |
|
87 for (js::GCChunkSet::Range r = rt->gcChunkSet.all(); !r.empty(); r.popFront()) |
|
88 chunkCallback(rt, data, r.front()); |
|
89 } |
|
90 |
|
91 void |
|
92 js::IterateScripts(JSRuntime *rt, JSCompartment *compartment, |
|
93 void *data, IterateScriptCallback scriptCallback) |
|
94 { |
|
95 MinorGC(rt, JS::gcreason::EVICT_NURSERY); |
|
96 AutoPrepareForTracing prep(rt, SkipAtoms); |
|
97 |
|
98 if (compartment) { |
|
99 for (CellIterUnderGC i(compartment->zone(), gc::FINALIZE_SCRIPT); !i.done(); i.next()) { |
|
100 JSScript *script = i.get<JSScript>(); |
|
101 if (script->compartment() == compartment) |
|
102 scriptCallback(rt, data, script); |
|
103 } |
|
104 } else { |
|
105 for (ZonesIter zone(rt, SkipAtoms); !zone.done(); zone.next()) { |
|
106 for (CellIterUnderGC i(zone, gc::FINALIZE_SCRIPT); !i.done(); i.next()) |
|
107 scriptCallback(rt, data, i.get<JSScript>()); |
|
108 } |
|
109 } |
|
110 } |
|
111 |
|
112 void |
|
113 js::IterateGrayObjects(Zone *zone, GCThingCallback cellCallback, void *data) |
|
114 { |
|
115 MinorGC(zone->runtimeFromMainThread(), JS::gcreason::EVICT_NURSERY); |
|
116 AutoPrepareForTracing prep(zone->runtimeFromMainThread(), SkipAtoms); |
|
117 |
|
118 for (size_t finalizeKind = 0; finalizeKind <= FINALIZE_OBJECT_LAST; finalizeKind++) { |
|
119 for (CellIterUnderGC i(zone, AllocKind(finalizeKind)); !i.done(); i.next()) { |
|
120 JSObject *obj = i.get<JSObject>(); |
|
121 if (obj->isMarked(GRAY)) |
|
122 cellCallback(data, obj); |
|
123 } |
|
124 } |
|
125 } |
|
126 |
|
127 JS_PUBLIC_API(void) |
|
128 JS_IterateCompartments(JSRuntime *rt, void *data, |
|
129 JSIterateCompartmentCallback compartmentCallback) |
|
130 { |
|
131 JS_ASSERT(!rt->isHeapBusy()); |
|
132 |
|
133 AutoTraceSession session(rt); |
|
134 |
|
135 for (CompartmentsIter c(rt, WithAtoms); !c.done(); c.next()) |
|
136 (*compartmentCallback)(rt, data, c); |
|
137 } |