198 in.readInt(); // Timestamp of this record
199 // Length of record: readInt() will return negative value for record
200 // length >2GB. so store 32bit value in long to keep it unsigned.
201 long length = in.readInt() & 0xffffffffL;
202 if (debugLevel > 0) {
203 System.out.println("Read record type " + type
204 + ", length " + length
205 + " at position " + toHex(currPos));
206 }
207 if (length < 0) {
208 throw new IOException("Bad record length of " + length
209 + " at byte " + toHex(currPos+5)
210 + " of file.");
211 }
212 currPos += 9 + length;
213 switch (type) {
214 case HPROF_UTF8: {
215 long id = readID();
216 byte[] chars = new byte[(int)length - identifierSize];
217 in.readFully(chars);
218 names.put(new Long(id), new String(chars));
219 break;
220 }
221 case HPROF_LOAD_CLASS: {
222 int serialNo = in.readInt(); // Not used
223 long classID = readID();
224 int stackTraceSerialNo = in.readInt();
225 long classNameID = readID();
226 Long classIdI = new Long(classID);
227 String nm = getNameFromID(classNameID).replace('/', '.');
228 classNameFromObjectID.put(classIdI, nm);
229 if (classNameFromSerialNo != null) {
230 classNameFromSerialNo.put(new Integer(serialNo), nm);
231 }
232 break;
233 }
234
235 case HPROF_HEAP_DUMP: {
236 if (dumpsToSkip <= 0) {
237 try {
238 readHeapDump(length, currPos);
239 } catch (EOFException exp) {
240 handleEOF(exp, snapshot);
241 }
242 if (debugLevel > 0) {
243 System.out.println(" Finished processing instances in heap dump.");
244 }
245 return snapshot;
246 } else {
286 skipBytes(length);
287 }
288 break;
289 }
290
291 case HPROF_FRAME: {
292 if (stackFrames == null) {
293 skipBytes(length);
294 } else {
295 long id = readID();
296 String methodName = getNameFromID(readID());
297 String methodSig = getNameFromID(readID());
298 String sourceFile = getNameFromID(readID());
299 int classSer = in.readInt();
300 String className = classNameFromSerialNo.get(new Integer(classSer));
301 int lineNumber = in.readInt();
302 if (lineNumber < StackFrame.LINE_NUMBER_NATIVE) {
303 warn("Weird stack frame line number: " + lineNumber);
304 lineNumber = StackFrame.LINE_NUMBER_UNKNOWN;
305 }
306 stackFrames.put(new Long(id),
307 new StackFrame(methodName, methodSig,
308 className, sourceFile,
309 lineNumber));
310 }
311 break;
312 }
313 case HPROF_TRACE: {
314 if (stackTraces == null) {
315 skipBytes(length);
316 } else {
317 int serialNo = in.readInt();
318 int threadSeq = in.readInt(); // Not used
319 StackFrame[] frames = new StackFrame[in.readInt()];
320 for (int i = 0; i < frames.length; i++) {
321 long fid = readID();
322 frames[i] = stackFrames.get(new Long(fid));
323 if (frames[i] == null) {
324 throw new IOException("Stack frame " + toHex(fid) + " not found");
325 }
326 }
327 stackTraces.put(new Integer(serialNo),
328 new StackTrace(frames));
329 }
330 break;
331 }
332 case HPROF_UNLOAD_CLASS:
333 case HPROF_ALLOC_SITES:
334 case HPROF_START_THREAD:
335 case HPROF_END_THREAD:
336 case HPROF_HEAP_SUMMARY:
337 case HPROF_CPU_SAMPLES:
338 case HPROF_CONTROL_SETTINGS:
339 case HPROF_LOCKSTATS_WAIT_TIME:
340 case HPROF_LOCKSTATS_HOLD_TIME:
341 {
342 // Ignore these record types
602 }
603 return 8;
604 }
605 default: {
606 throw new IOException("Bad value signature: " + type);
607 }
608 }
609 }
610
611 private ThreadObject getThreadObjectFromSequence(int threadSeq)
612 throws IOException {
613 ThreadObject to = threadObjects.get(new Integer(threadSeq));
614 if (to == null) {
615 throw new IOException("Thread " + threadSeq +
616 " not found for JNI local ref");
617 }
618 return to;
619 }
620
621 private String getNameFromID(long id) throws IOException {
622 return getNameFromID(new Long(id));
623 }
624
625 private String getNameFromID(Long id) throws IOException {
626 if (id.longValue() == 0L) {
627 return "";
628 }
629 String result = names.get(id);
630 if (result == null) {
631 warn("Name not found at " + toHex(id.longValue()));
632 return "unresolved name " + toHex(id.longValue());
633 }
634 return result;
635 }
636
637 private StackTrace getStackTraceFromSerial(int ser) throws IOException {
638 if (stackTraces == null) {
639 return null;
640 }
641 StackTrace result = stackTraces.get(new Integer(ser));
642 if (result == null) {
686 String signature = "" + ((char) type);
687 JavaField f = new JavaField(fieldName, signature);
688 statics[i] = new JavaStatic(f, valueBin[0]);
689 }
690
691 int numFields = in.readUnsignedShort();
692 bytesRead += 2;
693 JavaField[] fields = new JavaField[numFields];
694 for (int i = 0; i < numFields; i++) {
695 long nameId = readID();
696 bytesRead += identifierSize;
697 byte type = in.readByte();
698 bytesRead++;
699 String fieldName = getNameFromID(nameId);
700 if (version >= VERSION_JDK12BETA4) {
701 type = signatureFromTypeId(type);
702 }
703 String signature = "" + ((char) type);
704 fields[i] = new JavaField(fieldName, signature);
705 }
706 String name = classNameFromObjectID.get(new Long(id));
707 if (name == null) {
708 warn("Class name not found for " + toHex(id));
709 name = "unknown-name@" + toHex(id);
710 }
711 JavaClass c = new JavaClass(id, name, superId, classLoaderId, signersId,
712 protDomainId, fields, statics,
713 instanceSize);
714 snapshot.addClass(id, c);
715 snapshot.setSiteTrace(c, stackTrace);
716
717 return bytesRead;
718 }
719
720 private String toHex(long addr) {
721 return com.sun.tools.hat.internal.util.Misc.toHex(addr);
722 }
723
724 //
725 // Handle a HPROF_GC_INSTANCE_DUMP
726 // Return number of bytes read
|
198 in.readInt(); // Timestamp of this record
199 // Length of record: readInt() will return negative value for record
200 // length >2GB. so store 32bit value in long to keep it unsigned.
201 long length = in.readInt() & 0xffffffffL;
202 if (debugLevel > 0) {
203 System.out.println("Read record type " + type
204 + ", length " + length
205 + " at position " + toHex(currPos));
206 }
207 if (length < 0) {
208 throw new IOException("Bad record length of " + length
209 + " at byte " + toHex(currPos+5)
210 + " of file.");
211 }
212 currPos += 9 + length;
213 switch (type) {
214 case HPROF_UTF8: {
215 long id = readID();
216 byte[] chars = new byte[(int)length - identifierSize];
217 in.readFully(chars);
218 names.put(id, new String(chars));
219 break;
220 }
221 case HPROF_LOAD_CLASS: {
222 int serialNo = in.readInt(); // Not used
223 long classID = readID();
224 int stackTraceSerialNo = in.readInt();
225 long classNameID = readID();
226 Long classIdI = classID;
227 String nm = getNameFromID(classNameID).replace('/', '.');
228 classNameFromObjectID.put(classIdI, nm);
229 if (classNameFromSerialNo != null) {
230 classNameFromSerialNo.put(new Integer(serialNo), nm);
231 }
232 break;
233 }
234
235 case HPROF_HEAP_DUMP: {
236 if (dumpsToSkip <= 0) {
237 try {
238 readHeapDump(length, currPos);
239 } catch (EOFException exp) {
240 handleEOF(exp, snapshot);
241 }
242 if (debugLevel > 0) {
243 System.out.println(" Finished processing instances in heap dump.");
244 }
245 return snapshot;
246 } else {
286 skipBytes(length);
287 }
288 break;
289 }
290
291 case HPROF_FRAME: {
292 if (stackFrames == null) {
293 skipBytes(length);
294 } else {
295 long id = readID();
296 String methodName = getNameFromID(readID());
297 String methodSig = getNameFromID(readID());
298 String sourceFile = getNameFromID(readID());
299 int classSer = in.readInt();
300 String className = classNameFromSerialNo.get(new Integer(classSer));
301 int lineNumber = in.readInt();
302 if (lineNumber < StackFrame.LINE_NUMBER_NATIVE) {
303 warn("Weird stack frame line number: " + lineNumber);
304 lineNumber = StackFrame.LINE_NUMBER_UNKNOWN;
305 }
306 stackFrames.put(id,
307 new StackFrame(methodName, methodSig,
308 className, sourceFile,
309 lineNumber));
310 }
311 break;
312 }
313 case HPROF_TRACE: {
314 if (stackTraces == null) {
315 skipBytes(length);
316 } else {
317 int serialNo = in.readInt();
318 int threadSeq = in.readInt(); // Not used
319 StackFrame[] frames = new StackFrame[in.readInt()];
320 for (int i = 0; i < frames.length; i++) {
321 long fid = readID();
322 frames[i] = stackFrames.get(fid);
323 if (frames[i] == null) {
324 throw new IOException("Stack frame " + toHex(fid) + " not found");
325 }
326 }
327 stackTraces.put(new Integer(serialNo),
328 new StackTrace(frames));
329 }
330 break;
331 }
332 case HPROF_UNLOAD_CLASS:
333 case HPROF_ALLOC_SITES:
334 case HPROF_START_THREAD:
335 case HPROF_END_THREAD:
336 case HPROF_HEAP_SUMMARY:
337 case HPROF_CPU_SAMPLES:
338 case HPROF_CONTROL_SETTINGS:
339 case HPROF_LOCKSTATS_WAIT_TIME:
340 case HPROF_LOCKSTATS_HOLD_TIME:
341 {
342 // Ignore these record types
602 }
603 return 8;
604 }
605 default: {
606 throw new IOException("Bad value signature: " + type);
607 }
608 }
609 }
610
611 private ThreadObject getThreadObjectFromSequence(int threadSeq)
612 throws IOException {
613 ThreadObject to = threadObjects.get(new Integer(threadSeq));
614 if (to == null) {
615 throw new IOException("Thread " + threadSeq +
616 " not found for JNI local ref");
617 }
618 return to;
619 }
620
621 private String getNameFromID(long id) throws IOException {
622 return getNameFromID(id);
623 }
624
625 private String getNameFromID(Long id) throws IOException {
626 if (id.longValue() == 0L) {
627 return "";
628 }
629 String result = names.get(id);
630 if (result == null) {
631 warn("Name not found at " + toHex(id.longValue()));
632 return "unresolved name " + toHex(id.longValue());
633 }
634 return result;
635 }
636
637 private StackTrace getStackTraceFromSerial(int ser) throws IOException {
638 if (stackTraces == null) {
639 return null;
640 }
641 StackTrace result = stackTraces.get(new Integer(ser));
642 if (result == null) {
686 String signature = "" + ((char) type);
687 JavaField f = new JavaField(fieldName, signature);
688 statics[i] = new JavaStatic(f, valueBin[0]);
689 }
690
691 int numFields = in.readUnsignedShort();
692 bytesRead += 2;
693 JavaField[] fields = new JavaField[numFields];
694 for (int i = 0; i < numFields; i++) {
695 long nameId = readID();
696 bytesRead += identifierSize;
697 byte type = in.readByte();
698 bytesRead++;
699 String fieldName = getNameFromID(nameId);
700 if (version >= VERSION_JDK12BETA4) {
701 type = signatureFromTypeId(type);
702 }
703 String signature = "" + ((char) type);
704 fields[i] = new JavaField(fieldName, signature);
705 }
706 String name = classNameFromObjectID.get(id);
707 if (name == null) {
708 warn("Class name not found for " + toHex(id));
709 name = "unknown-name@" + toHex(id);
710 }
711 JavaClass c = new JavaClass(id, name, superId, classLoaderId, signersId,
712 protDomainId, fields, statics,
713 instanceSize);
714 snapshot.addClass(id, c);
715 snapshot.setSiteTrace(c, stackTrace);
716
717 return bytesRead;
718 }
719
720 private String toHex(long addr) {
721 return com.sun.tools.hat.internal.util.Misc.toHex(addr);
722 }
723
724 //
725 // Handle a HPROF_GC_INSTANCE_DUMP
726 // Return number of bytes read
|