Commit 1bf96d6e authored by fpizlo@apple.com's avatar fpizlo@apple.com

Disassembly methods should be able to disassemble to any PrintStream& rather...

Disassembly methods should be able to disassemble to any PrintStream& rather than always using WTF::dataFile()
https://bugs.webkit.org/show_bug.cgi?id=103492

Reviewed by Mark Hahnenberg.

Switched disassembly code to use PrintStream&, and to use print() rather than printf().

* dfg/DFGDisassembler.cpp:
(JSC::DFG::Disassembler::dump):
(DFG):
(JSC::DFG::Disassembler::dumpDisassembly):
* dfg/DFGDisassembler.h:
(Disassembler):
* dfg/DFGGraph.cpp:
(JSC::DFG::printWhiteSpace):
(JSC::DFG::Graph::dumpCodeOrigin):
(JSC::DFG::Graph::printNodeWhiteSpace):
(JSC::DFG::Graph::dump):
(DFG):
(JSC::DFG::Graph::dumpBlockHeader):
* dfg/DFGGraph.h:
(Graph):
* jit/JITDisassembler.cpp:
(JSC::JITDisassembler::dump):
(JSC::JITDisassembler::dumpForInstructions):
(JSC::JITDisassembler::dumpDisassembly):
* jit/JITDisassembler.h:
(JITDisassembler):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@136069 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 250df02c
2012-11-28 Filip Pizlo <fpizlo@apple.com>
Disassembly methods should be able to disassemble to any PrintStream& rather than always using WTF::dataFile()
https://bugs.webkit.org/show_bug.cgi?id=103492
Reviewed by Mark Hahnenberg.
Switched disassembly code to use PrintStream&, and to use print() rather than printf().
* dfg/DFGDisassembler.cpp:
(JSC::DFG::Disassembler::dump):
(DFG):
(JSC::DFG::Disassembler::dumpDisassembly):
* dfg/DFGDisassembler.h:
(Disassembler):
* dfg/DFGGraph.cpp:
(JSC::DFG::printWhiteSpace):
(JSC::DFG::Graph::dumpCodeOrigin):
(JSC::DFG::Graph::printNodeWhiteSpace):
(JSC::DFG::Graph::dump):
(DFG):
(JSC::DFG::Graph::dumpBlockHeader):
* dfg/DFGGraph.h:
(Graph):
* jit/JITDisassembler.cpp:
(JSC::JITDisassembler::dump):
(JSC::JITDisassembler::dumpForInstructions):
(JSC::JITDisassembler::dumpDisassembly):
* jit/JITDisassembler.h:
(JITDisassembler):
2012-11-28 Filip Pizlo <fpizlo@apple.com>
It should be possible to say dataLog("count = ", count, "\n") instead of dataLogF("count = %d\n", count)
......
......@@ -39,12 +39,12 @@ Disassembler::Disassembler(Graph& graph)
m_labelForNodeIndex.resize(graph.size());
}
void Disassembler::dump(LinkBuffer& linkBuffer)
void Disassembler::dump(PrintStream& out, LinkBuffer& linkBuffer)
{
m_graph.m_dominators.computeIfNecessary(m_graph);
dataLogF("Generated JIT code for DFG CodeBlock %p, instruction count = %u:\n", m_graph.m_codeBlock, m_graph.m_codeBlock->instructionCount());
dataLogF(" Code at [%p, %p):\n", linkBuffer.debugAddress(), static_cast<char*>(linkBuffer.debugAddress()) + linkBuffer.debugSize());
out.print("Generated JIT code for DFG CodeBlock ", RawPointer(m_graph.m_codeBlock), ", instruction count = ", m_graph.m_codeBlock->instructionCount(), ":\n");
out.print(" Code at [", RawPointer(linkBuffer.debugAddress()), ", ", RawPointer(static_cast<char*>(linkBuffer.debugAddress()) + linkBuffer.debugSize()), "):\n");
const char* prefix = " ";
const char* disassemblyPrefix = " ";
......@@ -55,8 +55,8 @@ void Disassembler::dump(LinkBuffer& linkBuffer)
BasicBlock* block = m_graph.m_blocks[blockIndex].get();
if (!block)
continue;
dumpDisassembly(disassemblyPrefix, linkBuffer, previousLabel, m_labelForBlockIndex[blockIndex], lastNodeIndex);
m_graph.dumpBlockHeader(prefix, blockIndex, Graph::DumpLivePhisOnly);
dumpDisassembly(out, disassemblyPrefix, linkBuffer, previousLabel, m_labelForBlockIndex[blockIndex], lastNodeIndex);
m_graph.dumpBlockHeader(out, prefix, blockIndex, Graph::DumpLivePhisOnly);
NodeIndex lastNodeIndexForDisassembly = block->at(0);
for (size_t i = 0; i < block->size(); ++i) {
if (!m_graph[block->at(i)].willHaveCodeGenOrOSR() && !Options::showAllDFGNodes())
......@@ -74,19 +74,24 @@ void Disassembler::dump(LinkBuffer& linkBuffer)
else
currentLabel = m_endOfMainPath;
}
dumpDisassembly(disassemblyPrefix, linkBuffer, previousLabel, currentLabel, lastNodeIndexForDisassembly);
m_graph.dumpCodeOrigin(prefix, lastNodeIndex, block->at(i));
m_graph.dump(prefix, block->at(i));
dumpDisassembly(out, disassemblyPrefix, linkBuffer, previousLabel, currentLabel, lastNodeIndexForDisassembly);
m_graph.dumpCodeOrigin(out, prefix, lastNodeIndex, block->at(i));
m_graph.dump(out, prefix, block->at(i));
lastNodeIndex = block->at(i);
lastNodeIndexForDisassembly = block->at(i);
}
}
dumpDisassembly(disassemblyPrefix, linkBuffer, previousLabel, m_endOfMainPath, lastNodeIndex);
dataLogF("%s(End Of Main Path)\n", prefix);
dumpDisassembly(disassemblyPrefix, linkBuffer, previousLabel, m_endOfCode, NoNode);
dumpDisassembly(out, disassemblyPrefix, linkBuffer, previousLabel, m_endOfMainPath, lastNodeIndex);
out.print(prefix, "(End Of Main Path)\n");
dumpDisassembly(out, disassemblyPrefix, linkBuffer, previousLabel, m_endOfCode, NoNode);
}
void Disassembler::dump(LinkBuffer& linkBuffer)
{
dump(WTF::dataFile(), linkBuffer);
}
void Disassembler::dumpDisassembly(const char* prefix, LinkBuffer& linkBuffer, MacroAssembler::Label& previousLabel, MacroAssembler::Label currentLabel, NodeIndex context)
void Disassembler::dumpDisassembly(PrintStream& out, const char* prefix, LinkBuffer& linkBuffer, MacroAssembler::Label& previousLabel, MacroAssembler::Label currentLabel, NodeIndex context)
{
size_t prefixLength = strlen(prefix);
int amountOfNodeWhiteSpace;
......@@ -104,7 +109,7 @@ void Disassembler::dumpDisassembly(const char* prefix, LinkBuffer& linkBuffer, M
CodeLocationLabel end = linkBuffer.locationOf(currentLabel);
previousLabel = currentLabel;
ASSERT(bitwise_cast<uintptr_t>(end.executableAddress()) >= bitwise_cast<uintptr_t>(start.executableAddress()));
disassemble(start, bitwise_cast<uintptr_t>(end.executableAddress()) - bitwise_cast<uintptr_t>(start.executableAddress()), prefixBuffer.get(), WTF::dataFile());
disassemble(start, bitwise_cast<uintptr_t>(end.executableAddress()) - bitwise_cast<uintptr_t>(start.executableAddress()), prefixBuffer.get(), out);
}
} } // namespace JSC::DFG
......
......@@ -62,10 +62,11 @@ public:
m_endOfCode = label;
}
void dump(PrintStream&, LinkBuffer&);
void dump(LinkBuffer&);
private:
void dumpDisassembly(const char* prefix, LinkBuffer&, MacroAssembler::Label& previousLabel, MacroAssembler::Label currentLabel, NodeIndex context);
void dumpDisassembly(PrintStream&, const char* prefix, LinkBuffer&, MacroAssembler::Label& previousLabel, MacroAssembler::Label currentLabel, NodeIndex context);
Graph& m_graph;
MacroAssembler::Label m_startOfCode;
......
This diff is collapsed.
......@@ -190,16 +190,17 @@ public:
}
// CodeBlock is optional, but may allow additional information to be dumped (e.g. Identifier names).
void dump();
void dump(PrintStream& = WTF::dataFile());
enum PhiNodeDumpMode { DumpLivePhisOnly, DumpAllPhis };
void dumpBlockHeader(const char* prefix, BlockIndex, PhiNodeDumpMode);
void dump(const char* prefix, NodeIndex);
void dumpBlockHeader(PrintStream&, const char* prefix, BlockIndex, PhiNodeDumpMode);
void dump(PrintStream&, Edge);
void dump(PrintStream&, const char* prefix, NodeIndex);
static int amountOfNodeWhiteSpace(Node&);
static void printNodeWhiteSpace(Node&);
static void printNodeWhiteSpace(PrintStream&, Node&);
// Dump the code origin of the given node as a diff from the code origin of the
// preceding node.
void dumpCodeOrigin(const char* prefix, NodeIndex, NodeIndex);
void dumpCodeOrigin(PrintStream&, const char* prefix, NodeIndex, NodeIndex);
BlockIndex blockIndexForBytecodeOffset(Vector<BlockIndex>& blocks, unsigned bytecodeBegin);
......
......@@ -44,11 +44,11 @@ JITDisassembler::~JITDisassembler()
{
}
void JITDisassembler::dump(LinkBuffer& linkBuffer)
void JITDisassembler::dump(PrintStream& out, LinkBuffer& linkBuffer)
{
dataLogF("Baseline JIT code for CodeBlock %p, instruction count = %u:\n", m_codeBlock, m_codeBlock->instructionCount());
dataLogF(" Code at [%p, %p):\n", linkBuffer.debugAddress(), static_cast<char*>(linkBuffer.debugAddress()) + linkBuffer.debugSize());
dumpDisassembly(linkBuffer, m_startOfCode, m_labelForBytecodeIndexInMainPath[0]);
out.print("Baseline JIT code for CodeBlock ", RawPointer(m_codeBlock), ", instruction count = ", m_codeBlock->instructionCount(), "\n");
out.print(" Code at [", RawPointer(linkBuffer.debugAddress()), ", ", RawPointer(static_cast<char*>(linkBuffer.debugAddress()) + linkBuffer.debugSize()), "):\n");
dumpDisassembly(out, linkBuffer, m_startOfCode, m_labelForBytecodeIndexInMainPath[0]);
MacroAssembler::Label firstSlowLabel;
for (unsigned i = 0; i < m_labelForBytecodeIndexInSlowPath.size(); ++i) {
......@@ -57,30 +57,35 @@ void JITDisassembler::dump(LinkBuffer& linkBuffer)
break;
}
}
dumpForInstructions(linkBuffer, " ", m_labelForBytecodeIndexInMainPath, firstSlowLabel.isSet() ? firstSlowLabel : m_endOfSlowPath);
dataLogF(" (End Of Main Path)\n");
dumpForInstructions(linkBuffer, " (S) ", m_labelForBytecodeIndexInSlowPath, m_endOfSlowPath);
dataLogF(" (End Of Slow Path)\n");
dumpForInstructions(out, linkBuffer, " ", m_labelForBytecodeIndexInMainPath, firstSlowLabel.isSet() ? firstSlowLabel : m_endOfSlowPath);
out.print(" (End Of Main Path)\n");
dumpForInstructions(out, linkBuffer, " (S) ", m_labelForBytecodeIndexInSlowPath, m_endOfSlowPath);
out.print(" (End Of Slow Path)\n");
dumpDisassembly(out, linkBuffer, m_endOfSlowPath, m_endOfCode);
}
dumpDisassembly(linkBuffer, m_endOfSlowPath, m_endOfCode);
void JITDisassembler::dump(LinkBuffer& linkBuffer)
{
dump(WTF::dataFile(), linkBuffer);
}
void JITDisassembler::dumpForInstructions(LinkBuffer& linkBuffer, const char* prefix, Vector<MacroAssembler::Label>& labels, MacroAssembler::Label endLabel)
void JITDisassembler::dumpForInstructions(PrintStream& out, LinkBuffer& linkBuffer, const char* prefix, Vector<MacroAssembler::Label>& labels, MacroAssembler::Label endLabel)
{
for (unsigned i = 0 ; i < labels.size();) {
if (!labels[i].isSet()) {
i++;
continue;
}
dataLogF("%s", prefix);
out.print(prefix);
m_codeBlock->dump(i);
for (unsigned nextIndex = i + 1; ; nextIndex++) {
if (nextIndex >= labels.size()) {
dumpDisassembly(linkBuffer, labels[i], endLabel);
dumpDisassembly(out, linkBuffer, labels[i], endLabel);
return;
}
if (labels[nextIndex].isSet()) {
dumpDisassembly(linkBuffer, labels[i], labels[nextIndex]);
dumpDisassembly(out, linkBuffer, labels[i], labels[nextIndex]);
i = nextIndex;
break;
}
......@@ -88,11 +93,11 @@ void JITDisassembler::dumpForInstructions(LinkBuffer& linkBuffer, const char* pr
}
}
void JITDisassembler::dumpDisassembly(LinkBuffer& linkBuffer, MacroAssembler::Label from, MacroAssembler::Label to)
void JITDisassembler::dumpDisassembly(PrintStream& out, LinkBuffer& linkBuffer, MacroAssembler::Label from, MacroAssembler::Label to)
{
CodeLocationLabel fromLocation = linkBuffer.locationOf(from);
CodeLocationLabel toLocation = linkBuffer.locationOf(to);
disassemble(fromLocation, bitwise_cast<uintptr_t>(toLocation.executableAddress()) - bitwise_cast<uintptr_t>(fromLocation.executableAddress()), " ", WTF::dataFile());
disassemble(fromLocation, bitwise_cast<uintptr_t>(toLocation.executableAddress()) - bitwise_cast<uintptr_t>(fromLocation.executableAddress()), " ", out);
}
} // namespace JSC
......
......@@ -57,10 +57,11 @@ public:
void setEndOfCode(MacroAssembler::Label label) { m_endOfCode = label; }
void dump(LinkBuffer&);
void dump(PrintStream&, LinkBuffer&);
private:
void dumpForInstructions(LinkBuffer&, const char* prefix, Vector<MacroAssembler::Label>& labels, MacroAssembler::Label endLabel);
void dumpDisassembly(LinkBuffer&, MacroAssembler::Label from, MacroAssembler::Label to);
void dumpForInstructions(PrintStream&, LinkBuffer&, const char* prefix, Vector<MacroAssembler::Label>& labels, MacroAssembler::Label endLabel);
void dumpDisassembly(PrintStream&, LinkBuffer&, MacroAssembler::Label from, MacroAssembler::Label to);
CodeBlock* m_codeBlock;
MacroAssembler::Label m_startOfCode;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment