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 js_GCAnnotations_h
8 #define js_GCAnnotations_h
10 // Set of annotations for the rooting hazard analysis, used to categorize types
14 # define JS_EXPECT_HAZARDS __attribute__((annotate("Expect Hazards")))
16 // Mark a type as being a GC thing (eg js::gc::Cell has this annotation).
17 # define JS_HAZ_GC_THING __attribute__((annotate("GC Thing")))
19 // Mark a type as holding a pointer to a GC thing (eg JS::Value has this
20 // annotation.) "Inherited" by templatized types with
21 // MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS.
22 # define JS_HAZ_GC_POINTER __attribute__((annotate("GC Pointer")))
24 // Same as JS_HAZ_GC_POINTER, except additionally treat pointers to these
25 // as GC pointers themselves in order to check references to them, since
26 // the analysis cannot distinguish between pointers and references.
27 # define JS_HAZ_GC_REF __attribute__((annotate("GC Pointer or Reference")))
29 // Mark a type as a rooted pointer, suitable for use on the stack (eg all
30 // Rooted<T> instantiations should have this.) "Inherited" by templatized types
31 // with MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS.
32 # define JS_HAZ_ROOTED __attribute__((annotate("Rooted Pointer")))
34 // Mark a type as something that should not be held live across a GC, but which
35 // is not itself a GC pointer. Note that this property is *not* inherited by
36 // templatized types with MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS.
37 # define JS_HAZ_GC_INVALIDATED __attribute__((annotate("Invalidated by GC")))
39 // Mark a class as a base class of rooted types, eg CustomAutoRooter. All
40 // descendants of this class will be considered rooted, though classes that
41 // merely contain these as a field member will not be. "Inherited" by
42 // templatized types with MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS
43 # define JS_HAZ_ROOTED_BASE __attribute__((annotate("Rooted Base")))
45 // Mark a type that would otherwise be considered a GC Pointer (eg because it
46 // contains a JS::Value field) as a non-GC pointer. It is handled almost the
47 // same in the analysis as a rooted pointer, except it will not be reported as
48 // an unnecessary root if used across a GC call. This should rarely be used,
49 // but makes sense for something like ErrorResult, which only contains a GC
50 // pointer when it holds an exception (and it does its own rooting,
52 # define JS_HAZ_NON_GC_POINTER \
53 __attribute__((annotate("Suppressed GC Pointer")))
55 // Mark a function as something that runs a garbage collection, potentially
56 // invalidating GC pointers.
57 # define JS_HAZ_GC_CALL __attribute__((annotate("GC Call")))
59 // Mark an RAII class as suppressing GC within its scope.
60 # define JS_HAZ_GC_SUPPRESSED __attribute__((annotate("Suppress GC")))
62 // Mark a function as one that can run script if called. This obviously
63 // subsumes JS_HAZ_GC_CALL, since anything that can run script can GC.`
64 # define JS_HAZ_CAN_RUN_SCRIPT __attribute__((annotate("Can run script")))
66 // Mark a function as able to call JSNatives. Otherwise, JSNatives don't show
67 // up in the callgraph. This doesn't matter for the can-GC analysis, but it is
68 // very nice for other uses of the callgraph.
69 # define JS_HAZ_JSNATIVE_CALLER __attribute__((annotate("Calls JSNatives")))
71 // Mark a variable as being "GC safe", i.e., it does not contain any
72 // invalidatable pointers at the current point in the code. A typical
73 // example might be a collection containing GC pointers, which at the
74 // present time is empty. This property is only temporary; the next use
75 // of the variable will invalidate it (on the assumption that a GC pointer
76 // might be added to it.) Try to use this as early as possible, probably
77 // immediately after construction, so that if future mutations through
78 // the variable are added, they won't be covered by the annotation.
79 # define JS_HAZ_VALUE_IS_GC_SAFE(var) JS::detail::MarkVariableAsGCSafe(var)
83 # define JS_EXPECT_HAZARDS
84 # define JS_HAZ_GC_THING
85 # define JS_HAZ_GC_POINTER
86 # define JS_HAZ_GC_REF
87 # define JS_HAZ_ROOTED
88 # define JS_HAZ_GC_INVALIDATED
89 # define JS_HAZ_ROOTED_BASE
90 # define JS_HAZ_NON_GC_POINTER
91 # define JS_HAZ_GC_CALL
92 # define JS_HAZ_GC_SUPPRESSED
93 # define JS_HAZ_CAN_RUN_SCRIPT
94 # define JS_HAZ_JSNATIVE_CALLER
95 # define JS_HAZ_VALUE_IS_GC_SAFE(var)
101 // Implemented by passing variable to a dummy function so that it shows up
102 // in the control flow graph.
106 template <typename T
>
107 static inline void MarkVariableAsGCSafe(T
& var
) {
111 } // namespace detail
116 #endif /* js_GCAnnotations_h */