Backed out changeset 61f6c63bcb3d (bug 928056) for m-oth failures.
[gecko.git] / js / src / gc / GCInternals.h
blob27e39a8e4f406631035f99dbc4915f97dec4da10
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/. */
7 #ifndef gc_GCInternals_h
8 #define gc_GCInternals_h
10 #include "jsworkers.h"
12 #include "vm/Runtime.h"
14 namespace js {
15 namespace gc {
17 void
18 MarkRuntime(JSTracer *trc, bool useSavedRoots = false);
20 void
21 BufferGrayRoots(GCMarker *gcmarker);
23 class AutoCopyFreeListToArenas {
24 JSRuntime *runtime;
26 public:
27 AutoCopyFreeListToArenas(JSRuntime *rt);
28 ~AutoCopyFreeListToArenas();
31 struct AutoFinishGC
33 AutoFinishGC(JSRuntime *rt);
37 * This class should be used by any code that needs to exclusive access to the
38 * heap in order to trace through it...
40 class AutoTraceSession {
41 public:
42 AutoTraceSession(JSRuntime *rt, HeapState state = Tracing);
43 ~AutoTraceSession();
45 protected:
46 JSRuntime *runtime;
48 private:
49 AutoTraceSession(const AutoTraceSession&) MOZ_DELETE;
50 void operator=(const AutoTraceSession&) MOZ_DELETE;
52 js::HeapState prevState;
53 AutoPauseWorkersForGC pause;
56 struct AutoPrepareForTracing
58 AutoFinishGC finish;
59 AutoTraceSession session;
60 AutoCopyFreeListToArenas copy;
62 AutoPrepareForTracing(JSRuntime *rt);
65 class IncrementalSafety
67 const char *reason_;
69 IncrementalSafety(const char *reason) : reason_(reason) {}
71 public:
72 static IncrementalSafety Safe() { return IncrementalSafety(nullptr); }
73 static IncrementalSafety Unsafe(const char *reason) { return IncrementalSafety(reason); }
75 typedef void (IncrementalSafety::* ConvertibleToBool)();
76 void nonNull() {}
78 operator ConvertibleToBool() const {
79 return reason_ == nullptr ? &IncrementalSafety::nonNull : 0;
82 const char *reason() {
83 JS_ASSERT(reason_);
84 return reason_;
88 IncrementalSafety
89 IsIncrementalGCSafe(JSRuntime *rt);
91 #ifdef JSGC_ROOT_ANALYSIS
92 void *
93 GetAddressableGCThing(JSRuntime *rt, uintptr_t w);
94 #endif
96 #ifdef JS_GC_ZEAL
97 void
98 StartVerifyPreBarriers(JSRuntime *rt);
100 void
101 EndVerifyPreBarriers(JSRuntime *rt);
103 void
104 StartVerifyPostBarriers(JSRuntime *rt);
106 void
107 EndVerifyPostBarriers(JSRuntime *rt);
109 void
110 FinishVerifier(JSRuntime *rt);
112 class AutoStopVerifyingBarriers
114 JSRuntime *runtime;
115 bool restartPreVerifier;
116 bool restartPostVerifier;
117 MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
119 public:
120 AutoStopVerifyingBarriers(JSRuntime *rt, bool isShutdown
121 MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
122 : runtime(rt)
124 restartPreVerifier = !isShutdown && rt->gcVerifyPreData;
125 restartPostVerifier = !isShutdown && rt->gcVerifyPostData && rt->gcGenerationalEnabled;
126 if (rt->gcVerifyPreData)
127 EndVerifyPreBarriers(rt);
128 if (rt->gcVerifyPostData)
129 EndVerifyPostBarriers(rt);
130 MOZ_GUARD_OBJECT_NOTIFIER_INIT;
133 ~AutoStopVerifyingBarriers() {
134 if (restartPreVerifier)
135 StartVerifyPreBarriers(runtime);
136 if (restartPostVerifier)
137 StartVerifyPostBarriers(runtime);
140 #else
141 struct AutoStopVerifyingBarriers
143 AutoStopVerifyingBarriers(JSRuntime *, bool) {}
145 #endif /* JS_GC_ZEAL */
147 } /* namespace gc */
148 } /* namespace js */
150 #endif /* gc_GCInternals_h */