~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/JavaScriptCore/dfg/DFGDisassembler.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Apple Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
7
 * 1. Redistributions of source code must retain the above copyright
 
8
 *    notice, this list of conditions and the following disclaimer.
 
9
 * 2. Redistributions in binary form must reproduce the above copyright
 
10
 *    notice, this list of conditions and the following disclaimer in the
 
11
 *    documentation and/or other materials provided with the distribution.
 
12
 *
 
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 
24
 */
 
25
 
 
26
#include "config.h"
 
27
#include "DFGDisassembler.h"
 
28
 
 
29
#if ENABLE(DFG_JIT)
 
30
 
 
31
#include "CodeBlockWithJITType.h"
 
32
#include "DFGGraph.h"
 
33
 
 
34
namespace JSC { namespace DFG {
 
35
 
 
36
Disassembler::Disassembler(Graph& graph)
 
37
    : m_graph(graph)
 
38
{
 
39
    m_labelForBlockIndex.resize(graph.m_blocks.size());
 
40
    m_labelForNodeIndex.resize(graph.size());
 
41
}
 
42
 
 
43
void Disassembler::dump(PrintStream& out, LinkBuffer& linkBuffer)
 
44
{
 
45
    m_graph.m_dominators.computeIfNecessary(m_graph);
 
46
    
 
47
    out.print("Generated JIT code for ", CodeBlockWithJITType(m_graph.m_codeBlock, JITCode::DFGJIT), ", instruction count = ", m_graph.m_codeBlock->instructionCount(), ":\n");
 
48
    out.print("    Code at [", RawPointer(linkBuffer.debugAddress()), ", ", RawPointer(static_cast<char*>(linkBuffer.debugAddress()) + linkBuffer.debugSize()), "):\n");
 
49
    
 
50
    const char* prefix = "    ";
 
51
    const char* disassemblyPrefix = "        ";
 
52
    
 
53
    NodeIndex lastNodeIndex = NoNode;
 
54
    MacroAssembler::Label previousLabel = m_startOfCode;
 
55
    for (size_t blockIndex = 0; blockIndex < m_graph.m_blocks.size(); ++blockIndex) {
 
56
        BasicBlock* block = m_graph.m_blocks[blockIndex].get();
 
57
        if (!block)
 
58
            continue;
 
59
        dumpDisassembly(out, disassemblyPrefix, linkBuffer, previousLabel, m_labelForBlockIndex[blockIndex], lastNodeIndex);
 
60
        m_graph.dumpBlockHeader(out, prefix, blockIndex, Graph::DumpLivePhisOnly);
 
61
        NodeIndex lastNodeIndexForDisassembly = block->at(0);
 
62
        for (size_t i = 0; i < block->size(); ++i) {
 
63
            if (!m_graph[block->at(i)].willHaveCodeGenOrOSR() && !Options::showAllDFGNodes())
 
64
                continue;
 
65
            MacroAssembler::Label currentLabel;
 
66
            if (m_labelForNodeIndex[block->at(i)].isSet())
 
67
                currentLabel = m_labelForNodeIndex[block->at(i)];
 
68
            else {
 
69
                // Dump the last instruction by using the first label of the next block
 
70
                // as the end point. This case is hit either during peephole compare
 
71
                // optimizations (the Branch won't have its own label) or if we have a
 
72
                // forced OSR exit.
 
73
                if (blockIndex + 1 < m_graph.m_blocks.size())
 
74
                    currentLabel = m_labelForBlockIndex[blockIndex + 1];
 
75
                else
 
76
                    currentLabel = m_endOfMainPath;
 
77
            }
 
78
            dumpDisassembly(out, disassemblyPrefix, linkBuffer, previousLabel, currentLabel, lastNodeIndexForDisassembly);
 
79
            m_graph.dumpCodeOrigin(out, prefix, lastNodeIndex, block->at(i));
 
80
            m_graph.dump(out, prefix, block->at(i));
 
81
            lastNodeIndex = block->at(i);
 
82
            lastNodeIndexForDisassembly = block->at(i);
 
83
        }
 
84
    }
 
85
    dumpDisassembly(out, disassemblyPrefix, linkBuffer, previousLabel, m_endOfMainPath, lastNodeIndex);
 
86
    out.print(prefix, "(End Of Main Path)\n");
 
87
    dumpDisassembly(out, disassemblyPrefix, linkBuffer, previousLabel, m_endOfCode, NoNode);
 
88
}
 
89
 
 
90
void Disassembler::dump(LinkBuffer& linkBuffer)
 
91
{
 
92
    dump(WTF::dataFile(), linkBuffer);
 
93
}
 
94
 
 
95
void Disassembler::dumpDisassembly(PrintStream& out, const char* prefix, LinkBuffer& linkBuffer, MacroAssembler::Label& previousLabel, MacroAssembler::Label currentLabel, NodeIndex context)
 
96
{
 
97
    size_t prefixLength = strlen(prefix);
 
98
    int amountOfNodeWhiteSpace;
 
99
    if (context == NoNode)
 
100
        amountOfNodeWhiteSpace = 0;
 
101
    else
 
102
        amountOfNodeWhiteSpace = Graph::amountOfNodeWhiteSpace(m_graph[context]);
 
103
    OwnArrayPtr<char> prefixBuffer = adoptArrayPtr(new char[prefixLength + amountOfNodeWhiteSpace + 1]);
 
104
    strcpy(prefixBuffer.get(), prefix);
 
105
    for (int i = 0; i < amountOfNodeWhiteSpace; ++i)
 
106
        prefixBuffer[i + prefixLength] = ' ';
 
107
    prefixBuffer[prefixLength + amountOfNodeWhiteSpace] = 0;
 
108
    
 
109
    CodeLocationLabel start = linkBuffer.locationOf(previousLabel);
 
110
    CodeLocationLabel end = linkBuffer.locationOf(currentLabel);
 
111
    previousLabel = currentLabel;
 
112
    ASSERT(bitwise_cast<uintptr_t>(end.executableAddress()) >= bitwise_cast<uintptr_t>(start.executableAddress()));
 
113
    disassemble(start, bitwise_cast<uintptr_t>(end.executableAddress()) - bitwise_cast<uintptr_t>(start.executableAddress()), prefixBuffer.get(), out);
 
114
}
 
115
 
 
116
} } // namespace JSC::DFG
 
117
 
 
118
#endif // ENABLE(DFG_JIT)