790 return genHTML(parseAddress(addrStr));
791 }
792
793 public String genHTML(sun.jvm.hotspot.debugger.Address pc) {
794 CodeBlob blob = null;
795
796 try {
797 blob = (CodeBlob)VM.getVM().getCodeCache().findBlobUnsafe(pc);
798 } catch (Exception exp) {
799 // ignore
800 }
801
802 if (blob != null) {
803 if (blob instanceof NMethod) {
804 return genHTML((NMethod)blob);
805 } else {
806 // may be interpreter code.
807 Interpreter interp = VM.getVM().getInterpreter();
808 if (interp.contains(pc)) {
809 InterpreterCodelet codelet = interp.getCodeletContaining(pc);
810 return genHTML(codelet);
811 }
812 return genHTML(blob);
813 }
814 } else if (VM.getVM().getCodeCache().contains(pc)) {
815 return "Unknown location in the CodeCache: " + pc;
816 }
817
818 // did not find nmethod.
819 // try methodOop, klassOop and constantPoolOop.
820 try {
821 Oop obj = getOopAtAddress(pc);
822 if (obj != null) {
823 if (obj instanceof Method) {
824 return genHTML((Method) obj);
825 } else if (obj instanceof InstanceKlass) {
826 return genHTML((InstanceKlass) obj);
827 } else if (obj instanceof ConstantPool) {
828 return genHTML((ConstantPool) obj);
829 }
955 if (prevPCs != null) {
956 tmpBuf.append(',');
957 tmpBuf.append(prevPCs);
958 }
959 if (genHTML) {
960 buf.link(genMultPCHref(tmpBuf.toString()), "show more code ..");
961 buf.endTag("p");
962 }
963
964 buf.genHTMLEpilogue();
965 return buf.toString();
966 } catch (Exception exp) {
967 return genHTMLErrorMessage(exp);
968 }
969 }
970
971 protected String genSafepointInfo(NMethod nm, PCDesc pcDesc) {
972 ScopeDesc sd = nm.getScopeDescAt(pcDesc.getRealPC(nm));
973 Formatter buf = new Formatter(genHTML);
974 Formatter tabs = new Formatter(genHTML);
975
976 buf.beginTag("pre");
977 genScope(buf, tabs, sd);
978 buf.endTag("pre");
979 buf.append(genOopMapInfo(nm, pcDesc));
980
981 return buf.toString();
982 }
983
984 protected void genScope(Formatter buf, Formatter tabs, ScopeDesc sd) {
985 if (sd == null) {
986 return;
987 }
988
989 genScope(buf, tabs, sd.sender());
990
991 buf.append(tabs);
992 Method m = sd.getMethod();
993 buf.append(genMethodAndKlassLink(m));
994 int bci = sd.getBCI();
995 buf.append(" @ bci = ");
996 buf.append(Integer.toString(bci));
997
998 int line = m.getLineNumberFromBCI(bci);
1005 if (locals != null) {
1006 buf.br();
1007 buf.append(tabs);
1008 buf.append(genHTMLForLocals(sd, locals));
1009 }
1010
1011 List expressions = sd.getExpressions();
1012 if (expressions != null) {
1013 buf.br();
1014 buf.append(tabs);
1015 buf.append(genHTMLForExpressions(sd, expressions));
1016 }
1017
1018 List monitors = sd.getMonitors();
1019 if (monitors != null) {
1020 buf.br();
1021 buf.append(tabs);
1022 buf.append(genHTMLForMonitors(sd, monitors));
1023 }
1024
1025 tabs.append(tab);
1026 buf.br();
1027 }
1028
1029 protected String genHTMLForOopMap(OopMap map) {
1030 final int stack0 = VMRegImpl.getStack0().getValue();
1031 Formatter buf = new Formatter(genHTML);
1032
1033 final class OopMapValueIterator {
1034 final Formatter iterate(OopMapStream oms, String type, boolean printContentReg) {
1035 Formatter tmpBuf = new Formatter(genHTML);
1036 boolean found = false;
1037 tmpBuf.beginTag("tr");
1038 tmpBuf.beginTag("td");
1039 tmpBuf.append(type);
1040 tmpBuf.endTag("td");
1041 tmpBuf.endTag("tr");
1042 for (; ! oms.isDone(); oms.next()) {
1043 OopMapValue omv = oms.getCurrent();
1044 if (omv == null) {
1045 continue;
1046 }
1047 found = true;
1048 VMReg vmReg = omv.getReg();
1049 int reg = vmReg.getValue();
1050 if (reg < stack0) {
1051 tmpBuf.append(VMRegImpl.getRegisterName(vmReg.getValue()));
1052 } else {
1053 tmpBuf.append('[');
1054 tmpBuf.append(Integer.toString((reg - stack0) * 4));
1055 tmpBuf.append(']');
1056 }
1057 if (printContentReg) {
1058 tmpBuf.append(" = ");
1059 VMReg vmContentReg = omv.getContentReg();
1060 int contentReg = vmContentReg.getValue();
1061 tmpBuf.append(VMRegImpl.getRegisterName(vmContentReg.getValue()));
1062 }
1063 tmpBuf.append(spaces);
1064 }
1065 tmpBuf.endTag("td");
1066 tmpBuf.endTag("tr");
1067 return found ? tmpBuf : new Formatter(genHTML);
1068 }
1069 }
1070
1071 buf.beginTable(0);
1072
1073 OopMapValueIterator omvIterator = new OopMapValueIterator();
1074 OopMapStream oms = new OopMapStream(map, OopMapValue.OopTypes.OOP_VALUE);
1075 buf.append(omvIterator.iterate(oms, "Oop:", false));
1076
1077 oms = new OopMapStream(map, OopMapValue.OopTypes.VALUE_VALUE);
1078 buf.append(omvIterator.iterate(oms, "Value:", false));
1079
1080 oms = new OopMapStream(map, OopMapValue.OopTypes.NARROWOOP_VALUE);
1081 buf.append(omvIterator.iterate(oms, "Oop:", false));
1082
1083 oms = new OopMapStream(map, OopMapValue.OopTypes.CALLEE_SAVED_VALUE);
1084 buf.append(omvIterator.iterate(oms, "Callee saved:", true));
1085
1086 oms = new OopMapStream(map, OopMapValue.OopTypes.DERIVED_OOP_VALUE);
1087 buf.append(omvIterator.iterate(oms, "Derived oop:", true));
1088
1089 buf.endTag("table");
1090 return buf.toString();
1091 }
1092
1093
1094 protected String genOopMapInfo(NMethod nmethod, PCDesc pcDesc) {
1095 OopMapSet mapSet = nmethod.getOopMaps();
1096 int pcOffset = pcDesc.getPCOffset();
1097 OopMap map = mapSet.findMapAtOffset(pcOffset, VM.getVM().isDebugging());
1098 if (map == null) {
1099 throw new IllegalArgumentException("no oopmap at safepoint!");
1100 }
1101
1102 return genOopMapInfo(map);
1103 }
1104
1105 protected String genOopMapInfo(OopMap map) {
1106 Formatter buf = new Formatter(genHTML);
1107 buf.beginTag("pre");
1108 buf.append("OopMap: ");
1109 buf.append(genHTMLForOopMap(map));
1110 buf.endTag("pre");
1111
1112 return buf.toString();
1113 }
1114
1115 protected String locationAsString(Location loc) {
1116 Formatter buf = new Formatter(genHTML);
1117 if (loc.isIllegal()) {
1118 buf.append("illegal");
1119 } else {
1120 Location.Where w = loc.getWhere();
1121 Location.Type type = loc.getType();
1122
1123 if (w == Location.Where.ON_STACK) {
1124 buf.append("stack[" + loc.getStackOffset() + "]");
1125 } else if (w == Location.Where.IN_REGISTER) {
1126 boolean isFloat = (type == Location.Type.FLOAT_IN_DBL ||
1127 type == Location.Type.DBL);
1128 int regNum = loc.getRegisterNumber();
1137 buf.append("oop");
1138 } else if (type == Location.Type.NARROWOOP) {
1139 buf.append("narrowoop");
1140 } else if (type == Location.Type.INT_IN_LONG) {
1141 buf.append("int");
1142 } else if (type == Location.Type.LNG) {
1143 buf.append("long");
1144 } else if (type == Location.Type.FLOAT_IN_DBL) {
1145 buf.append("float");
1146 } else if (type == Location.Type.DBL) {
1147 buf.append("double");
1148 } else if (type == Location.Type.ADDR) {
1149 buf.append("address");
1150 } else if (type == Location.Type.INVALID) {
1151 buf.append("invalid");
1152 }
1153 }
1154 return buf.toString();
1155 }
1156
1157 private String scopeValueAsString(ScopeValue sv) {
1158 Formatter buf = new Formatter(genHTML);
1159 if (sv.isConstantInt()) {
1160 buf.append("int ");
1161 ConstantIntValue intValue = (ConstantIntValue) sv;
1162 buf.append(Integer.toString(intValue.getValue()));
1163 } else if (sv.isConstantLong()) {
1164 buf.append("long ");
1165 ConstantLongValue longValue = (ConstantLongValue) sv;
1166 buf.append(Long.toString(longValue.getValue()));
1167 buf.append("L");
1168 } else if (sv.isConstantDouble()) {
1169 buf.append("double ");
1170 ConstantDoubleValue dblValue = (ConstantDoubleValue) sv;
1171 buf.append(Double.toString(dblValue.getValue()));
1172 buf.append("D");
1173 } else if (sv.isConstantOop()) {
1174 buf.append("oop ");
1175 ConstantOopReadValue oopValue = (ConstantOopReadValue) sv;
1176 OopHandle oopHandle = oopValue.getValue();
1177 if (oopHandle != null) {
1178 buf.append(oopHandle.toString());
1179 } else {
1180 buf.append("null");
1181 }
1182 } else if (sv.isLocation()) {
1183 LocationValue lvalue = (LocationValue) sv;
1184 Location loc = lvalue.getLocation();
1185 if (loc != null) {
1186 buf.append(locationAsString(loc));
1187 } else {
1188 buf.append("null");
1189 }
1190 }
1191 return buf.toString();
1192 }
1193
1194 protected String genHTMLForScopeValues(ScopeDesc sd, boolean locals, List values) {
1195 int length = values.size();
1196 Formatter buf = new Formatter(genHTML);
1197 buf.append(locals? "locals " : "expressions ");
1198 for (int i = 0; i < length; i++) {
1199 ScopeValue sv = (ScopeValue) values.get(i);
1200 if (sv == null) {
1201 continue;
1202 }
1203 buf.append('(');
1204 if (locals) {
1205 Symbol name = sd.getMethod().getLocalVariableName(sd.getBCI(), i);
1206 if (name != null) {
1207 buf.append("'");
1208 buf.append(name.asString());
1209 buf.append('\'');
1210 } else {
1211 buf.append("[");
1212 buf.append(Integer.toString(i));
1213 buf.append(']');
1214 }
1215 } else {
1216 buf.append("[");
1217 buf.append(Integer.toString(i));
1218 buf.append(']');
1219 }
1220
1221 buf.append(", ");
1222 buf.append(scopeValueAsString(sv));
1223 buf.append(") ");
1224 }
1225
1226 return buf.toString();
1227 }
1228
1229 protected String genHTMLForLocals(ScopeDesc sd, List locals) {
1230 return genHTMLForScopeValues(sd, true, locals);
1231 }
1232
1233 protected String genHTMLForExpressions(ScopeDesc sd, List expressions) {
1234 return genHTMLForScopeValues(sd, false, expressions);
1235 }
1236
1237 protected String genHTMLForMonitors(ScopeDesc sd, List monitors) {
1238 int length = monitors.size();
1239 Formatter buf = new Formatter(genHTML);
1240 buf.append("monitors ");
1241 for (int i = 0; i < length; i++) {
1242 MonitorValue mv = (MonitorValue) monitors.get(i);
1243 if (mv == null) {
1244 continue;
1245 }
1246 buf.append("(owner = ");
1247 ScopeValue owner = mv.owner();
1248 if (owner != null) {
1249 buf.append(scopeValueAsString(owner));
1250 } else {
1251 buf.append("null");
1252 }
1253 buf.append(", lock = ");
1254
1255 Location loc = mv.basicLock();
1256 if (loc != null) {
1257 buf.append(locationAsString(loc));
1258 } else {
1259 buf.append("null");
1260 }
1261 buf.append(") ");
1262 }
1263 return buf.toString();
1264 }
1265
1266 public String genHTML(final NMethod nmethod) {
1267 try {
1268 final Formatter buf = new Formatter(genHTML);
1269 buf.genHTMLPrologue(genNMethodTitle(nmethod));
1307 }
1308
1309 PCDesc pcDesc = (PCDesc) safepoints.get(longToAddress(currentPc));
1310
1311 boolean isSafepoint = (pcDesc != null);
1312 if (isSafepoint && prevWasCall) {
1313 buf.append(genSafepointInfo(nmethod, pcDesc));
1314 }
1315
1316 buf.append("0x");
1317 buf.append(Long.toHexString(currentPc));
1318 buf.append(':');
1319 buf.append(tab);
1320
1321 if (href != null) {
1322 buf.link(href, instr.asString(currentPc, symFinder));
1323 } else {
1324 buf.append(instr.asString(currentPc, symFinder));
1325 }
1326
1327 if (isSafepoint && !prevWasCall) {
1328 buf.append(genSafepointInfo(nmethod, pcDesc));
1329 }
1330
1331 buf.br();
1332 prevWasCall = instr.isCall();
1333 }
1334
1335 public void epilogue() {
1336 }
1337 };
1338
1339 disasm.decode(new NMethodVisitor());
1340
1341 sun.jvm.hotspot.debugger.Address stubBegin = nmethod.stubBegin();
1342 if (stubBegin != null) {
1343 sun.jvm.hotspot.debugger.Address stubEnd = nmethod.stubEnd();
1344 buf.h3("Stub");
1345 long stubStartPc = addressToLong(stubBegin);
1346 long stubEndPc = addressToLong(stubEnd);
1347 int range = (int) (stubEndPc - stubStartPc);
1348 byte[] stubCode = readBuffer(stubBegin, range);
1349 Disassembler disasm2 = createDisassembler(stubStartPc, stubCode);
1350 disasm2.decode(new NMethodVisitor());
1351 }
|
790 return genHTML(parseAddress(addrStr));
791 }
792
793 public String genHTML(sun.jvm.hotspot.debugger.Address pc) {
794 CodeBlob blob = null;
795
796 try {
797 blob = (CodeBlob)VM.getVM().getCodeCache().findBlobUnsafe(pc);
798 } catch (Exception exp) {
799 // ignore
800 }
801
802 if (blob != null) {
803 if (blob instanceof NMethod) {
804 return genHTML((NMethod)blob);
805 } else {
806 // may be interpreter code.
807 Interpreter interp = VM.getVM().getInterpreter();
808 if (interp.contains(pc)) {
809 InterpreterCodelet codelet = interp.getCodeletContaining(pc);
810 if (codelet == null) {
811 return "Unknown location in the Interpreter: " + pc;
812 }
813 return genHTML(codelet);
814 }
815 return genHTML(blob);
816 }
817 } else if (VM.getVM().getCodeCache().contains(pc)) {
818 return "Unknown location in the CodeCache: " + pc;
819 }
820
821 // did not find nmethod.
822 // try methodOop, klassOop and constantPoolOop.
823 try {
824 Oop obj = getOopAtAddress(pc);
825 if (obj != null) {
826 if (obj instanceof Method) {
827 return genHTML((Method) obj);
828 } else if (obj instanceof InstanceKlass) {
829 return genHTML((InstanceKlass) obj);
830 } else if (obj instanceof ConstantPool) {
831 return genHTML((ConstantPool) obj);
832 }
958 if (prevPCs != null) {
959 tmpBuf.append(',');
960 tmpBuf.append(prevPCs);
961 }
962 if (genHTML) {
963 buf.link(genMultPCHref(tmpBuf.toString()), "show more code ..");
964 buf.endTag("p");
965 }
966
967 buf.genHTMLEpilogue();
968 return buf.toString();
969 } catch (Exception exp) {
970 return genHTMLErrorMessage(exp);
971 }
972 }
973
974 protected String genSafepointInfo(NMethod nm, PCDesc pcDesc) {
975 ScopeDesc sd = nm.getScopeDescAt(pcDesc.getRealPC(nm));
976 Formatter buf = new Formatter(genHTML);
977 Formatter tabs = new Formatter(genHTML);
978 tabs.append(tab + tab + tab); // Initial indent for debug info
979
980 buf.beginTag("pre");
981 genScope(buf, tabs, sd);
982
983 // Reset indent for scalar replaced objects
984 tabs = new Formatter(genHTML);
985 tabs.append(tab + tab + tab); // Initial indent for debug info
986
987 genScObjInfo(buf, tabs, sd);
988 buf.endTag("pre");
989
990 buf.append(genOopMapInfo(nm, pcDesc));
991
992 return buf.toString();
993 }
994
995 protected void genScope(Formatter buf, Formatter tabs, ScopeDesc sd) {
996 if (sd == null) {
997 return;
998 }
999
1000 genScope(buf, tabs, sd.sender());
1001
1002 buf.append(tabs);
1003 Method m = sd.getMethod();
1004 buf.append(genMethodAndKlassLink(m));
1005 int bci = sd.getBCI();
1006 buf.append(" @ bci = ");
1007 buf.append(Integer.toString(bci));
1008
1009 int line = m.getLineNumberFromBCI(bci);
1016 if (locals != null) {
1017 buf.br();
1018 buf.append(tabs);
1019 buf.append(genHTMLForLocals(sd, locals));
1020 }
1021
1022 List expressions = sd.getExpressions();
1023 if (expressions != null) {
1024 buf.br();
1025 buf.append(tabs);
1026 buf.append(genHTMLForExpressions(sd, expressions));
1027 }
1028
1029 List monitors = sd.getMonitors();
1030 if (monitors != null) {
1031 buf.br();
1032 buf.append(tabs);
1033 buf.append(genHTMLForMonitors(sd, monitors));
1034 }
1035
1036 buf.br();
1037 tabs.append(tab);
1038 }
1039
1040 protected void genScObjInfo(Formatter buf, Formatter tabs, ScopeDesc sd) {
1041 if (sd == null) {
1042 return;
1043 }
1044
1045 List objects = sd.getObjects();
1046 if (objects == null) {
1047 return;
1048 }
1049 int length = objects.size();
1050 for (int i = 0; i < length; i++) {
1051 buf.append(tabs);
1052 ObjectValue ov = (ObjectValue)objects.get(i);
1053 buf.append("ScObj" + i);
1054 ScopeValue sv = ov.getKlass();
1055 if (Assert.ASSERTS_ENABLED) {
1056 Assert.that(sv.isConstantOop(), "scalar replaced object klass must be constant oop");
1057 }
1058 ConstantOopReadValue klv = (ConstantOopReadValue)sv;
1059 OopHandle klHandle = klv.getValue();
1060 if (Assert.ASSERTS_ENABLED) {
1061 Assert.that(klHandle != null, "scalar replaced object klass must be not NULL");
1062 }
1063 Oop obj = VM.getVM().getObjectHeap().newOop(klHandle);
1064 if (obj instanceof InstanceKlass) {
1065 InstanceKlass kls = (InstanceKlass) obj;
1066 buf.append(" " + kls.getName().asString() + "={");
1067 int flen = ov.fieldsSize();
1068
1069 TypeArray klfields = kls.getFields();
1070 int klen = (int) klfields.getLength();
1071
1072 ConstantPool cp = kls.getConstants();
1073 int findex = 0;
1074 for (int index = 0; index < klen; index += kls.NEXT_OFFSET) {
1075 int accsFlags = klfields.getShortAt(index + kls.ACCESS_FLAGS_OFFSET);
1076 int nameIndex = klfields.getShortAt(index + kls.NAME_INDEX_OFFSET);
1077 AccessFlags access = new AccessFlags(accsFlags);
1078 if (!access.isStatic()) {
1079 ScopeValue svf = ov.getFieldAt(findex++);
1080 String fstr = scopeValueAsString(sd, svf);
1081 Symbol f_name = cp.getSymbolAt(nameIndex);
1082 buf.append(" [" + f_name.asString() + " :"+ index + "]=(#" + fstr + ")");
1083 }
1084 }
1085 buf.append(" }");
1086 } else {
1087 buf.append(" ");
1088 int flen = ov.fieldsSize();
1089 if (obj instanceof TypeArrayKlass) {
1090 TypeArrayKlass kls = (TypeArrayKlass) obj;
1091 buf.append(kls.getElementTypeName() + "[" + flen + "]");
1092 } else if (obj instanceof ObjArrayKlass) {
1093 ObjArrayKlass kls = (ObjArrayKlass) obj;
1094 Klass elobj = kls.getBottomKlass();
1095 if (elobj instanceof InstanceKlass) {
1096 buf.append(elobj.getName().asString());
1097 } else if (elobj instanceof TypeArrayKlass) {
1098 TypeArrayKlass elkls = (TypeArrayKlass) elobj;
1099 buf.append(elkls.getElementTypeName());
1100 } else {
1101 if (Assert.ASSERTS_ENABLED) {
1102 Assert.that(false, "unknown scalar replaced object klass!");
1103 }
1104 }
1105 buf.append("[" + flen + "]");
1106 int ndim = (int) kls.getDimension();
1107 while (--ndim > 0) {
1108 buf.append("[]");
1109 }
1110 } else {
1111 if (Assert.ASSERTS_ENABLED) {
1112 Assert.that(false, "unknown scalar replaced object klass!");
1113 }
1114 }
1115 buf.append("={");
1116 for (int findex = 0; findex < flen; findex++) {
1117 ScopeValue svf = ov.getFieldAt(findex);
1118 String fstr = scopeValueAsString(sd, svf);
1119 buf.append(" [" + findex + "]=(#" + fstr + ")");
1120 }
1121 buf.append(" }");
1122 }
1123 buf.br();
1124 }
1125 }
1126
1127 protected String genHTMLForOopMap(OopMap map) {
1128 final int stack0 = VMRegImpl.getStack0().getValue();
1129 Formatter buf = new Formatter(genHTML);
1130
1131 final class OopMapValueIterator {
1132 final Formatter iterate(OopMapStream oms, String type, boolean printContentReg) {
1133 Formatter tmpBuf = new Formatter(genHTML);
1134 boolean found = false;
1135 tmpBuf.beginTag("tr");
1136 tmpBuf.beginTag("td");
1137 tmpBuf.append(type);
1138 for (; ! oms.isDone(); oms.next()) {
1139 OopMapValue omv = oms.getCurrent();
1140 if (omv == null) {
1141 continue;
1142 }
1143 found = true;
1144 VMReg vmReg = omv.getReg();
1145 int reg = vmReg.getValue();
1146 if (reg < stack0) {
1147 tmpBuf.append(VMRegImpl.getRegisterName(reg));
1148 } else {
1149 tmpBuf.append('[');
1150 tmpBuf.append(Integer.toString((reg - stack0) * 4));
1151 tmpBuf.append(']');
1152 }
1153 if (printContentReg) {
1154 tmpBuf.append(" = ");
1155 VMReg vmContentReg = omv.getContentReg();
1156 int contentReg = vmContentReg.getValue();
1157 if (contentReg < stack0) {
1158 tmpBuf.append(VMRegImpl.getRegisterName(contentReg));
1159 } else {
1160 tmpBuf.append('[');
1161 tmpBuf.append(Integer.toString((contentReg - stack0) * 4));
1162 tmpBuf.append(']');
1163 }
1164 }
1165 tmpBuf.append(spaces);
1166 }
1167 tmpBuf.endTag("td");
1168 tmpBuf.endTag("tr");
1169 return found ? tmpBuf : new Formatter(genHTML);
1170 }
1171 }
1172
1173 buf.beginTable(0);
1174
1175 OopMapValueIterator omvIterator = new OopMapValueIterator();
1176 OopMapStream oms = new OopMapStream(map, OopMapValue.OopTypes.OOP_VALUE);
1177 buf.append(omvIterator.iterate(oms, "Oops:", false));
1178
1179 oms = new OopMapStream(map, OopMapValue.OopTypes.NARROWOOP_VALUE);
1180 buf.append(omvIterator.iterate(oms, "narrowOops:", false));
1181
1182 oms = new OopMapStream(map, OopMapValue.OopTypes.VALUE_VALUE);
1183 buf.append(omvIterator.iterate(oms, "Values:", false));
1184
1185 oms = new OopMapStream(map, OopMapValue.OopTypes.CALLEE_SAVED_VALUE);
1186 buf.append(omvIterator.iterate(oms, "Callee saved:", true));
1187
1188 oms = new OopMapStream(map, OopMapValue.OopTypes.DERIVED_OOP_VALUE);
1189 buf.append(omvIterator.iterate(oms, "Derived oops:", true));
1190
1191 buf.endTag("table");
1192 return buf.toString();
1193 }
1194
1195
1196 protected String genOopMapInfo(NMethod nmethod, PCDesc pcDesc) {
1197 OopMapSet mapSet = nmethod.getOopMaps();
1198 if (mapSet == null || (mapSet.getSize() <= 0))
1199 return "";
1200 int pcOffset = pcDesc.getPCOffset();
1201 OopMap map = mapSet.findMapAtOffset(pcOffset, VM.getVM().isDebugging());
1202 if (map == null) {
1203 throw new IllegalArgumentException("no oopmap at safepoint!");
1204 }
1205
1206 return genOopMapInfo(map);
1207 }
1208
1209 protected String genOopMapInfo(OopMap map) {
1210 Formatter buf = new Formatter(genHTML);
1211 buf.beginTag("pre");
1212 buf.append("OopMap: ");
1213 buf.br();
1214 buf.append(genHTMLForOopMap(map));
1215 buf.endTag("pre");
1216
1217 return buf.toString();
1218 }
1219
1220 protected String locationAsString(Location loc) {
1221 Formatter buf = new Formatter(genHTML);
1222 if (loc.isIllegal()) {
1223 buf.append("illegal");
1224 } else {
1225 Location.Where w = loc.getWhere();
1226 Location.Type type = loc.getType();
1227
1228 if (w == Location.Where.ON_STACK) {
1229 buf.append("stack[" + loc.getStackOffset() + "]");
1230 } else if (w == Location.Where.IN_REGISTER) {
1231 boolean isFloat = (type == Location.Type.FLOAT_IN_DBL ||
1232 type == Location.Type.DBL);
1233 int regNum = loc.getRegisterNumber();
1242 buf.append("oop");
1243 } else if (type == Location.Type.NARROWOOP) {
1244 buf.append("narrowoop");
1245 } else if (type == Location.Type.INT_IN_LONG) {
1246 buf.append("int");
1247 } else if (type == Location.Type.LNG) {
1248 buf.append("long");
1249 } else if (type == Location.Type.FLOAT_IN_DBL) {
1250 buf.append("float");
1251 } else if (type == Location.Type.DBL) {
1252 buf.append("double");
1253 } else if (type == Location.Type.ADDR) {
1254 buf.append("address");
1255 } else if (type == Location.Type.INVALID) {
1256 buf.append("invalid");
1257 }
1258 }
1259 return buf.toString();
1260 }
1261
1262 private String scopeValueAsString(ScopeDesc sd, ScopeValue sv) {
1263 Formatter buf = new Formatter(genHTML);
1264 if (sv.isConstantInt()) {
1265 buf.append("int ");
1266 ConstantIntValue intValue = (ConstantIntValue) sv;
1267 buf.append(Integer.toString(intValue.getValue()));
1268 } else if (sv.isConstantLong()) {
1269 buf.append("long ");
1270 ConstantLongValue longValue = (ConstantLongValue) sv;
1271 buf.append(Long.toString(longValue.getValue()));
1272 buf.append("L");
1273 } else if (sv.isConstantDouble()) {
1274 buf.append("double ");
1275 ConstantDoubleValue dblValue = (ConstantDoubleValue) sv;
1276 buf.append(Double.toString(dblValue.getValue()));
1277 buf.append("D");
1278 } else if (sv.isConstantOop()) {
1279 buf.append("oop ");
1280 ConstantOopReadValue oopValue = (ConstantOopReadValue) sv;
1281 OopHandle oopHandle = oopValue.getValue();
1282 if (oopHandle != null) {
1283 buf.append(oopHandle.toString());
1284 } else {
1285 buf.append("null");
1286 }
1287 } else if (sv.isLocation()) {
1288 LocationValue lvalue = (LocationValue) sv;
1289 Location loc = lvalue.getLocation();
1290 if (loc != null) {
1291 buf.append(locationAsString(loc));
1292 } else {
1293 buf.append("null");
1294 }
1295 } else if (sv.isObject()) {
1296 ObjectValue ov = (ObjectValue)sv;
1297 buf.append("#ScObj" + sd.getObjects().indexOf(ov));
1298 } else {
1299 buf.append("unknown scope value " + sv);
1300 }
1301 return buf.toString();
1302 }
1303
1304 protected String genHTMLForScopeValues(ScopeDesc sd, boolean locals, List values) {
1305 int length = values.size();
1306 Formatter buf = new Formatter(genHTML);
1307 buf.append(locals? "locals " : "expressions ");
1308 for (int i = 0; i < length; i++) {
1309 ScopeValue sv = (ScopeValue) values.get(i);
1310 if (sv == null) {
1311 continue;
1312 }
1313 buf.append('(');
1314 if (locals) {
1315 Symbol name = sd.getMethod().getLocalVariableName(sd.getBCI(), i);
1316 if (name != null) {
1317 buf.append("'");
1318 buf.append(name.asString());
1319 buf.append('\'');
1320 } else {
1321 buf.append("[");
1322 buf.append(Integer.toString(i));
1323 buf.append(']');
1324 }
1325 } else {
1326 buf.append("[");
1327 buf.append(Integer.toString(i));
1328 buf.append(']');
1329 }
1330
1331 buf.append(", ");
1332 buf.append(scopeValueAsString(sd, sv));
1333 buf.append(") ");
1334 }
1335
1336 return buf.toString();
1337 }
1338
1339 protected String genHTMLForLocals(ScopeDesc sd, List locals) {
1340 return genHTMLForScopeValues(sd, true, locals);
1341 }
1342
1343 protected String genHTMLForExpressions(ScopeDesc sd, List expressions) {
1344 return genHTMLForScopeValues(sd, false, expressions);
1345 }
1346
1347 protected String genHTMLForMonitors(ScopeDesc sd, List monitors) {
1348 int length = monitors.size();
1349 Formatter buf = new Formatter(genHTML);
1350 buf.append("monitors ");
1351 for (int i = 0; i < length; i++) {
1352 MonitorValue mv = (MonitorValue) monitors.get(i);
1353 if (mv == null) {
1354 continue;
1355 }
1356 buf.append("(owner = ");
1357 ScopeValue owner = mv.owner();
1358 if (owner != null) {
1359 buf.append(scopeValueAsString(sd, owner));
1360 } else {
1361 buf.append("null");
1362 }
1363 buf.append(", lock = ");
1364
1365 Location loc = mv.basicLock();
1366 if (loc != null) {
1367 buf.append(locationAsString(loc));
1368 } else {
1369 buf.append("null");
1370 }
1371 buf.append(") ");
1372 }
1373 return buf.toString();
1374 }
1375
1376 public String genHTML(final NMethod nmethod) {
1377 try {
1378 final Formatter buf = new Formatter(genHTML);
1379 buf.genHTMLPrologue(genNMethodTitle(nmethod));
1417 }
1418
1419 PCDesc pcDesc = (PCDesc) safepoints.get(longToAddress(currentPc));
1420
1421 boolean isSafepoint = (pcDesc != null);
1422 if (isSafepoint && prevWasCall) {
1423 buf.append(genSafepointInfo(nmethod, pcDesc));
1424 }
1425
1426 buf.append("0x");
1427 buf.append(Long.toHexString(currentPc));
1428 buf.append(':');
1429 buf.append(tab);
1430
1431 if (href != null) {
1432 buf.link(href, instr.asString(currentPc, symFinder));
1433 } else {
1434 buf.append(instr.asString(currentPc, symFinder));
1435 }
1436
1437 buf.br();
1438 if (isSafepoint && !prevWasCall) {
1439 buf.append(genSafepointInfo(nmethod, pcDesc));
1440 }
1441
1442 prevWasCall = instr.isCall();
1443 }
1444
1445 public void epilogue() {
1446 }
1447 };
1448
1449 disasm.decode(new NMethodVisitor());
1450
1451 sun.jvm.hotspot.debugger.Address stubBegin = nmethod.stubBegin();
1452 if (stubBegin != null) {
1453 sun.jvm.hotspot.debugger.Address stubEnd = nmethod.stubEnd();
1454 buf.h3("Stub");
1455 long stubStartPc = addressToLong(stubBegin);
1456 long stubEndPc = addressToLong(stubEnd);
1457 int range = (int) (stubEndPc - stubStartPc);
1458 byte[] stubCode = readBuffer(stubBegin, range);
1459 Disassembler disasm2 = createDisassembler(stubStartPc, stubCode);
1460 disasm2.decode(new NMethodVisitor());
1461 }
|