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 sadis Cdiff agent/src/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java

agent/src/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java

Print this page

        

*** 25,37 **** 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.*; --- 25,34 ----
*** 179,214 **** 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(); --- 176,185 ----
*** 773,786 **** } 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 --- 744,753 ----
*** 870,955 **** 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 href; ! } ! ! class RawCodeVisitor implements InstructionVisitor { private int instrSize = 0; private Formatter buf; private SymbolFinder symFinder = createSymbolFinder(); ! RawCodeVisitor(Formatter buf) { this.buf = buf; } 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); } - instrSize += instr.getSize(); 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(); } public void epilogue() { } }; protected String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address addr, String prevPCs, byte[] code) { try { - long startPc = addressToLong(addr); - Disassembler disasm = createDisassembler(startPc, code); final Formatter buf = new Formatter(genHTML); ! buf.genHTMLPrologue("Disassembly @0x" + Long.toHexString(startPc)); 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); if (genHTML) buf.beginTag("p"); Formatter tmpBuf = new Formatter(genHTML); tmpBuf.append("0x"); tmpBuf.append(Long.toHexString(startPc + visitor.getInstructionSize()).toString()); tmpBuf.append(",0x"); tmpBuf.append(Long.toHexString(startPc)); if (prevPCs != null) { --- 837,963 ---- buf.append("pc_multiple="); buf.append(pcs); return buf.toString(); } ! protected String genPCHref(Address addr) { ! return genPCHref(addressToLong(addr)); } ! 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; ! 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 beginInstruction(long currentPc) { ! pc = currentPc; ! ! if (nmethod != null) { ! if (pc == addressToLong(nmethod.getEntryPoint())) print("[Entry Point]\n"); ! if (pc == addressToLong(nmethod.getVerifiedEntryPoint())) print("[Verified Entry Point]\n"); ! if (pc == addressToLong(nmethod.exceptionBegin())) print("[Exception Handler]\n"); ! if (pc == addressToLong(nmethod.stubBegin())) print("[Stub Code]\n"); ! // if (p == addressToLong(nmethod.getConstsBegin())) print("[Constants]\n"); } buf.append("0x"); buf.append(Long.toHexString(currentPc)); buf.append(':'); buf.append(tab); + } ! public void printAddress(long address) { ! Address addr = longToAddress(address); ! if (VM.getVM().getCodeCache().contains(addr)) { ! buf.link(genPCHref(address), addr.toString()); } else { ! 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(nmethod.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; + } + } + } + } + public void epilogue() { } }; protected String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address addr, String prevPCs, byte[] code) { try { final Formatter buf = new Formatter(genHTML); ! buf.genHTMLPrologue("Disassembly @ " + addr); if (prevPCs != null && genHTML) { buf.beginTag("p"); buf.link(genMultPCHref(prevPCs), "show previous code .."); buf.endTag("p"); } buf.h3("Code"); ! HTMLDisassembler visitor = new HTMLDisassembler(buf, null); ! Disassembler.decode(visitor, null, addr, addr.addOffsetTo(code.length)); 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 **** } catch (Exception exp) { return genHTMLErrorMessage(exp); } } ! protected String genSafepointInfo(NMethod nm, PCDesc pcDesc) { ! ScopeDesc sd = nm.getScopeDescAt(pcDesc.getRealPC(nm)); 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) { --- 974,990 ---- } catch (Exception exp) { return genHTMLErrorMessage(exp); } } ! 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"); return buf.toString(); } protected void genScope(Formatter buf, Formatter tabs, ScopeDesc sd) {
*** 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, "Oop:", 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); --- 1082,1092 ---- 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 **** 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()); ! } buf.genHTMLEpilogue(); return buf.toString(); } catch (Exception exp) { return genHTMLErrorMessage(exp); } --- 1275,1285 ---- buf.genHTMLPrologue(genNMethodTitle(nmethod)); buf.h3("Method"); buf.append(genMethodAndKlassLink(nmethod.getMethod())); buf.h3("Compiled Code"); ! Disassembler.decode(new HTMLDisassembler(buf, nmethod), nmethod); buf.genHTMLEpilogue(); return buf.toString(); } catch (Exception exp) { return genHTMLErrorMessage(exp); }
*** 1361,1437 **** 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); - 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); } --- 1290,1301 ---- final Formatter buf = new Formatter(genHTML); buf.genHTMLPrologue(genCodeBlobTitle(blob)); buf.h3("CodeBlob"); buf.h3("Compiled Code"); ! Disassembler.decode(new HTMLDisassembler(buf, blob), blob); buf.genHTMLEpilogue(); return buf.toString(); } catch (Exception exp) { return genHTMLErrorMessage(exp); }
*** 1497,1514 **** 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)); - Stub next = stubq.getNext(codelet); if (next != null) { if (genHTML) { buf.beginTag("h3"); buf.link(genPCHref(addressToLong(next.codeBegin())), "View Next Codelet"); --- 1361,1373 ---- buf.h3("Previous Codelet = 0x" + Long.toHexString(addressToLong(prev.codeBegin()))); } } buf.h3("Code"); ! 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