Backed out changeset 1e582a0e5593 (bug 1852921) for causing build bustages
[gecko.git] / js / src / gc / Marking.h
blob7043eccc535b1322d041d220424195c0d75e736a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
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 /*
8 * Marking and sweeping APIs for use by implementations of different GC cell
9 * kinds.
12 #ifndef gc_Marking_h
13 #define gc_Marking_h
15 #include "gc/Barrier.h"
16 #include "js/TypeDecls.h"
18 class JSTracer;
19 struct JSClass;
21 namespace js {
22 class GCMarker;
23 class Shape;
24 class WeakMapBase;
26 namespace gc {
28 struct Cell;
30 /*** Liveness ***/
32 // The IsMarkedInternal and IsAboutToBeFinalizedInternal function templates are
33 // used to implement the IsMarked and IsAboutToBeFinalized set of functions.
34 // These internal functions are instantiated for the base GC types and should
35 // not be called directly.
37 // Note that there are two function templates declared for each, not one
38 // template and a specialization. This is necessary so that pointer arguments
39 // (e.g. JSObject**) and tagged value arguments (e.g. JS::Value*) are routed to
40 // separate implementations.
42 template <typename T>
43 bool IsMarkedInternal(JSRuntime* rt, T* thing);
45 template <typename T>
46 bool IsAboutToBeFinalizedInternal(T* thing);
47 template <typename T>
48 bool IsAboutToBeFinalizedInternal(const T& thing);
50 // Report whether a GC thing has been marked with any color. Things which are in
51 // zones that are not currently being collected or are owned by another runtime
52 // are always reported as being marked.
53 template <typename T>
54 inline bool IsMarked(JSRuntime* rt, const BarrieredBase<T>& thing) {
55 return IsMarkedInternal(rt, *ConvertToBase(thing.unbarrieredAddress()));
57 template <typename T>
58 inline bool IsMarkedUnbarriered(JSRuntime* rt, T thing) {
59 return IsMarkedInternal(rt, *ConvertToBase(&thing));
62 // Report whether a GC thing is dead and will be finalized in the current sweep
63 // group. This is mainly used in read barriers for incremental sweeping.
65 // This no longer updates pointers moved by the GC (tracing should be used for
66 // this instead).
67 template <typename T>
68 inline bool IsAboutToBeFinalized(const BarrieredBase<T>& thing) {
69 return IsAboutToBeFinalizedInternal(
70 *ConvertToBase(thing.unbarrieredAddress()));
72 template <typename T>
73 inline bool IsAboutToBeFinalizedUnbarriered(T thing) {
74 return IsAboutToBeFinalizedInternal(*ConvertToBase(&thing));
77 inline bool IsAboutToBeFinalizedDuringMinorSweep(Cell* cell);
79 inline Cell* ToMarkable(const Value& v) {
80 if (v.isGCThing()) {
81 return (Cell*)v.toGCThing();
83 return nullptr;
86 inline Cell* ToMarkable(Cell* cell) { return cell; }
88 bool UnmarkGrayGCThingUnchecked(GCMarker* marker, JS::GCCellPtr thing);
90 } /* namespace gc */
92 // The return value indicates if anything was unmarked.
93 bool UnmarkGrayShapeRecursively(Shape* shape);
95 namespace gc {
97 // Functions for checking and updating GC thing pointers that might have been
98 // moved by compacting GC. Overloads are also provided that work with Values.
100 // IsForwarded - check whether a pointer refers to an GC thing that has been
101 // moved.
103 // Forwarded - return a pointer to the new location of a GC thing given a
104 // pointer to old location.
106 // MaybeForwarded - used before dereferencing a pointer that may refer to a
107 // moved GC thing without updating it. For JSObjects this will
108 // also update the object's shape pointer if it has been moved
109 // to allow slots to be accessed.
111 template <typename T>
112 inline bool IsForwarded(const T* t);
114 template <typename T>
115 inline T* Forwarded(const T* t);
117 inline Value Forwarded(const JS::Value& value);
119 template <typename T>
120 inline T MaybeForwarded(T t);
122 // Helper functions for use in situations where the object's group might be
123 // forwarded, for example while marking.
125 inline const JSClass* MaybeForwardedObjectClass(const JSObject* obj);
127 template <typename T>
128 inline bool MaybeForwardedObjectIs(const JSObject* obj);
130 template <typename T>
131 inline T& MaybeForwardedObjectAs(JSObject* obj);
133 #ifdef JSGC_HASH_TABLE_CHECKS
135 template <typename T>
136 inline bool IsGCThingValidAfterMovingGC(T* t);
138 template <typename T>
139 inline void CheckGCThingAfterMovingGC(T* t);
141 template <typename T>
142 inline void CheckGCThingAfterMovingGC(const WeakHeapPtr<T*>& t);
144 #endif // JSGC_HASH_TABLE_CHECKS
146 } /* namespace gc */
148 } /* namespace js */
150 #endif /* gc_Marking_h */