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/. */
8 * Marking and sweeping APIs for use by implementations of different GC cell
15 #include "gc/Barrier.h"
16 #include "js/TypeDecls.h"
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.
43 bool IsMarkedInternal(JSRuntime
* rt
, T
* thing
);
46 bool IsAboutToBeFinalizedInternal(T
* thing
);
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.
54 inline bool IsMarked(JSRuntime
* rt
, const BarrieredBase
<T
>& thing
) {
55 return IsMarkedInternal(rt
, *ConvertToBase(thing
.unbarrieredAddress()));
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
68 inline bool IsAboutToBeFinalized(const BarrieredBase
<T
>& thing
) {
69 return IsAboutToBeFinalizedInternal(
70 *ConvertToBase(thing
.unbarrieredAddress()));
73 inline bool IsAboutToBeFinalizedUnbarriered(T thing
) {
74 return IsAboutToBeFinalizedInternal(*ConvertToBase(&thing
));
77 inline bool IsAboutToBeFinalizedDuringMinorSweep(Cell
* cell
);
79 inline Cell
* ToMarkable(const Value
& v
) {
81 return (Cell
*)v
.toGCThing();
86 inline Cell
* ToMarkable(Cell
* cell
) { return cell
; }
88 bool UnmarkGrayGCThingUnchecked(GCMarker
* marker
, JS::GCCellPtr thing
);
92 // The return value indicates if anything was unmarked.
93 bool UnmarkGrayShapeRecursively(Shape
* shape
);
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
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
150 #endif /* gc_Marking_h */