Debian Codegraph @

src/3rdparty/javascriptcore/JavaScriptCore/profiler/Profiler.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "config.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/config.h`/
30 #include "Profiler.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/profiler/Profiler.h`/
31
32 #include "CommonIdentifiers.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/CommonIdentifiers.h`/
33 #include "CallFrame.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/interpreter/CallFrame.h`/
34 #include "CodeBlock.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/bytecode/CodeBlock.h`/
35 #include "JSFunction.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSFunction.h`/
36 #include "JSGlobalObject.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSGlobalObject.h`/
37 #include "Nodes.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/parser/Nodes.h`/
38 #include "Profile.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/profiler/Profile.h`/
39 #include "ProfileGenerator.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/profiler/ProfileGenerator.h`/
40 #include "ProfileNode.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/profiler/ProfileNode.h`/
41 #include <stdio.h>
42
43 namespace JSCcxx . . $ `<built-in>:463:9`! {
44
45 static const char* GlobalCodeExecutioncxx . . $ QTJSC/GlobalCodeExecution. = "(program)";
46 static const char* AnonymousFunctioncxx . . $ QTJSC/AnonymousFunction. = "(anonymous function)";
47 static unsigned ProfilesUIDcxx . . $ QTJSC/ProfilesUID. = 0;
48
49 static CallIdentifiercxx . . $ QTJSC/CallIdentifier# createCallIdentifierFromFunctionImpcxx . . $ QTJSC/createCallIdentifierFromFunctionImp(9c52184720c1d4e1).(ExecStatecxx . . $ QTJSC/ExecState#*, JSFunctioncxx . . $ QTJSC/JSFunction#*);
50
51 Profilercxx . . $ QTJSC/Profiler#* Profilercxx . . $ QTJSC/Profiler#::s_sharedProfilercxx . . $ QTJSC/Profiler#s_sharedProfiler. = 0;
52 Profilercxx . . $ QTJSC/Profiler#* Profilercxx . . $ QTJSC/Profiler#::s_sharedEnabledProfilerReferencecxx . . $ QTJSC/Profiler#s_sharedEnabledProfilerReference. = 0;
53
54 Profilercxx . . $ QTJSC/Profiler#* Profilercxx . . $ QTJSC/Profiler#::profilercxx . . $ QTJSC/Profiler#profiler(8ec02ee3ac6bd078).()
55 {
56 if (!s_sharedProfilercxx . . $ QTJSC/Profiler#s_sharedProfiler.)
57 s_sharedProfilercxx . . $ QTJSC/Profiler#s_sharedProfiler. = new Profilercxx . . $ QTJSC/Profiler#();
58 return s_sharedProfilercxx . . $ QTJSC/Profiler#s_sharedProfiler.;
59 }
60
61 void Profilercxx . . $ QTJSC/Profiler#::startProfilingcxx . . $ QTJSC/Profiler#startProfiling(7710b6c66c0f9b39).(ExecStatecxx . . $ QTJSC/ExecState#* exec, const UStringcxx . . $ QTJSC/UString#& title)
62 {
63 ASSERT_ARGcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:228:9`!(title, !title.isNull());
64
65 // Check if we currently have a Profile for this global ExecState and title.
66 // If so return early and don't create a new Profile.
67 ExecStatecxx . . $ QTJSC/ExecState#* globalExec = exec ? exec->lexicalGlobalObjectcxx . . $ QTJSC/ExecState#lexicalGlobalObject(3d50c730b5e26899).()->globalExeccxx . . $ QTJSC/JSGlobalObject#globalExec(27c3d7386a195136).() : 0;
68
69 for (size_t i = 0; i < m_currentProfiles.size(); ++i) {
70 ProfileGeneratorcxx . . $ QTJSC/ProfileGenerator#* profileGenerator = m_currentProfiles[i].get();
71 if (profileGenerator->originatingGlobalExeccxx . . $ QTJSC/ProfileGenerator#originatingGlobalExec(5952b97f5bc87321).() == globalExec && profileGenerator->titlecxx . . $ QTJSC/ProfileGenerator#title(de21ee9ecbd506fd).() ==cxx . . $ QTJSC/`operator==`(11610d830df66bbf). title)
72 return;
73 }
74
75 s_sharedEnabledProfilerReferencecxx . . $ QTJSC/Profiler#s_sharedEnabledProfilerReference. = this;
76 RefPtrcxx . . $ RefPtr#<ProfileGeneratorcxx . . $ QTJSC/ProfileGenerator#> profileGenerator = ProfileGenerator::create(title, exec, ++ProfilesUID);
77 m_currentProfiles.append(profileGenerator);
78 }
79
80 PassRefPtrcxx . . $ PassRefPtr#<Profilecxx . . $ QTJSC/Profile#> Profilercxx . . $ QTJSC/Profiler#::stopProfilingcxx . . $ QTJSC/Profiler#stopProfiling(61c399322a76e605).(ExecStatecxx . . $ QTJSC/ExecState#* exec, const UStringcxx . . $ QTJSC/UString#& title)
81 {
82 ExecStatecxx . . $ QTJSC/ExecState#* globalExec = exec ? exec->lexicalGlobalObjectcxx . . $ QTJSC/ExecState#lexicalGlobalObject(3d50c730b5e26899).()->globalExeccxx . . $ QTJSC/JSGlobalObject#globalExec(27c3d7386a195136).() : 0;
83 for (ptrdiff_t i = m_currentProfiles.size() - 1; i >= 0; --i) {
84 ProfileGeneratorcxx . . $ QTJSC/ProfileGenerator#* profileGenerator = m_currentProfiles[i].get();
85 if (profileGenerator->originatingGlobalExeccxx . . $ QTJSC/ProfileGenerator#originatingGlobalExec(5952b97f5bc87321).() == globalExec && (title.isNullcxx . . $ QTJSC/UString#isNull(50ce9a9e25b4a850).() || profileGenerator->titlecxx . . $ QTJSC/ProfileGenerator#title(de21ee9ecbd506fd).() ==cxx . . $ QTJSC/`operator==`(11610d830df66bbf). title)) {
86 profileGenerator->stopProfilingcxx . . $ QTJSC/ProfileGenerator#stopProfiling(49f6e7a06ebc5aa8).();
87 RefPtrcxx . . $ RefPtr#<Profilecxx . . $ QTJSC/Profile#> returnProfile = profileGenerator->profile();
88
89 m_currentProfiles.remove(i);
90 if (!m_currentProfiles.size())
91 s_sharedEnabledProfilerReferencecxx . . $ QTJSC/Profiler#s_sharedEnabledProfilerReference. = 0;
92
93 return returnProfile;
94 }
95 }
96
97 return 0;
98 }
99
100 static inline void dispatchFunctionToProfilescxx . . $ QTJSC/dispatchFunctionToProfiles(7d92e60f032d159).(const Vector<RefPtr<ProfileGenerator> >& profiles, ProfileGeneratorcxx . . $ QTJSC/ProfileGenerator#::ProfileFunctioncxx . . $ QTJSC/ProfileGenerator#ProfileFunction# function, const CallIdentifiercxx . . $ QTJSC/CallIdentifier#& callIdentifier, unsigned currentProfileTargetGroup)
101 {
102 for (size_t i = 0; i <cxx . . $ QTJSC/`operator<`(11610d830df66bbf). profiles.size(); ++i) {
103 if (profiles[i]->profileGroup() ==cxx . . $ QTJSC/`operator==`(e9142ab59ce7dac8). currentProfileTargetGroup || !profiles[i]->originatingGlobalExec())
104 (profiles[i].get()->*function)(callIdentifier);
105 }
106 }
107
108 void Profilercxx . . $ QTJSC/Profiler#::willExecutecxx . . $ QTJSC/Profiler#willExecute(1aadac95d0a8d6ce).(ExecStatecxx . . $ QTJSC/ExecState#* exec, JSValuecxx . . $ QTJSC/JSValue# function)
109 {
110 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!m_currentProfiles.isEmpty());
111
112 dispatchFunctionToProfilescxx . . $ QTJSC/dispatchFunctionToProfiles(7d92e60f032d159).(m_currentProfiles, &ProfileGeneratorcxx . . $ QTJSC/ProfileGenerator#::willExecutecxx . . $ QTJSC/ProfileGenerator#willExecute(8a1d71aab8ab5a09)., createCallIdentifiercxx . . $ QTJSC/Profiler#createCallIdentifier(df90f5aa91bddef8).(exec, function, ""cxx . . $ QTJSC/UString#UString(85c52e162fed56f9)., 0), exec->lexicalGlobalObjectcxx . . $ QTJSC/ExecState#lexicalGlobalObject(3d50c730b5e26899).()->profileGroupcxx . . $ QTJSC/JSGlobalObject#profileGroup(ddd8539a2fcdd4ce).());
113 }
114
115 void Profilercxx . . $ QTJSC/Profiler#::willExecutecxx . . $ QTJSC/Profiler#willExecute(ac8610a35a2ea244).(ExecStatecxx . . $ QTJSC/ExecState#* exec, const UStringcxx . . $ QTJSC/UString#& sourceURL, int startingLineNumber)
116 {
117 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!m_currentProfiles.isEmpty());
118
119 CallIdentifiercxx . . $ QTJSC/CallIdentifier# callIdentifier = createCallIdentifiercxx . . $ QTJSC/Profiler#createCallIdentifier(df90f5aa91bddef8).(exec, JSValuecxx . . $ QTJSC/JSValue#JSValue(49f6e7a06ebc5aa8).(), sourceURL, startingLineNumber);
120
121 dispatchFunctionToProfilescxx . . $ QTJSC/dispatchFunctionToProfiles(7d92e60f032d159).(m_currentProfiles, &ProfileGeneratorcxx . . $ QTJSC/ProfileGenerator#::willExecutecxx . . $ QTJSC/ProfileGenerator#willExecute(8a1d71aab8ab5a09)., callIdentifier, exec->lexicalGlobalObjectcxx . . $ QTJSC/ExecState#lexicalGlobalObject(3d50c730b5e26899).()->profileGroupcxx . . $ QTJSC/JSGlobalObject#profileGroup(ddd8539a2fcdd4ce).());
122 }
123
124 void Profilercxx . . $ QTJSC/Profiler#::didExecutecxx . . $ QTJSC/Profiler#didExecute(1aadac95d0a8d6ce).(ExecStatecxx . . $ QTJSC/ExecState#* exec, JSValuecxx . . $ QTJSC/JSValue# function)
125 {
126 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!m_currentProfiles.isEmpty());
127
128 dispatchFunctionToProfilescxx . . $ QTJSC/dispatchFunctionToProfiles(7d92e60f032d159).(m_currentProfiles, &ProfileGeneratorcxx . . $ QTJSC/ProfileGenerator#::didExecutecxx . . $ QTJSC/ProfileGenerator#didExecute(8a1d71aab8ab5a09)., createCallIdentifiercxx . . $ QTJSC/Profiler#createCallIdentifier(df90f5aa91bddef8).(exec, function, ""cxx . . $ QTJSC/UString#UString(85c52e162fed56f9)., 0), exec->lexicalGlobalObjectcxx . . $ QTJSC/ExecState#lexicalGlobalObject(3d50c730b5e26899).()->profileGroupcxx . . $ QTJSC/JSGlobalObject#profileGroup(ddd8539a2fcdd4ce).());
129 }
130
131 void Profilercxx . . $ QTJSC/Profiler#::didExecutecxx . . $ QTJSC/Profiler#didExecute(ac8610a35a2ea244).(ExecStatecxx . . $ QTJSC/ExecState#* exec, const UStringcxx . . $ QTJSC/UString#& sourceURL, int startingLineNumber)
132 {
133 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!m_currentProfiles.isEmpty());
134
135 dispatchFunctionToProfilescxx . . $ QTJSC/dispatchFunctionToProfiles(7d92e60f032d159).(m_currentProfiles, &ProfileGeneratorcxx . . $ QTJSC/ProfileGenerator#::didExecutecxx . . $ QTJSC/ProfileGenerator#didExecute(8a1d71aab8ab5a09)., createCallIdentifiercxx . . $ QTJSC/Profiler#createCallIdentifier(df90f5aa91bddef8).(exec, JSValuecxx . . $ QTJSC/JSValue#JSValue(49f6e7a06ebc5aa8).(), sourceURL, startingLineNumber), exec->lexicalGlobalObjectcxx . . $ QTJSC/ExecState#lexicalGlobalObject(3d50c730b5e26899).()->profileGroupcxx . . $ QTJSC/JSGlobalObject#profileGroup(ddd8539a2fcdd4ce).());
136 }
137
138 CallIdentifiercxx . . $ QTJSC/CallIdentifier# Profilercxx . . $ QTJSC/Profiler#::createCallIdentifiercxx . . $ QTJSC/Profiler#createCallIdentifier(df90f5aa91bddef8).(ExecStatecxx . . $ QTJSC/ExecState#* exec, JSValuecxx . . $ QTJSC/JSValue# functionValue, const UStringcxx . . $ QTJSC/UString#& defaultSourceURL, int defaultLineNumber)
139 {
140 if (!functionValue)
141 return CallIdentifiercxx . . $ QTJSC/CallIdentifier#CallIdentifier(43fff5afe796ed68).(GlobalCodeExecutioncxx . . $ QTJSC/UString#UString(85c52e162fed56f9)., defaultSourceURL, defaultLineNumber);
142 if (!functionValue.isObjectcxx . . $ QTJSC/JSValue#isObject(50ce9a9e25b4a850).())
143 return CallIdentifiercxx . . $ QTJSC/CallIdentifier#CallIdentifier(43fff5afe796ed68).("(unknown)"cxx . . $ QTJSC/UString#UString(85c52e162fed56f9)., defaultSourceURL, defaultLineNumber);
144 if (asObjectcxx . . $ QTJSC/asObject(107e81180f8dd622).(functionValue)->inheritscxx . . $ QTJSC/JSCell#inherits(7eca403b06d48463).(&JSFunctioncxx . . $ QTJSC/JSFunction#::infocxx . . $ QTJSC/JSFunction#info.)) {
145 JSFunctioncxx . . $ QTJSC/JSFunction#* function = asFunctioncxx . . $ QTJSC/asFunction(deffc94ad83de35f).(functionValue);
146 if (!function->executablecxx . . $ QTJSC/JSFunction#executable(278b097dd65ecae5).()->isHostFunctioncxx . . $ QTJSC/ExecutableBase#isHostFunction(50ce9a9e25b4a850).())
147 return createCallIdentifierFromFunctionImpcxx . . $ QTJSC/createCallIdentifierFromFunctionImp(9c52184720c1d4e1).(exec, function);
148 }
149 if (asObject(functionValue)->inherits(&InternalFunction::info))
150 return CallIdentifier(static_cast<InternalFunction*>(asObject(functionValue))->name(exec), defaultSourceURL, defaultLineNumber);
151 return CallIdentifiercxx . . $ QTJSC/CallIdentifier#CallIdentifier(43fff5afe796ed68).(makeStringcxx . . $ QTJSC/makeString(b1788f951b46c19b).("(", asObjectcxx . . $ QTJSC/asObject(107e81180f8dd622).(functionValue)->classNamecxx . . $ QTJSC/JSObject#className(ba9ec689f7dd9231).(), " object)"), defaultSourceURL, defaultLineNumber);
152 }
153
154 CallIdentifiercxx . . $ QTJSC/CallIdentifier# createCallIdentifierFromFunctionImpcxx . . $ QTJSC/createCallIdentifierFromFunctionImp(9c52184720c1d4e1).(ExecStatecxx . . $ QTJSC/ExecState#* exec, JSFunctioncxx . . $ QTJSC/JSFunction#* function)
155 {
156 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!function->isHostFunction());
157 const UStringcxx . . $ QTJSC/UString#& name = function->calculatedDisplayNamecxx . . $ QTJSC/InternalFunction#calculatedDisplayName(607b87b3e5df695).(exec);
158 return CallIdentifiercxx . . $ QTJSC/CallIdentifier#(name.isEmptycxx . . $ QTJSC/UString#isEmpty(50ce9a9e25b4a850).() ? AnonymousFunctioncxx . . $ QTJSC/UString#UString(e6bad6cb9b63b14d). : namecxx . . $ QTJSC/UString#UString(e6bad6cb9b63b14d)., function->jsExecutablecxx . . $ QTJSC/JSFunction#jsExecutable(41a6d61c9ef790ed).()->sourceURLcxx . . $ QTJSC/ScriptExecutable#sourceURL(de21ee9ecbd506fd).(), function->jsExecutablecxx . . $ QTJSC/JSFunction#jsExecutable(41a6d61c9ef790ed).()->lineNocxx . . $ QTJSC/ScriptExecutable#lineNo(455f465bc33b4cdf).());
159 }
160
161 } // namespace JSC