|
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 #include "vm/Probes-inl.h" |
|
8 |
|
9 #include "jscntxt.h" |
|
10 |
|
11 #ifdef INCLUDE_MOZILLA_DTRACE |
|
12 #include "jsscriptinlines.h" |
|
13 #endif |
|
14 |
|
15 #define TYPEOF(cx,v) (JSVAL_IS_NULL(v) ? JSTYPE_NULL : JS_TypeOfValue(cx,v)) |
|
16 |
|
17 using namespace js; |
|
18 |
|
19 const char probes::nullName[] = "(null)"; |
|
20 const char probes::anonymousName[] = "(anonymous)"; |
|
21 |
|
22 bool probes::ProfilingActive = true; |
|
23 |
|
24 probes::JITReportGranularity |
|
25 probes::JITGranularityRequested(JSContext *cx) |
|
26 { |
|
27 if (cx->runtime()->spsProfiler.enabled()) |
|
28 return JITREPORT_GRANULARITY_LINE; |
|
29 return JITREPORT_GRANULARITY_NONE; |
|
30 } |
|
31 |
|
32 /* ICs are unregistered in a batch */ |
|
33 void |
|
34 probes::DiscardExecutableRegion(void *start, size_t size) |
|
35 { |
|
36 /* |
|
37 * Not needed for SPS because ICs are disposed of when the normal JITChunk |
|
38 * is disposed of |
|
39 */ |
|
40 } |
|
41 |
|
42 #ifdef INCLUDE_MOZILLA_DTRACE |
|
43 static const char * |
|
44 ScriptFilename(const JSScript *script) |
|
45 { |
|
46 if (!script) |
|
47 return probes::nullName; |
|
48 if (!script->filename()) |
|
49 return probes::anonymousName; |
|
50 return script->filename(); |
|
51 } |
|
52 |
|
53 static const char * |
|
54 FunctionName(JSContext *cx, JSFunction *fun, JSAutoByteString* bytes) |
|
55 { |
|
56 if (!fun) |
|
57 return probes::nullName; |
|
58 if (!fun->displayAtom()) |
|
59 return probes::anonymousName; |
|
60 return bytes->encodeLatin1(cx, fun->displayAtom()) ? bytes->ptr() : probes::nullName; |
|
61 } |
|
62 |
|
63 /* |
|
64 * These functions call the DTrace macros for the JavaScript USDT probes. |
|
65 * Originally this code was inlined in the JavaScript code; however since |
|
66 * a number of operations are called, these have been placed into functions |
|
67 * to reduce any negative compiler optimization effect that the addition of |
|
68 * a number of usually unused lines of code would cause. |
|
69 */ |
|
70 void |
|
71 probes::DTraceEnterJSFun(JSContext *cx, JSFunction *fun, JSScript *script) |
|
72 { |
|
73 JSAutoByteString funNameBytes; |
|
74 JAVASCRIPT_FUNCTION_ENTRY(ScriptFilename(script), probes::nullName, |
|
75 FunctionName(cx, fun, &funNameBytes)); |
|
76 } |
|
77 |
|
78 void |
|
79 probes::DTraceExitJSFun(JSContext *cx, JSFunction *fun, JSScript *script) |
|
80 { |
|
81 JSAutoByteString funNameBytes; |
|
82 JAVASCRIPT_FUNCTION_RETURN(ScriptFilename(script), probes::nullName, |
|
83 FunctionName(cx, fun, &funNameBytes)); |
|
84 } |
|
85 #endif |