no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / js / src / gc / Marking.h
blobed146ee236398d2b079d3dc7e25bd3b6f1ff074c
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 "gc/Tracer.h"
17 #include "js/TypeDecls.h"
19 class JSTracer;
20 struct JSClass;
22 namespace js {
23 class GCMarker;
24 class Shape;
25 class WeakMapBase;
27 namespace gc {
29 struct Cell;
31 /*** Liveness ***/
33 // The IsMarkedInternal and IsAboutToBeFinalizedInternal function templates are
34 // used to implement the IsMarked and IsAboutToBeFinalized set of functions.
35 // These internal functions are instantiated for the base GC types and should
36 // not be called directly.
38 // Note that there are two function templates declared for each, not one
39 // template and a specialization. This is necessary so that pointer arguments
40 // (e.g. JSObject**) and tagged value arguments (e.g. JS::Value*) are routed to
41 // separate implementations.
43 template <typename T>
44 bool IsMarkedInternal(JSRuntime* rt, T* thing);
46 template <typename T>
47 bool IsAboutToBeFinalizedInternal(T* thing);
48 template <typename T>
49 bool IsAboutToBeFinalizedInternal(const T& thing);
51 // Report whether a GC thing has been marked with any color. Things which are in
52 // zones that are not currently being collected or are owned by another runtime
53 // are always reported as being marked.
54 template <typename T>
55 inline bool IsMarked(JSRuntime* rt, const BarrieredBase<T>& thing) {
56 return IsMarkedInternal(rt, *ConvertToBase(thing.unbarrieredAddress()));
58 template <typename T>
59 inline bool IsMarkedUnbarriered(JSRuntime* rt, T thing) {
60 return IsMarkedInternal(rt, *ConvertToBase(&thing));
63 // Report whether a GC thing is dead and will be finalized in the current sweep
64 // group. This is mainly used in read barriers for incremental sweeping.
66 // This no longer updates pointers moved by the GC (tracing should be used for
67 // this instead).
68 template <typename T>
69 inline bool IsAboutToBeFinalized(const BarrieredBase<T>& thing) {
70 return IsAboutToBeFinalizedInternal(
71 *ConvertToBase(thing.unbarrieredAddress()));
73 template <typename T>
74 inline bool IsAboutToBeFinalizedUnbarriered(T* thing) {
75 return IsAboutToBeFinalizedInternal(*ConvertToBase(&thing));
77 template <typename T>
78 inline bool IsAboutToBeFinalizedUnbarriered(const T& thing) {
79 return IsAboutToBeFinalizedInternal(thing);
82 inline bool IsAboutToBeFinalizedDuringMinorSweep(Cell* cell);
84 inline Cell* ToMarkable(const Value& v) {
85 if (v.isGCThing()) {
86 return (Cell*)v.toGCThing();
88 return nullptr;
91 inline Cell* ToMarkable(Cell* cell) { return cell; }
93 bool UnmarkGrayGCThingUnchecked(GCMarker* marker, JS::GCCellPtr thing);
95 } /* namespace gc */
97 // The return value indicates if anything was unmarked.
98 bool UnmarkGrayShapeRecursively(Shape* shape);
100 namespace gc {
102 // Functions for checking and updating GC thing pointers that might have been
103 // moved by compacting GC. Overloads are also provided that work with Values.
105 // IsForwarded - check whether a pointer refers to an GC thing that has been
106 // moved.
108 // Forwarded - return a pointer to the new location of a GC thing given a
109 // pointer to old location.
111 // MaybeForwarded - used before dereferencing a pointer that may refer to a
112 // moved GC thing without updating it. For JSObjects this will
113 // also update the object's shape pointer if it has been moved
114 // to allow slots to be accessed.
116 template <typename T>
117 inline bool IsForwarded(const T* t);
119 template <typename T>
120 inline T* Forwarded(const T* t);
122 inline Value Forwarded(const JS::Value& value);
124 template <typename T>
125 inline T MaybeForwarded(T t);
127 // Helper functions for use in situations where the object's group might be
128 // forwarded, for example while marking.
130 inline const JSClass* MaybeForwardedObjectClass(const JSObject* obj);
132 template <typename T>
133 inline bool MaybeForwardedObjectIs(const JSObject* obj);
135 template <typename T>
136 inline T& MaybeForwardedObjectAs(JSObject* obj);
138 #ifdef JSGC_HASH_TABLE_CHECKS
140 template <typename T>
141 inline bool IsGCThingValidAfterMovingGC(T* t);
143 template <typename T>
144 inline void CheckGCThingAfterMovingGC(T* t);
146 template <typename T>
147 inline void CheckGCThingAfterMovingGC(const WeakHeapPtr<T*>& t);
149 #endif // JSGC_HASH_TABLE_CHECKS
151 } /* namespace gc */
153 } /* namespace js */
155 #endif /* gc_Marking_h */