Debian Codegraph @

js/src/vm/Probes.h

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