|
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 #ifndef gc_GCInternals_h |
|
8 #define gc_GCInternals_h |
|
9 |
|
10 #include "jscntxt.h" |
|
11 #include "jsworkers.h" |
|
12 |
|
13 #include "gc/Zone.h" |
|
14 #include "vm/Runtime.h" |
|
15 |
|
16 namespace js { |
|
17 namespace gc { |
|
18 |
|
19 void |
|
20 MarkPersistentRootedChains(JSTracer *trc); |
|
21 |
|
22 void |
|
23 MarkRuntime(JSTracer *trc, bool useSavedRoots = false); |
|
24 |
|
25 void |
|
26 BufferGrayRoots(GCMarker *gcmarker); |
|
27 |
|
28 class AutoCopyFreeListToArenas |
|
29 { |
|
30 JSRuntime *runtime; |
|
31 ZoneSelector selector; |
|
32 |
|
33 public: |
|
34 AutoCopyFreeListToArenas(JSRuntime *rt, ZoneSelector selector); |
|
35 ~AutoCopyFreeListToArenas(); |
|
36 }; |
|
37 |
|
38 struct AutoFinishGC |
|
39 { |
|
40 AutoFinishGC(JSRuntime *rt); |
|
41 }; |
|
42 |
|
43 /* |
|
44 * This class should be used by any code that needs to exclusive access to the |
|
45 * heap in order to trace through it... |
|
46 */ |
|
47 class AutoTraceSession |
|
48 { |
|
49 public: |
|
50 AutoTraceSession(JSRuntime *rt, HeapState state = Tracing); |
|
51 ~AutoTraceSession(); |
|
52 |
|
53 protected: |
|
54 AutoLockForExclusiveAccess lock; |
|
55 JSRuntime *runtime; |
|
56 |
|
57 private: |
|
58 AutoTraceSession(const AutoTraceSession&) MOZ_DELETE; |
|
59 void operator=(const AutoTraceSession&) MOZ_DELETE; |
|
60 |
|
61 HeapState prevState; |
|
62 }; |
|
63 |
|
64 struct AutoPrepareForTracing |
|
65 { |
|
66 AutoFinishGC finish; |
|
67 AutoTraceSession session; |
|
68 AutoCopyFreeListToArenas copy; |
|
69 |
|
70 AutoPrepareForTracing(JSRuntime *rt, ZoneSelector selector); |
|
71 }; |
|
72 |
|
73 class IncrementalSafety |
|
74 { |
|
75 const char *reason_; |
|
76 |
|
77 IncrementalSafety(const char *reason) : reason_(reason) {} |
|
78 |
|
79 public: |
|
80 static IncrementalSafety Safe() { return IncrementalSafety(nullptr); } |
|
81 static IncrementalSafety Unsafe(const char *reason) { return IncrementalSafety(reason); } |
|
82 |
|
83 typedef void (IncrementalSafety::* ConvertibleToBool)(); |
|
84 void nonNull() {} |
|
85 |
|
86 operator ConvertibleToBool() const { |
|
87 return reason_ == nullptr ? &IncrementalSafety::nonNull : 0; |
|
88 } |
|
89 |
|
90 const char *reason() { |
|
91 JS_ASSERT(reason_); |
|
92 return reason_; |
|
93 } |
|
94 }; |
|
95 |
|
96 IncrementalSafety |
|
97 IsIncrementalGCSafe(JSRuntime *rt); |
|
98 |
|
99 #ifdef JS_GC_ZEAL |
|
100 void |
|
101 StartVerifyPreBarriers(JSRuntime *rt); |
|
102 |
|
103 void |
|
104 EndVerifyPreBarriers(JSRuntime *rt); |
|
105 |
|
106 void |
|
107 StartVerifyPostBarriers(JSRuntime *rt); |
|
108 |
|
109 void |
|
110 EndVerifyPostBarriers(JSRuntime *rt); |
|
111 |
|
112 void |
|
113 FinishVerifier(JSRuntime *rt); |
|
114 |
|
115 class AutoStopVerifyingBarriers |
|
116 { |
|
117 JSRuntime *runtime; |
|
118 bool restartPreVerifier; |
|
119 bool restartPostVerifier; |
|
120 MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER |
|
121 |
|
122 public: |
|
123 AutoStopVerifyingBarriers(JSRuntime *rt, bool isShutdown |
|
124 MOZ_GUARD_OBJECT_NOTIFIER_PARAM) |
|
125 : runtime(rt) |
|
126 { |
|
127 restartPreVerifier = !isShutdown && rt->gcVerifyPreData; |
|
128 restartPostVerifier = !isShutdown && rt->gcVerifyPostData && JS::IsGenerationalGCEnabled(rt); |
|
129 if (rt->gcVerifyPreData) |
|
130 EndVerifyPreBarriers(rt); |
|
131 if (rt->gcVerifyPostData) |
|
132 EndVerifyPostBarriers(rt); |
|
133 MOZ_GUARD_OBJECT_NOTIFIER_INIT; |
|
134 } |
|
135 |
|
136 ~AutoStopVerifyingBarriers() { |
|
137 if (restartPreVerifier) |
|
138 StartVerifyPreBarriers(runtime); |
|
139 if (restartPostVerifier) |
|
140 StartVerifyPostBarriers(runtime); |
|
141 } |
|
142 }; |
|
143 #else |
|
144 struct AutoStopVerifyingBarriers |
|
145 { |
|
146 AutoStopVerifyingBarriers(JSRuntime *, bool) {} |
|
147 }; |
|
148 #endif /* JS_GC_ZEAL */ |
|
149 |
|
150 } /* namespace gc */ |
|
151 } /* namespace js */ |
|
152 |
|
153 #endif /* gc_GCInternals_h */ |