|
| 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 "DFGGraph.h" |
| 32 | + |
| 33 | +namespace JSC { namespace DFG { |
| 34 | + |
| 35 | +Disassembler::Disassembler(Graph& graph) |
| 36 | + : m_graph(graph) |
| 37 | +{ |
| 38 | + m_labelForBlockIndex.resize(graph.m_blocks.size()); |
| 39 | + m_labelForNodeIndex.resize(graph.size()); |
| 40 | +} |
| 41 | + |
| 42 | +void Disassembler::dump(LinkBuffer& linkBuffer) |
| 43 | +{ |
| 44 | + m_graph.m_dominators.computeIfNecessary(m_graph); |
| 45 | + |
| 46 | + dataLog("Generated JIT code for DFG CodeBlock %p:\n", m_graph.m_codeBlock); |
| 47 | + dataLog(" Code at [%p, %p):\n", linkBuffer.debugAddress(), static_cast<char*>(linkBuffer.debugAddress()) + linkBuffer.debugSize()); |
| 48 | + |
| 49 | + const char* prefix = " "; |
| 50 | + const char* disassemblyPrefix = " "; |
| 51 | + |
| 52 | + NodeIndex lastNodeIndex = NoNode; |
| 53 | + MacroAssembler::Label previousLabel = m_startOfCode; |
| 54 | + for (size_t blockIndex = 0; blockIndex < m_graph.m_blocks.size(); ++blockIndex) { |
| 55 | + BasicBlock* block = m_graph.m_blocks[blockIndex].get(); |
| 56 | + if (!block) |
| 57 | + continue; |
| 58 | + dumpDisassembly(disassemblyPrefix, linkBuffer, previousLabel, m_labelForBlockIndex[blockIndex], lastNodeIndex); |
| 59 | + m_graph.dumpBlockHeader(prefix, blockIndex, Graph::DumpLivePhisOnly); |
| 60 | + NodeIndex lastNodeIndexForDisassembly = block->at(0); |
| 61 | + for (size_t i = 0; i < block->size(); ++i) { |
| 62 | + if (!m_graph[block->at(i)].willHaveCodeGen()) |
| 63 | + continue; |
| 64 | + MacroAssembler::Label currentLabel; |
| 65 | + if (m_labelForNodeIndex[block->at(i)].isSet()) |
| 66 | + currentLabel = m_labelForNodeIndex[block->at(i)]; |
| 67 | + else { |
| 68 | + // Dump the last instruction by using the first label of the next block |
| 69 | + // as the end point. This case is hit either during peephole compare |
| 70 | + // optimizations (the Branch won't have its own label) or if we have a |
| 71 | + // forced OSR exit. |
| 72 | + if (blockIndex + 1 < m_graph.m_blocks.size()) |
| 73 | + currentLabel = m_labelForBlockIndex[blockIndex + 1]; |
| 74 | + else |
| 75 | + currentLabel = m_endOfMainPath; |
| 76 | + } |
| 77 | + dumpDisassembly(disassemblyPrefix, linkBuffer, previousLabel, currentLabel, lastNodeIndexForDisassembly); |
| 78 | + m_graph.dumpCodeOrigin(prefix, lastNodeIndex, block->at(i)); |
| 79 | + m_graph.dump(prefix, block->at(i)); |
| 80 | + lastNodeIndex = block->at(i); |
| 81 | + lastNodeIndexForDisassembly = block->at(i); |
| 82 | + } |
| 83 | + } |
| 84 | + dumpDisassembly(disassemblyPrefix, linkBuffer, previousLabel, m_endOfMainPath, lastNodeIndex); |
| 85 | + dataLog("%s(End Of Main Path)\n", prefix); |
| 86 | + dumpDisassembly(disassemblyPrefix, linkBuffer, previousLabel, m_endOfCode, NoNode); |
| 87 | +} |
| 88 | + |
| 89 | +void Disassembler::dumpDisassembly(const char* prefix, LinkBuffer& linkBuffer, MacroAssembler::Label& previousLabel, MacroAssembler::Label currentLabel, NodeIndex context) |
| 90 | +{ |
| 91 | + size_t prefixLength = strlen(prefix); |
| 92 | + int amountOfNodeWhiteSpace; |
| 93 | + if (context == NoNode) |
| 94 | + amountOfNodeWhiteSpace = 0; |
| 95 | + else |
| 96 | + amountOfNodeWhiteSpace = Graph::amountOfNodeWhiteSpace(m_graph[context]); |
| 97 | + OwnArrayPtr<char> prefixBuffer = adoptArrayPtr(new char[prefixLength + amountOfNodeWhiteSpace + 1]); |
| 98 | + strcpy(prefixBuffer.get(), prefix); |
| 99 | + for (int i = 0; i < amountOfNodeWhiteSpace; ++i) |
| 100 | + prefixBuffer[i + prefixLength] = ' '; |
| 101 | + prefixBuffer[prefixLength + amountOfNodeWhiteSpace] = 0; |
| 102 | + |
| 103 | + CodeLocationLabel start = linkBuffer.locationOf(previousLabel); |
| 104 | + CodeLocationLabel end = linkBuffer.locationOf(currentLabel); |
| 105 | + previousLabel = currentLabel; |
| 106 | + ASSERT(bitwise_cast<uintptr_t>(end.executableAddress()) >= bitwise_cast<uintptr_t>(start.executableAddress())); |
| 107 | + if (tryToDisassemble(start, bitwise_cast<uintptr_t>(end.executableAddress()) - bitwise_cast<uintptr_t>(start.executableAddress()), prefixBuffer.get(), WTF::dataFile())) |
| 108 | + return; |
| 109 | + |
| 110 | + dataLog("%s disassembly not available for range %p...%p\n", prefixBuffer.get(), start.executableAddress(), end.executableAddress()); |
| 111 | +} |
| 112 | + |
| 113 | +} } // namespace JSC::DFG |
| 114 | + |
| 115 | +#endif // ENABLE(DFG_JIT) |
0 commit comments