| 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 | #ifndef SamplingTool_h |
| 30 | #define SamplingTool_hcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/bytecode/SamplingTool.h:30:9`! |
| 31 | |
| 32 | #include <wtf/Assertions.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h`/ |
| 33 | #include <wtf/HashMap.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/HashMap.h`/ |
| 34 | #include <wtf/Threading.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Threading.h`/ |
| 35 | |
| 36 | #include "Nodes.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/parser/Nodes.h`/ |
| 37 | #include "Opcode.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/bytecode/Opcode.h`/ |
| 38 | |
| 39 | namespace JSCcxx . . $ `<built-in>:463:9`! { |
| 40 | |
| 41 | class ScriptExecutablecxx . . $ QTJSC/ScriptExecutable#; |
| 42 | |
| 43 | class SamplingFlagscxx . . $ QTJSC/SamplingFlags# { |
| 44 | friend class JITcxx . . $ QTJSC/JIT#; |
| 45 | public: |
| 46 | static void startcxx . . $ QTJSC/SamplingFlags#start(49f6e7a06ebc5aa8).(); |
| 47 | static void stopcxx . . $ QTJSC/SamplingFlags#stop(49f6e7a06ebc5aa8).(); |
| 48 | |
| 49 | #if ENABLEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:57:9`!(SAMPLING_FLAGS) |
| 50 | static void setFlag(unsigned flag) |
| 51 | { |
| 52 | ASSERT(flag >= 1); |
| 53 | ASSERT(flag <= 32); |
| 54 | s_flags |= 1u << (flag - 1); |
| 55 | } |
| 56 | |
| 57 | static void clearFlag(unsigned flag) |
| 58 | { |
| 59 | ASSERT(flag >= 1); |
| 60 | ASSERT(flag <= 32); |
| 61 | s_flags &= ~(1u << (flag - 1)); |
| 62 | } |
| 63 | |
| 64 | static void sample(); |
| 65 | |
| 66 | class ScopedFlag { |
| 67 | public: |
| 68 | ScopedFlag(int flag) |
| 69 | : m_flag(flag) |
| 70 | { |
| 71 | setFlag(flag); |
| 72 | } |
| 73 | |
| 74 | ~ScopedFlag() |
| 75 | { |
| 76 | clearFlag(m_flag); |
| 77 | } |
| 78 | |
| 79 | private: |
| 80 | int m_flag; |
| 81 | }; |
| 82 | |
| 83 | #endif |
| 84 | private: |
| 85 | static uint32_tcxx . . $ uint32_t# s_flagscxx . . $ QTJSC/SamplingFlags#s_flags.; |
| 86 | #if ENABLEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:57:9`!(SAMPLING_FLAGS) |
| 87 | static uint64_t s_flagCounts[33]; |
| 88 | #endif |
| 89 | }; |
| 90 | |
| 91 | class CodeBlockcxx . . $ QTJSC/CodeBlock#; |
| 92 | class ExecStatecxx . . $ QTJSC/ExecState#; |
| 93 | class Interpretercxx . . $ QTJSC/Interpreter#; |
| 94 | class ScopeNodecxx . . $ QTJSC/ScopeNode#; |
| 95 | struct Instructioncxx . . $ QTJSC/Instruction#; |
| 96 | |
| 97 | struct ScriptSampleRecordcxx . . $ QTJSC/ScriptSampleRecord# { |
| 98 | ScriptSampleRecordcxx . . $ QTJSC/ScriptSampleRecord#ScriptSampleRecord(c201001c67bff53d).(ScriptExecutablecxx . . $ QTJSC/ScriptExecutable#* executable) |
| 99 | : m_executable(executable) |
| 100 | , m_codeBlockcxx . . $ QTJSC/ScriptSampleRecord#m_codeBlock.(0) |
| 101 | , m_sampleCountcxx . . $ QTJSC/ScriptSampleRecord#m_sampleCount.(0) |
| 102 | , m_opcodeSampleCountcxx . . $ QTJSC/ScriptSampleRecord#m_opcodeSampleCount.(0) |
| 103 | , m_samplescxx . . $ QTJSC/ScriptSampleRecord#m_samples.(0) |
| 104 | , m_sizecxx . . $ QTJSC/ScriptSampleRecord#m_size.(0) |
| 105 | { |
| 106 | } |
| 107 | |
| 108 | ~cxx . . $ QTJSC/ScriptSampleRecord#`~ScriptSampleRecord`(49f6e7a06ebc5aa8).ScriptSampleRecordcxx . . $ QTJSC/ScriptSampleRecord#() |
| 109 | { |
| 110 | if (m_samplescxx . . $ QTJSC/ScriptSampleRecord#m_samples.) |
| 111 | freecxx . . $ free(5d22bdacc48458e8).(m_samplescxx . . $ QTJSC/ScriptSampleRecord#m_samples.); |
| 112 | } |
| 113 | |
| 114 | void samplecxx . . $ QTJSC/ScriptSampleRecord#sample(dd36cf60fd3c15f9).(CodeBlockcxx . . $ QTJSC/CodeBlock#*, Instructioncxx . . $ QTJSC/Instruction#*); |
| 115 | |
| 116 | #if COMPILERcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:39:9`!(WINSCW) || COMPILERcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:39:9`!(ACC) |
| 117 | ScriptExecutable* m_executable; |
| 118 | #else |
| 119 | RefPtrcxx . . $ RefPtr#<ScriptExecutablecxx . . $ QTJSC/ScriptExecutable#> m_executablecxx . . $ QTJSC/ScriptSampleRecord#m_executable.; |
| 120 | #endif |
| 121 | CodeBlockcxx . . $ QTJSC/CodeBlock#* m_codeBlockcxx . . $ QTJSC/ScriptSampleRecord#m_codeBlock.; |
| 122 | int m_sampleCountcxx . . $ QTJSC/ScriptSampleRecord#m_sampleCount.; |
| 123 | int m_opcodeSampleCountcxx . . $ QTJSC/ScriptSampleRecord#m_opcodeSampleCount.; |
| 124 | int* m_samplescxx . . $ QTJSC/ScriptSampleRecord#m_samples.; |
| 125 | unsigned m_sizecxx . . $ QTJSC/ScriptSampleRecord#m_size.; |
| 126 | }; |
| 127 | |
| 128 | typedef WTFcxx . . $ `<built-in>:467:9`!::HashMap<ScriptExecutable*, ScriptSampleRecord*> ScriptSampleRecordMapcxx . . $ QTJSC/ScriptSampleRecordMap#; |
| 129 | |
| 130 | class SamplingThreadcxx . . $ QTJSC/SamplingThread# { |
| 131 | public: |
| 132 | // Sampling thread state. |
| 133 | static bool s_runningcxx . . $ QTJSC/SamplingThread#s_running.; |
| 134 | static unsigned s_hertzcxx . . $ QTJSC/SamplingThread#s_hertz.; |
| 135 | static ThreadIdentifiercxx . . $ ThreadIdentifier# s_samplingThreadcxx . . $ QTJSC/SamplingThread#s_samplingThread.; |
| 136 | |
| 137 | static void startcxx . . $ QTJSC/SamplingThread#start(cb2f890c2fdad230).(unsigned hertz=10000); |
| 138 | static void stopcxx . . $ QTJSC/SamplingThread#stop(49f6e7a06ebc5aa8).(); |
| 139 | |
| 140 | static void* threadStartFunccxx . . $ QTJSC/SamplingThread#threadStartFunc(9f162e79bfc6c74).(void*); |
| 141 | }; |
| 142 | |
| 143 | class SamplingToolcxx . . $ QTJSC/SamplingTool# { |
| 144 | public: |
| 145 | friend struct CallRecordcxx . . $ QTJSC/CallRecord#; |
| 146 | friend class HostCallRecordcxx . . $ QTJSC/HostCallRecord#; |
| 147 | |
| 148 | #if ENABLEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:57:9`!(OPCODE_SAMPLING) |
| 149 | class CallRecord : public Noncopyable { |
| 150 | public: |
| 151 | CallRecord(SamplingTool* samplingTool) |
| 152 | : m_samplingTool(samplingTool) |
| 153 | , m_savedSample(samplingTool->m_sample) |
| 154 | , m_savedCodeBlock(samplingTool->m_codeBlock) |
| 155 | { |
| 156 | } |
| 157 | |
| 158 | ~CallRecord() |
| 159 | { |
| 160 | m_samplingTool->m_sample = m_savedSample; |
| 161 | m_samplingTool->m_codeBlock = m_savedCodeBlock; |
| 162 | } |
| 163 | |
| 164 | private: |
| 165 | SamplingTool* m_samplingTool; |
| 166 | intptr_t m_savedSample; |
| 167 | CodeBlock* m_savedCodeBlock; |
| 168 | }; |
| 169 | |
| 170 | class HostCallRecord : public CallRecord { |
| 171 | public: |
| 172 | HostCallRecord(SamplingTool* samplingTool) |
| 173 | : CallRecord(samplingTool) |
| 174 | { |
| 175 | samplingTool->m_sample |= 0x1; |
| 176 | } |
| 177 | }; |
| 178 | #else |
| 179 | class CallRecordcxx . . $ QTJSC/SamplingTool#CallRecord# : public Noncopyablecxx . . $ Noncopyable# { |
| 180 | public: |
| 181 | CallRecordcxx . . $ QTJSC/SamplingTool#CallRecord#CallRecord(79910c455db97a43).(SamplingToolcxx . . $ QTJSC/SamplingTool#*) |
| 182 | { |
| 183 | } |
| 184 | }; |
| 185 | |
| 186 | class HostCallRecordcxx . . $ QTJSC/SamplingTool#HostCallRecord# : public CallRecordcxx . . $ QTJSC/SamplingTool#CallRecord# { |
| 187 | public: |
| 188 | HostCallRecordcxx . . $ QTJSC/SamplingTool#HostCallRecord#HostCallRecord(79910c455db97a43).(SamplingToolcxx . . $ QTJSC/SamplingTool#* samplingTool) |
| 189 | : CallRecordcxx . . $ QTJSC/SamplingTool#CallRecord#CallRecord(79910c455db97a43).(samplingTool) |
| 190 | { |
| 191 | } |
| 192 | }; |
| 193 | #endif |
| 194 | |
| 195 | SamplingToolcxx . . $ QTJSC/SamplingTool#SamplingTool(5879d92b45fd1584).(Interpretercxx . . $ QTJSC/Interpreter#* interpreter) |
| 196 | : m_interpretercxx . . $ QTJSC/SamplingTool#m_interpreter.(interpreter) |
| 197 | , m_codeBlockcxx . . $ QTJSC/SamplingTool#m_codeBlock.(0) |
| 198 | , m_samplecxx . . $ QTJSC/SamplingTool#m_sample.(0) |
| 199 | , m_sampleCountcxx . . $ QTJSC/SamplingTool#m_sampleCount.(0) |
| 200 | , m_opcodeSampleCountcxx . . $ QTJSC/SamplingTool#m_opcodeSampleCount.(0) |
| 201 | #if ENABLEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:57:9`!(CODEBLOCK_SAMPLING) |
| 202 | , m_scopeSampleMap(new ScriptSampleRecordMap()) |
| 203 | #endif |
| 204 | { |
| 205 | memset(m_opcodeSamplescxx . . $ QTJSC/SamplingTool#m_opcodeSamples., 0, sizeof(m_opcodeSamplescxx . . $ QTJSC/SamplingTool#m_opcodeSamples.)); |
| 206 | memset(m_opcodeSamplesInCTIFunctionscxx . . $ QTJSC/SamplingTool#m_opcodeSamplesInCTIFunctions., 0, sizeof(m_opcodeSamplesInCTIFunctionscxx . . $ QTJSC/SamplingTool#m_opcodeSamplesInCTIFunctions.)); |
| 207 | } |
| 208 | |
| 209 | ~cxx . . $ QTJSC/SamplingTool#`~SamplingTool`(49f6e7a06ebc5aa8).SamplingToolcxx . . $ QTJSC/SamplingTool#() |
| 210 | { |
| 211 | #if ENABLEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:57:9`!(CODEBLOCK_SAMPLING) |
| 212 | deleteAllValues(*m_scopeSampleMap); |
| 213 | #endif |
| 214 | } |
| 215 | |
| 216 | void setupcxx . . $ QTJSC/SamplingTool#setup(49f6e7a06ebc5aa8).(); |
| 217 | void dumpcxx . . $ QTJSC/SamplingTool#dump(d2cb180e190a9680).(ExecStatecxx . . $ QTJSC/ExecState#*); |
| 218 | |
| 219 | void notifyOfScopecxx . . $ QTJSC/SamplingTool#notifyOfScope(c201001c67bff53d).(ScriptExecutablecxx . . $ QTJSC/ScriptExecutable#* scope); |
| 220 | |
| 221 | void samplecxx . . $ QTJSC/SamplingTool#sample(dd36cf60fd3c15f9).(CodeBlockcxx . . $ QTJSC/CodeBlock#* codeBlock, Instructioncxx . . $ QTJSC/Instruction#* vPC) |
| 222 | { |
| 223 | ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!(reinterpret_cast<intptr_t>(vPC) & 0x3)); |
| 224 | m_codeBlockcxx . . $ QTJSC/SamplingTool#m_codeBlock. = codeBlock; |
| 225 | m_samplecxx . . $ QTJSC/SamplingTool#m_sample. = reinterpret_cast<intptr_tcxx . . $ intptr_t#>(vPC); |
| 226 | } |
| 227 | |
| 228 | CodeBlockcxx . . $ QTJSC/CodeBlock#** codeBlockSlotcxx . . $ QTJSC/SamplingTool#codeBlockSlot(169016c403d48a40).() { return &m_codeBlockcxx . . $ QTJSC/SamplingTool#m_codeBlock.; } |
| 229 | intptr_tcxx . . $ intptr_t#* sampleSlotcxx . . $ QTJSC/SamplingTool#sampleSlot(5f3b2fea3b28dfd5).() { return &m_samplecxx . . $ QTJSC/SamplingTool#m_sample.; } |
| 230 | |
| 231 | void* encodeSamplecxx . . $ QTJSC/SamplingTool#encodeSample(ca874700661d80cc).(Instructioncxx . . $ QTJSC/Instruction#* vPC, bool inCTIFunction = false, bool inHostFunction = false) |
| 232 | { |
| 233 | ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!(reinterpret_cast<intptr_t>(vPC) & 0x3)); |
| 234 | return reinterpret_cast<void*>(reinterpret_cast<intptr_tcxx . . $ intptr_t#>(vPC) | (static_cast<intptr_tcxx . . $ intptr_t#>(inCTIFunction) << 1) | static_cast<intptr_tcxx . . $ intptr_t#>(inHostFunction)); |
| 235 | } |
| 236 | |
| 237 | static void samplecxx . . $ QTJSC/SamplingTool#sample(49f6e7a06ebc5aa8).(); |
| 238 | |
| 239 | private: |
| 240 | class Samplecxx . . $ QTJSC/SamplingTool#Sample# { |
| 241 | public: |
| 242 | Samplecxx . . $ QTJSC/SamplingTool#Sample#Sample(1534989921af49e5).(volatile intptr_tcxx . . $ intptr_t# sample, CodeBlockcxx . . $ QTJSC/CodeBlock#* volatile codeBlock) |
| 243 | : m_samplecxx . . $ QTJSC/SamplingTool#Sample#m_sample.(sample) |
| 244 | , m_codeBlockcxx . . $ QTJSC/SamplingTool#Sample#m_codeBlock.(codeBlock) |
| 245 | { |
| 246 | } |
| 247 | |
| 248 | bool isNullcxx . . $ QTJSC/SamplingTool#Sample#isNull(c9857a73d68e59ba).() { return !m_samplecxx . . $ QTJSC/SamplingTool#Sample#m_sample.; } |
| 249 | CodeBlockcxx . . $ QTJSC/CodeBlock#* codeBlockcxx . . $ QTJSC/SamplingTool#Sample#codeBlock(1b2dba6d348fbcb8).() { return m_codeBlockcxx . . $ QTJSC/SamplingTool#Sample#m_codeBlock.; } |
| 250 | Instructioncxx . . $ QTJSC/Instruction#* vPCcxx . . $ QTJSC/SamplingTool#Sample#vPC(7b86da79c27ebc40).() { return reinterpret_cast<Instructioncxx . . $ QTJSC/Instruction#*>(m_samplecxx . . $ QTJSC/SamplingTool#Sample#m_sample. & ~0x3); } |
| 251 | bool inHostFunctioncxx . . $ QTJSC/SamplingTool#Sample#inHostFunction(c9857a73d68e59ba).() { return m_samplecxx . . $ QTJSC/SamplingTool#Sample#m_sample. & 0x1; } |
| 252 | bool inCTIFunctioncxx . . $ QTJSC/SamplingTool#Sample#inCTIFunction(c9857a73d68e59ba).() { return m_samplecxx . . $ QTJSC/SamplingTool#Sample#m_sample. & 0x2; } |
| 253 | |
| 254 | private: |
| 255 | intptr_tcxx . . $ intptr_t# m_samplecxx . . $ QTJSC/SamplingTool#Sample#m_sample.; |
| 256 | CodeBlockcxx . . $ QTJSC/CodeBlock#* m_codeBlockcxx . . $ QTJSC/SamplingTool#Sample#m_codeBlock.; |
| 257 | }; |
| 258 | |
| 259 | void doRuncxx . . $ QTJSC/SamplingTool#doRun(49f6e7a06ebc5aa8).(); |
| 260 | static SamplingToolcxx . . $ QTJSC/SamplingTool#* s_samplingToolcxx . . $ QTJSC/SamplingTool#s_samplingTool.; |
| 261 | |
| 262 | Interpretercxx . . $ QTJSC/Interpreter#* m_interpretercxx . . $ QTJSC/SamplingTool#m_interpreter.; |
| 263 | |
| 264 | // State tracked by the main thread, used by the sampling thread. |
| 265 | CodeBlockcxx . . $ QTJSC/CodeBlock#* m_codeBlockcxx . . $ QTJSC/SamplingTool#m_codeBlock.; |
| 266 | intptr_tcxx . . $ intptr_t# m_samplecxx . . $ QTJSC/SamplingTool#m_sample.; |
| 267 | |
| 268 | // Gathered sample data. |
| 269 | long long m_sampleCountcxx . . $ QTJSC/SamplingTool#m_sampleCount.; |
| 270 | long long m_opcodeSampleCountcxx . . $ QTJSC/SamplingTool#m_opcodeSampleCount.; |
| 271 | unsigned m_opcodeSamplescxx . . $ QTJSC/SamplingTool#m_opcodeSamples.[numOpcodeIDscxx . . $ QTJSC/numOpcodeIDs.]; |
| 272 | unsigned m_opcodeSamplesInCTIFunctionscxx . . $ QTJSC/SamplingTool#m_opcodeSamplesInCTIFunctions.[numOpcodeIDscxx . . $ QTJSC/numOpcodeIDs.]; |
| 273 | |
| 274 | #if ENABLEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:57:9`!(CODEBLOCK_SAMPLING) |
| 275 | Mutex m_scriptSampleMapMutex; |
| 276 | OwnPtr<ScriptSampleRecordMap> m_scopeSampleMap; |
| 277 | #endif |
| 278 | }; |
| 279 | |
| 280 | // AbstractSamplingCounter: |
| 281 | // |
| 282 | // Implements a named set of counters, printed on exit if ENABLE(SAMPLING_COUNTERS). |
| 283 | // See subclasses below, SamplingCounter, GlobalSamplingCounter and DeletableSamplingCounter. |
| 284 | class AbstractSamplingCountercxx . . $ QTJSC/AbstractSamplingCounter# { |
| 285 | friend class JITcxx . . $ QTJSC/JIT#; |
| 286 | friend class DeletableSamplingCountercxx . . $ QTJSC/DeletableSamplingCounter#; |
| 287 | public: |
| 288 | void countcxx . . $ QTJSC/AbstractSamplingCounter#count(cb2f890c2fdad230).(uint32_tcxx . . $ uint32_t# count = 1) |
| 289 | { |
| 290 | m_countercxx . . $ QTJSC/AbstractSamplingCounter#m_counter. += count; |
| 291 | } |
| 292 | |
| 293 | static void dumpcxx . . $ QTJSC/AbstractSamplingCounter#dump(49f6e7a06ebc5aa8).(); |
| 294 | |
| 295 | protected: |
| 296 | // Effectively the contructor, however called lazily in the case of GlobalSamplingCounter. |
| 297 | void initcxx . . $ QTJSC/AbstractSamplingCounter#init(85c52e162fed56f9).(const char* name) |
| 298 | { |
| 299 | m_countercxx . . $ QTJSC/AbstractSamplingCounter#m_counter. = 0; |
| 300 | m_namecxx . . $ QTJSC/AbstractSamplingCounter#m_name. = name; |
| 301 | |
| 302 | // Set m_next to point to the head of the chain, and inform whatever is |
| 303 | // currently at the head that this node will now hold the pointer to it. |
| 304 | m_nextcxx . . $ QTJSC/AbstractSamplingCounter#m_next. = s_abstractSamplingCounterChaincxx . . $ QTJSC/AbstractSamplingCounter#s_abstractSamplingCounterChain.; |
| 305 | s_abstractSamplingCounterChaincxx . . $ QTJSC/AbstractSamplingCounter#s_abstractSamplingCounterChain.->m_referercxx . . $ QTJSC/AbstractSamplingCounter#m_referer. = &m_nextcxx . . $ QTJSC/AbstractSamplingCounter#m_next.; |
| 306 | // Add this node to the head of the list. |
| 307 | s_abstractSamplingCounterChaincxx . . $ QTJSC/AbstractSamplingCounter#s_abstractSamplingCounterChain. = this; |
| 308 | m_referercxx . . $ QTJSC/AbstractSamplingCounter#m_referer. = &s_abstractSamplingCounterChaincxx . . $ QTJSC/AbstractSamplingCounter#s_abstractSamplingCounterChain.; |
| 309 | } |
| 310 | |
| 311 | int64_tcxx . . $ int64_t# m_countercxx . . $ QTJSC/AbstractSamplingCounter#m_counter.; |
| 312 | const char* m_namecxx . . $ QTJSC/AbstractSamplingCounter#m_name.; |
| 313 | AbstractSamplingCountercxx . . $ QTJSC/AbstractSamplingCounter#* m_nextcxx . . $ QTJSC/AbstractSamplingCounter#m_next.; |
| 314 | // This is a pointer to the pointer to this node in the chain; used to |
| 315 | // allow fast linked list deletion. |
| 316 | AbstractSamplingCountercxx . . $ QTJSC/AbstractSamplingCounter#** m_referercxx . . $ QTJSC/AbstractSamplingCounter#m_referer.; |
| 317 | // Null object used to detect end of static chain. |
| 318 | static AbstractSamplingCountercxx . . $ QTJSC/AbstractSamplingCounter# s_abstractSamplingCounterChainEndcxx . . $ QTJSC/AbstractSamplingCounter#s_abstractSamplingCounterChainEnd.; |
| 319 | static AbstractSamplingCountercxx . . $ QTJSC/AbstractSamplingCounter#* s_abstractSamplingCounterChaincxx . . $ QTJSC/AbstractSamplingCounter#s_abstractSamplingCounterChain.; |
| 320 | static bool s_completedcxx . . $ QTJSC/AbstractSamplingCounter#s_completed.; |
| 321 | }; |
| 322 | |
| 323 | #if ENABLEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:57:9`!(SAMPLING_COUNTERS) |
| 324 | // SamplingCounter: |
| 325 | // |
| 326 | // This class is suitable and (hopefully!) convenient for cases where a counter is |
| 327 | // required within the scope of a single function. It can be instantiated as a |
| 328 | // static variable since it contains a constructor but not a destructor (static |
| 329 | // variables in WebKit cannot have destructors). |
| 330 | // |
| 331 | // For example: |
| 332 | // |
| 333 | // void someFunction() |
| 334 | // { |
| 335 | // static SamplingCounter countMe("This is my counter. There are many like it, but this one is mine."); |
| 336 | // countMe.count(); |
| 337 | // // ... |
| 338 | // } |
| 339 | // |
| 340 | class SamplingCounter : public AbstractSamplingCounter { |
| 341 | public: |
| 342 | SamplingCounter(const char* name) { init(name); } |
| 343 | }; |
| 344 | |
| 345 | // GlobalSamplingCounter: |
| 346 | // |
| 347 | // This class is suitable for use where a counter is to be declared globally, |
| 348 | // since it contains neither a constructor nor destructor. Instead, ensure |
| 349 | // that 'name()' is called to provide the counter with a name (and also to |
| 350 | // allow it to be printed out on exit). |
| 351 | // |
| 352 | // GlobalSamplingCounter globalCounter; |
| 353 | // |
| 354 | // void firstFunction() |
| 355 | // { |
| 356 | // // Put this within a function that is definitely called! |
| 357 | // // (Or alternatively alongside all calls to 'count()'). |
| 358 | // globalCounter.name("I Name You Destroyer."); |
| 359 | // globalCounter.count(); |
| 360 | // // ... |
| 361 | // } |
| 362 | // |
| 363 | // void secondFunction() |
| 364 | // { |
| 365 | // globalCounter.count(); |
| 366 | // // ... |
| 367 | // } |
| 368 | // |
| 369 | class GlobalSamplingCounter : public AbstractSamplingCounter { |
| 370 | public: |
| 371 | void name(const char* name) |
| 372 | { |
| 373 | // Global objects should be mapped in zero filled memory, so this should |
| 374 | // be a safe (albeit not necessarily threadsafe) check for 'first call'. |
| 375 | if (!m_next) |
| 376 | init(name); |
| 377 | } |
| 378 | }; |
| 379 | |
| 380 | // DeletableSamplingCounter: |
| 381 | // |
| 382 | // The above classes (SamplingCounter, GlobalSamplingCounter), are intended for |
| 383 | // use within a global or static scope, and as such cannot have a destructor. |
| 384 | // This means there is no convenient way for them to remove themselves from the |
| 385 | // static list of counters, and should an instance of either class be freed |
| 386 | // before 'dump()' has walked over the list it will potentially walk over an |
| 387 | // invalid pointer. |
| 388 | // |
| 389 | // This class is intended for use where the counter may possibly be deleted before |
| 390 | // the program exits. Should this occur, the counter will print it's value to |
| 391 | // stderr, and remove itself from the static list. Example: |
| 392 | // |
| 393 | // DeletableSamplingCounter* counter = new DeletableSamplingCounter("The Counter With No Name"); |
| 394 | // counter->count(); |
| 395 | // delete counter; |
| 396 | // |
| 397 | class DeletableSamplingCounter : public AbstractSamplingCounter { |
| 398 | public: |
| 399 | DeletableSamplingCounter(const char* name) { init(name); } |
| 400 | |
| 401 | ~DeletableSamplingCounter() |
| 402 | { |
| 403 | if (!s_completed) |
| 404 | fprintf(stderr, "DeletableSamplingCounter \"%s\" deleted early (with count %lld)\n", m_name, m_counter); |
| 405 | // Our m_referer pointer should know where the pointer to this node is, |
| 406 | // and m_next should know that this node is the previous node in the list. |
| 407 | ASSERT(*m_referer == this); |
| 408 | ASSERT(m_next->m_referer == &m_next); |
| 409 | // Remove this node from the list, and inform m_next that we have done so. |
| 410 | m_next->m_referer = m_referer; |
| 411 | *m_referer = m_next; |
| 412 | } |
| 413 | }; |
| 414 | #endif |
| 415 | |
| 416 | } // namespace JSC |
| 417 | |
| 418 | #endif // SamplingTool_h |