Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / js / src / vm / Probes.h
blob83c984e55c6051cc3978568aa852a0f7bcaf5025
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 vm_Probes_h
8 #define vm_Probes_h
10 #ifdef INCLUDE_MOZILLA_DTRACE
11 # include "javascript-trace.h"
12 #endif
14 #include "vm/JSObject.h"
16 namespace js {
18 class InterpreterFrame;
20 namespace probes {
23 * Static probes
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).
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.)
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.
45 * Not all backends handle all of the probes listed here.
49 * Internal use only: remember whether "profiling", whatever that means, is
50 * currently active. Used for state management.
52 extern bool ProfilingActive;
54 extern const char nullName[];
55 extern const char anonymousName[];
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.
62 bool CallTrackingActive(JSContext*);
64 /* Entering a JS function */
65 bool EnterScript(JSContext*, JSScript*, JSFunction*, InterpreterFrame*);
67 /* About to leave a JS function */
68 void ExitScript(JSContext*, JSScript*, JSFunction*, bool popProfilerFrame);
70 /* Executing a script */
71 bool StartExecution(JSScript* script);
73 /* Script has completed execution */
74 bool StopExecution(JSScript* script);
77 * Object has been created. |obj| must exist (its class and size are read)
79 bool CreateObject(JSContext* cx, JSObject* obj);
82 * Object is about to be finalized. |obj| must still exist (its class is
83 * read)
85 bool FinalizeObject(JSObject* obj);
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.
93 void DTraceEnterJSFun(JSContext* cx, JSFunction* fun, JSScript* script);
94 void DTraceExitJSFun(JSContext* cx, JSFunction* fun, JSScript* script);
96 } // namespace probes
98 #ifdef INCLUDE_MOZILLA_DTRACE
99 static const char* ObjectClassname(JSObject* obj) {
100 if (!obj) {
101 return "(null object)";
103 const JSClass* clasp = obj->getClass();
104 if (!clasp) {
105 return "(null)";
107 const char* class_name = clasp->name;
108 if (!class_name) {
109 return "(null class name)";
111 return class_name;
113 #endif
115 inline bool probes::CreateObject(JSContext* cx, JSObject* obj) {
116 bool ok = true;
118 #ifdef INCLUDE_MOZILLA_DTRACE
119 if (JAVASCRIPT_OBJECT_CREATE_ENABLED()) {
120 JAVASCRIPT_OBJECT_CREATE(ObjectClassname(obj), (uintptr_t)obj);
122 #endif
124 return ok;
127 inline bool probes::FinalizeObject(JSObject* obj) {
128 bool ok = true;
130 #ifdef INCLUDE_MOZILLA_DTRACE
131 if (JAVASCRIPT_OBJECT_FINALIZE_ENABLED()) {
132 const JSClass* clasp = obj->getClass();
134 /* the first arg is nullptr - reserved for future use (filename?) */
135 JAVASCRIPT_OBJECT_FINALIZE(nullptr, (char*)clasp->name, (uintptr_t)obj);
137 #endif
139 return ok;
142 } /* namespace js */
144 #endif /* vm_Probes_h */