Ignore:
Timestamp:
Jul 24, 2013, 9:02:28 PM (12 years ago)
Author:
[email protected]
Message:

fourthTier: Introducing the StackIterator class.

This was a non trivial merge as trunk has changed computation of line and column information

Introducing the StackIterator class.
https://bugs.webkit.org/show_bug.cgi?id=117390.

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

The StackIterator class is meant to unify the way we iterate the JS
stack. It also makes it so that we don't have to copy the frame data
into the intermediate StackFrame struct before processing it.
Unfortunately we still can't get rid of StackFrame because it is used
to record frame information for the Exception stack that is expected
to persist beyond when the frames have been popped off the JS stack.

The StackIterator will iterate over all "logical" frames (i.e. including
inlined frames). As it iterates the JS stack, if it encounters a DFG
frame that has inlined frames, the iterator will canonicalize the
inlined frames before returning. Once canonicalized, the frame can be
read like any other frame.

The StackIterator implements a Frame class that inherits from CallFrame.
The StackIterator::Frame serves as reader of the CallFrame that makes
it easier to access information about the frame. The StackIterator::Frame
only adds functions, and no additional data fields.

  • API/JSContextRef.cpp:

(JSContextCreateBacktrace):

  • CMakeLists.txt:
  • GNUmakefile.list.am:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
  • JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • Target.pri:
  • interpreter/CallFrame.cpp:

(JSC::CallFrame::begin):
(JSC::CallFrame::beginAt):

  • interpreter/CallFrame.h:

(JSC::ExecState::setInlineCallFrame):
(ExecState):
(JSC::ExecState::end):

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::dumpRegisters):
(JSC::Interpreter::unwindCallFrame):
(JSC::Interpreter::getStackTrace):
(JSC::Interpreter::throwException):
(JSC::Interpreter::debug):

  • interpreter/Interpreter.h:

(Interpreter):

  • interpreter/StackIterator.cpp: Added.

(JSC::StackIterator::StackIterator):
(JSC::StackIterator::beginAt):
(JSC::StackIterator::gotoNextFrame):

  • Based on the deleted Interpreter::findFunctionCallFrameFromVMCode().

(JSC::StackIterator::findFrameForFunction):

  • Based on the deleted Interpreter::retrieveCallerFromVMCode().

(JSC::StackIterator::Frame::codeType):

  • Based on the deleted getStackFrameCodeType().

(JSC::StackIterator::Frame::functionName):

  • Based on StackFrame::friendlyFunctionName().

(JSC::StackIterator::Frame::sourceURL):

  • Based on StackFrame::friendlySourceURL().

(JSC::StackIterator::Frame::toString):

  • Based on StackFrame::toString().

(JSC::StackIterator::Frame::bytecodeOffset):
(JSC::StackIterator::Frame::line):

  • Based on StackFrame::line().

(JSC::StackIterator::Frame::column):

  • Based on StackFrame::column().

(JSC::StackIterator::Frame::arguments):

  • Based on the deleted Interpreter::retrieveArgumentsFromVMCode().

(JSC::StackIterator::Frame::retrieveExpressionInfo):

  • Based on StackFrame::expressionInfo().

(JSC::StackIterator::Frame::logicalFrame):

  • Based on the now deleted CallFrame::trueCallFrame().

(JSC::StackIterator::Frame::logicalCallerFrame):

  • Based on the now deleted CallFrame::trueCallerFrame().

(JSC::jitTypeName):
(JSC::printIndents):
(JSC::printif):
(JSC::StackIterator::Frame::print):
(debugPrintCallFrame):

  • Prints the contents of the frame for debugging purposes. There are 2 versions that can be used as follows:
  1. When you have a valid StackIterator, you can print the current frame's content using the print instance method:

iter->print(indentLevel);

  1. When you have a CallFrame* that you want to dump from a debugger console, you can print its content as follows:

(gdb) call debugPrintCallFrame(callFrame)

A sample of the output looks like this:

frame 0x1510c70b0 {

name 'shouldBe'
sourceURL 'testapi.js'
hostFlag 0
isInlinedFrame 0
callee 0x15154efb0
returnPC 0x10ed0786d
callerFrame 0x1510c7058
logicalCallerFrame 0x1510c7058
rawLocationBits 27 0x1b
codeBlock 0x7fe79b037200

bytecodeOffset 27 0x1b / 210
line 46
column 20
jitType 3 <BaselineJIT> isOptimizingJIT 0
hasCodeOrigins 0

}

  • interpreter/StackIterator.h: Added.

(StackIterator::Frame):
(JSC::StackIterator::Frame::create):
(JSC::StackIterator::Frame::isJSFrame):
(JSC::StackIterator::Frame::callFrame):

  • interpreter/StackIteratorPrivate.h: Added.

(StackIterator):
(JSC::StackIterator::operator*):
(JSC::StackIterator::operator->):
(JSC::StackIterator::operator==):
(JSC::StackIterator::operator!=):
(JSC::StackIterator::operator++):
(JSC::StackIterator::end):
(JSC::StackIterator::empty):

  • jsc.cpp:

(functionJSCStack):

  • profiler/ProfileGenerator.cpp:

(JSC::ProfileGenerator::addParentForConsoleStart):

  • profiler/ProfileNode.h:

(ProfileNode):

  • runtime/JSFunction.cpp:

(JSC::retrieveArguments):
(JSC::JSFunction::argumentsGetter):
(JSC::skipOverBoundFunctions):
(JSC::retrieveCallerFunction):
(JSC::JSFunction::callerGetter):
(JSC::JSFunction::getOwnPropertyDescriptor):
(JSC::JSFunction::defineOwnProperty):

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::globalFuncProtoGetter):
(JSC::globalFuncProtoSetter):

  • runtime/ObjectConstructor.cpp:

(JSC::objectConstructorGetPrototypeOf):

  • runtime/Operations.h:

Source/WebCore:

No new tests.

  • ForwardingHeaders/interpreter/StackIterator.h: Added.
  • bindings/js/JSXMLHttpRequestCustom.cpp:

(WebCore::JSXMLHttpRequest::send):

  • bindings/js/ScriptCallStackFactory.cpp:

(WebCore::createScriptCallStack):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jsc.cpp

    r151149 r153218  
    11/*
    22 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    3  *  Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserved.
     3 *  Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012, 2013 Apple Inc. All rights reserved.
    44 *  Copyright (C) 2006 Bjoern Graf ([email protected])
    55 *
     
    2626#include "ButterflyInlines.h"
    2727#include "BytecodeGenerator.h"
     28#include "CallFrameInlines.h"
    2829#include "Completion.h"
    2930#include "CopiedSpaceInlines.h"
     
    4041#include "Operations.h"
    4142#include "SamplingTool.h"
     43#include "StackIterator.h"
    4244#include "StructureRareDataInlines.h"
    4345#include <math.h>
     
    341343    trace.appendLiteral("--> Stack trace:\n");
    342344
    343     Vector<StackFrame> stackTrace;
    344     Interpreter::getStackTrace(&exec->vm(), stackTrace);
    345345    int i = 0;
    346 
    347     for (Vector<StackFrame>::iterator iter = stackTrace.begin(); iter < stackTrace.end(); iter++) {
    348         StackFrame level = *iter;
    349         trace.append(String::format("    %i   %s\n", i, level.toString(exec).utf8().data()));
    350         i++;
    351     }
     346    for (StackIterator iter = exec->begin(); iter != exec->end(); ++iter, ++i)
     347        trace.append(String::format("    %i   %s\n", i, iter->toString().utf8().data()));
    352348    fprintf(stderr, "%s", trace.toString().utf8().data());
    353349    return JSValue::encode(jsUndefined());
Note: See TracChangeset for help on using the changeset viewer.