js/src/gc/GCInternals.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/gc/GCInternals.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,153 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef gc_GCInternals_h
    1.11 +#define gc_GCInternals_h
    1.12 +
    1.13 +#include "jscntxt.h"
    1.14 +#include "jsworkers.h"
    1.15 +
    1.16 +#include "gc/Zone.h"
    1.17 +#include "vm/Runtime.h"
    1.18 +
    1.19 +namespace js {
    1.20 +namespace gc {
    1.21 +
    1.22 +void
    1.23 +MarkPersistentRootedChains(JSTracer *trc);
    1.24 +
    1.25 +void
    1.26 +MarkRuntime(JSTracer *trc, bool useSavedRoots = false);
    1.27 +
    1.28 +void
    1.29 +BufferGrayRoots(GCMarker *gcmarker);
    1.30 +
    1.31 +class AutoCopyFreeListToArenas
    1.32 +{
    1.33 +    JSRuntime *runtime;
    1.34 +    ZoneSelector selector;
    1.35 +
    1.36 +  public:
    1.37 +    AutoCopyFreeListToArenas(JSRuntime *rt, ZoneSelector selector);
    1.38 +    ~AutoCopyFreeListToArenas();
    1.39 +};
    1.40 +
    1.41 +struct AutoFinishGC
    1.42 +{
    1.43 +    AutoFinishGC(JSRuntime *rt);
    1.44 +};
    1.45 +
    1.46 +/*
    1.47 + * This class should be used by any code that needs to exclusive access to the
    1.48 + * heap in order to trace through it...
    1.49 + */
    1.50 +class AutoTraceSession
    1.51 +{
    1.52 +  public:
    1.53 +    AutoTraceSession(JSRuntime *rt, HeapState state = Tracing);
    1.54 +    ~AutoTraceSession();
    1.55 +
    1.56 +  protected:
    1.57 +    AutoLockForExclusiveAccess lock;
    1.58 +    JSRuntime *runtime;
    1.59 +
    1.60 +  private:
    1.61 +    AutoTraceSession(const AutoTraceSession&) MOZ_DELETE;
    1.62 +    void operator=(const AutoTraceSession&) MOZ_DELETE;
    1.63 +
    1.64 +    HeapState prevState;
    1.65 +};
    1.66 +
    1.67 +struct AutoPrepareForTracing
    1.68 +{
    1.69 +    AutoFinishGC finish;
    1.70 +    AutoTraceSession session;
    1.71 +    AutoCopyFreeListToArenas copy;
    1.72 +
    1.73 +    AutoPrepareForTracing(JSRuntime *rt, ZoneSelector selector);
    1.74 +};
    1.75 +
    1.76 +class IncrementalSafety
    1.77 +{
    1.78 +    const char *reason_;
    1.79 +
    1.80 +    IncrementalSafety(const char *reason) : reason_(reason) {}
    1.81 +
    1.82 +  public:
    1.83 +    static IncrementalSafety Safe() { return IncrementalSafety(nullptr); }
    1.84 +    static IncrementalSafety Unsafe(const char *reason) { return IncrementalSafety(reason); }
    1.85 +
    1.86 +    typedef void (IncrementalSafety::* ConvertibleToBool)();
    1.87 +    void nonNull() {}
    1.88 +
    1.89 +    operator ConvertibleToBool() const {
    1.90 +        return reason_ == nullptr ? &IncrementalSafety::nonNull : 0;
    1.91 +    }
    1.92 +
    1.93 +    const char *reason() {
    1.94 +        JS_ASSERT(reason_);
    1.95 +        return reason_;
    1.96 +    }
    1.97 +};
    1.98 +
    1.99 +IncrementalSafety
   1.100 +IsIncrementalGCSafe(JSRuntime *rt);
   1.101 +
   1.102 +#ifdef JS_GC_ZEAL
   1.103 +void
   1.104 +StartVerifyPreBarriers(JSRuntime *rt);
   1.105 +
   1.106 +void
   1.107 +EndVerifyPreBarriers(JSRuntime *rt);
   1.108 +
   1.109 +void
   1.110 +StartVerifyPostBarriers(JSRuntime *rt);
   1.111 +
   1.112 +void
   1.113 +EndVerifyPostBarriers(JSRuntime *rt);
   1.114 +
   1.115 +void
   1.116 +FinishVerifier(JSRuntime *rt);
   1.117 +
   1.118 +class AutoStopVerifyingBarriers
   1.119 +{
   1.120 +    JSRuntime *runtime;
   1.121 +    bool restartPreVerifier;
   1.122 +    bool restartPostVerifier;
   1.123 +    MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
   1.124 +
   1.125 +  public:
   1.126 +    AutoStopVerifyingBarriers(JSRuntime *rt, bool isShutdown
   1.127 +                              MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
   1.128 +      : runtime(rt)
   1.129 +    {
   1.130 +        restartPreVerifier = !isShutdown && rt->gcVerifyPreData;
   1.131 +        restartPostVerifier = !isShutdown && rt->gcVerifyPostData && JS::IsGenerationalGCEnabled(rt);
   1.132 +        if (rt->gcVerifyPreData)
   1.133 +            EndVerifyPreBarriers(rt);
   1.134 +        if (rt->gcVerifyPostData)
   1.135 +            EndVerifyPostBarriers(rt);
   1.136 +        MOZ_GUARD_OBJECT_NOTIFIER_INIT;
   1.137 +    }
   1.138 +
   1.139 +    ~AutoStopVerifyingBarriers() {
   1.140 +        if (restartPreVerifier)
   1.141 +            StartVerifyPreBarriers(runtime);
   1.142 +        if (restartPostVerifier)
   1.143 +            StartVerifyPostBarriers(runtime);
   1.144 +    }
   1.145 +};
   1.146 +#else
   1.147 +struct AutoStopVerifyingBarriers
   1.148 +{
   1.149 +    AutoStopVerifyingBarriers(JSRuntime *, bool) {}
   1.150 +};
   1.151 +#endif /* JS_GC_ZEAL */
   1.152 +
   1.153 +} /* namespace gc */
   1.154 +} /* namespace js */
   1.155 +
   1.156 +#endif /* gc_GCInternals_h */

mercurial