Changeset 153825 in webkit


Ignore:
Timestamp:
Aug 8, 2013, 9:57:07 AM (12 years ago)
Author:
mark.lam@apple.com
Message:

Restoring use of StackIterator instead of Interpreter::getStacktrace().
https://bugs.webkit.org/show_bug.cgi?id=119575.

Reviewed by Oliver Hunt.

Source/JavaScriptCore:

  • interpreter/Interpreter.h:
  • Made getStackTrace() private.
  • interpreter/StackIterator.cpp:

(JSC::StackIterator::StackIterator):
(JSC::StackIterator::numberOfFrames):

  • Computes the number of frames by iterating through the whole stack from the starting frame. The iterator will save its current frame position before counting the frames, and then restoring it after the counting.

(JSC::StackIterator::gotoFrameAtIndex):
(JSC::StackIterator::gotoNextFrame):
(JSC::StackIterator::resetIterator):

  • Points the iterator to the starting frame.
  • interpreter/StackIteratorPrivate.h:

Source/WebCore:

No new tests.

  • bindings/js/ScriptCallStackFactory.cpp:

(WebCore::createScriptCallStack):

Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r153823 r153825  
     12013-08-08  Mark Lam  <mark.lam@apple.com>
     2
     3        Restoring use of StackIterator instead of Interpreter::getStacktrace().
     4        https://bugs.webkit.org/show_bug.cgi?id=119575.
     5
     6        Reviewed by Oliver Hunt.
     7
     8        * interpreter/Interpreter.h:
     9        - Made getStackTrace() private.
     10        * interpreter/StackIterator.cpp:
     11        (JSC::StackIterator::StackIterator):
     12        (JSC::StackIterator::numberOfFrames):
     13        - Computes the number of frames by iterating through the whole stack
     14          from the starting frame. The iterator will save its current frame
     15          position before counting the frames, and then restoring it after
     16          the counting.
     17        (JSC::StackIterator::gotoFrameAtIndex):
     18        (JSC::StackIterator::gotoNextFrame):
     19        (JSC::StackIterator::resetIterator):
     20        - Points the iterator to the starting frame.
     21        * interpreter/StackIteratorPrivate.h:
     22
    1232013-08-08  Mark Lam  <mark.lam@apple.com>
    224
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.h

    r153823 r153825  
    234234        JS_EXPORT_PRIVATE void dumpCallFrame(CallFrame*);
    235235
    236         JS_EXPORT_PRIVATE void getStackTrace(Vector<StackFrame>& results, size_t maxStackSize = std::numeric_limits<size_t>::max());
    237 
    238236    private:
    239237        enum ExecutionFlag { Normal, InitializeAndReturn };
     
    243241        JSValue execute(CallFrameClosure&);
    244242
     243        void getStackTrace(Vector<StackFrame>& results, size_t maxStackSize = std::numeric_limits<size_t>::max());
    245244        NEVER_INLINE bool unwindCallFrame(StackIterator&, JSValue);
    246245
  • trunk/Source/JavaScriptCore/interpreter/StackIterator.cpp

    r153329 r153825  
    3535namespace JSC {
    3636
    37 StackIterator::StackIterator(CallFrame* frame, StackIterator::FrameFilter filter)
    38     : m_filter(filter)
    39 {
    40     ASSERT(frame);
    41     m_frame = Frame::create(frame);
    42     m_frame = m_frame->logicalFrame();
     37StackIterator::StackIterator(CallFrame* startFrame, StackIterator::FrameFilter filter)
     38    : m_startFrame(startFrame)
     39    , m_filter(filter)
     40{
     41    ASSERT(startFrame);
     42    resetIterator();
     43}
     44
     45size_t StackIterator::numberOfFrames()
     46{
     47    int savedFrameIndex = m_frameIndex;
     48    resetIterator();
     49    while (m_frame)
     50        gotoNextFrame();
     51    size_t numberOfFrames = m_frameIndex;
     52
     53    resetIterator();
     54    gotoFrameAtIndex(savedFrameIndex);
     55
     56    return numberOfFrames;
     57}
     58
     59void StackIterator::gotoFrameAtIndex(size_t index)
     60{
     61    while (m_frame && (m_frameIndex != index))
     62        gotoNextFrame();
    4363}
    4464
     
    5272    }
    5373    m_frame = frame;
     74    m_frameIndex++;
     75}
     76
     77void StackIterator::resetIterator()
     78{
     79    m_frameIndex = 0;
     80    m_frame = Frame::create(m_startFrame);
     81    m_frame = m_frame->logicalFrame();
    5482}
    5583
  • trunk/Source/JavaScriptCore/interpreter/StackIteratorPrivate.h

    r153299 r153825  
    4040    typedef bool (*FrameFilter)(Frame*);
    4141
     42    JS_EXPORT_PRIVATE size_t numberOfFrames();
     43
    4244    Frame& operator*() { return *m_frame; }
    4345    ALWAYS_INLINE Frame* operator->() { return m_frame; }
     
    5254
    5355    static Frame* end() { return 0; }
     56    void gotoFrameAtIndex(size_t frameIndex);
    5457    JS_EXPORT_PRIVATE void gotoNextFrame();
     58    void resetIterator();
    5559
     60    CallFrame* m_startFrame;
     61    size_t m_frameIndex;
    5662    Frame* m_frame;
    5763    FrameFilter m_filter;
  • trunk/Source/WebCore/ChangeLog

    r153822 r153825  
     12013-08-08  Mark Lam  <mark.lam@apple.com>
     2
     3        Restoring use of StackIterator instead of Interpreter::getStacktrace().
     4        https://bugs.webkit.org/show_bug.cgi?id=119575.
     5
     6        Reviewed by Oliver Hunt.
     7
     8        No new tests.
     9
     10        * bindings/js/ScriptCallStackFactory.cpp:
     11        (WebCore::createScriptCallStack):
     12
    1132013-08-08  Zalan Bujtas  <zalan@apple.com>
    214
  • trunk/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp

    r153383 r153825  
    7979{
    8080    Vector<ScriptCallFrame> frames;
    81     Vector<StackFrame> stackTrace;
    82     exec->vm().interpreter->getStackTrace(stackTrace, maxStackSize + 1);
    83     for (size_t i = stackTrace.size() == 1 ? 0 : 1; i < stackTrace.size(); i++) {
     81    ASSERT(exec);
     82    CallFrame* frame = exec->vm().topCallFrame;
     83    StackIterator iter = frame->begin();
     84    if (iter.numberOfFrames() > 1)
     85        ++iter;
     86    for (; iter != frame->end() && maxStackSize--; ++iter) {
    8487        // This early exit is necessary to maintain our old behaviour
    8588        // but the stack trace we produce now is complete and handles all
    8689        // ways in which code may be running
    87         if (!stackTrace[i].callee && frames.size())
     90        if (!iter->callee() && frames.size())
    8891            break;
    89 
    90         String functionName = stackTrace[i].friendlyFunctionName(exec);
    9192        unsigned line;
    9293        unsigned column;
    93         stackTrace[i].computeLineAndColumn(line, column);
    94         frames.append(ScriptCallFrame(functionName, stackTrace[i].sourceURL, line, column));
     94        iter->computeLineAndColumn(line, column);
     95        frames.append(ScriptCallFrame(iter->functionName(), iter->sourceURL(), line, column));
    9596    }
    96    
    9797    return ScriptCallStack::create(frames);
    9898}
Note: See TracChangeset for help on using the changeset viewer.