js/src/gc/GCInternals.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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 "jscntxt.h"
    11 #include "jsworkers.h"
    13 #include "gc/Zone.h"
    14 #include "vm/Runtime.h"
    16 namespace js {
    17 namespace gc {
    19 void
    20 MarkPersistentRootedChains(JSTracer *trc);
    22 void
    23 MarkRuntime(JSTracer *trc, bool useSavedRoots = false);
    25 void
    26 BufferGrayRoots(GCMarker *gcmarker);
    28 class AutoCopyFreeListToArenas
    29 {
    30     JSRuntime *runtime;
    31     ZoneSelector selector;
    33   public:
    34     AutoCopyFreeListToArenas(JSRuntime *rt, ZoneSelector selector);
    35     ~AutoCopyFreeListToArenas();
    36 };
    38 struct AutoFinishGC
    39 {
    40     AutoFinishGC(JSRuntime *rt);
    41 };
    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();
    53   protected:
    54     AutoLockForExclusiveAccess lock;
    55     JSRuntime *runtime;
    57   private:
    58     AutoTraceSession(const AutoTraceSession&) MOZ_DELETE;
    59     void operator=(const AutoTraceSession&) MOZ_DELETE;
    61     HeapState prevState;
    62 };
    64 struct AutoPrepareForTracing
    65 {
    66     AutoFinishGC finish;
    67     AutoTraceSession session;
    68     AutoCopyFreeListToArenas copy;
    70     AutoPrepareForTracing(JSRuntime *rt, ZoneSelector selector);
    71 };
    73 class IncrementalSafety
    74 {
    75     const char *reason_;
    77     IncrementalSafety(const char *reason) : reason_(reason) {}
    79   public:
    80     static IncrementalSafety Safe() { return IncrementalSafety(nullptr); }
    81     static IncrementalSafety Unsafe(const char *reason) { return IncrementalSafety(reason); }
    83     typedef void (IncrementalSafety::* ConvertibleToBool)();
    84     void nonNull() {}
    86     operator ConvertibleToBool() const {
    87         return reason_ == nullptr ? &IncrementalSafety::nonNull : 0;
    88     }
    90     const char *reason() {
    91         JS_ASSERT(reason_);
    92         return reason_;
    93     }
    94 };
    96 IncrementalSafety
    97 IsIncrementalGCSafe(JSRuntime *rt);
    99 #ifdef JS_GC_ZEAL
   100 void
   101 StartVerifyPreBarriers(JSRuntime *rt);
   103 void
   104 EndVerifyPreBarriers(JSRuntime *rt);
   106 void
   107 StartVerifyPostBarriers(JSRuntime *rt);
   109 void
   110 EndVerifyPostBarriers(JSRuntime *rt);
   112 void
   113 FinishVerifier(JSRuntime *rt);
   115 class AutoStopVerifyingBarriers
   116 {
   117     JSRuntime *runtime;
   118     bool restartPreVerifier;
   119     bool restartPostVerifier;
   120     MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
   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     }
   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 */
   150 } /* namespace gc */
   151 } /* namespace js */
   153 #endif /* gc_GCInternals_h */

mercurial