Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * vim: set ts=8 sts=4 et sw=4 tw=99:
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 : #ifndef gc_AtomMarking_h
8 : #define gc_AtomMarking_h
9 :
10 : #include "NamespaceImports.h"
11 : #include "ds/Bitmap.h"
12 : #include "gc/Heap.h"
13 : #include "threading/ProtectedData.h"
14 : #include "vm/Symbol.h"
15 :
16 : namespace js {
17 : namespace gc {
18 :
19 : // This class manages state used for marking atoms during GCs.
20 : // See AtomMarking.cpp for details.
21 0 : class AtomMarkingRuntime
22 : {
23 : // Unused arena atom bitmap indexes. Protected by the GC lock.
24 : js::ExclusiveAccessLockOrGCTaskData<Vector<size_t, 0, SystemAllocPolicy>> freeArenaIndexes;
25 :
26 202282 : void markChildren(JSContext* cx, JSAtom*) {}
27 :
28 20 : void markChildren(JSContext* cx, JS::Symbol* symbol) {
29 20 : if (JSAtom* description = symbol->description())
30 20 : markAtom(cx, description);
31 20 : }
32 :
33 : public:
34 : // The extent of all allocated and free words in atom mark bitmaps.
35 : // This monotonically increases and may be read from without locking.
36 : mozilla::Atomic<size_t> allocatedWords;
37 :
38 4 : AtomMarkingRuntime()
39 4 : : allocatedWords(0)
40 4 : {}
41 :
42 : // Mark an arena as holding things in the atoms zone.
43 : void registerArena(Arena* arena);
44 :
45 : // Mark an arena as no longer holding things in the atoms zone.
46 : void unregisterArena(Arena* arena);
47 :
48 : // Fill |bitmap| with an atom marking bitmap based on the things that are
49 : // currently marked in the chunks used by atoms zone arenas. This returns
50 : // false on an allocation failure (but does not report an exception).
51 : bool computeBitmapFromChunkMarkBits(JSRuntime* runtime, DenseBitmap& bitmap);
52 :
53 : // Update the atom marking bitmap in |zone| according to another
54 : // overapproximation of the reachable atoms in |bitmap|.
55 : void updateZoneBitmap(Zone* zone, const DenseBitmap& bitmap);
56 :
57 : // Set any bits in the chunk mark bitmaps for atoms which are marked in any
58 : // zone in the runtime.
59 : void updateChunkMarkBits(JSRuntime* runtime);
60 :
61 : // Mark an atom or id as being newly reachable by the context's zone.
62 : template <typename T> void markAtom(JSContext* cx, T* thing);
63 :
64 : // Version of markAtom that's always inlined, for performance-sensitive
65 : // callers.
66 : template <typename T> MOZ_ALWAYS_INLINE void inlinedMarkAtom(JSContext* cx, T* thing);
67 :
68 : void markId(JSContext* cx, jsid id);
69 : void markAtomValue(JSContext* cx, const Value& value);
70 :
71 : // Mark all atoms in |source| as being reachable within |target|.
72 : void adoptMarkedAtoms(Zone* target, Zone* source);
73 :
74 : #ifdef DEBUG
75 : // Return whether |thing/id| is in the atom marking bitmap for |zone|.
76 : template <typename T> bool atomIsMarked(Zone* zone, T* thing);
77 : bool idIsMarked(Zone* zone, jsid id);
78 : bool valueIsMarked(Zone* zone, const Value& value);
79 : #endif
80 : };
81 :
82 : } // namespace gc
83 : } // namespace js
84 :
85 : #endif // gc_AtomMarking_h
|