|
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 vm_Probes_h |
|
8 #define vm_Probes_h |
|
9 |
|
10 #ifdef INCLUDE_MOZILLA_DTRACE |
|
11 #include "javascript-trace.h" |
|
12 #endif |
|
13 |
|
14 #include "vm/Stack.h" |
|
15 |
|
16 namespace js { |
|
17 |
|
18 namespace probes { |
|
19 |
|
20 /* |
|
21 * Static probes |
|
22 * |
|
23 * The probe points defined in this file are scattered around the SpiderMonkey |
|
24 * source tree. The presence of probes::SomeEvent() means that someEvent is |
|
25 * about to happen or has happened. To the extent possible, probes should be |
|
26 * inserted in all paths associated with a given event, regardless of the |
|
27 * active runmode (interpreter/traceJIT/methodJIT/ionJIT). |
|
28 * |
|
29 * When a probe fires, it is handled by any probe handling backends that have |
|
30 * been compiled in. By default, most probes do nothing or at least do nothing |
|
31 * expensive, so the presence of the probe should have negligible effect on |
|
32 * running time. (Probes in slow paths may do something by default, as long as |
|
33 * there is no noticeable slowdown.) |
|
34 * |
|
35 * For some probes, the mere existence of the probe is too expensive even if it |
|
36 * does nothing when called. For example, just having consistent information |
|
37 * available for a function call entry/exit probe causes the JITs to |
|
38 * de-optimize function calls. In those cases, the JITs may query at compile |
|
39 * time whether a probe is desired, and omit the probe invocation if not. If a |
|
40 * probe is runtime-disabled at compilation time, it is not guaranteed to fire |
|
41 * within a compiled function if it is later enabled. |
|
42 * |
|
43 * Not all backends handle all of the probes listed here. |
|
44 */ |
|
45 |
|
46 /* |
|
47 * Internal use only: remember whether "profiling", whatever that means, is |
|
48 * currently active. Used for state management. |
|
49 */ |
|
50 extern bool ProfilingActive; |
|
51 |
|
52 extern const char nullName[]; |
|
53 extern const char anonymousName[]; |
|
54 |
|
55 /* |
|
56 * Test whether we are tracking JS function call enter/exit. The JITs use this |
|
57 * to decide whether they can optimize in a way that would prevent probes from |
|
58 * firing. |
|
59 */ |
|
60 bool CallTrackingActive(JSContext *); |
|
61 |
|
62 /* |
|
63 * Test whether anything is looking for JIT native code registration events. |
|
64 * This information will not be collected otherwise. |
|
65 */ |
|
66 bool WantNativeAddressInfo(JSContext *); |
|
67 |
|
68 /* Entering a JS function */ |
|
69 bool EnterScript(JSContext *, JSScript *, JSFunction *, InterpreterFrame *); |
|
70 |
|
71 /* About to leave a JS function */ |
|
72 void ExitScript(JSContext *, JSScript *, JSFunction *, bool popSPSFrame); |
|
73 |
|
74 /* Executing a script */ |
|
75 bool StartExecution(JSScript *script); |
|
76 |
|
77 /* Script has completed execution */ |
|
78 bool StopExecution(JSScript *script); |
|
79 |
|
80 /* |
|
81 * Object has been created. |obj| must exist (its class and size are read) |
|
82 */ |
|
83 bool CreateObject(ExclusiveContext *cx, JSObject *obj); |
|
84 |
|
85 /* |
|
86 * Object is about to be finalized. |obj| must still exist (its class is |
|
87 * read) |
|
88 */ |
|
89 bool FinalizeObject(JSObject *obj); |
|
90 |
|
91 /* JIT code observation */ |
|
92 |
|
93 enum JITReportGranularity { |
|
94 JITREPORT_GRANULARITY_NONE = 0, |
|
95 JITREPORT_GRANULARITY_FUNCTION = 1, |
|
96 JITREPORT_GRANULARITY_LINE = 2, |
|
97 JITREPORT_GRANULARITY_OP = 3 |
|
98 }; |
|
99 |
|
100 /* |
|
101 * Finest granularity of JIT information desired by all watchers. |
|
102 */ |
|
103 JITReportGranularity |
|
104 JITGranularityRequested(JSContext *cx); |
|
105 |
|
106 /* |
|
107 * A whole region of code has been deallocated, containing any number of ICs. |
|
108 * (ICs are unregistered in a batch, so individual ICs are not registered.) |
|
109 */ |
|
110 void |
|
111 DiscardExecutableRegion(void *start, size_t size); |
|
112 |
|
113 /* |
|
114 * Internal: DTrace-specific functions to be called during probes::EnterScript |
|
115 * and probes::ExitScript. These will not be inlined, but the argument |
|
116 * marshalling required for these probe points is expensive enough that it |
|
117 * shouldn't really matter. |
|
118 */ |
|
119 void DTraceEnterJSFun(JSContext *cx, JSFunction *fun, JSScript *script); |
|
120 void DTraceExitJSFun(JSContext *cx, JSFunction *fun, JSScript *script); |
|
121 |
|
122 } /* namespace Probes */ |
|
123 |
|
124 #ifdef INCLUDE_MOZILLA_DTRACE |
|
125 static const char *ObjectClassname(JSObject *obj) { |
|
126 if (!obj) |
|
127 return "(null object)"; |
|
128 const Class *clasp = obj->getClass(); |
|
129 if (!clasp) |
|
130 return "(null)"; |
|
131 const char *class_name = clasp->name; |
|
132 if (!class_name) |
|
133 return "(null class name)"; |
|
134 return class_name; |
|
135 } |
|
136 #endif |
|
137 |
|
138 inline bool |
|
139 probes::CreateObject(ExclusiveContext *cx, JSObject *obj) |
|
140 { |
|
141 bool ok = true; |
|
142 |
|
143 #ifdef INCLUDE_MOZILLA_DTRACE |
|
144 if (JAVASCRIPT_OBJECT_CREATE_ENABLED()) |
|
145 JAVASCRIPT_OBJECT_CREATE(ObjectClassname(obj), (uintptr_t)obj); |
|
146 #endif |
|
147 |
|
148 return ok; |
|
149 } |
|
150 |
|
151 inline bool |
|
152 probes::FinalizeObject(JSObject *obj) |
|
153 { |
|
154 bool ok = true; |
|
155 |
|
156 #ifdef INCLUDE_MOZILLA_DTRACE |
|
157 if (JAVASCRIPT_OBJECT_FINALIZE_ENABLED()) { |
|
158 const Class *clasp = obj->getClass(); |
|
159 |
|
160 /* the first arg is nullptr - reserved for future use (filename?) */ |
|
161 JAVASCRIPT_OBJECT_FINALIZE(nullptr, (char *)clasp->name, (uintptr_t)obj); |
|
162 } |
|
163 #endif |
|
164 |
|
165 return ok; |
|
166 } |
|
167 |
|
168 } /* namespace js */ |
|
169 |
|
170 #endif /* vm_Probes_h */ |