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"
18 MarkRuntime(JSTracer
*trc
, bool useSavedRoots
= false);
21 BufferGrayRoots(GCMarker
*gcmarker
);
23 class AutoCopyFreeListToArenas
{
27 AutoCopyFreeListToArenas(JSRuntime
*rt
);
28 ~AutoCopyFreeListToArenas();
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
{
42 AutoTraceSession(JSRuntime
*rt
, HeapState state
= Tracing
);
49 AutoTraceSession(const AutoTraceSession
&) MOZ_DELETE
;
50 void operator=(const AutoTraceSession
&) MOZ_DELETE
;
52 js::HeapState prevState
;
53 AutoPauseWorkersForGC pause
;
56 struct AutoPrepareForTracing
59 AutoTraceSession session
;
60 AutoCopyFreeListToArenas copy
;
62 AutoPrepareForTracing(JSRuntime
*rt
);
65 class IncrementalSafety
69 IncrementalSafety(const char *reason
) : reason_(reason
) {}
72 static IncrementalSafety
Safe() { return IncrementalSafety(nullptr); }
73 static IncrementalSafety
Unsafe(const char *reason
) { return IncrementalSafety(reason
); }
75 typedef void (IncrementalSafety::* ConvertibleToBool
)();
78 operator ConvertibleToBool() const {
79 return reason_
== nullptr ? &IncrementalSafety::nonNull
: 0;
82 const char *reason() {
89 IsIncrementalGCSafe(JSRuntime
*rt
);
91 #ifdef JSGC_ROOT_ANALYSIS
93 GetAddressableGCThing(JSRuntime
*rt
, uintptr_t w
);
98 StartVerifyPreBarriers(JSRuntime
*rt
);
101 EndVerifyPreBarriers(JSRuntime
*rt
);
104 StartVerifyPostBarriers(JSRuntime
*rt
);
107 EndVerifyPostBarriers(JSRuntime
*rt
);
110 FinishVerifier(JSRuntime
*rt
);
112 class AutoStopVerifyingBarriers
115 bool restartPreVerifier
;
116 bool restartPostVerifier
;
117 MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
120 AutoStopVerifyingBarriers(JSRuntime
*rt
, bool isShutdown
121 MOZ_GUARD_OBJECT_NOTIFIER_PARAM
)
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
);
141 struct AutoStopVerifyingBarriers
143 AutoStopVerifyingBarriers(JSRuntime
*, bool) {}
145 #endif /* JS_GC_ZEAL */
150 #endif /* gc_GCInternals_h */