Changeset 35454 in webkit for trunk/JavaScriptCore/VM/Opcode.h
- Timestamp:
- Jul 30, 2008, 10:38:35 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/VM/Opcode.h
r35310 r35454 31 31 #define Opcodes_h 32 32 33 #include <algorithm> 34 #include <string.h> 35 33 36 #include <wtf/Assertions.h> 34 #include <wtf/HashMap.h>35 37 36 38 namespace KJS { 37 39 38 #define SAMPLING_TOOL_ENABLED 039 40 #define DUMP_OPCODE_STATS 0 40 41 … … 149 150 #endif 150 151 151 class ExecState; 152 class ScopeNode; 153 class CodeBlock; 154 struct Instruction; 152 #if ENABLE(SAMPLING_TOOL) || DUMP_OPCODE_STATS 155 153 156 #if SAMPLING_TOOL_ENABLED 154 #define PADDING_STRING " " 155 #define PADDING_STRING_LENGTH static_cast<unsigned>(strlen(PADDING_STRING)) 157 156 158 struct ScopeSampleRecord 157 extern const char* const opcodeNames[]; 158 159 inline const char* padOpcodeName(OpcodeID op, unsigned width) 159 160 { 160 RefPtr<ScopeNode> m_scope; 161 CodeBlock* m_codeBlock; 162 int m_totalCount; 163 int* m_vpcCounts; 164 unsigned m_size; 165 166 ScopeSampleRecord(ScopeNode* scope) 167 : m_scope(scope) 168 , m_codeBlock(0) 169 , m_totalCount(0) 170 , m_vpcCounts(0) 171 , m_size(0) 172 { 173 } 174 175 ~ScopeSampleRecord() 176 { 177 if (m_vpcCounts) 178 free(m_vpcCounts); 179 } 180 181 void sample(CodeBlock* codeBlock, Instruction* vPC); 182 }; 161 unsigned pad = width - strlen(opcodeNames[op]); 162 pad = std::min(pad, PADDING_STRING_LENGTH); 163 return PADDING_STRING + PADDING_STRING_LENGTH - pad; 164 } 183 165 184 typedef WTF::HashMap<ScopeNode*, ScopeSampleRecord*> ScopeSampleRecordMap; 185 186 class SamplingTool 187 { 188 public: 189 SamplingTool() 190 : m_running(false) 191 , m_recordedCodeBlock(0) 192 , m_recordedVPC(0) 193 , m_totalSamples(0) 194 , m_scopeSampleMap(new ScopeSampleRecordMap()) 195 { 196 } 197 198 ~SamplingTool() 199 { 200 for (ScopeSampleRecordMap::iterator iter = m_scopeSampleMap->begin(); iter != m_scopeSampleMap->end(); ++iter) 201 delete iter->second; 202 delete m_scopeSampleMap; 203 } 204 205 void start(unsigned hertz=1000); 206 void stop(); 207 void dump(ExecState*); 208 209 void notifyOfScope(ScopeNode* scope); 210 211 void sample(CodeBlock* recordedCodeBlock, Instruction* recordedVPC) 212 { 213 m_recordedCodeBlock = recordedCodeBlock; 214 m_recordedVPC = recordedVPC; 215 } 216 217 void privateExecuteReturned() 218 { 219 m_recordedCodeBlock = 0; 220 m_recordedVPC = 0; 221 } 222 223 void callingNativeFunction() 224 { 225 m_recordedCodeBlock = 0; 226 m_recordedVPC = 0; 227 } 228 229 private: 230 static void* threadStartFunc(void*); 231 void run(); 232 233 // Sampling thread state. 234 bool m_running; 235 unsigned m_hertz; 236 pthread_t m_samplingThread; 237 238 // State tracked by the main thread, used by the sampling thread. 239 CodeBlock* m_recordedCodeBlock; 240 Instruction* m_recordedVPC; 241 242 // Gathered sample data. 243 long long m_totalSamples; 244 ScopeSampleRecordMap* m_scopeSampleMap; 245 }; 166 #undef PADDING_STRING_LENGTH 167 #undef PADDING_STRING 246 168 247 169 #endif 248 249 // SCOPENODE_ / MACHINE_ macros for use from within member methods on ScopeNode / Machine respectively.250 #if SAMPLING_TOOL_ENABLED251 #define SCOPENODE_SAMPLING_notifyOfScope(sampler) sampler->notifyOfScope(this)252 #define MACHINE_SAMPLING_sample(codeBlock, vPC) m_sampler->sample(codeBlock, vPC)253 #define MACHINE_SAMPLING_privateExecuteReturned() m_sampler->privateExecuteReturned()254 #define MACHINE_SAMPLING_callingNativeFunction() m_sampler->callingNativeFunction()255 #else256 #define SCOPENODE_SAMPLING_notifyOfScope(sampler)257 #define MACHINE_SAMPLING_sample(codeBlock, vPC)258 #define MACHINE_SAMPLING_privateExecuteReturned()259 #define MACHINE_SAMPLING_callingNativeFunction()260 #endif261 262 170 263 171 #if DUMP_OPCODE_STATS
Note:
See TracChangeset
for help on using the changeset viewer.