Changeset 34036 in webkit for trunk/JavaScriptCore/VM/Machine.cpp


Ignore:
Timestamp:
May 22, 2008, 3:09:43 PM (17 years ago)
Author:
[email protected]
Message:

2008-05-22 Kevin McCullough <[email protected]>

Reviewed by Sam.

<rdar://problem/5951561> Turn on JavaScript Profiler
Get basic JS profiling working.
Even with this patch the profiler will not be compiled in because we do
not know the extend, if any, of the performance regression it would cause
when it is not in use. However with these changes, if the profiler were
on, it would not crash and show good profiling data.

  • VM/Machine.cpp: Instrument the calls sites that are needed for profiling. (KJS::callEval): (KJS::Machine::unwindCallFrame): (KJS::Machine::execute): (KJS::Machine::privateExecute):
  • kjs/function.cpp: Ditto. (KJS::globalFuncEval):
  • kjs/interpreter.cpp: Ditto. (KJS::Interpreter::evaluate):
  • profiler/Profile.cpp: (KJS::Profile::willExecute): (KJS::Profile::didExecute): Because we do not get a good context when startProfiling is called it is possible that m_currentNode will be at the top of the known stack when a didExecute() is called. What we then do is create a new node that represents the function being exited and insert it between the head and the currently known children, since they should be children of this new node.
  • profiler/ProfileNode.cpp: (KJS::ProfileNode::ProfileNode): (KJS::ProfileNode::willExecute): Rename the add function for consistency. (KJS::ProfileNode::addChild): Appends the child to this node but also sets the parent pointer of the children to this node. (KJS::ProfileNode::insertNode): Insert a node between this node and its children. Also set the time for the new node since it is now exiting and we don't really know when it started. (KJS::ProfileNode::stopProfiling): (KJS::ProfileNode::startTimer):
  • profiler/ProfileNode.h: (KJS::CallIdentifier::toString): Added for debugging. (KJS::ProfileNode::setParent): (KJS::ProfileNode::setSelfTime): Fixed an old bug where we set the visibleTotalTime not the visibleSelfTime. (KJS::ProfileNode::children): (KJS::ProfileNode::toString): Added for debugging.
  • profiler/Profiler.cpp: remove unecessary calls. (KJS::Profiler::startProfiling):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/VM/Machine.cpp

    r34032 r34036  
    3939#include "JSPropertyNameIterator.h"
    4040#include "Parser.h"
     41#include "Profiler.h"
    4142#include "Register.h"
    4243#include "array_object.h"
     
    437438}
    438439
    439 static NEVER_INLINE JSValue* eval(ExecState* exec, JSObject* thisObj, ScopeChainNode* scopeChain, RegisterFile* registerFile, Register* r, int argv, int argc, JSValue*& exceptionValue)
    440 {
     440#if JAVASCRIPT_PROFILING
     441static NEVER_INLINE JSValue* callEval(ExecState* exec, JSObject* evalFunction, JSObject* thisObj, ScopeChainNode* scopeChain, RegisterFile* registerFile, Register* r, int argv, int argc, JSValue*& exceptionValue)
     442{
     443    Profiler::profiler()->willExecute(exec, evalFunction);
     444#else
     445static NEVER_INLINE JSValue* callEval(ExecState* exec, JSObject* thisObj, ScopeChainNode* scopeChain, RegisterFile* registerFile, Register* r, int argv, int argc, JSValue*& exceptionValue)
     446{
     447#endif
     448
    441449    JSValue* x = argc >= 2 ? r[argv + 1].u.jsValue : jsUndefined();
    442450   
     
    461469    }
    462470
     471#if JAVASCRIPT_PROFILING
     472    JSValue* result = machine().execute(evalNode.get(), exec, thisObj, registerFile, r - (*registerFile->basePointer()) + argv + argc, scopeChain, &exceptionValue);
     473
     474    Profiler::profiler()->didExecute(exec, evalFunction);
     475
     476    return result;
     477#else
    463478    return machine().execute(evalNode.get(), exec, thisObj, registerFile, r - (*registerFile->basePointer()) + argv + argc, scopeChain, &exceptionValue);
     479#endif
    464480}
    465481
     
    590606    exec->m_callFrameOffset = callerRegisterOffset - codeBlock->numLocals - CallFrameHeaderSize;
    591607    vPC = callFrame[ReturnVPC].u.vPC;
     608
     609#if JAVASCRIPT_PROFILING
     610    Profiler::profiler()->didExecute(exec, callFrame[Callee].u.jsObject);
     611#endif
    592612    return true;
    593613}
     
    638658    }
    639659
     660#if JAVASCRIPT_PROFILING
     661    Profiler::profiler()->willExecute(exec, programNode->sourceURL(), programNode->lineNo());
     662#endif
     663
    640664    RegisterFile* registerFile = registerFileStack->pushGlobalRegisterFile();
    641665    ASSERT(registerFile->numGlobalSlots());
     
    658682
    659683    registerFileStack->popGlobalRegisterFile();
     684
     685#if JAVASCRIPT_PROFILING
     686    Profiler::profiler()->didExecute(exec, programNode->sourceURL(), programNode->lineNo());
     687#endif
     688
    660689    return result;
    661690}
     
    667696        return 0;
    668697    }
     698
     699#if JAVASCRIPT_PROFILING
     700    Profiler::profiler()->willExecute(exec, function);
     701#endif
    669702
    670703    RegisterFile* registerFile = registerFileStack->current();
     
    712745    registerFile->shrink(oldSize);
    713746    return result;
    714    
    715747}
    716748
     
    721753        return 0;
    722754    }
     755
     756#if JAVASCRIPT_PROFILING
     757    Profiler::profiler()->willExecute(exec, evalNode->sourceURL(), evalNode->lineNo());
     758#endif
     759
    723760    EvalCodeBlock* codeBlock = &evalNode->code(scopeChain);
    724761   
     
    768805
    769806    registerFile->shrink(oldSize);
     807
     808#if JAVASCRIPT_PROFILING
     809    Profiler::profiler()->didExecute(exec, evalNode->sourceURL(), evalNode->lineNo());
     810#endif
     811
    770812    return result;
    771813}
     
    18141856
    18151857            registerFile->setSafeForReentry(true);
    1816             JSValue* result = eval(exec, thisObject, scopeChain, registerFile, r, argv, argc, exceptionValue);
     1858#if JAVASCRIPT_PROFILING
     1859            JSValue* result = callEval(exec, static_cast<JSObject*>(v), thisObject, scopeChain, registerFile, r, argv, argc, exceptionValue);
     1860#else
     1861            JSValue* result = callEval(exec, thisObject, scopeChain, registerFile, r, argv, argc, exceptionValue);
     1862#endif
    18171863            registerFile->setSafeForReentry(false);
    18181864            r = (*registerBase) + registerOffset;
     
    18541900       
    18551901        if (callType == CallTypeJS) {
     1902#if JAVASCRIPT_PROFILING
     1903            Profiler::profiler()->willExecute(exec, static_cast<JSObject*>(v));
     1904#endif
    18561905            int registerOffset = r - (*registerBase);
    18571906            Register* callFrame = r + argv - CallFrameHeaderSize;
     
    18791928
    18801929        if (callType == CallTypeNative) {
     1930#if JAVASCRIPT_PROFILING
     1931            Profiler::profiler()->willExecute(exec, static_cast<JSObject*>(v));
     1932#endif
    18811933            int registerOffset = r - (*registerBase);
    1882            
     1934
    18831935            r[argv].u.jsValue = base == missingThisObjectMarker() ? exec->globalThisValue() : (r[base].u.jsValue)->toObject(exec); // "this" value
    18841936            JSObject* thisObj = static_cast<JSObject*>(r[argv].u.jsValue);
     
    18931945            r[dst].u.jsValue = returnValue;
    18941946
     1947#if JAVASCRIPT_PROFILING
     1948            Profiler::profiler()->didExecute(exec, static_cast<JSObject*>(v));
     1949#endif
    18951950            VM_CHECK_EXCEPTION();
    18961951
     
    19391994        r[r0].u.jsValue = returnValue;
    19401995       
     1996#if JAVASCRIPT_PROFILING
     1997        Profiler::profiler()->didExecute(exec, callFrame[Callee].u.jsObject);
     1998#endif
    19411999        NEXT_OPCODE;
    19422000    }
     
    19562014
    19572015        if (constructType == ConstructTypeJS) {
     2016#if JAVASCRIPT_PROFILING
     2017            Profiler::profiler()->willExecute(exec, constructor);
     2018#endif
    19582019            int registerOffset = r - (*registerBase);
    19592020            Register* callFrame = r + argv - CallFrameHeaderSize;
     
    19892050
    19902051        if (constructType == ConstructTypeNative) {
     2052#if JAVASCRIPT_PROFILING
     2053            Profiler::profiler()->willExecute(exec, constructor);
     2054#endif
    19912055            int registerOffset = r - (*registerBase);
    19922056
     
    20002064            r[dst].u.jsValue = returnValue;
    20012065
     2066#if JAVASCRIPT_PROFILING
     2067            Profiler::profiler()->didExecute(exec, constructor);
     2068#endif
    20022069            ++vPC;
    20032070            NEXT_OPCODE;
Note: See TracChangeset for help on using the changeset viewer.