private void readHeapDump()

in src/application/org.openjdk.jmc.joverflow/src/main/java/org/openjdk/jmc/joverflow/heap/parser/HprofReader.java [547:662]


	private void readHeapDump(long dumpLength)
			throws DumpCorruptedException, IOException, HprofParsingCancelledException {
		long startPos = in.position();
		long endPos = startPos + dumpLength;
		// "Chunks" below are used to check for cancellation periodically
		int curChunk = (int) (in.position() >> 19); // Check every 512K

		long id, pos;
		while ((pos = in.position()) < endPos) {
			int recordType = in.readUnsignedByte();

			int newCurChunk = (int) (pos >> 19);
			if (newCurChunk > curChunk) {
				curChunk = newCurChunk;
				checkForCancellation();
			}

			switch (recordType) {
			case HPROF_GC_INSTANCE_DUMP: {
				readInstance();
				break;
			}
			case HPROF_GC_OBJ_ARRAY_DUMP: {
				readArray(false);
				break;
			}
			case HPROF_GC_PRIM_ARRAY_DUMP: {
				readArray(true);
				break;
			}

			case HPROF_GC_ROOT_UNKNOWN: {
				id = readID();
				snpBuilder.addRoot(new Root(id, 0, Root.UNKNOWN, ""));
				break;
			}
			case HPROF_GC_ROOT_THREAD_OBJ: {
				id = readID();
				int threadSeq = in.readInt();
				int stackSeq = in.readInt();
				threadObjects.put(threadSeq, new ThreadObject(id, stackSeq));
				break;
			}
			case HPROF_GC_ROOT_JNI_GLOBAL: {
				id = readID();
				readID(); // long globalRefId, ignored for now
				snpBuilder.addRoot(new Root(id, 0, Root.JNI_GLOBAL, ""));
				break;
			}
			case HPROF_GC_ROOT_JNI_LOCAL: {
				id = readID();
				int threadSeq = in.readInt();
				int depth = in.readInt();
				ThreadObject to = getThreadObjectFromSequence(threadSeq);
				StackTrace st = getStackTraceFromSerial(to.stackSeq);
				if (st != null) {
					st = st.traceForDepth(depth + 1);
				}
				snpBuilder.addRoot(new Root(id, to.threadId, Root.JNI_LOCAL, "", st));
				break;
			}
			case HPROF_GC_ROOT_JAVA_FRAME: {
				id = readID();
				int threadSeq = in.readInt();
				int depth = in.readInt();
				ThreadObject to = getThreadObjectFromSequence(threadSeq);
				StackTrace st = getStackTraceFromSerial(to.stackSeq);
				if (st != null) {
					st = st.traceForDepth(depth + 1);
				}
				snpBuilder.addRoot(new Root(id, to.threadId, Root.JAVA_LOCAL, "", st));
				break;
			}
			case HPROF_GC_ROOT_NATIVE_STACK: {
				id = readID();
				int threadSeq = in.readInt();
				ThreadObject to = getThreadObjectFromSequence(threadSeq);
				StackTrace st = getStackTraceFromSerial(to.stackSeq);
				snpBuilder.addRoot(new Root(id, to.threadId, Root.NATIVE_STACK, "", st));
				break;
			}
			case HPROF_GC_ROOT_STICKY_CLASS: {
				id = readID();
				snpBuilder.addRoot(new Root(id, 0, Root.SYSTEM_CLASS, ""));
				break;
			}
			case HPROF_GC_ROOT_THREAD_BLOCK: {
				id = readID();
				int threadSeq = in.readInt();
				ThreadObject to = getThreadObjectFromSequence(threadSeq);
				StackTrace st = getStackTraceFromSerial(to.stackSeq);
				snpBuilder.addRoot(new Root(id, to.threadId, Root.THREAD_BLOCK, "", st));
				break;
			}
			case HPROF_GC_ROOT_MONITOR_USED: {
				id = readID();
				snpBuilder.addRoot(new Root(id, 0, Root.BUSY_MONITOR, ""));
				break;
			}
			case HPROF_GC_CLASS_DUMP: {
				readClass();
				break;
			}
			default: {
				throw new DumpCorruptedException("unrecognized heap dump sub-record type:  " + recordType
						+ ". Technical info: position = " + pos + ", bytes left = " + (endPos - pos));
			}
			}
		}

		if (pos != endPos) {
			vc.addWarning("Error reading heap dump or heap dump segment",
					"Byte count is " + pos + " instead of " + endPos + ". Difference is " + (endPos - pos));
			skipBytes(endPos - pos);
		}
	}