Source code

Revision control

Other Tools

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/. */
6
7
/*
8
* Marking and sweeping APIs for use by implementations of different GC cell
9
* kinds.
10
*/
11
12
#ifndef gc_Marking_h
13
#define gc_Marking_h
14
15
#include "js/TypeDecls.h"
16
#include "vm/TaggedProto.h"
17
18
class JSLinearString;
19
class JSRope;
20
class JSTracer;
21
22
namespace js {
23
class BaseShape;
24
class GCMarker;
25
class LazyScript;
26
class NativeObject;
27
class ObjectGroup;
28
class Shape;
29
class WeakMapBase;
30
31
namespace jit {
32
class JitCode;
33
} // namespace jit
34
35
#ifdef DEBUG
36
bool IsTracerKind(JSTracer* trc, JS::CallbackTracer::TracerKind kind);
37
#endif
38
39
namespace gc {
40
41
struct Cell;
42
class TenuredCell;
43
44
/*** Liveness ***/
45
46
// The IsMarkedInternal and IsAboutToBeFinalizedInternal function templates are
47
// used to implement the IsMarked and IsAboutToBeFinalized set of functions.
48
// These internal functions are instantiated for the base GC types and should
49
// not be called directly.
50
//
51
// Note that there are two function templates declared for each, not one
52
// template and a specialization. This is necessary so that pointer arguments
53
// (e.g. JSObject**) and tagged value arguments (e.g. JS::Value*) are routed to
54
// separate implementations.
55
56
template <typename T>
57
bool IsMarkedInternal(JSRuntime* rt, T** thing);
58
59
template <typename T>
60
bool IsAboutToBeFinalizedInternal(T* thingp);
61
template <typename T>
62
bool IsAboutToBeFinalizedInternal(T** thingp);
63
64
// Report whether a GC thing has been marked with any color. Things which are in
65
// zones that are not currently being collected or are owned by another runtime
66
// are always reported as being marked.
67
template <typename T>
68
inline bool IsMarkedUnbarriered(JSRuntime* rt, T* thingp) {
69
return IsMarkedInternal(rt, ConvertToBase(thingp));
70
}
71
72
// Report whether a GC thing has been marked with any color. Things which are in
73
// zones that are not currently being collected or are owned by another runtime
74
// are always reported as being marked.
75
template <typename T>
76
inline bool IsMarked(JSRuntime* rt, BarrieredBase<T>* thingp) {
77
return IsMarkedInternal(rt,
78
ConvertToBase(thingp->unsafeUnbarrieredForTracing()));
79
}
80
81
template <typename T>
82
inline bool IsAboutToBeFinalizedUnbarriered(T* thingp) {
83
return IsAboutToBeFinalizedInternal(ConvertToBase(thingp));
84
}
85
86
template <typename T>
87
inline bool IsAboutToBeFinalized(const WriteBarriered<T>* thingp) {
88
return IsAboutToBeFinalizedInternal(
89
ConvertToBase(thingp->unsafeUnbarrieredForTracing()));
90
}
91
92
template <typename T>
93
inline bool IsAboutToBeFinalized(ReadBarriered<T>* thingp) {
94
return IsAboutToBeFinalizedInternal(
95
ConvertToBase(thingp->unsafeUnbarrieredForTracing()));
96
}
97
98
bool IsAboutToBeFinalizedDuringSweep(TenuredCell& tenured);
99
100
inline bool IsAboutToBeFinalizedDuringMinorSweep(Cell* cell);
101
102
inline Cell* ToMarkable(const Value& v) {
103
if (v.isGCThing()) {
104
return (Cell*)v.toGCThing();
105
}
106
return nullptr;
107
}
108
109
inline Cell* ToMarkable(Cell* cell) { return cell; }
110
111
} /* namespace gc */
112
113
// The return value indicates if anything was unmarked.
114
bool UnmarkGrayShapeRecursively(Shape* shape);
115
116
template <typename T>
117
void CheckTracedThing(JSTracer* trc, T* thing);
118
119
template <typename T>
120
void CheckTracedThing(JSTracer* trc, T thing);
121
122
namespace gc {
123
124
// Functions for checking and updating GC thing pointers that might have been
125
// moved by compacting GC. Overloads are also provided that work with Values.
126
//
127
// IsForwarded - check whether a pointer refers to an GC thing that has been
128
// moved.
129
//
130
// Forwarded - return a pointer to the new location of a GC thing given a
131
// pointer to old location.
132
//
133
// MaybeForwarded - used before dereferencing a pointer that may refer to a
134
// moved GC thing without updating it. For JSObjects this will
135
// also update the object's shape pointer if it has been moved
136
// to allow slots to be accessed.
137
138
template <typename T>
139
inline bool IsForwarded(const T* t);
140
inline bool IsForwarded(const JS::Value& value);
141
142
template <typename T>
143
inline T* Forwarded(const T* t);
144
145
inline Value Forwarded(const JS::Value& value);
146
147
template <typename T>
148
inline T MaybeForwarded(T t);
149
150
#ifdef JSGC_HASH_TABLE_CHECKS
151
152
template <typename T>
153
inline bool IsGCThingValidAfterMovingGC(T* t);
154
155
template <typename T>
156
inline void CheckGCThingAfterMovingGC(T* t);
157
158
template <typename T>
159
inline void CheckGCThingAfterMovingGC(const WeakHeapPtr<T*>& t);
160
161
inline void CheckValueAfterMovingGC(const JS::Value& value);
162
163
#endif // JSGC_HASH_TABLE_CHECKS
164
165
} /* namespace gc */
166
} /* namespace js */
167
168
#endif /* gc_Marking_h */