DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (d8847129d134)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: set ts=8 sts=4 et sw=4 tw=99:
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef gc_Marking_h
#define gc_Marking_h

#include "gc/Barrier.h"

class JSAtom;
class JSLinearString;

namespace js {

class ArgumentsObject;
class ArrayBufferObject;
class ArrayBufferViewObject;
class SharedArrayBufferObject;
class BaseShape;
class DebugScopeObject;
class GCMarker;
class GlobalObject;
class LazyScript;
class NestedScopeObject;
class SavedFrame;
class ScopeObject;
class Shape;
class UnownedBaseShape;

template<class> class HeapPtr;

namespace jit {
class JitCode;
struct IonScript;
struct VMFunction;
}

namespace types {
class Type;
}

namespace gc {

/*** Object Marking ***/

/*
 * These functions expose marking functionality for all of the different GC
 * thing kinds. For each GC thing, there are several variants. As an example,
 * these are the variants generated for JSObject. They are listed from most to
 * least desirable for use:
 *
 * MarkObject(JSTracer* trc, const HeapPtrObject& thing, const char* name);
 *     This function should be used for marking JSObjects, in preference to all
 *     others below. Use it when you have HeapPtrObject, which automatically
 *     implements write barriers.
 *
 * MarkObjectRoot(JSTracer* trc, JSObject* thing, const char* name);
 *     This function is only valid during the root marking phase of GC (i.e.,
 *     when MarkRuntime is on the stack).
 *
 * MarkObjectUnbarriered(JSTracer* trc, JSObject* thing, const char* name);
 *     Like MarkObject, this function can be called at any time. It is more
 *     forgiving, since it doesn't demand a HeapPtr as an argument. Its use
 *     should always be accompanied by a comment explaining how write barriers
 *     are implemented for the given field.
 *
 * Additionally, the functions MarkObjectRange and MarkObjectRootRange are
 * defined for marking arrays of object pointers.
 *
 * The following functions are provided to test whether a GC thing is marked
 * under different circumstances:
 *
 * IsObjectAboutToBeFinalized(JSObject** thing);
 *     This function is indended to be used in code used to sweep GC things.  It
 *     indicates whether the object will will be finialized in the current group
 *     of compartments being swept.  Note that this will return false for any
 *     object not in the group of compartments currently being swept, as even if
 *     it is unmarked it may still become marked before it is swept.
 *
 * IsObjectMarked(JSObject** thing);
 *     This function is indended to be used in rare cases in code used to mark
 *     GC things.  It indicates whether the object is currently marked.
 *
 * UpdateObjectIfRelocated(JSObject** thingp);
 *     In some circumstances -- e.g. optional weak marking -- it is necessary
 *     to look at the pointer before marking it strongly or weakly. In these
 *     cases, the following must be called to update the pointer before use.
 */

#define DeclMarker(base, type)                                                                    \
void Mark##base(JSTracer* trc, BarrieredBase<type*>* thing, const char* name);                    \
void Mark##base##Root(JSTracer* trc, type** thingp, const char* name);                            \
void Mark##base##Unbarriered(JSTracer* trc, type** thingp, const char* name);                     \
void Mark##base##Range(JSTracer* trc, size_t len, HeapPtr<type*>* thing, const char* name);       \
void Mark##base##RootRange(JSTracer* trc, size_t len, type** thing, const char* name);            \
bool Is##base##Marked(type** thingp);                                                             \
bool Is##base##Marked(BarrieredBase<type*>* thingp);                                              \
bool Is##base##MarkedFromAnyThread(BarrieredBase<type*>* thingp);                                 \
bool Is##base##AboutToBeFinalized(type** thingp);                                                 \
bool Is##base##AboutToBeFinalizedFromAnyThread(type** thingp);                                    \
bool Is##base##AboutToBeFinalized(BarrieredBase<type*>* thingp);                                  \
type* Update##base##IfRelocated(JSRuntime* rt, BarrieredBase<type*>* thingp);                     \
type* Update##base##IfRelocated(JSRuntime* rt, type** thingp);

DeclMarker(BaseShape, BaseShape)
DeclMarker(BaseShape, UnownedBaseShape)
DeclMarker(JitCode, jit::JitCode)
DeclMarker(Object, NativeObject)
DeclMarker(Object, ArrayObject)
DeclMarker(Object, ArgumentsObject)
DeclMarker(Object, ArrayBufferObject)
DeclMarker(Object, ArrayBufferObjectMaybeShared)
DeclMarker(Object, ArrayBufferViewObject)
DeclMarker(Object, DebugScopeObject)
DeclMarker(Object, GlobalObject)
DeclMarker(Object, JSObject)
DeclMarker(Object, JSFunction)
DeclMarker(Object, NestedScopeObject)
DeclMarker(Object, PlainObject)
DeclMarker(Object, SavedFrame)
DeclMarker(Object, ScopeObject)
DeclMarker(Object, SharedArrayBufferObject)
DeclMarker(Object, SharedTypedArrayObject)
DeclMarker(Script, JSScript)
DeclMarker(LazyScript, LazyScript)
DeclMarker(Shape, Shape)
DeclMarker(String, JSAtom)
DeclMarker(String, JSString)
DeclMarker(String, JSFlatString)
DeclMarker(String, JSLinearString)
DeclMarker(String, PropertyName)
DeclMarker(Symbol, JS::Symbol)
DeclMarker(TypeObject, types::TypeObject)

#undef DeclMarker

void
MarkPermanentAtom(JSTracer* trc, JSAtom* atom, const char* name);

void
MarkWellKnownSymbol(JSTracer* trc, JS::Symbol* sym);

/* Return true if the pointer is nullptr, or if it is a tagged pointer to
 * nullptr.
 */
MOZ_ALWAYS_INLINE bool
IsNullTaggedPointer(void* p)
{
    return uintptr_t(p) < 32;
}

/*** Externally Typed Marking ***/

/*
 * Note: this must only be called by the GC and only when we are tracing through
 * MarkRoots. It is explicitly for ConservativeStackMarking and should go away
 * after we transition to exact rooting.
 */
void
MarkKind(JSTracer* trc, void** thingp, JSGCTraceKind kind);

void
MarkGCThingRoot(JSTracer* trc, void** thingp, const char* name);

void
MarkGCThingUnbarriered(JSTracer* trc, void** thingp, const char* name);

/*** ID Marking ***/

void
MarkId(JSTracer* trc, BarrieredBase<jsid>* id, const char* name);

void
MarkIdRoot(JSTracer* trc, jsid* id, const char* name);

void
MarkIdUnbarriered(JSTracer* trc, jsid* id, const char* name);

void
MarkIdRange(JSTracer* trc, size_t len, HeapId* vec, const char* name);

void
MarkIdRootRange(JSTracer* trc, size_t len, jsid* vec, const char* name);

/*** Value Marking ***/

void
MarkValue(JSTracer* trc, BarrieredBase<Value>* v, const char* name);

void
MarkValueRange(JSTracer* trc, size_t len, BarrieredBase<Value>* vec, const char* name);

inline void
MarkValueRange(JSTracer* trc, HeapValue* begin, HeapValue* end, const char* name)
{
    return MarkValueRange(trc, end - begin, begin, name);
}

void
MarkValueRoot(JSTracer* trc, Value* v, const char* name);

void
MarkThingOrValueUnbarriered(JSTracer* trc, uintptr_t* word, const char* name);

void
MarkValueRootRange(JSTracer* trc, size_t len, Value* vec, const char* name);

inline void
MarkValueRootRange(JSTracer* trc, Value* begin, Value* end, const char* name)
{
    MarkValueRootRange(trc, end - begin, begin, name);
}

void
MarkTypeRoot(JSTracer* trc, types::Type* v, const char* name);

bool
IsValueMarked(Value* v);

bool
IsValueAboutToBeFinalized(Value* v);

bool
IsValueAboutToBeFinalizedFromAnyThread(Value* v);

/*** Slot Marking ***/

bool
IsSlotMarked(HeapSlot* s);

void
MarkSlot(JSTracer* trc, HeapSlot* s, const char* name);

void
MarkArraySlots(JSTracer* trc, size_t len, HeapSlot* vec, const char* name);

void
MarkObjectSlots(JSTracer* trc, NativeObject* obj, uint32_t start, uint32_t nslots);

void
MarkCrossCompartmentObjectUnbarriered(JSTracer* trc, JSObject* src, JSObject** dst_obj,
                                      const char* name);

void
MarkCrossCompartmentScriptUnbarriered(JSTracer* trc, JSObject* src, JSScript** dst_script,
                                      const char* name);

/*
 * Mark a value that may be in a different compartment from the compartment
 * being GC'd. (Although it won't be marked if it's in the wrong compartment.)
 */
void
MarkCrossCompartmentSlot(JSTracer* trc, JSObject* src, HeapValue* dst_slot, const char* name);


/*** Special Cases ***/

/*
 * MarkChildren<JSObject> is exposed solely for preWriteBarrier on
 * JSObject::swap. It should not be considered external interface.
 */
void
MarkChildren(JSTracer* trc, JSObject* obj);

/*
 * Trace through the shape and any shapes it contains to mark
 * non-shape children. This is exposed to the JS API as
 * JS_TraceShapeCycleCollectorChildren.
 */
void
MarkCycleCollectorChildren(JSTracer* trc, Shape* shape);

void
PushArena(GCMarker* gcmarker, ArenaHeader* aheader);

/*** Generic ***/

/*
 * The Mark() functions interface should only be used by code that must be
 * templated.  Other uses should use the more specific, type-named functions.
 */

inline void
Mark(JSTracer* trc, BarrieredBase<Value>* v, const char* name)
{
    MarkValue(trc, v, name);
}

inline void
Mark(JSTracer* trc, BarrieredBase<JSObject*>* o, const char* name)
{
    MarkObject(trc, o, name);
}

inline void
Mark(JSTracer* trc, BarrieredBase<JSScript*>* o, const char* name)
{
    MarkScript(trc, o, name);
}

inline void
Mark(JSTracer* trc, HeapPtrJitCode* code, const char* name)
{
    MarkJitCode(trc, code, name);
}

/* For use by WeakMap's HashKeyRef instantiation. */
inline void
Mark(JSTracer* trc, JSObject** objp, const char* name)
{
    MarkObjectUnbarriered(trc, objp, name);
}

/* For use by Debugger::WeakMap's missingScopes HashKeyRef instantiation. */
inline void
Mark(JSTracer* trc, NativeObject** obj, const char* name)
{
    MarkObjectUnbarriered(trc, obj, name);
}

/* For use by Debugger::WeakMap's proxiedScopes HashKeyRef instantiation. */
inline void
Mark(JSTracer* trc, ScopeObject** obj, const char* name)
{
    MarkObjectUnbarriered(trc, obj, name);
}

bool
IsCellMarked(Cell** thingp);

bool
IsCellAboutToBeFinalized(Cell** thing);

bool
IsCellAboutToBeFinalizedFromAnyThread(Cell** thing);

inline bool
IsMarked(BarrieredBase<Value>* v)
{
    if (!v->isMarkable())
        return true;
    return IsValueMarked(v->unsafeGet());
}

inline bool
IsMarked(BarrieredBase<JSObject*>* objp)
{
    return IsObjectMarked(objp);
}

inline bool
IsMarked(BarrieredBase<JSScript*>* scriptp)
{
    return IsScriptMarked(scriptp);
}

inline bool
IsAboutToBeFinalized(BarrieredBase<Value>* v)
{
    if (!v->isMarkable())
        return false;
    return IsValueAboutToBeFinalized(v->unsafeGet());
}

inline bool
IsAboutToBeFinalized(BarrieredBase<JSObject*>* objp)
{
    return IsObjectAboutToBeFinalized(objp);
}

inline bool
IsAboutToBeFinalized(BarrieredBase<JSScript*>* scriptp)
{
    return IsScriptAboutToBeFinalized(scriptp);
}

inline bool
IsAboutToBeFinalized(const js::jit::VMFunction** vmfunc)
{
    /*
     * Preserves entries in the WeakCache<VMFunction, JitCode>
     * iff the JitCode has been marked.
     */
    return false;
}

inline bool
IsAboutToBeFinalized(ReadBarrieredJitCode code)
{
    return IsJitCodeAboutToBeFinalized(code.unsafeGet());
}

inline Cell*
ToMarkable(const Value& v)
{
    if (v.isMarkable())
        return (Cell*)v.toGCThing();
    return nullptr;
}

inline Cell*
ToMarkable(Cell* cell)
{
    return cell;
}

} /* namespace gc */

void
TraceChildren(JSTracer* trc, void* thing, JSGCTraceKind kind);

bool
UnmarkGrayShapeRecursively(Shape* shape);

} /* namespace js */

#endif /* gc_Marking_h */