Ignore:
Timestamp:
Jun 28, 2012, 4:03:07 PM (13 years ago)
Author:
[email protected]
Message:

Adding a commenting utility to record BytecodeGenerator comments
with opcodes that are emitted. Presently, the comments can only
be constant strings. Adding comments for opcodes is optional.
If a comment is added, the comment will be printed following the
opcode when CodeBlock::dump() is called.

This utility is disabled by default, and is only meant for VM
development purposes. It should not be enabled for product builds.

To enable this utility, set ENABLE_BYTECODE_COMMENTS in CodeBlock.h
to 1.

https://bugs.webkit.org/show_bug.cgi?id=90095

Patch by Mark Lam <[email protected]> on 2012-06-28
Reviewed by Geoffrey Garen.

  • GNUmakefile.list.am:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::dumpBytecodeCommentAndNewLine): Dumps the comment.
(JSC):
(JSC::CodeBlock::printUnaryOp): Add comment dumps.
(JSC::CodeBlock::printBinaryOp): Add comment dumps.
(JSC::CodeBlock::printConditionalJump): Add comment dumps.
(JSC::CodeBlock::printCallOp): Add comment dumps.
(JSC::CodeBlock::printPutByIdOp): Add comment dumps.
(JSC::CodeBlock::dump): Add comment dumps.
(JSC::CodeBlock::CodeBlock):
(JSC::CodeBlock::commentForBytecodeOffset):

Finds the comment for an opcode if available.

(JSC::CodeBlock::dumpBytecodeComments):

For debugging whether comments are collected.
It is not being called anywhere.

  • bytecode/CodeBlock.h:

(CodeBlock):
(JSC::CodeBlock::bytecodeComments):

  • bytecode/Comment.h: Added.

(JSC):
(Comment):

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::emitOpcode): Calls emitComment().
(JSC):
(JSC::BytecodeGenerator::emitComment): Adds comment to CodeBlock.
(JSC::BytecodeGenerator::prependComment):

Registers a comment for emitComemnt() to use later.

  • bytecompiler/BytecodeGenerator.h:

(BytecodeGenerator):
(JSC::BytecodeGenerator::emitComment):
(JSC::BytecodeGenerator::prependComment):

These are inlined versions of these functions that nullify them
when ENABLE_BYTECODE_COMMENTS is 0.

(JSC::BytecodeGenerator::comments):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.h

    r121215 r121480  
    3636#include "CodeOrigin.h"
    3737#include "CodeType.h"
     38#include "Comment.h"
    3839#include "CompactJITCodeMap.h"
    3940#include "DFGCodeBlocks.h"
     
    6768#include <wtf/FastAllocBase.h>
    6869#include <wtf/PassOwnPtr.h>
     70#include <wtf/Platform.h>
    6971#include <wtf/RefPtr.h>
    7072#include <wtf/SegmentedVector.h>
    7173#include <wtf/Vector.h>
     74
     75// Set ENABLE_BYTECODE_COMMENTS to 1 to enable recording bytecode generator
     76// comments for the bytecodes that it generates. This will allow
     77// CodeBlock::dump() to provide some contextual info about the bytecodes.
     78//
     79// The way this comment system works is as follows:
     80// 1. The BytecodeGenerator calls prependComment() with a constant comment
     81//    string in .text. The string must not be a stack or heap allocated
     82//    string.
     83// 2. When the BytecodeGenerator's emitOpcode() is called, the last
     84//    prepended comment will be recorded with the PC of the opcode being
     85//    emitted. This comment is being recorded in the CodeBlock's
     86//    m_bytecodeComments.
     87// 3. When CodeBlock::dump() is called, it will pair up the comments with
     88//    their corresponding bytecodes based on the bytecode and comment's
     89//    PC. If a matching pair is found, the comment will be printed after
     90//    the bytecode. If not, no comment is printed.
     91//
     92// NOTE: Enabling this will consume additional memory at runtime to store
     93// the comments. Since these comments are only useful for VM debugging
     94// (as opposed to app debugging), this feature is to be disabled by default,
     95// and can be enabled as needed for VM development use only.
     96
     97#define ENABLE_BYTECODE_COMMENTS 0
    7298
    7399namespace JSC {
     
    155181            return index >= m_numVars;
    156182        }
     183
     184        void dumpBytecodeCommentAndNewLine(int location);
     185#if ENABLE(BYTECODE_COMMENTS)
     186        const char* commentForBytecodeOffset(unsigned bytecodeOffset);
     187        void dumpBytecodeComments();
     188#endif
    157189
    158190        HandlerInfo* handlerForBytecodeOffset(unsigned bytecodeOffset);
     
    366398        const RefCountedArray<Instruction>& instructions() const { return m_instructions; }
    367399       
     400#if ENABLE(BYTECODE_COMMENTS)
     401        Vector<Comment>& bytecodeComments() { return m_bytecodeComments; }
     402#endif
     403
    368404        size_t predictedMachineCodeSize();
    369405       
     
    13031339
    13041340        Vector<LineInfo> m_lineInfo;
     1341#if ENABLE(BYTECODE_COMMENTS)
     1342        Vector<Comment>  m_bytecodeComments;
     1343        size_t m_bytecodeCommentIterator;
     1344#endif
    13051345
    13061346        struct RareData {
Note: See TracChangeset for help on using the changeset viewer.