// // Handle a HPROF_GC_INSTANCE_DUMP // Return number of bytes read // private int readInstance() throws IOException { long start = in.position(); long id = readID(); StackTrace stackTrace = getStackTraceFromSerial(in.readInt()); long classID = readID(); int bytesFollowing = in.readInt(); int bytesRead = (2 * identifierSize) + 8 + bytesFollowing; JavaObject jobj = new JavaObject(classID, start); skipBytes(bytesFollowing); snapshot.addHeapObject(id, jobj); snapshot.setSiteTrace(jobj, stackTrace); return bytesRead; }
// // Handle a HPROF_GC_OBJ_ARRAY_DUMP or HPROF_GC_PRIM_ARRAY_DUMP // Return number of bytes read // private int readArray(boolean isPrimitive) throws IOException { long start = in.position(); long id = readID(); StackTrace stackTrace = getStackTraceFromSerial(in.readInt()); int num = in.readInt(); int bytesRead = identifierSize + 8; long elementClassID; if (isPrimitive) { elementClassID = in.readByte(); bytesRead++; } else { elementClassID = readID(); bytesRead += identifierSize; } // Check for primitive arrays: byte primitiveSignature = 0x00; int elSize = 0; if (isPrimitive || version < VERSION_JDK12BETA4) { switch ((int) elementClassID) { case T_BOOLEAN: { primitiveSignature = (byte) 'Z'; elSize = 1; break; } case T_CHAR: { primitiveSignature = (byte) 'C'; elSize = 2; break; } case T_FLOAT: { primitiveSignature = (byte) 'F'; elSize = 4; break; } case T_DOUBLE: { primitiveSignature = (byte) 'D'; elSize = 8; break; } case T_BYTE: { primitiveSignature = (byte) 'B'; elSize = 1; break; } case T_SHORT: { primitiveSignature = (byte) 'S'; elSize = 2; break; } case T_INT: { primitiveSignature = (byte) 'I'; elSize = 4; break; } case T_LONG: { primitiveSignature = (byte) 'J'; elSize = 8; break; } } if (version >= VERSION_JDK12BETA4 && primitiveSignature == 0x00) { throw new IOException("Unrecognized typecode: " + elementClassID); } } if (primitiveSignature != 0x00) { int size = elSize * num; bytesRead += size; JavaValueArray va = new JavaValueArray(primitiveSignature, start); skipBytes(size); snapshot.addHeapObject(id, va); snapshot.setSiteTrace(va, stackTrace); } else { int sz = num * identifierSize; bytesRead += sz; JavaObjectArray arr = new JavaObjectArray(elementClassID, start); skipBytes(sz); snapshot.addHeapObject(id, arr); snapshot.setSiteTrace(arr, stackTrace); } return bytesRead; }
// // Handle a HPROF_GC_CLASS_DUMP // Return number of bytes read // private int readClass() throws IOException { long id = readID(); StackTrace stackTrace = getStackTraceFromSerial(in.readInt()); long superId = readID(); long classLoaderId = readID(); long signersId = readID(); long protDomainId = readID(); long reserved1 = readID(); long reserved2 = readID(); int instanceSize = in.readInt(); int bytesRead = 7 * identifierSize + 8; int numConstPoolEntries = in.readUnsignedShort(); bytesRead += 2; for (int i = 0; i < numConstPoolEntries; i++) { int index = in.readUnsignedShort(); // unused bytesRead += 2; bytesRead += readValue(null); // We ignore the values } int numStatics = in.readUnsignedShort(); bytesRead += 2; JavaThing[] valueBin = new JavaThing[1]; JavaStatic[] statics = new JavaStatic[numStatics]; for (int i = 0; i < numStatics; i++) { long nameId = readID(); bytesRead += identifierSize; byte type = in.readByte(); bytesRead++; bytesRead += readValueForType(type, valueBin); String fieldName = getNameFromID(nameId); if (version >= VERSION_JDK12BETA4) { type = signatureFromTypeId(type); } String signature = "" + ((char) type); JavaField f = new JavaField(fieldName, signature); statics[i] = new JavaStatic(f, valueBin[0]); } int numFields = in.readUnsignedShort(); bytesRead += 2; JavaField[] fields = new JavaField[numFields]; for (int i = 0; i < numFields; i++) { long nameId = readID(); bytesRead += identifierSize; byte type = in.readByte(); bytesRead++; String fieldName = getNameFromID(nameId); if (version >= VERSION_JDK12BETA4) { type = signatureFromTypeId(type); } String signature = "" + ((char) type); fields[i] = new JavaField(fieldName, signature); } String name = classNameFromObjectID.get(new Long(id)); if (name == null) { warn("Class name not found for " + toHex(id)); name = "unknown-name@" + toHex(id); } JavaClass c = new JavaClass( id, name, superId, classLoaderId, signersId, protDomainId, fields, statics, instanceSize); snapshot.addClass(id, c); snapshot.setSiteTrace(c, stackTrace); return bytesRead; }