michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef gc_GCInternals_h michael@0: #define gc_GCInternals_h michael@0: michael@0: #include "jscntxt.h" michael@0: #include "jsworkers.h" michael@0: michael@0: #include "gc/Zone.h" michael@0: #include "vm/Runtime.h" michael@0: michael@0: namespace js { michael@0: namespace gc { michael@0: michael@0: void michael@0: MarkPersistentRootedChains(JSTracer *trc); michael@0: michael@0: void michael@0: MarkRuntime(JSTracer *trc, bool useSavedRoots = false); michael@0: michael@0: void michael@0: BufferGrayRoots(GCMarker *gcmarker); michael@0: michael@0: class AutoCopyFreeListToArenas michael@0: { michael@0: JSRuntime *runtime; michael@0: ZoneSelector selector; michael@0: michael@0: public: michael@0: AutoCopyFreeListToArenas(JSRuntime *rt, ZoneSelector selector); michael@0: ~AutoCopyFreeListToArenas(); michael@0: }; michael@0: michael@0: struct AutoFinishGC michael@0: { michael@0: AutoFinishGC(JSRuntime *rt); michael@0: }; michael@0: michael@0: /* michael@0: * This class should be used by any code that needs to exclusive access to the michael@0: * heap in order to trace through it... michael@0: */ michael@0: class AutoTraceSession michael@0: { michael@0: public: michael@0: AutoTraceSession(JSRuntime *rt, HeapState state = Tracing); michael@0: ~AutoTraceSession(); michael@0: michael@0: protected: michael@0: AutoLockForExclusiveAccess lock; michael@0: JSRuntime *runtime; michael@0: michael@0: private: michael@0: AutoTraceSession(const AutoTraceSession&) MOZ_DELETE; michael@0: void operator=(const AutoTraceSession&) MOZ_DELETE; michael@0: michael@0: HeapState prevState; michael@0: }; michael@0: michael@0: struct AutoPrepareForTracing michael@0: { michael@0: AutoFinishGC finish; michael@0: AutoTraceSession session; michael@0: AutoCopyFreeListToArenas copy; michael@0: michael@0: AutoPrepareForTracing(JSRuntime *rt, ZoneSelector selector); michael@0: }; michael@0: michael@0: class IncrementalSafety michael@0: { michael@0: const char *reason_; michael@0: michael@0: IncrementalSafety(const char *reason) : reason_(reason) {} michael@0: michael@0: public: michael@0: static IncrementalSafety Safe() { return IncrementalSafety(nullptr); } michael@0: static IncrementalSafety Unsafe(const char *reason) { return IncrementalSafety(reason); } michael@0: michael@0: typedef void (IncrementalSafety::* ConvertibleToBool)(); michael@0: void nonNull() {} michael@0: michael@0: operator ConvertibleToBool() const { michael@0: return reason_ == nullptr ? &IncrementalSafety::nonNull : 0; michael@0: } michael@0: michael@0: const char *reason() { michael@0: JS_ASSERT(reason_); michael@0: return reason_; michael@0: } michael@0: }; michael@0: michael@0: IncrementalSafety michael@0: IsIncrementalGCSafe(JSRuntime *rt); michael@0: michael@0: #ifdef JS_GC_ZEAL michael@0: void michael@0: StartVerifyPreBarriers(JSRuntime *rt); michael@0: michael@0: void michael@0: EndVerifyPreBarriers(JSRuntime *rt); michael@0: michael@0: void michael@0: StartVerifyPostBarriers(JSRuntime *rt); michael@0: michael@0: void michael@0: EndVerifyPostBarriers(JSRuntime *rt); michael@0: michael@0: void michael@0: FinishVerifier(JSRuntime *rt); michael@0: michael@0: class AutoStopVerifyingBarriers michael@0: { michael@0: JSRuntime *runtime; michael@0: bool restartPreVerifier; michael@0: bool restartPostVerifier; michael@0: MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER michael@0: michael@0: public: michael@0: AutoStopVerifyingBarriers(JSRuntime *rt, bool isShutdown michael@0: MOZ_GUARD_OBJECT_NOTIFIER_PARAM) michael@0: : runtime(rt) michael@0: { michael@0: restartPreVerifier = !isShutdown && rt->gcVerifyPreData; michael@0: restartPostVerifier = !isShutdown && rt->gcVerifyPostData && JS::IsGenerationalGCEnabled(rt); michael@0: if (rt->gcVerifyPreData) michael@0: EndVerifyPreBarriers(rt); michael@0: if (rt->gcVerifyPostData) michael@0: EndVerifyPostBarriers(rt); michael@0: MOZ_GUARD_OBJECT_NOTIFIER_INIT; michael@0: } michael@0: michael@0: ~AutoStopVerifyingBarriers() { michael@0: if (restartPreVerifier) michael@0: StartVerifyPreBarriers(runtime); michael@0: if (restartPostVerifier) michael@0: StartVerifyPostBarriers(runtime); michael@0: } michael@0: }; michael@0: #else michael@0: struct AutoStopVerifyingBarriers michael@0: { michael@0: AutoStopVerifyingBarriers(JSRuntime *, bool) {} michael@0: }; michael@0: #endif /* JS_GC_ZEAL */ michael@0: michael@0: } /* namespace gc */ michael@0: } /* namespace js */ michael@0: michael@0: #endif /* gc_GCInternals_h */