1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/vm/Probes.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,170 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef vm_Probes_h 1.11 +#define vm_Probes_h 1.12 + 1.13 +#ifdef INCLUDE_MOZILLA_DTRACE 1.14 +#include "javascript-trace.h" 1.15 +#endif 1.16 + 1.17 +#include "vm/Stack.h" 1.18 + 1.19 +namespace js { 1.20 + 1.21 +namespace probes { 1.22 + 1.23 +/* 1.24 + * Static probes 1.25 + * 1.26 + * The probe points defined in this file are scattered around the SpiderMonkey 1.27 + * source tree. The presence of probes::SomeEvent() means that someEvent is 1.28 + * about to happen or has happened. To the extent possible, probes should be 1.29 + * inserted in all paths associated with a given event, regardless of the 1.30 + * active runmode (interpreter/traceJIT/methodJIT/ionJIT). 1.31 + * 1.32 + * When a probe fires, it is handled by any probe handling backends that have 1.33 + * been compiled in. By default, most probes do nothing or at least do nothing 1.34 + * expensive, so the presence of the probe should have negligible effect on 1.35 + * running time. (Probes in slow paths may do something by default, as long as 1.36 + * there is no noticeable slowdown.) 1.37 + * 1.38 + * For some probes, the mere existence of the probe is too expensive even if it 1.39 + * does nothing when called. For example, just having consistent information 1.40 + * available for a function call entry/exit probe causes the JITs to 1.41 + * de-optimize function calls. In those cases, the JITs may query at compile 1.42 + * time whether a probe is desired, and omit the probe invocation if not. If a 1.43 + * probe is runtime-disabled at compilation time, it is not guaranteed to fire 1.44 + * within a compiled function if it is later enabled. 1.45 + * 1.46 + * Not all backends handle all of the probes listed here. 1.47 + */ 1.48 + 1.49 +/* 1.50 + * Internal use only: remember whether "profiling", whatever that means, is 1.51 + * currently active. Used for state management. 1.52 + */ 1.53 +extern bool ProfilingActive; 1.54 + 1.55 +extern const char nullName[]; 1.56 +extern const char anonymousName[]; 1.57 + 1.58 +/* 1.59 + * Test whether we are tracking JS function call enter/exit. The JITs use this 1.60 + * to decide whether they can optimize in a way that would prevent probes from 1.61 + * firing. 1.62 + */ 1.63 +bool CallTrackingActive(JSContext *); 1.64 + 1.65 +/* 1.66 + * Test whether anything is looking for JIT native code registration events. 1.67 + * This information will not be collected otherwise. 1.68 + */ 1.69 +bool WantNativeAddressInfo(JSContext *); 1.70 + 1.71 +/* Entering a JS function */ 1.72 +bool EnterScript(JSContext *, JSScript *, JSFunction *, InterpreterFrame *); 1.73 + 1.74 +/* About to leave a JS function */ 1.75 +void ExitScript(JSContext *, JSScript *, JSFunction *, bool popSPSFrame); 1.76 + 1.77 +/* Executing a script */ 1.78 +bool StartExecution(JSScript *script); 1.79 + 1.80 +/* Script has completed execution */ 1.81 +bool StopExecution(JSScript *script); 1.82 + 1.83 +/* 1.84 + * Object has been created. |obj| must exist (its class and size are read) 1.85 + */ 1.86 +bool CreateObject(ExclusiveContext *cx, JSObject *obj); 1.87 + 1.88 +/* 1.89 + * Object is about to be finalized. |obj| must still exist (its class is 1.90 + * read) 1.91 + */ 1.92 +bool FinalizeObject(JSObject *obj); 1.93 + 1.94 +/* JIT code observation */ 1.95 + 1.96 +enum JITReportGranularity { 1.97 + JITREPORT_GRANULARITY_NONE = 0, 1.98 + JITREPORT_GRANULARITY_FUNCTION = 1, 1.99 + JITREPORT_GRANULARITY_LINE = 2, 1.100 + JITREPORT_GRANULARITY_OP = 3 1.101 +}; 1.102 + 1.103 +/* 1.104 + * Finest granularity of JIT information desired by all watchers. 1.105 + */ 1.106 +JITReportGranularity 1.107 +JITGranularityRequested(JSContext *cx); 1.108 + 1.109 +/* 1.110 + * A whole region of code has been deallocated, containing any number of ICs. 1.111 + * (ICs are unregistered in a batch, so individual ICs are not registered.) 1.112 + */ 1.113 +void 1.114 +DiscardExecutableRegion(void *start, size_t size); 1.115 + 1.116 +/* 1.117 + * Internal: DTrace-specific functions to be called during probes::EnterScript 1.118 + * and probes::ExitScript. These will not be inlined, but the argument 1.119 + * marshalling required for these probe points is expensive enough that it 1.120 + * shouldn't really matter. 1.121 + */ 1.122 +void DTraceEnterJSFun(JSContext *cx, JSFunction *fun, JSScript *script); 1.123 +void DTraceExitJSFun(JSContext *cx, JSFunction *fun, JSScript *script); 1.124 + 1.125 +} /* namespace Probes */ 1.126 + 1.127 +#ifdef INCLUDE_MOZILLA_DTRACE 1.128 +static const char *ObjectClassname(JSObject *obj) { 1.129 + if (!obj) 1.130 + return "(null object)"; 1.131 + const Class *clasp = obj->getClass(); 1.132 + if (!clasp) 1.133 + return "(null)"; 1.134 + const char *class_name = clasp->name; 1.135 + if (!class_name) 1.136 + return "(null class name)"; 1.137 + return class_name; 1.138 +} 1.139 +#endif 1.140 + 1.141 +inline bool 1.142 +probes::CreateObject(ExclusiveContext *cx, JSObject *obj) 1.143 +{ 1.144 + bool ok = true; 1.145 + 1.146 +#ifdef INCLUDE_MOZILLA_DTRACE 1.147 + if (JAVASCRIPT_OBJECT_CREATE_ENABLED()) 1.148 + JAVASCRIPT_OBJECT_CREATE(ObjectClassname(obj), (uintptr_t)obj); 1.149 +#endif 1.150 + 1.151 + return ok; 1.152 +} 1.153 + 1.154 +inline bool 1.155 +probes::FinalizeObject(JSObject *obj) 1.156 +{ 1.157 + bool ok = true; 1.158 + 1.159 +#ifdef INCLUDE_MOZILLA_DTRACE 1.160 + if (JAVASCRIPT_OBJECT_FINALIZE_ENABLED()) { 1.161 + const Class *clasp = obj->getClass(); 1.162 + 1.163 + /* the first arg is nullptr - reserved for future use (filename?) */ 1.164 + JAVASCRIPT_OBJECT_FINALIZE(nullptr, (char *)clasp->name, (uintptr_t)obj); 1.165 + } 1.166 +#endif 1.167 + 1.168 + return ok; 1.169 +} 1.170 + 1.171 +} /* namespace js */ 1.172 + 1.173 +#endif /* vm_Probes_h */