agent/src/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File
*** old/agent/src/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java Thu Sep 17 16:09:23 2009
--- new/agent/src/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java Thu Sep 17 16:09:23 2009
*** 25,37 ****
--- 25,34 ----
package sun.jvm.hotspot.ui.classbrowser;
import java.io.*;
import java.util.*;
import sun.jvm.hotspot.asm.*;
import sun.jvm.hotspot.asm.sparc.*;
import sun.jvm.hotspot.asm.x86.*;
import sun.jvm.hotspot.asm.ia64.*;
import sun.jvm.hotspot.code.*;
import sun.jvm.hotspot.compiler.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.interpreter.*;
import sun.jvm.hotspot.memory.*;
*** 179,214 ****
--- 176,185 ----
spaces = " ";
tab = " ";
}
}
private static CPUHelper cpuHelper;
static {
VM.registerVMInitializedObserver(new Observer() {
public void update(Observable o, Object data) {
initialize();
}
});
}
private static synchronized void initialize() {
String cpu = VM.getVM().getCPU();
if (cpu.equals("sparc")) {
cpuHelper = new SPARCHelper();
} else if (cpu.equals("x86")) {
cpuHelper = new X86Helper();
} else if (cpu.equals("ia64")) {
cpuHelper = new IA64Helper();
} else {
throw new RuntimeException("cpu '" + cpu + "' is not yet supported!");
}
}
protected static synchronized CPUHelper getCPUHelper() {
return cpuHelper;
}
protected String escapeHTMLSpecialChars(String value) {
if (!genHTML) return value;
Formatter buf = new Formatter(genHTML);
int len = value.length();
*** 773,786 ****
--- 744,753 ----
} catch (Exception exp) {
return genHTMLErrorMessage(exp);
}
}
protected Disassembler createDisassembler(long startPc, byte[] code) {
return getCPUHelper().createDisassembler(startPc, code);
}
protected SymbolFinder createSymbolFinder() {
return new DummySymbolFinder();
}
// genHTML for a given address. Address may be a PC or
*** 834,863 ****
--- 801,822 ----
// didn't find any. do raw disassembly.
return genHTMLForRawDisassembly(pc, null);
}
protected byte[] readBuffer(sun.jvm.hotspot.debugger.Address addr, int size) {
byte[] buf = new byte[size];
for (int b = 0; b < size; b++) {
buf[b] = (byte) addr.getJByteAt(b);
}
return buf;
}
public String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address startPc, int size) {
try {
! return genHTMLForRawDisassembly(startPc, null, readBuffer(startPc, size));
! return genHTMLForRawDisassembly(startPc, size, null);
} catch (Exception exp) {
return genHTMLErrorMessage(exp);
}
}
protected String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address startPc,
String prevPCs) {
try {
! return genHTMLForRawDisassembly(startPc, prevPCs, readBuffer(startPc, NATIVE_CODE_SIZE));
! return genHTMLForRawDisassembly(startPc, NATIVE_CODE_SIZE, prevPCs);
} catch (Exception exp) {
return genHTMLErrorMessage(exp);
}
}
*** 870,955 ****
--- 829,957 ----
buf.append("pc_multiple=");
buf.append(pcs);
return buf.toString();
}
- protected String genPCHref(long currentPc, sun.jvm.hotspot.asm.Address addr) {
! String href = null;
if (addr instanceof PCRelativeAddress) {
PCRelativeAddress pcRelAddr = (PCRelativeAddress) addr;
href = genPCHref(currentPc + pcRelAddr.getDisplacement());
} else if(addr instanceof DirectAddress) {
href = genPCHref(((DirectAddress) addr).getValue());
! return genPCHref(addressToLong(addr));
}
return href;
}
class RawCodeVisitor implements InstructionVisitor {
+ class HTMLDisassembler implements InstructionVisitor {
private int instrSize = 0;
private Formatter buf;
private SymbolFinder symFinder = createSymbolFinder();
+ private long pc;
+ private OopMapSet oms;
+ private CodeBlob blob;
+ private NMethod nmethod;
! RawCodeVisitor(Formatter buf) {
! HTMLDisassembler(Formatter buf, CodeBlob blob) {
this.buf = buf;
+ this.blob = blob;
+ if (blob != null) {
+ if (blob instanceof NMethod) {
+ nmethod = (NMethod)blob;
}
+ oms = blob.getOopMaps();
+ }
+ }
public int getInstructionSize() {
return instrSize;
}
public void prologue() {
}
! public void visit(long currentPc, Instruction instr) {
! String href = null;
if (instr.isCall()) {
! CallInstruction call = (CallInstruction) instr;
sun.jvm.hotspot.asm.Address addr = call.getBranchDestination();
! href = genPCHref(currentPc, addr);
! public void beginInstruction(long currentPc) {
! pc = currentPc;
+
! Address adr = longToAddress(pc);
+ if (nmethod != null) {
! if (adr.equals(nmethod.getEntryPoint())) print("[Entry Point]\n");
+ if (adr.equals(nmethod.getVerifiedEntryPoint())) print("[Verified Entry Point]\n");
+ if (adr.equals(nmethod.exceptionBegin())) print("[Exception Handler]\n");
+ if (adr.equals(nmethod.stubBegin())) print("[Stub Code]\n");
+ // if (adr.equals(nmethod.constsBegin())) print("[Constants]\n");
}
! instrSize += instr.getSize();
buf.append("0x");
buf.append(Long.toHexString(currentPc));
! buf.append(adr.toString());
buf.append(':');
buf.append(tab);
+ }
! if (href != null) {
! buf.link(href, instr.asString(currentPc, symFinder));
! public void printAddress(long address) {
! Address addr = longToAddress(address);
+ if (VM.getVM().getCodeCache().contains(addr)) {
+ buf.link(genPCHref(address), addr.toString());
} else {
! buf.append(instr.asString(currentPc, symFinder));
! buf.append(addr.toString());
}
+ }
+
+ public void print(String s) {
+ buf.append(s);
+ }
+
+ public void endInstruction(long endPc) {
+ instrSize += endPc - pc;
+ if (genHTML) buf.br();
+
+ if (nmethod != null) {
+ ScopeDesc sd = nmethod.scope_desc_in(pc, endPc);
+ if (sd != null) {
buf.br();
+ buf.append(genSafepointInfo(nmethod, sd));
}
+ }
+ if (oms != null) {
+ long base = addressToLong(blob.instructionsBegin());
+ for (int i = 0, imax = (int)oms.getSize(); i < imax; i++) {
+ OopMap om = oms.getMapAt(i);
+ long omspc = base + om.getOffset();
+ if (omspc > pc) {
+ if (omspc <= endPc) {
+ buf.br();
+ buf.append(genOopMapInfo(om));
+ // st.move_to(column);
+ // visitor.print("; ");
+ // om.print_on(st);
+ }
+ break;
+ }
+ }
+ }
+ // follow each complete insn by a nice newline
+ buf.br();
+ }
+
public void epilogue() {
}
};
protected String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address addr,
! String prevPCs,
! byte[] code) {
! int size,
! String prevPCs) {
try {
long startPc = addressToLong(addr);
Disassembler disasm = createDisassembler(startPc, code);
final Formatter buf = new Formatter(genHTML);
! buf.genHTMLPrologue("Disassembly @0x" + Long.toHexString(startPc));
! buf.genHTMLPrologue("Disassembly @ " + addr);
if (prevPCs != null && genHTML) {
buf.beginTag("p");
buf.link(genMultPCHref(prevPCs), "show previous code ..");
buf.endTag("p");
}
buf.h3("Code");
! RawCodeVisitor visitor = new RawCodeVisitor(buf);
! disasm.decode(visitor);
! HTMLDisassembler visitor = new HTMLDisassembler(buf, null);
! Disassembler.decode(visitor, null, addr, addr.addOffsetTo(size));
if (genHTML) buf.beginTag("p");
Formatter tmpBuf = new Formatter(genHTML);
+ long startPc = addressToLong(addr);
tmpBuf.append("0x");
tmpBuf.append(Long.toHexString(startPc + visitor.getInstructionSize()).toString());
tmpBuf.append(",0x");
tmpBuf.append(Long.toHexString(startPc));
if (prevPCs != null) {
*** 966,984 ****
--- 968,984 ----
} catch (Exception exp) {
return genHTMLErrorMessage(exp);
}
}
! protected String genSafepointInfo(NMethod nm, PCDesc pcDesc) {
ScopeDesc sd = nm.getScopeDescAt(pcDesc.getRealPC(nm));
! protected String genSafepointInfo(NMethod nm, ScopeDesc sd) {
Formatter buf = new Formatter(genHTML);
Formatter tabs = new Formatter(genHTML);
buf.beginTag("pre");
genScope(buf, tabs, sd);
buf.endTag("pre");
buf.append(genOopMapInfo(nm, pcDesc));
return buf.toString();
}
protected void genScope(Formatter buf, Formatter tabs, ScopeDesc sd) {
*** 1076,1086 ****
--- 1076,1086 ----
oms = new OopMapStream(map, OopMapValue.OopTypes.VALUE_VALUE);
buf.append(omvIterator.iterate(oms, "Value:", false));
oms = new OopMapStream(map, OopMapValue.OopTypes.NARROWOOP_VALUE);
! buf.append(omvIterator.iterate(oms, "NarrowOop:", false));
oms = new OopMapStream(map, OopMapValue.OopTypes.CALLEE_SAVED_VALUE);
buf.append(omvIterator.iterate(oms, "Callee saved:", true));
oms = new OopMapStream(map, OopMapValue.OopTypes.DERIVED_OOP_VALUE);
*** 1269,1356 ****
--- 1269,1279 ----
buf.genHTMLPrologue(genNMethodTitle(nmethod));
buf.h3("Method");
buf.append(genMethodAndKlassLink(nmethod.getMethod()));
buf.h3("Compiled Code");
! sun.jvm.hotspot.debugger.Address codeBegin = nmethod.codeBegin();
sun.jvm.hotspot.debugger.Address codeEnd = nmethod.codeEnd();
final int codeSize = (int)codeEnd.minus(codeBegin);
final long startPc = addressToLong(codeBegin);
final byte[] code = new byte[codeSize];
for (int i=0; i < code.length; i++)
code[i] = codeBegin.getJByteAt(i);
final long verifiedEntryPoint = addressToLong(nmethod.getVerifiedEntryPoint());
final long entryPoint = addressToLong(nmethod.getEntryPoint());
final Map safepoints = nmethod.getSafepoints();
final SymbolFinder symFinder = createSymbolFinder();
final Disassembler disasm = createDisassembler(startPc, code);
class NMethodVisitor implements InstructionVisitor {
boolean prevWasCall;
public void prologue() {
prevWasCall = false;
}
public void visit(long currentPc, Instruction instr) {
String href = null;
if (instr.isCall()) {
CallInstruction call = (CallInstruction) instr;
sun.jvm.hotspot.asm.Address addr = call.getBranchDestination();
href = genPCHref(currentPc, addr);
}
if (currentPc == verifiedEntryPoint) {
buf.bold("Verified Entry Point"); buf.br();
}
if (currentPc == entryPoint) {
buf.bold(">Entry Point"); buf.br();
}
PCDesc pcDesc = (PCDesc) safepoints.get(longToAddress(currentPc));
boolean isSafepoint = (pcDesc != null);
if (isSafepoint && prevWasCall) {
buf.append(genSafepointInfo(nmethod, pcDesc));
}
buf.append("0x");
buf.append(Long.toHexString(currentPc));
buf.append(':');
buf.append(tab);
if (href != null) {
buf.link(href, instr.asString(currentPc, symFinder));
} else {
buf.append(instr.asString(currentPc, symFinder));
}
if (isSafepoint && !prevWasCall) {
buf.append(genSafepointInfo(nmethod, pcDesc));
}
buf.br();
prevWasCall = instr.isCall();
}
public void epilogue() {
}
};
disasm.decode(new NMethodVisitor());
sun.jvm.hotspot.debugger.Address stubBegin = nmethod.stubBegin();
if (stubBegin != null) {
sun.jvm.hotspot.debugger.Address stubEnd = nmethod.stubEnd();
buf.h3("Stub");
long stubStartPc = addressToLong(stubBegin);
long stubEndPc = addressToLong(stubEnd);
int range = (int) (stubEndPc - stubStartPc);
byte[] stubCode = readBuffer(stubBegin, range);
Disassembler disasm2 = createDisassembler(stubStartPc, stubCode);
disasm2.decode(new NMethodVisitor());
}
! Disassembler.decode(new HTMLDisassembler(buf, nmethod), nmethod);
buf.genHTMLEpilogue();
return buf.toString();
} catch (Exception exp) {
return genHTMLErrorMessage(exp);
}
*** 1361,1437 ****
--- 1284,1295 ----
final Formatter buf = new Formatter(genHTML);
buf.genHTMLPrologue(genCodeBlobTitle(blob));
buf.h3("CodeBlob");
buf.h3("Compiled Code");
! final sun.jvm.hotspot.debugger.Address codeBegin = blob.instructionsBegin();
final int codeSize = blob.getInstructionsSize();
final long startPc = addressToLong(codeBegin);
final byte[] code = new byte[codeSize];
for (int i=0; i < code.length; i++)
code[i] = codeBegin.getJByteAt(i);
! Disassembler.decode(new HTMLDisassembler(buf, blob), blob);
final SymbolFinder symFinder = createSymbolFinder();
final Disassembler disasm = createDisassembler(startPc, code);
class CodeBlobVisitor implements InstructionVisitor {
OopMapSet maps;
OopMap curMap;
int curMapIndex;
long curMapOffset;
public void prologue() {
maps = blob.getOopMaps();
if (maps != null && (maps.getSize() > 0)) {
curMap = maps.getMapAt(0);
if (curMap != null) {
curMapOffset = curMap.getOffset();
}
}
}
public void visit(long currentPc, Instruction instr) {
String href = null;
if (instr.isCall()) {
CallInstruction call = (CallInstruction) instr;
sun.jvm.hotspot.asm.Address addr = call.getBranchDestination();
href = genPCHref(currentPc, addr);
}
buf.append("0x");
buf.append(Long.toHexString(currentPc));
buf.append(':');
buf.append(tab);
if (href != null) {
buf.link(href, instr.asString(currentPc, symFinder));
} else {
buf.append(instr.asString(currentPc, symFinder));
}
buf.br();
// See whether we have an oop map at this PC
if (curMap != null) {
long curOffset = currentPc - startPc;
if (curOffset == curMapOffset) {
buf.append(genOopMapInfo(curMap));
if (++curMapIndex >= maps.getSize()) {
curMap = null;
} else {
curMap = maps.getMapAt(curMapIndex);
if (curMap != null) {
curMapOffset = curMap.getOffset();
}
}
}
}
}
public void epilogue() {
}
};
disasm.decode(new CodeBlobVisitor());
buf.genHTMLEpilogue();
return buf.toString();
} catch (Exception exp) {
return genHTMLErrorMessage(exp);
}
*** 1497,1514 ****
--- 1355,1367 ----
buf.h3("Previous Codelet = 0x" + Long.toHexString(addressToLong(prev.codeBegin())));
}
}
buf.h3("Code");
long stubStartPc = addressToLong(codelet.codeBegin());
! long stubEndPc = addressToLong(codelet.codeEnd());
int range = (int) (stubEndPc - stubStartPc);
byte[] stubCode = readBuffer(codelet.codeBegin(), range);
Disassembler disasm = createDisassembler(stubStartPc, stubCode);
disasm.decode(new RawCodeVisitor(buf));
+ Disassembler.decode(new HTMLDisassembler(buf, null), null,
! codelet.codeBegin(), codelet.codeEnd());
Stub next = stubq.getNext(codelet);
if (next != null) {
if (genHTML) {
buf.beginTag("h3");
buf.link(genPCHref(addressToLong(next.codeBegin())), "View Next Codelet");
agent/src/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File