Changeset 35454 in webkit for trunk/JavaScriptCore/VM/Opcode.h


Ignore:
Timestamp:
Jul 30, 2008, 10:38:35 AM (17 years ago)
Author:
[email protected]
Message:

2008-07-30 Gavin Barraclough <[email protected]>

Reviewed by Geoff Garen.

Fixes for Windows and non-AllInOne file build with SamplingTool, plus review fixes.

  • GNUmakefile.am: Adding SamplingTool.cpp to build.
  • JavaScriptCore.exp: Export hooks to init & control SamplingTool.
  • JavaScriptCore.pri: Adding SamplingTool.cpp to build.
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj: Adding SamplingTool.cpp to build.
  • JavaScriptCore.xcodeproj/project.pbxproj: Adding SamplingTool.cpp to build.
  • JavaScriptCoreSources.bkl: Adding SamplingTool.cpp to build.
  • VM/Machine.cpp: MACHINE_SAMPLING_callingNativeFunction renamed MACHINE_SAMPLING_callingHostFunction
  • VM/Machine.h:
  • VM/Opcode.cpp: SamplingTool moved to SamplingTool.cpp/.h, opcodeNames generated from FOR_EACH_OPCODE_ID.
  • VM/Opcode.h:
  • VM/SamplingTool.cpp: Added .cpp/.h for SamplingTool.
  • VM/SamplingTool.h:
  • kjs/Shell.cpp: Switched SAMPLING_TOOL_ENABLED to ENABLE_SAMPLING_TOOL.
  • wtf/Platform.h: Added ENABLE_SAMPLING_TOOL config option.
  • kjs/nodes.cpp: Header include to fix non-AllInOne builds.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/VM/Opcode.h

    r35310 r35454  
    3131#define Opcodes_h
    3232
     33#include <algorithm>
     34#include <string.h>
     35
    3336#include <wtf/Assertions.h>
    34 #include <wtf/HashMap.h>
    3537
    3638namespace KJS {
    3739
    38 #define SAMPLING_TOOL_ENABLED 0
    3940#define DUMP_OPCODE_STATS 0
    4041
     
    149150#endif
    150151
    151     class ExecState;
    152     class ScopeNode;
    153     class CodeBlock;
    154     struct Instruction;
     152#if ENABLE(SAMPLING_TOOL) || DUMP_OPCODE_STATS
    155153
    156 #if SAMPLING_TOOL_ENABLED
     154#define PADDING_STRING "                                "
     155#define PADDING_STRING_LENGTH static_cast<unsigned>(strlen(PADDING_STRING))
    157156
    158     struct ScopeSampleRecord
     157    extern const char* const opcodeNames[];
     158
     159    inline const char* padOpcodeName(OpcodeID op, unsigned width)
    159160    {
    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    }
    183165
    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
    246168
    247169#endif
    248 
    249 // SCOPENODE_ / MACHINE_ macros for use from within member methods on ScopeNode / Machine respectively.
    250 #if SAMPLING_TOOL_ENABLED
    251 #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 #else
    256 #define SCOPENODE_SAMPLING_notifyOfScope(sampler)
    257 #define MACHINE_SAMPLING_sample(codeBlock, vPC)
    258 #define MACHINE_SAMPLING_privateExecuteReturned()
    259 #define MACHINE_SAMPLING_callingNativeFunction()
    260 #endif
    261 
    262170
    263171#if DUMP_OPCODE_STATS
Note: See TracChangeset for help on using the changeset viewer.