Backed out changeset 1e582a0e5593 (bug 1852921) for causing build bustages
[gecko.git] / js / src / gc / AtomMarking.h
blobe7e97fb389c9a0fffbfe6d417207665caaf5e488
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 #ifndef gc_AtomMarking_h
8 #define gc_AtomMarking_h
10 #include "NamespaceImports.h"
11 #include "js/Vector.h"
12 #include "threading/ProtectedData.h"
14 namespace js {
16 class AutoLockGC;
17 class DenseBitmap;
19 namespace gc {
21 class Arena;
23 // This class manages state used for marking atoms during GCs.
24 // See AtomMarking.cpp for details.
25 class AtomMarkingRuntime {
26 // Unused arena atom bitmap indexes. Protected by the GC lock.
27 js::GCLockData<Vector<size_t, 0, SystemAllocPolicy>> freeArenaIndexes;
29 inline void markChildren(JSContext* cx, JSAtom*);
30 inline void markChildren(JSContext* cx, JS::Symbol* symbol);
32 public:
33 // The extent of all allocated and free words in atom mark bitmaps.
34 // This monotonically increases and may be read from without locking.
35 mozilla::Atomic<size_t, mozilla::SequentiallyConsistent> allocatedWords;
37 AtomMarkingRuntime() : allocatedWords(0) {}
39 // Mark an arena as holding things in the atoms zone.
40 void registerArena(Arena* arena, const AutoLockGC& lock);
42 // Mark an arena as no longer holding things in the atoms zone.
43 void unregisterArena(Arena* arena, const AutoLockGC& lock);
45 // Fill |bitmap| with an atom marking bitmap based on the things that are
46 // currently marked in the chunks used by atoms zone arenas. This returns
47 // false on an allocation failure (but does not report an exception).
48 bool computeBitmapFromChunkMarkBits(JSRuntime* runtime, DenseBitmap& bitmap);
50 // Update the atom marking bitmap in |zone| according to another
51 // overapproximation of the reachable atoms in |bitmap|.
52 void refineZoneBitmapForCollectedZone(Zone* zone, const DenseBitmap& bitmap);
54 // Set any bits in the chunk mark bitmaps for atoms which are marked in any
55 // uncollected zone in the runtime.
56 void markAtomsUsedByUncollectedZones(JSRuntime* runtime);
58 // Mark an atom or id as being newly reachable by the context's zone.
59 template <typename T>
60 void markAtom(JSContext* cx, T* thing);
62 // Version of markAtom that's always inlined, for performance-sensitive
63 // callers.
64 template <typename T, bool Fallible>
65 MOZ_ALWAYS_INLINE bool inlinedMarkAtomInternal(JSContext* cx, T* thing);
66 template <typename T>
67 MOZ_ALWAYS_INLINE void inlinedMarkAtom(JSContext* cx, T* thing);
68 template <typename T>
69 MOZ_ALWAYS_INLINE bool inlinedMarkAtomFallible(JSContext* cx, T* thing);
71 void markId(JSContext* cx, jsid id);
72 void markAtomValue(JSContext* cx, const Value& value);
74 #ifdef DEBUG
75 // Return whether |thing/id| is in the atom marking bitmap for |zone|.
76 template <typename T>
77 bool atomIsMarked(Zone* zone, T* thing);
78 bool idIsMarked(Zone* zone, jsid id);
79 bool valueIsMarked(Zone* zone, const Value& value);
80 #endif
83 } // namespace gc
84 } // namespace js
86 #endif // gc_AtomMarking_h