Changeset 48905 in webkit


Ignore:
Timestamp:
Sep 29, 2009 2:48:52 PM (15 years ago)
Author:
oliver@apple.com
Message:

Tidy up codeblock sampler
https://bugs.webkit.org/show_bug.cgi?id=29836

Reviewed by Gavin Barraclough.

Some rather simple refactoring of codeblock sampler so that
it's easier for us to use it to find problems in non-jsc
environments

Location:
trunk/JavaScriptCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r48898 r48905  
     12009-09-28  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Gavin Barraclough.
     4
     5        Tidy up codeblock sampler
     6        https://bugs.webkit.org/show_bug.cgi?id=29836
     7
     8        Some rather simple refactoring of codeblock sampler so that
     9        it's easier for us to use it to find problems in non-jsc
     10        environments
     11
     12        * JavaScriptCore.exp:
     13        * bytecode/SamplingTool.h:
     14        * debugger/Debugger.cpp:
     15        (JSC::evaluateInGlobalCallFrame):
     16        * debugger/DebuggerCallFrame.cpp:
     17        (JSC::DebuggerCallFrame::evaluate):
     18        * interpreter/Interpreter.cpp:
     19        (JSC::Interpreter::Interpreter):
     20        (JSC::Interpreter::execute):
     21        (JSC::Interpreter::privateExecute):
     22        (JSC::Interpreter::enableSampler):
     23        (JSC::Interpreter::dumpSampleData):
     24        (JSC::Interpreter::startSampling):
     25        (JSC::Interpreter::stopSampling):
     26        * interpreter/Interpreter.h:
     27        (JSC::Interpreter::sampler):
     28        * jit/JIT.h:
     29        * jsc.cpp:
     30        (runWithScripts):
     31        * runtime/Completion.cpp:
     32        (JSC::checkSyntax):
     33        (JSC::evaluate):
     34        * runtime/Executable.h:
     35        (JSC::EvalExecutable::EvalExecutable):
     36        (JSC::ProgramExecutable::create):
     37        (JSC::ProgramExecutable::ProgramExecutable):
     38        * runtime/JSGlobalData.cpp:
     39        (JSC::JSGlobalData::startSampling):
     40        (JSC::JSGlobalData::stopSampling):
     41        (JSC::JSGlobalData::dumpSampleData):
     42        * runtime/JSGlobalData.h:
     43        * runtime/JSGlobalObjectFunctions.cpp:
     44        (JSC::globalFuncEval):
     45
    1462009-09-29  Jeremy Orlow  <jorlow@chromium.org>
    247
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r48883 r48905  
    107107__ZN3JSC12JSGlobalData10ClientDataD2Ev
    108108__ZN3JSC12JSGlobalData12createLeakedEv
     109__ZN3JSC12JSGlobalData12stopSamplingEv
     110__ZN3JSC12JSGlobalData13startSamplingEv
     111__ZN3JSC12JSGlobalData14dumpSampleDataEPNS_9ExecStateE
    109112__ZN3JSC12JSGlobalData14sharedInstanceEv
    110113__ZN3JSC12JSGlobalData6createEb
    111114__ZN3JSC12JSGlobalDataD1Ev
    112 __ZN3JSC12SamplingTool4dumpEPNS_9ExecStateE
    113115__ZN3JSC12SamplingTool5setupEv
    114116__ZN3JSC12SmallStrings17createEmptyStringEPNS_12JSGlobalDataE
  • trunk/JavaScriptCore/bytecode/SamplingTool.h

    r48662 r48905  
    114114        void sample(CodeBlock*, Instruction*);
    115115
    116         ScriptExecutable* m_executable;
     116        RefPtr<ScriptExecutable> m_executable;
    117117        CodeBlock* m_codeBlock;
    118118        int m_sampleCount;
  • trunk/JavaScriptCore/debugger/Debugger.cpp

    r48662 r48905  
    101101    CallFrame* globalCallFrame = globalObject->globalExec();
    102102
    103     EvalExecutable eval(globalCallFrame, makeSource(script));
    104     JSObject* error = eval.compile(globalCallFrame, globalCallFrame->scopeChain());
     103    RefPtr<EvalExecutable> eval = EvalExecutable::create(globalCallFrame, makeSource(script));
     104    JSObject* error = eval->compile(globalCallFrame, globalCallFrame->scopeChain());
    105105    if (error)
    106106        return error;
    107107
    108     return globalObject->globalData()->interpreter->execute(&eval, globalCallFrame, globalObject, globalCallFrame->scopeChain(), &exception);
     108    return globalObject->globalData()->interpreter->execute(eval.get(), globalCallFrame, globalObject, globalCallFrame->scopeChain(), &exception);
    109109}
    110110
  • trunk/JavaScriptCore/debugger/DebuggerCallFrame.cpp

    r48662 r48905  
    8080        return JSValue();
    8181
    82     EvalExecutable eval(m_callFrame, makeSource(script));
    83     JSObject* error = eval.compile(m_callFrame, m_callFrame->scopeChain());
     82    RefPtr<EvalExecutable> eval = EvalExecutable::create(m_callFrame, makeSource(script));
     83    JSObject* error = eval->compile(m_callFrame, m_callFrame->scopeChain());
    8484    if (error)
    8585        return error;
    8686
    87     return m_callFrame->scopeChain()->globalData->interpreter->execute(&eval, m_callFrame, thisObject(), m_callFrame->scopeChain(), &exception);
     87    return m_callFrame->scopeChain()->globalData->interpreter->execute(eval.get(), m_callFrame, thisObject(), m_callFrame->scopeChain(), &exception);
    8888}
    8989
  • trunk/JavaScriptCore/interpreter/Interpreter.cpp

    r48774 r48905  
    364364
    365365Interpreter::Interpreter()
    366     : m_sampler(0)
     366    : m_sampleEntryDepth(0)
    367367    , m_reentryDepth(0)
    368368{
    369369    privateExecute(InitializeAndReturn, 0, 0, 0);
     370#if ENABLE(OPCODE_SAMPLING)
     371    enableSampler();
     372#endif
    370373}
    371374
     
    649652    JSValue result;
    650653    {
    651         SamplingTool::CallRecord callRecord(m_sampler);
     654        SamplingTool::CallRecord callRecord(m_sampler.get());
    652655
    653656        m_reentryDepth++;
     
    715718    JSValue result;
    716719    {
    717         SamplingTool::CallRecord callRecord(m_sampler);
     720        SamplingTool::CallRecord callRecord(m_sampler.get());
    718721
    719722        m_reentryDepth++;
     
    783786    JSValue result;
    784787    {
    785         SamplingTool::CallRecord callRecord(m_sampler);
     788        SamplingTool::CallRecord callRecord(m_sampler.get());
    786789       
    787790        m_reentryDepth++;
     
    877880    JSValue result;
    878881    {
    879         SamplingTool::CallRecord callRecord(m_sampler);
     882        SamplingTool::CallRecord callRecord(m_sampler.get());
    880883
    881884        m_reentryDepth++;
     
    30573060            JSValue returnValue;
    30583061            {
    3059                 SamplingTool::HostCallRecord callRecord(m_sampler);
     3062                SamplingTool::HostCallRecord callRecord(m_sampler.get());
    30603063                returnValue = callData.native.function(newCallFrame, asObject(v), thisValue, args);
    30613064            }
     
    32113214            JSValue returnValue;
    32123215            {
    3213                 SamplingTool::HostCallRecord callRecord(m_sampler);
     3216                SamplingTool::HostCallRecord callRecord(m_sampler.get());
    32143217                returnValue = callData.native.function(newCallFrame, asObject(v), thisValue, args);
    32153218            }
     
    34633466            JSValue returnValue;
    34643467            {
    3465                 SamplingTool::HostCallRecord callRecord(m_sampler);
     3468                SamplingTool::HostCallRecord callRecord(m_sampler.get());
    34663469                returnValue = constructData.native.function(newCallFrame, asObject(v), args);
    34673470            }
     
    39153918}
    39163919
     3920void Interpreter::enableSampler()
     3921{
     3922#if ENABLE(OPCODE_SAMPLING)
     3923    if (!m_sampler) {
     3924        m_sampler.set(new SamplingTool(this));
     3925        m_sampler->setup();
     3926    }
     3927#endif
     3928}
     3929void Interpreter::dumpSampleData(ExecState* exec)
     3930{
     3931#if ENABLE(OPCODE_SAMPLING)
     3932    if (m_sampler)
     3933        m_sampler->dump(exec);
     3934#else
     3935    UNUSED_PARAM(exec);
     3936#endif
     3937}
     3938void Interpreter::startSampling()
     3939{
     3940#if ENABLE(SAMPLING_THREAD)
     3941    if (!m_sampleEntryDepth)
     3942        SamplingThread::start();
     3943
     3944    m_sampleEntryDepth++;
     3945#endif
     3946}
     3947void Interpreter::stopSampling()
     3948{
     3949#if ENABLE(SAMPLING_THREAD)
     3950    m_sampleEntryDepth--;
     3951    if (!m_sampleEntryDepth)
     3952        SamplingThread::stop();
     3953#endif
     3954}
     3955
    39173956} // namespace JSC
  • trunk/JavaScriptCore/interpreter/Interpreter.h

    r47412 r48905  
    106106        void getArgumentsData(CallFrame*, JSFunction*&, ptrdiff_t& firstParameterIndex, Register*& argv, int& argc);
    107107       
    108         void setSampler(SamplingTool* sampler) { m_sampler = sampler; }
    109         SamplingTool* sampler() { return m_sampler; }
     108        SamplingTool* sampler() { return m_sampler.get(); }
    110109
    111110        NEVER_INLINE JSValue callEval(CallFrame*, RegisterFile*, Register* argv, int argc, int registerOffset, JSValue& exceptionValue);
     
    113112        NEVER_INLINE void debug(CallFrame*, DebugHookID, int firstLine, int lastLine);
    114113
     114        void dumpSampleData(ExecState* exec);
     115        void startSampling();
     116        void stopSampling();
    115117    private:
    116118        enum ExecutionFlag { Normal, InitializeAndReturn };
     
    150152        bool isCallBytecode(Opcode opcode) { return opcode == getOpcode(op_call) || opcode == getOpcode(op_construct) || opcode == getOpcode(op_call_eval); }
    151153
    152         SamplingTool* m_sampler;
     154        void enableSampler();
     155        int m_sampleEntryDepth;
     156        OwnPtr<SamplingTool> m_sampler;
    153157
    154158        int m_reentryDepth;
  • trunk/JavaScriptCore/jit/JIT.h

    r48744 r48905  
    539539        static const int patchOffsetGetByIdPutResult = 31;
    540540#if ENABLE(OPCODE_SAMPLING)
    541         static const int patchOffsetGetByIdSlowCaseCall = 63;
     541        static const int patchOffsetGetByIdSlowCaseCall = 64;
    542542#else
    543543        static const int patchOffsetGetByIdSlowCaseCall = 41;
  • trunk/JavaScriptCore/jsc.cpp

    r48736 r48905  
    361361        BytecodeGenerator::setDumpsGeneratedCode(true);
    362362
    363 #if ENABLE(OPCODE_SAMPLING)
    364     Interpreter* interpreter = globalObject->globalData()->interpreter;
    365     interpreter->setSampler(new SamplingTool(interpreter));
    366     interpreter->sampler()->setup();
    367 #endif
     363    JSGlobalData* globalData = globalObject->globalData();
     364
    368365#if ENABLE(SAMPLING_FLAGS)
    369366    SamplingFlags::start();
     
    382379        }
    383380
    384 #if ENABLE(SAMPLING_THREAD)
    385         SamplingThread::start();
    386 #endif
     381        globalData->startSampling();
    387382
    388383        Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(script, fileName));
     
    395390        }
    396391
    397 #if ENABLE(SAMPLING_THREAD)
    398         SamplingThread::stop();
    399 #endif
    400 
     392        globalData->stopSampling();
    401393        globalObject->globalExec()->clearException();
    402394    }
     
    405397    SamplingFlags::stop();
    406398#endif
    407 #if ENABLE(OPCODE_SAMPLING)
    408     interpreter->sampler()->dump(globalObject->globalExec());
    409     delete interpreter->sampler();
    410 #endif
     399    globalData->dumpSampleData(globalObject->globalExec());
    411400#if ENABLE(SAMPLING_COUNTERS)
    412401    AbstractSamplingCounter::dump();
  • trunk/JavaScriptCore/runtime/Completion.cpp

    r48662 r48905  
    3838    JSLock lock(exec);
    3939
    40     ProgramExecutable program(exec, source);
    41     JSObject* error = program.checkSyntax(exec);
     40    RefPtr<ProgramExecutable> program = ProgramExecutable::create(exec, source);
     41    JSObject* error = program->checkSyntax(exec);
    4242    if (error)
    4343        return Completion(Throw, error);
     
    5050    JSLock lock(exec);
    5151
    52     ProgramExecutable program(exec, source);
    53     JSObject* error = program.compile(exec, scopeChain.node());
     52    RefPtr<ProgramExecutable> program = ProgramExecutable::create(exec, source);
     53    JSObject* error = program->compile(exec, scopeChain.node());
    5454    if (error)
    5555        return Completion(Throw, error);
     
    5858
    5959    JSValue exception;
    60     JSValue result = exec->interpreter()->execute(&program, exec, scopeChain.node(), thisObj, &exception);
     60    JSValue result = exec->interpreter()->execute(program.get(), exec, scopeChain.node(), thisObj, &exception);
    6161
    6262    if (exception) {
  • trunk/JavaScriptCore/runtime/Executable.h

    r48662 r48905  
    159159    class EvalExecutable : public ScriptExecutable {
    160160    public:
    161         EvalExecutable(ExecState* exec, const SourceCode& source)
    162             : ScriptExecutable(exec, source)
    163             , m_evalCodeBlock(0)
    164         {
    165         }
    166161
    167162        ~EvalExecutable();
     
    182177
    183178    private:
     179        EvalExecutable(ExecState* exec, const SourceCode& source)
     180            : ScriptExecutable(exec, source)
     181            , m_evalCodeBlock(0)
     182        {
     183        }
    184184        EvalCodeBlock* m_evalCodeBlock;
    185185
     
    200200    class ProgramExecutable : public ScriptExecutable {
    201201    public:
    202         ProgramExecutable(ExecState* exec, const SourceCode& source)
    203             : ScriptExecutable(exec, source)
    204             , m_programCodeBlock(0)
    205         {
    206         }
    207        
     202        static PassRefPtr<ProgramExecutable> create(ExecState* exec, const SourceCode& source)
     203        {
     204            return adoptRef(new ProgramExecutable(exec, source));
     205        }
     206
    208207        ~ProgramExecutable();
    209208
     
    224223
    225224    private:
     225        ProgramExecutable(ExecState* exec, const SourceCode& source)
     226            : ScriptExecutable(exec, source)
     227            , m_programCodeBlock(0)
     228        {
     229        }
    226230        ProgramCodeBlock* m_programCodeBlock;
    227231
  • trunk/JavaScriptCore/runtime/JSGlobalData.cpp

    r48315 r48905  
    252252}
    253253
     254void JSGlobalData::startSampling()
     255{
     256    interpreter->startSampling();
     257}
     258
     259void JSGlobalData::stopSampling()
     260{
     261    interpreter->stopSampling();
     262}
     263
     264void JSGlobalData::dumpSampleData(ExecState* exec)
     265{
     266    interpreter->dumpSampleData(exec);
     267}
     268
    254269} // namespace JSC
  • trunk/JavaScriptCore/runtime/JSGlobalData.h

    r48315 r48905  
    156156#endif
    157157
     158        void startSampling();
     159        void stopSampling();
     160        void dumpSampleData(ExecState* exec);
    158161    private:
    159162        JSGlobalData(bool isShared, const VPtrSet&);
  • trunk/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp

    r48662 r48905  
    287287        return parsedObject;
    288288
    289     EvalExecutable eval(exec, makeSource(s));
    290     JSObject* error = eval.compile(exec, static_cast<JSGlobalObject*>(unwrappedObject)->globalScopeChain().node());
     289    RefPtr<EvalExecutable> eval = EvalExecutable::create(exec, makeSource(s));
     290    JSObject* error = eval->compile(exec, static_cast<JSGlobalObject*>(unwrappedObject)->globalScopeChain().node());
    291291    if (error)
    292292        return throwError(exec, error);
    293293
    294     return exec->interpreter()->execute(&eval, exec, thisObject, static_cast<JSGlobalObject*>(unwrappedObject)->globalScopeChain().node(), exec->exceptionSlot());
     294    return exec->interpreter()->execute(eval.get(), exec, thisObject, static_cast<JSGlobalObject*>(unwrappedObject)->globalScopeChain().node(), exec->exceptionSlot());
    295295}
    296296
Note: See TracChangeset for help on using the changeset viewer.