8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy

Reviewed-by: dsamersoff
This commit is contained in:
Andreas Eriksson 2015-12-14 15:17:52 +01:00
parent 34319b3505
commit ed2eaccb97

View File

@ -354,7 +354,14 @@ public class HprofReader extends Reader /* imports */ implements ArrayTypeCodes
} }
private void skipBytes(long length) throws IOException { private void skipBytes(long length) throws IOException {
in.skipBytes((int)length); while (length > 0) {
long skipped = in.skip(length);
if (skipped == 0) {
// EOF or other problem, throw exception
throw new EOFException("Couldn't skip enough bytes");
}
length -= skipped;
}
} }
private int readVersionHeader() throws IOException { private int readVersionHeader() throws IOException {
@ -486,12 +493,12 @@ public class HprofReader extends Reader /* imports */ implements ArrayTypeCodes
break; break;
} }
case HPROF_GC_OBJ_ARRAY_DUMP: { case HPROF_GC_OBJ_ARRAY_DUMP: {
int bytesRead = readArray(false); long bytesRead = readArray(false);
bytesLeft -= bytesRead; bytesLeft -= bytesRead;
break; break;
} }
case HPROF_GC_PRIM_ARRAY_DUMP: { case HPROF_GC_PRIM_ARRAY_DUMP: {
int bytesRead = readArray(true); long bytesRead = readArray(true);
bytesLeft -= bytesRead; bytesLeft -= bytesRead;
break; break;
} }
@ -743,12 +750,12 @@ public class HprofReader extends Reader /* imports */ implements ArrayTypeCodes
// Handle a HPROF_GC_OBJ_ARRAY_DUMP or HPROF_GC_PRIM_ARRAY_DUMP // Handle a HPROF_GC_OBJ_ARRAY_DUMP or HPROF_GC_PRIM_ARRAY_DUMP
// Return number of bytes read // Return number of bytes read
// //
private int readArray(boolean isPrimitive) throws IOException { private long readArray(boolean isPrimitive) throws IOException {
long start = in.position(); long start = in.position();
long id = readID(); long id = readID();
StackTrace stackTrace = getStackTraceFromSerial(in.readInt()); StackTrace stackTrace = getStackTraceFromSerial(in.readInt());
int num = in.readInt(); int num = in.readInt();
int bytesRead = identifierSize + 8; long bytesRead = identifierSize + 8;
long elementClassID; long elementClassID;
if (isPrimitive) { if (isPrimitive) {
elementClassID = in.readByte(); elementClassID = in.readByte();
@ -810,14 +817,14 @@ public class HprofReader extends Reader /* imports */ implements ArrayTypeCodes
} }
} }
if (primitiveSignature != 0x00) { if (primitiveSignature != 0x00) {
int size = elSize * num; long size = elSize * (long)num;
bytesRead += size; bytesRead += size;
JavaValueArray va = new JavaValueArray(primitiveSignature, start); JavaValueArray va = new JavaValueArray(primitiveSignature, start);
skipBytes(size); skipBytes(size);
snapshot.addHeapObject(id, va); snapshot.addHeapObject(id, va);
snapshot.setSiteTrace(va, stackTrace); snapshot.setSiteTrace(va, stackTrace);
} else { } else {
int sz = num * identifierSize; long sz = (long)num * identifierSize;
bytesRead += sz; bytesRead += sz;
JavaObjectArray arr = new JavaObjectArray(elementClassID, start); JavaObjectArray arr = new JavaObjectArray(elementClassID, start);
skipBytes(sz); skipBytes(sz);