Changeset 201641 in webkit


Ignore:
Timestamp:
Jun 3, 2016 7:53:16 AM (8 years ago)
Author:
mark.lam@apple.com
Message:

Clean up how StackVisitor dumps its frames.
https://bugs.webkit.org/show_bug.cgi?id=158316

Reviewed by Keith Miller.

Source/JavaScriptCore:

  1. Updated to do dumping to a PrintStream.
  2. Added support for printing a prefix for each frame. This is currently used by JSDollarVMPrototype to print frame numbers.
  3. Fix the incrementing of the frame index in StackVisitor. It was initialized but never incremented before when iterating the frames.
  • interpreter/StackVisitor.cpp:

(JSC::StackVisitor::gotoNextFrame):
(JSC::StackVisitor::Frame::codeType):
(JSC::StackVisitor::Frame::functionName):
(JSC::StackVisitor::Frame::sourceURL):
(JSC::StackVisitor::Frame::toString):
(JSC::StackVisitor::Frame::createArguments):
(JSC::StackVisitor::Frame::computeLineAndColumn):
(JSC::StackVisitor::Frame::retrieveExpressionInfo):
(JSC::StackVisitor::Frame::setToEnd):
(JSC::StackVisitor::Frame::dump):
(JSC::StackVisitor::Indent::dump):
(JSC::printIndents): Deleted.
(JSC::log): Deleted.
(JSC::logF): Deleted.
(JSC::StackVisitor::Frame::print): Deleted.

  • interpreter/StackVisitor.h:

(JSC::StackVisitor::Indent::Indent):
(JSC::StackVisitor::Indent::operator++):
(JSC::StackVisitor::Indent::operator--):
(JSC::StackVisitor::Frame::isJSFrame):
(JSC::StackVisitor::Frame::isInlinedFrame):
(JSC::StackVisitor::Frame::vmEntryFrame):
(JSC::StackVisitor::Frame::callFrame):
(JSC::StackVisitor::Frame::Frame):
(JSC::StackVisitor::Frame::~Frame):

  • tools/JSDollarVMPrototype.cpp:

(JSC::PrintFrameFunctor::operator()):

Source/WTF:

Added an Indenter class what works with dataLog.

  • WTF.xcodeproj/project.pbxproj:
  • wtf/Indenter.h: Added.

(WTF::Indenter::Indenter):
(WTF::Indenter::dump):
(WTF::Indenter::operator++):
(WTF::Indenter::operator--):

Location:
trunk/Source
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r201628 r201641  
     12016-06-03  Mark Lam  <mark.lam@apple.com>
     2
     3        Clean up how StackVisitor dumps its frames.
     4        https://bugs.webkit.org/show_bug.cgi?id=158316
     5
     6        Reviewed by Keith Miller.
     7
     8        1. Updated to do dumping to a PrintStream.
     9        2. Added support for printing a prefix for each frame.
     10           This is currently used by JSDollarVMPrototype to print frame numbers.
     11        3. Fix the incrementing of the frame index in StackVisitor.
     12           It was initialized but never incremented before when iterating the frames.
     13
     14        * interpreter/StackVisitor.cpp:
     15        (JSC::StackVisitor::gotoNextFrame):
     16        (JSC::StackVisitor::Frame::codeType):
     17        (JSC::StackVisitor::Frame::functionName):
     18        (JSC::StackVisitor::Frame::sourceURL):
     19        (JSC::StackVisitor::Frame::toString):
     20        (JSC::StackVisitor::Frame::createArguments):
     21        (JSC::StackVisitor::Frame::computeLineAndColumn):
     22        (JSC::StackVisitor::Frame::retrieveExpressionInfo):
     23        (JSC::StackVisitor::Frame::setToEnd):
     24        (JSC::StackVisitor::Frame::dump):
     25        (JSC::StackVisitor::Indent::dump):
     26        (JSC::printIndents): Deleted.
     27        (JSC::log): Deleted.
     28        (JSC::logF): Deleted.
     29        (JSC::StackVisitor::Frame::print): Deleted.
     30        * interpreter/StackVisitor.h:
     31        (JSC::StackVisitor::Indent::Indent):
     32        (JSC::StackVisitor::Indent::operator++):
     33        (JSC::StackVisitor::Indent::operator--):
     34        (JSC::StackVisitor::Frame::isJSFrame):
     35        (JSC::StackVisitor::Frame::isInlinedFrame):
     36        (JSC::StackVisitor::Frame::vmEntryFrame):
     37        (JSC::StackVisitor::Frame::callFrame):
     38        (JSC::StackVisitor::Frame::Frame):
     39        (JSC::StackVisitor::Frame::~Frame):
     40        * tools/JSDollarVMPrototype.cpp:
     41        (JSC::PrintFrameFunctor::operator()):
     42
    1432016-06-02  Saam Barati  <sbarati@apple.com>
    244
  • trunk/Source/JavaScriptCore/interpreter/StackVisitor.cpp

    r199852 r201641  
    11/*
    2  * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013, 2015-2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5858void StackVisitor::gotoNextFrame()
    5959{
     60    m_frame.m_index++;
    6061#if ENABLE(DFG_JIT)
    6162    if (m_frame.isInlinedFrame()) {
     
    209210}
    210211
    211 String StackVisitor::Frame::functionName()
     212String StackVisitor::Frame::functionName() const
    212213{
    213214    String traceLine;
     
    235236}
    236237
    237 String StackVisitor::Frame::sourceURL()
     238String StackVisitor::Frame::sourceURL() const
    238239{
    239240    String traceLine;
     
    256257}
    257258
    258 String StackVisitor::Frame::toString()
     259String StackVisitor::Frame::toString() const
    259260{
    260261    StringBuilder traceBuild;
     
    306307}
    307308
    308 void StackVisitor::Frame::computeLineAndColumn(unsigned& line, unsigned& column)
     309void StackVisitor::Frame::computeLineAndColumn(unsigned& line, unsigned& column) const
    309310{
    310311    CodeBlock* codeBlock = this->codeBlock();
     
    329330}
    330331
    331 void StackVisitor::Frame::retrieveExpressionInfo(int& divot, int& startOffset, int& endOffset, unsigned& line, unsigned& column)
     332void StackVisitor::Frame::retrieveExpressionInfo(int& divot, int& startOffset, int& endOffset, unsigned& line, unsigned& column) const
    332333{
    333334    CodeBlock* codeBlock = this->codeBlock();
     
    344345}
    345346
    346 static void printIndents(int levels)
    347 {
    348     while (levels--)
    349         dataLogFString("   ");
    350 }
    351 
    352 template<typename... Types>
    353 void log(unsigned indent, const Types&... values)
    354 {
    355     printIndents(indent);
    356     dataLog(values...);
    357 }
    358 
    359 template<typename... Types>
    360 void logF(unsigned indent, const char* format, const Types&... values)
    361 {
    362     printIndents(indent);
    363 
    364 #if COMPILER(GCC_OR_CLANG)
    365 #pragma GCC diagnostic push
    366 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
    367 #pragma GCC diagnostic ignored "-Wmissing-format-attribute"
    368 #endif
    369 
    370     dataLogF(format, values...);
    371 
    372 #if COMPILER(GCC_OR_CLANG)
    373 #pragma GCC diagnostic pop
    374 #endif
    375 }
    376 
    377 void StackVisitor::Frame::print(int indent)
     347void StackVisitor::Frame::dump(PrintStream& out, Indenter indent) const
     348{
     349    dump(out, indent, [] (PrintStream&) { });
     350}
     351
     352void StackVisitor::Frame::dump(PrintStream& out, Indenter indent, std::function<void(PrintStream&)> prefix) const
    378353{
    379354    if (!this->callFrame()) {
    380         log(indent, "frame 0x0\n");
     355        out.print(indent, "frame 0x0\n");
    381356        return;
    382357    }
    383358
    384359    CodeBlock* codeBlock = this->codeBlock();
    385     logF(indent, "frame %p {\n", this->callFrame());
     360    out.print(indent);
     361    prefix(out);
     362    out.print("frame ", RawPointer(this->callFrame()), " {\n");
    386363
    387364    {
     
    392369        void* returnPC = callFrame->hasReturnPC() ? callFrame->returnPC().value() : nullptr;
    393370
    394         log(indent, "name: ", functionName(), "\n");
    395         log(indent, "sourceURL: ", sourceURL(), "\n");
     371        out.print(indent, "name: ", functionName(), "\n");
     372        out.print(indent, "sourceURL: ", sourceURL(), "\n");
    396373
    397374        bool isInlined = false;
    398375#if ENABLE(DFG_JIT)
    399376        isInlined = isInlinedFrame();
    400         log(indent, "isInlinedFrame: ", isInlinedFrame(), "\n");
     377        out.print(indent, "isInlinedFrame: ", isInlinedFrame(), "\n");
    401378        if (isInlinedFrame())
    402             logF(indent, "InlineCallFrame: %p\n", m_inlineCallFrame);
    403 #endif
    404 
    405         logF(indent, "callee: %p\n", callee());
    406         logF(indent, "returnPC: %p\n", returnPC);
    407         logF(indent, "callerFrame: %p\n", callerFrame);
     379            out.print(indent, "InlineCallFrame: ", RawPointer(m_inlineCallFrame), "\n");
     380#endif
     381
     382        out.print(indent, "callee: ", RawPointer(callee()), "\n");
     383        out.print(indent, "returnPC: ", RawPointer(returnPC), "\n");
     384        out.print(indent, "callerFrame: ", RawPointer(callerFrame), "\n");
    408385        unsigned locationRawBits = callFrame->callSiteAsRawBits();
    409         logF(indent, "rawLocationBits: %u 0x%x\n", locationRawBits, locationRawBits);
    410         logF(indent, "codeBlock: %p ", codeBlock);
     386        out.print(indent, "rawLocationBits: ", static_cast<uintptr_t>(locationRawBits),
     387            " ", RawPointer(reinterpret_cast<void*>(locationRawBits)), "\n");
     388        out.print(indent, "codeBlock: ", RawPointer(codeBlock));
    411389        if (codeBlock)
    412             dataLog(*codeBlock);
    413         dataLog("\n");
     390            out.print(*codeBlock);
     391        out.print("\n");
    414392        if (codeBlock && !isInlined) {
    415393            indent++;
     
    417395            if (callFrame->callSiteBitsAreBytecodeOffset()) {
    418396                unsigned bytecodeOffset = callFrame->bytecodeOffset();
    419                 log(indent, "bytecodeOffset: ", bytecodeOffset, " of ", codeBlock->instructions().size(), "\n");
     397                out.print(indent, "bytecodeOffset: ", bytecodeOffset, " of ", codeBlock->instructions().size(), "\n");
    420398#if ENABLE(DFG_JIT)
    421399            } else {
    422                 log(indent, "hasCodeOrigins: ", codeBlock->hasCodeOrigins(), "\n");
     400                out.print(indent, "hasCodeOrigins: ", codeBlock->hasCodeOrigins(), "\n");
    423401                if (codeBlock->hasCodeOrigins()) {
    424402                    CallSiteIndex callSiteIndex = callFrame->callSiteIndex();
    425                     log(indent, "callSiteIndex: ", callSiteIndex.bits(), " of ", codeBlock->codeOrigins().size(), "\n");
     403                    out.print(indent, "callSiteIndex: ", callSiteIndex.bits(), " of ", codeBlock->codeOrigins().size(), "\n");
    426404
    427405                    JITCode::JITType jitType = codeBlock->jitType();
    428406                    if (jitType != JITCode::FTLJIT) {
    429407                        JITCode* jitCode = codeBlock->jitCode().get();
    430                         logF(indent, "jitCode: %p start %p end %p\n", jitCode, jitCode->start(), jitCode->end());
     408                        out.print(indent, "jitCode: ", RawPointer(jitCode),
     409                            " start ", RawPointer(jitCode->start()),
     410                            " end ", RawPointer(jitCode->end()), "\n");
    431411                    }
    432412                }
     
    436416            unsigned column = 0;
    437417            computeLineAndColumn(line, column);
    438             log(indent, "line: ", line, "\n");
    439             log(indent, "column: ", column, "\n");
     418            out.print(indent, "line: ", line, "\n");
     419            out.print(indent, "column: ", column, "\n");
    440420
    441421            indent--;
     
    443423        indent--;
    444424    }
    445     log(indent, "}\n");
     425    out.print(indent, "}\n");
    446426}
    447427
  • trunk/Source/JavaScriptCore/interpreter/StackVisitor.h

    r199852 r201641  
    2828
    2929#include "VMEntryRecord.h"
     30#include <wtf/Indenter.h>
    3031#include <wtf/text/WTFString.h>
    3132
     
    7576        bool isInlinedFrame() const { return !!inlineCallFrame(); }
    7677
    77         JS_EXPORT_PRIVATE String functionName();
    78         JS_EXPORT_PRIVATE String sourceURL();
    79         JS_EXPORT_PRIVATE String toString();
     78        JS_EXPORT_PRIVATE String functionName() const;
     79        JS_EXPORT_PRIVATE String sourceURL() const;
     80        JS_EXPORT_PRIVATE String toString() const;
    8081
    8182        intptr_t sourceID();
    8283
    8384        CodeType codeType() const;
    84         JS_EXPORT_PRIVATE void computeLineAndColumn(unsigned& line, unsigned& column);
     85        JS_EXPORT_PRIVATE void computeLineAndColumn(unsigned& line, unsigned& column) const;
    8586
    8687        ClonedArguments* createArguments();
     
    8889        CallFrame* callFrame() const { return m_callFrame; }
    8990       
    90         JS_EXPORT_PRIVATE void print(int indentLevel);
     91        void dump(PrintStream&, Indenter = Indenter()) const;
     92        void dump(PrintStream&, Indenter, std::function<void(PrintStream&)> prefix) const;
    9193
    9294    private:
     
    9496        ~Frame() { }
    9597
    96         void retrieveExpressionInfo(int& divot, int& startOffset, int& endOffset, unsigned& line, unsigned& column);
     98        void retrieveExpressionInfo(int& divot, int& startOffset, int& endOffset, unsigned& line, unsigned& column) const;
    9799        void setToEnd();
    98100
  • trunk/Source/JavaScriptCore/tools/JSDollarVMPrototype.cpp

    r199745 r201641  
    327327    {
    328328        m_currentFrame++;
    329         if (m_currentFrame > m_framesToSkip)
    330             visitor->print(2);
    331        
     329        if (m_currentFrame > m_framesToSkip) {
     330            visitor->dump(WTF::dataFile(), Indenter(2), [&] (PrintStream& out) {
     331                out.print("[", (m_currentFrame - m_framesToSkip - 1), "] ");
     332            });
     333        }
    332334        if (m_action == PrintOne && m_currentFrame > m_framesToSkip)
    333335            return StackVisitor::Done;
  • trunk/Source/WTF/ChangeLog

    r201629 r201641  
     12016-06-03  Mark Lam  <mark.lam@apple.com>
     2
     3        Clean up how StackVisitor dumps its frames.
     4        https://bugs.webkit.org/show_bug.cgi?id=158316
     5
     6        Reviewed by Keith Miller.
     7
     8        Added an Indenter class what works with dataLog.
     9
     10        * WTF.xcodeproj/project.pbxproj:
     11        * wtf/Indenter.h: Added.
     12        (WTF::Indenter::Indenter):
     13        (WTF::Indenter::dump):
     14        (WTF::Indenter::operator++):
     15        (WTF::Indenter::operator--):
     16
    1172016-06-02  Said Abou-Hallawa  <sabouhallawa@apple,com>
    218
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r201518 r201641  
    320320                EB95E1F0161A72410089A2F5 /* ByteOrder.h in Headers */ = {isa = PBXBuildFile; fileRef = EB95E1EF161A72410089A2F5 /* ByteOrder.h */; };
    321321                FE8225311B2A1E5B00BA68FD /* NakedPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = FE8225301B2A1E5B00BA68FD /* NakedPtr.h */; };
     322                FE8925B01D00DAEC0046907E /* Indenter.h in Headers */ = {isa = PBXBuildFile; fileRef = FE8925AF1D00DAEC0046907E /* Indenter.h */; };
    322323                FEDACD3D1630F83F00C69634 /* StackStats.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEDACD3B1630F83F00C69634 /* StackStats.cpp */; };
    323324                FEDACD3E1630F83F00C69634 /* StackStats.h in Headers */ = {isa = PBXBuildFile; fileRef = FEDACD3C1630F83F00C69634 /* StackStats.h */; };
     
    651652                EB95E1EF161A72410089A2F5 /* ByteOrder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ByteOrder.h; sourceTree = "<group>"; };
    652653                FE8225301B2A1E5B00BA68FD /* NakedPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NakedPtr.h; sourceTree = "<group>"; };
     654                FE8925AF1D00DAEC0046907E /* Indenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Indenter.h; sourceTree = "<group>"; };
    653655                FEDACD3B1630F83F00C69634 /* StackStats.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StackStats.cpp; sourceTree = "<group>"; };
    654656                FEDACD3C1630F83F00C69634 /* StackStats.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StackStats.h; sourceTree = "<group>"; };
     
    856858                                A8A472BA151A825A004123FF /* HashTraits.h */,
    857859                                A8A472BB151A825A004123FF /* HexNumber.h */,
     860                                FE8925AF1D00DAEC0046907E /* Indenter.h */,
    858861                                2684D4351C000D400081D663 /* IndexSparseSet.h */,
    859862                                A8A472BC151A825A004123FF /* InlineASM.h */,
     
    13611364                                83FBA93219DF459700F30ADB /* TypeCasts.h in Headers */,
    13621365                                1AFDE648195201C300C48FFA /* TypeCastsCF.h in Headers */,
     1366                                FE8925B01D00DAEC0046907E /* Indenter.h in Headers */,
    13631367                                A8A4746D151A825B004123FF /* UnionFind.h in Headers */,
    13641368                                70ECA60F1B02426800449739 /* UniquedStringImpl.h in Headers */,
Note: See TracChangeset for help on using the changeset viewer.