14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 package sun.jvm.hotspot.ui.classbrowser;
26
27 import java.io.*;
28 import java.util.*;
29 import sun.jvm.hotspot.asm.*;
30 import sun.jvm.hotspot.code.*;
31 import sun.jvm.hotspot.compiler.*;
32 import sun.jvm.hotspot.debugger.*;
33 import sun.jvm.hotspot.interpreter.*;
34 import sun.jvm.hotspot.memory.*;
35 import sun.jvm.hotspot.oops.*;
36 import sun.jvm.hotspot.runtime.*;
37 import sun.jvm.hotspot.tools.jcore.*;
38 import sun.jvm.hotspot.types.*;
39 import sun.jvm.hotspot.utilities.*;
40
41 public class HTMLGenerator implements /* imports */ ClassConstants {
42 static class Formatter {
43 boolean html;
44 StringBuffer buf = new StringBuffer();
45
46 Formatter(boolean h) {
47 html = h;
48 }
49
50 void append(String s) {
51 buf.append(s);
52 }
53
54 void append(int s) {
55 buf.append(s);
56 }
57
58 void append(char s) {
870 protected String genPCHref(long targetPc) {
871 return genBaseHref() + "pc=0x" + Long.toHexString(targetPc);
872 }
873
874 protected String genMultPCHref(String pcs) {
875 StringBuffer buf = new StringBuffer(genBaseHref());
876 buf.append("pc_multiple=");
877 buf.append(pcs);
878 return buf.toString();
879 }
880
881 protected String genPCHref(Address addr) {
882 return genPCHref(addressToLong(addr));
883 }
884
885 class HTMLDisassembler implements InstructionVisitor {
886 private int instrSize = 0;
887 private Formatter buf;
888 private SymbolFinder symFinder = createSymbolFinder();
889 private long pc;
890 private OopMapSet oms;
891 private CodeBlob blob;
892 private NMethod nmethod;
893
894 HTMLDisassembler(Formatter buf, CodeBlob blob) {
895 this.buf = buf;
896 this.blob = blob;
897 if (blob != null) {
898 if (blob instanceof NMethod) {
899 nmethod = (NMethod)blob;
900 }
901 oms = blob.getOopMaps();
902 }
903 }
904
905 public int getInstructionSize() {
906 return instrSize;
907 }
908
909 public void prologue() {
910 }
937 }
938
939 public void print(String s) {
940 buf.append(s);
941 }
942
943 public void endInstruction(long endPc) {
944 instrSize += endPc - pc;
945 if (genHTML) buf.br();
946
947 if (nmethod != null) {
948 ScopeDesc sd = nmethod.scope_desc_in(pc, endPc);
949 if (sd != null) {
950 buf.br();
951 buf.append(genSafepointInfo(nmethod, sd));
952 }
953 }
954
955 if (oms != null) {
956 long base = addressToLong(blob.codeBegin());
957 for (int i = 0, imax = (int)oms.getSize(); i < imax; i++) {
958 OopMap om = oms.getMapAt(i);
959 long omspc = base + om.getOffset();
960 if (omspc > pc) {
961 if (omspc <= endPc) {
962 buf.br();
963 buf.append(genOopMapInfo(om));
964 // st.move_to(column);
965 // visitor.print("; ");
966 // om.print_on(st);
967 }
968 break;
969 }
970 }
971 }
972 // follow each complete insn by a nice newline
973 buf.br();
974 }
975
976 public void epilogue() {
977 }
978 };
979
980 protected String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address addr,
981 int size,
982 String prevPCs) {
983 try {
1150 while (--ndim > 0) {
1151 buf.append("[]");
1152 }
1153 } else {
1154 if (Assert.ASSERTS_ENABLED) {
1155 Assert.that(false, "unknown scalar replaced object klass!");
1156 }
1157 }
1158 buf.append("={");
1159 for (int findex = 0; findex < flen; findex++) {
1160 ScopeValue svf = ov.getFieldAt(findex);
1161 String fstr = scopeValueAsString(sd, svf);
1162 buf.append(" [" + findex + "]=(#" + fstr + ")");
1163 }
1164 buf.append(" }");
1165 }
1166 buf.br();
1167 }
1168 }
1169
1170 protected String genHTMLForOopMap(OopMap map) {
1171 final int stack0 = VMRegImpl.getStack0().getValue();
1172 Formatter buf = new Formatter(genHTML);
1173
1174 final class OopMapValueIterator {
1175 final Formatter iterate(OopMapStream oms, String type, boolean printContentReg) {
1176 Formatter tmpBuf = new Formatter(genHTML);
1177 boolean found = false;
1178 tmpBuf.beginTag("tr");
1179 tmpBuf.beginTag("td");
1180 tmpBuf.append(type);
1181 for (; ! oms.isDone(); oms.next()) {
1182 OopMapValue omv = oms.getCurrent();
1183 if (omv == null) {
1184 continue;
1185 }
1186 found = true;
1187 VMReg vmReg = omv.getReg();
1188 int reg = vmReg.getValue();
1189 if (reg < stack0) {
1190 tmpBuf.append(VMRegImpl.getRegisterName(reg));
1220 buf.append(omvIterator.iterate(oms, "Oops:", false));
1221
1222 oms = new OopMapStream(map, OopMapValue.OopTypes.NARROWOOP_VALUE);
1223 buf.append(omvIterator.iterate(oms, "NarrowOops:", false));
1224
1225 oms = new OopMapStream(map, OopMapValue.OopTypes.VALUE_VALUE);
1226 buf.append(omvIterator.iterate(oms, "Values:", false));
1227
1228 oms = new OopMapStream(map, OopMapValue.OopTypes.CALLEE_SAVED_VALUE);
1229 buf.append(omvIterator.iterate(oms, "Callee saved:", true));
1230
1231 oms = new OopMapStream(map, OopMapValue.OopTypes.DERIVED_OOP_VALUE);
1232 buf.append(omvIterator.iterate(oms, "Derived oops:", true));
1233
1234 buf.endTag("table");
1235 return buf.toString();
1236 }
1237
1238
1239 protected String genOopMapInfo(NMethod nmethod, PCDesc pcDesc) {
1240 OopMapSet mapSet = nmethod.getOopMaps();
1241 if (mapSet == null || (mapSet.getSize() <= 0))
1242 return "";
1243 int pcOffset = pcDesc.getPCOffset();
1244 OopMap map = mapSet.findMapAtOffset(pcOffset, VM.getVM().isDebugging());
1245 if (map == null) {
1246 throw new IllegalArgumentException("no oopmap at safepoint!");
1247 }
1248
1249 return genOopMapInfo(map);
1250 }
1251
1252 protected String genOopMapInfo(OopMap map) {
1253 Formatter buf = new Formatter(genHTML);
1254 buf.beginTag("pre");
1255 buf.append("OopMap: ");
1256 buf.br();
1257 buf.append(genHTMLForOopMap(map));
1258 buf.endTag("pre");
1259
1260 return buf.toString();
1261 }
1262
1263 protected String locationAsString(Location loc) {
1264 Formatter buf = new Formatter(genHTML);
1265 if (loc.isIllegal()) {
1266 buf.append("illegal");
1267 } else {
1268 Location.Where w = loc.getWhere();
1269 Location.Type type = loc.getType();
1270
1271 if (w == Location.Where.ON_STACK) {
1272 buf.append("stack[" + loc.getStackOffset() + "]");
|
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 package sun.jvm.hotspot.ui.classbrowser;
26
27 import java.io.*;
28 import java.util.*;
29 import sun.jvm.hotspot.asm.*;
30 import sun.jvm.hotspot.code.*;
31 import sun.jvm.hotspot.compiler.*;
32 import sun.jvm.hotspot.debugger.*;
33 import sun.jvm.hotspot.interpreter.*;
34 import sun.jvm.hotspot.oops.*;
35 import sun.jvm.hotspot.runtime.*;
36 import sun.jvm.hotspot.tools.jcore.*;
37 import sun.jvm.hotspot.utilities.*;
38
39 public class HTMLGenerator implements /* imports */ ClassConstants {
40 static class Formatter {
41 boolean html;
42 StringBuffer buf = new StringBuffer();
43
44 Formatter(boolean h) {
45 html = h;
46 }
47
48 void append(String s) {
49 buf.append(s);
50 }
51
52 void append(int s) {
53 buf.append(s);
54 }
55
56 void append(char s) {
868 protected String genPCHref(long targetPc) {
869 return genBaseHref() + "pc=0x" + Long.toHexString(targetPc);
870 }
871
872 protected String genMultPCHref(String pcs) {
873 StringBuffer buf = new StringBuffer(genBaseHref());
874 buf.append("pc_multiple=");
875 buf.append(pcs);
876 return buf.toString();
877 }
878
879 protected String genPCHref(Address addr) {
880 return genPCHref(addressToLong(addr));
881 }
882
883 class HTMLDisassembler implements InstructionVisitor {
884 private int instrSize = 0;
885 private Formatter buf;
886 private SymbolFinder symFinder = createSymbolFinder();
887 private long pc;
888 private ImmutableOopMapSet oms;
889 private CodeBlob blob;
890 private NMethod nmethod;
891
892 HTMLDisassembler(Formatter buf, CodeBlob blob) {
893 this.buf = buf;
894 this.blob = blob;
895 if (blob != null) {
896 if (blob instanceof NMethod) {
897 nmethod = (NMethod)blob;
898 }
899 oms = blob.getOopMaps();
900 }
901 }
902
903 public int getInstructionSize() {
904 return instrSize;
905 }
906
907 public void prologue() {
908 }
935 }
936
937 public void print(String s) {
938 buf.append(s);
939 }
940
941 public void endInstruction(long endPc) {
942 instrSize += endPc - pc;
943 if (genHTML) buf.br();
944
945 if (nmethod != null) {
946 ScopeDesc sd = nmethod.scope_desc_in(pc, endPc);
947 if (sd != null) {
948 buf.br();
949 buf.append(genSafepointInfo(nmethod, sd));
950 }
951 }
952
953 if (oms != null) {
954 long base = addressToLong(blob.codeBegin());
955 for (int i = 0, imax = oms.getCount(); i < imax; i++) {
956 ImmutableOopMapPair pair = oms.getPairAt(i);
957 long omspc = base + pair.getPC();
958 if (omspc > pc) {
959 if (omspc <= endPc) {
960 buf.br();
961 buf.append(genOopMapInfo(oms.getMap(pair)));
962 // st.move_to(column);
963 // visitor.print("; ");
964 // om.print_on(st);
965 }
966 break;
967 }
968 }
969 }
970 // follow each complete insn by a nice newline
971 buf.br();
972 }
973
974 public void epilogue() {
975 }
976 };
977
978 protected String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address addr,
979 int size,
980 String prevPCs) {
981 try {
1148 while (--ndim > 0) {
1149 buf.append("[]");
1150 }
1151 } else {
1152 if (Assert.ASSERTS_ENABLED) {
1153 Assert.that(false, "unknown scalar replaced object klass!");
1154 }
1155 }
1156 buf.append("={");
1157 for (int findex = 0; findex < flen; findex++) {
1158 ScopeValue svf = ov.getFieldAt(findex);
1159 String fstr = scopeValueAsString(sd, svf);
1160 buf.append(" [" + findex + "]=(#" + fstr + ")");
1161 }
1162 buf.append(" }");
1163 }
1164 buf.br();
1165 }
1166 }
1167
1168 protected String genHTMLForOopMap(ImmutableOopMap map) {
1169 final int stack0 = VMRegImpl.getStack0().getValue();
1170 Formatter buf = new Formatter(genHTML);
1171
1172 final class OopMapValueIterator {
1173 final Formatter iterate(OopMapStream oms, String type, boolean printContentReg) {
1174 Formatter tmpBuf = new Formatter(genHTML);
1175 boolean found = false;
1176 tmpBuf.beginTag("tr");
1177 tmpBuf.beginTag("td");
1178 tmpBuf.append(type);
1179 for (; ! oms.isDone(); oms.next()) {
1180 OopMapValue omv = oms.getCurrent();
1181 if (omv == null) {
1182 continue;
1183 }
1184 found = true;
1185 VMReg vmReg = omv.getReg();
1186 int reg = vmReg.getValue();
1187 if (reg < stack0) {
1188 tmpBuf.append(VMRegImpl.getRegisterName(reg));
1218 buf.append(omvIterator.iterate(oms, "Oops:", false));
1219
1220 oms = new OopMapStream(map, OopMapValue.OopTypes.NARROWOOP_VALUE);
1221 buf.append(omvIterator.iterate(oms, "NarrowOops:", false));
1222
1223 oms = new OopMapStream(map, OopMapValue.OopTypes.VALUE_VALUE);
1224 buf.append(omvIterator.iterate(oms, "Values:", false));
1225
1226 oms = new OopMapStream(map, OopMapValue.OopTypes.CALLEE_SAVED_VALUE);
1227 buf.append(omvIterator.iterate(oms, "Callee saved:", true));
1228
1229 oms = new OopMapStream(map, OopMapValue.OopTypes.DERIVED_OOP_VALUE);
1230 buf.append(omvIterator.iterate(oms, "Derived oops:", true));
1231
1232 buf.endTag("table");
1233 return buf.toString();
1234 }
1235
1236
1237 protected String genOopMapInfo(NMethod nmethod, PCDesc pcDesc) {
1238 ImmutableOopMapSet mapSet = nmethod.getOopMaps();
1239 if (mapSet == null || (mapSet.getSize() <= 0))
1240 return "";
1241 int pcOffset = pcDesc.getPCOffset();
1242 ImmutableOopMap map = mapSet.findMapAtOffset(pcOffset, VM.getVM().isDebugging());
1243 if (map == null) {
1244 throw new IllegalArgumentException("no oopmap at safepoint!");
1245 }
1246
1247 return genOopMapInfo(map);
1248 }
1249
1250 protected String genOopMapInfo(ImmutableOopMap map) {
1251 Formatter buf = new Formatter(genHTML);
1252 buf.beginTag("pre");
1253 buf.append("OopMap: ");
1254 buf.br();
1255 buf.append(genHTMLForOopMap(map));
1256 buf.endTag("pre");
1257
1258 return buf.toString();
1259 }
1260
1261 protected String locationAsString(Location loc) {
1262 Formatter buf = new Formatter(genHTML);
1263 if (loc.isIllegal()) {
1264 buf.append("illegal");
1265 } else {
1266 Location.Where w = loc.getWhere();
1267 Location.Type type = loc.getType();
1268
1269 if (w == Location.Where.ON_STACK) {
1270 buf.append("stack[" + loc.getStackOffset() + "]");
|