You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kato-commits@incubator.apache.org by mo...@apache.org on 2009/05/07 14:50:35 UTC

svn commit: r772669 [3/7] - in /incubator/kato/trunk: HprofBinaryReaderPOC/ HprofBinaryReaderPOC/.settings/ HprofBinaryReaderPOC/META-INF/ HprofBinaryReaderPOC/bin/ HprofBinaryReaderPOC/bin/org/ HprofBinaryReaderPOC/bin/org/apache/ HprofBinaryReaderPOC...

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaObject.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaObject.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaObject.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaObject.java Thu May  7 14:50:21 2009
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof;
+
+/**
+ * Represents a JavaObject
+ * 
+ * @author monteith
+ *
+ */
+public interface IJavaObject {
+	public abstract long getID();
+	
+	public abstract long getClassObjectID();
+	
+	/**
+	 * Retrieve a byte field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return byte value
+	 */
+	public abstract byte getByteField(int offset);
+	
+	/**
+	 * Retrieve a char field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return char value
+	 */
+	public abstract char getCharField(int offset);
+	
+	/**
+	 * Retrieve a short field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return short value
+	 */
+	public abstract short getShortField(int offset);
+	
+	/**
+	 * Retrieve a int field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return int value
+	 */
+	public abstract int getIntegerField(int offset);
+	
+	/**
+	 * Retrieve a long field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return long value
+	 */
+	public abstract long getLongField(int offset);
+	
+	/**
+	 * Retrieve a float field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return float value
+	 */
+	public abstract float getFloatField(int offset);
+	
+	/**
+	 * Retrieve a double field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return double value
+	 */
+	public abstract double getDoubleField(int offset);
+	
+	/**
+	 * Retrieve an object ID field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return long value - an object ID.
+	 */
+	public abstract long getIDField(int offset);
+	
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaStack.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaStack.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaStack.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaStack.java Thu May  7 14:50:21 2009
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof;
+
+public interface IJavaStack {
+
+	
+	public IJavaThread getThread();
+	public IJavaStackFrame[] getStack();
+	
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaStackFrame.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaStackFrame.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaStackFrame.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaStackFrame.java Thu May  7 14:50:21 2009
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof;
+
+public interface IJavaStackFrame {
+	
+	public Long getID();
+	public String getMethodName();
+	public String getMethodSignature();
+	public String getSourceFileName();
+	public IJavaClass getMethodClass(); 
+	public int   getLineNumber();
+	
+	
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaThread.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaThread.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaThread.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaThread.java Thu May  7 14:50:21 2009
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof;
+
+public interface IJavaThread {
+
+	public boolean isActive();
+
+	public int getThreadSerialNumber();
+
+	public long getThreadObjectID();
+
+	public int getStackTraceSerialNumber();
+
+	public String getThreadName();
+
+	public String getThreadGroupParentName();
+
+	public String getThreadGroupName();
+	
+	public IJavaStack getStack();
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/ConstantPoolEntry.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/ConstantPoolEntry.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/ConstantPoolEntry.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/ConstantPoolEntry.java Thu May  7 14:50:21 2009
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+public class ConstantPoolEntry {
+	public int cpIndex = 0;
+	public short type = 0;
+	public byte[] data = null;
+
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/FieldEntry.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/FieldEntry.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/FieldEntry.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/FieldEntry.java Thu May  7 14:50:21 2009
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+/**
+ * A static or instance field.
+ * 
+ *
+ */
+public abstract class FieldEntry {
+	short type;
+	protected long fieldNameID;
+	
+	public short getType() {
+		return type;
+	}
+
+	public long getFieldNameID() {
+		return fieldNameID;
+	}
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfDataTypeSizes.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfDataTypeSizes.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfDataTypeSizes.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfDataTypeSizes.java Thu May  7 14:50:21 2009
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/package org.apache.kato.hprof.datalayer;
+
+import org.apache.kato.common.BasicType;
+
+/**
+ * Class to provide the mapping of a java type in a heap record
+ * to its actual size on disk
+ * 
+ *
+ */
+public class HProfDataTypeSizes implements BasicType {
+
+	private int idSize=0;
+	
+	public HProfDataTypeSizes(int idSize) {
+		this.idSize=idSize;
+	}
+	
+	public int getLengthFromType(short elementType) {
+		int elementLength=0;
+		switch(elementType) {
+		case 1: elementLength=idSize; break;  // array
+		case OBJECT: elementLength=idSize; break;  // object
+		case BOOLEAN: elementLength=1; break;  // boolean
+		case CHAR: elementLength=2; break;  // char
+		case FLOAT: elementLength=4; break;  // float
+		case DOUBLE: elementLength=8; break;  // double
+		case BYTE: elementLength=1; break;  // byte
+		case SHORT: elementLength=2; break;  // short
+		case INT: elementLength=4; break;  // int
+		case LONG: elementLength=8; break;  // long
+		}
+		return elementLength;
+	}
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfFactory.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfFactory.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfFactory.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfFactory.java Thu May  7 14:50:21 2009
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.kato.common.IDataProvider;
+
+public class HProfFactory {
+
+	
+	
+	public static HProfFile createReader(File reader) throws IOException {
+		
+		IDataProvider provider=new RandomAccesDataProvider(reader);
+		
+		return new HProfFile(provider);
+		
+	}
+	
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfFile.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfFile.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfFile.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfFile.java Thu May  7 14:50:21 2009
@@ -0,0 +1,1375 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+import org.apache.kato.common.BitMaskMappingArray;
+import org.apache.kato.common.DataProviderBackedArrayProvider;
+import org.apache.kato.common.DataReader;
+import org.apache.kato.common.IArrayEntryProvider;
+import org.apache.kato.common.IDataProvider;
+import org.apache.kato.common.InvalidFileFormat;
+import org.apache.kato.common.SubsetDataProvider;
+import org.apache.kato.hprof.HProfRecordFormatter;
+
+public class HProfFile {
+
+	class ControlSettingsHProfRecord extends HProfRecord implements
+			IControlSettingsHProfRecord {
+
+		public ControlSettingsHProfRecord(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+		public short getStackTraceDepth() {
+			return readShort(4);
+		}
+
+		public boolean isAllocTrace() {
+			return (readInt(0) & 1) == 1;
+		}
+
+		public boolean isCpuSampling() {
+			return (readInt(0) & 2) == 2;
+		}
+	}
+
+	class EndThreadHProfRecord extends HProfRecord implements
+			IThreadEndingHProfRecord {
+
+		public EndThreadHProfRecord(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+		public int getThreadSerialNumber() {
+			return readInt(0);
+		}
+	}
+
+	class FrameHProfRecord extends HProfRecord implements
+			IJavaStackFrameHProfRecord {
+
+		public FrameHProfRecord(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+		public int getClassSerialNumber() {
+			return readInt(idSize * 4);
+		}
+
+		public int getLineNumber() {
+			return readInt((idSize * 4) + 4);
+		}
+
+		public long getMethodNameID() {
+			return readNumber(idSize, idSize);
+		}
+
+		public long getMethodSignatureID() {
+			return readNumber(idSize + idSize, idSize);
+		}
+
+		public long getSourceFileNameID() {
+			return readNumber(idSize + idSize + idSize, idSize);
+		}
+
+		public long getStackFrameID() {
+			return readNumber(0, idSize);
+		}
+
+	}
+
+	class HeapDumpHProfRecord extends HProfRecord implements
+			IHeapDumpHProfRecord {
+
+		private BitMaskMappingArray subRecordArray = null;
+		private int subRecordCount = -1;
+		private long size = 0;
+		private IDataProvider myP = null;
+
+		public HeapDumpHProfRecord(short tag, IDataProvider dataProvider)
+				throws IOException {
+			super(tag, null);
+			size = dataProvider.getDataLength();
+			myP = dataProvider;
+			subRecordArray = new BitMaskMappingArray(1000, 25,
+					new HProfDumpRecordArrayProvider(dataProvider));
+		}
+
+		public IHProfRecord getSubRecord(int index) {
+
+			return (IHProfRecord) subRecordArray.get(index);
+		}
+
+		@Override
+		public int getSubRecordCount() {
+			if (subRecordCount == -1) {
+
+				subRecordCount = 0;
+				while (true) {
+					if (subRecordCount == 5) {
+						int a = 1;
+					}
+					Object o = subRecordArray.get(subRecordCount);
+					if (o == null)
+						break;
+					subRecordCount++;
+					if (o instanceof UnknownHProfRecord) {
+						break;
+					}
+				}
+
+			}
+			return subRecordCount;
+		}
+
+		@Override
+		public long getDataLength() {
+			return (int) size;
+		}
+
+		@Override
+		public byte[] getData() {
+			try {
+				return peek(myP, 20);
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			return null;
+		}
+
+		@Override
+		public long getSubRecordLocation(int index) {
+			return subRecordArray.getLocation(index);
+		}
+
+		@Override
+		/**
+		 * Return a record by its locations
+		 * 
+		 * @param location
+		 * @return IHProfRecord at given location
+		 */
+		public IHProfRecord getSubRecordByLocation(long location) {		
+			return (IHProfRecord) subRecordArray.getAtLocation(location);
+		}
+	}
+
+	private final class HProfDumpRecordArrayProvider extends
+			DataProviderBackedArrayProvider {
+		private HProfDumpRecordArrayProvider(IDataProvider provider) {
+			super(provider);
+		}
+
+		private IHProfRecord buildClassDumpRecord(int tag,
+				IDataProvider dumpRecordProvider) throws IOException {
+
+			long loc = dumpRecordProvider.getCurrentLocation();
+			dumpRecordProvider.moveBy((idSize * 7) + 8);
+			short elements = dumpRecordProvider.readU2(); // size of constant
+			// pool
+			int constantPoolIndex = (int)(dumpRecordProvider.getCurrentLocation()
+					- loc);
+			for (int i = 0; i < elements; i++) {
+				short cpIndex = dumpRecordProvider.readU2();
+				short type = dumpRecordProvider.readByte();
+				int arrayLength = sizes.getLengthFromType(type);
+				dumpRecordProvider.moveBy(arrayLength);
+			}
+
+			short staticFields = dumpRecordProvider.readU2();
+						
+			int staticFieldsIndex = (int)(dumpRecordProvider.getCurrentLocation()- loc);
+			for (int i = 0; i < staticFields; i++) {
+				long index = DataReader.readNumber(dumpRecordProvider, idSize);
+				short type = dumpRecordProvider.readByte();
+				int arrayLength = sizes.getLengthFromType(type);
+				dumpRecordProvider.moveBy(arrayLength);
+			}
+
+			short instFields = dumpRecordProvider.readU2();
+
+			int instFieldsIndex = (int) (dumpRecordProvider.getCurrentLocation()- loc);
+			for (int i = 0; i < instFields; i++) {
+				long index = DataReader.readNumber(dumpRecordProvider, idSize);
+				short type = dumpRecordProvider.readByte();
+			}
+
+			long datalength = dumpRecordProvider.getCurrentLocation() - loc;
+			SubsetDataProvider p = new SubsetDataProvider(dumpRecordProvider,
+					loc, datalength);
+
+			// Pass indices of static and instance fields - they are variable length.
+			return new GCClassHeapDumpRecord((byte) tag, p, staticFieldsIndex, instFieldsIndex );
+
+		}
+
+		@Override
+		public Object getCurrentElement() {
+			// read tag
+			try {
+				long l = getProvider().getCurrentLocation();
+
+				IDataProvider p = getProvider();
+				if (p.dataRemaining() < 1)
+					return null;
+				short tag = p.readByte();
+				int size = getRecordSize(tag);
+				byte[] data = null;
+				if (size >= 0) {
+					data = getProvider().readBytes(size);
+				}
+
+				switch (tag) {
+				case 0xFF: // unknown root
+					return new GCRootUnknownHeapRecord(tag, data);
+
+				case 0x01: // jni global root
+
+					return new GCRootJNIGlobalRefHeapRecord(tag, data);
+
+				case 0x02: // jni local
+					return new GCRootJNILocalHeapRecord(tag, data);
+
+				case 0x03: // java frame
+					return new GCRootJavaFrameHeapRecord(tag, data);
+
+				case 0x04: // native stack root
+					return new GCRootNativeStackHeapRecord(tag, data);
+
+				case 0x05: // stick class root
+					return new GCRootStickyClassHeapRecord(tag, data);
+
+				case 0x06: // thread block root
+					return new GCRoothreadBlockHeapRecord(tag, data);
+
+				case 0x07: // monitor used
+					return new GCRootMonitorUsedHeapRecord(tag, data);
+
+				case 0x08: // thread obj root
+					return new GCRootThreadObjHeapRecord(tag, data);
+
+				case 0x20: // class dump
+					return buildClassDumpRecord(tag, getProvider());
+				case 0x21: // instance
+					return buildInstanceDumpRecord(tag, getProvider());
+
+				case 0x22: // obj array
+					return buildObjArrayDumpRecord(tag, getProvider());
+				case 0x23: // primitive array
+					return buildPrimitiveArrayDumpRecord(tag, getProvider());
+
+				default:
+					// don't know what this is
+					return new UnknownHProfRecord(tag, null);
+
+				}
+
+			} catch (IOException e) {
+				e.printStackTrace();
+				return null;
+			}
+
+		}
+
+		private Object buildPrimitiveArrayDumpRecord(short tag,
+				IDataProvider arrayProvider) throws IOException {
+
+			long loc = arrayProvider.getCurrentLocation();
+			arrayProvider.moveBy(idSize + 4);
+			int elements = arrayProvider.readU4();
+			short elementType = arrayProvider.readByte();
+
+			int elementLength = sizes.getLengthFromType(elementType);
+			int datalength = idSize + 9 + (elementLength * elements);
+			arrayProvider.moveTo(loc);
+			SubsetDataProvider p = new SubsetDataProvider(arrayProvider,
+					datalength);
+			arrayProvider.moveTo(loc + datalength);
+			return new GCPrimitiveArrayHeapDumpRecord(tag, p);
+		}
+
+		/**
+		 * 
+		 * id array object ID u4 stack trace serial number u4 number of elements
+		 * id array class ID [id]* elements
+		 * 
+		 * @param tag
+		 * @param arrayProvider
+		 * @return
+		 * @throws IOException
+		 */
+		private Object buildObjArrayDumpRecord(short tag,
+				IDataProvider arrayProvider) throws IOException {
+
+			long loc = arrayProvider.getCurrentLocation();
+			arrayProvider.moveBy(idSize + 4);
+			int elements = arrayProvider.readU4();
+			int datalength = (idSize * 2) + 8 + (idSize * elements);
+			arrayProvider.moveTo(loc);
+			SubsetDataProvider p = new SubsetDataProvider(arrayProvider,
+					datalength);
+			arrayProvider.moveTo(loc + datalength);
+			return new GCObjectArrayHeapDumpRecord(tag, p);
+		}
+
+		/**
+		 * id object ID u4 stack trace serial number id class object ID u4
+		 * number of bytes that follow [vl]* instance field values (class,
+		 * followed by super, super's super ...)
+		 * 
+		 * @param tag
+		 * @param arrayProvider
+		 * @return
+		 * @throws IOException
+		 */
+		private Object buildInstanceDumpRecord(short tag,
+				IDataProvider arrayProvider) throws IOException {
+
+			long loc = arrayProvider.getCurrentLocation();
+			arrayProvider.moveBy((idSize * 2) + 4);
+			int byteCount = arrayProvider.readU4();
+			int datalength = (idSize * 2) + 8 + byteCount;
+			arrayProvider.moveTo(loc);
+			SubsetDataProvider p = new SubsetDataProvider(arrayProvider,
+					datalength);
+			arrayProvider.moveTo(loc + datalength);
+			return new GCInstanceHeapDumpRecord(tag, p);
+		}
+
+		/**
+		 * Returns record size for given tag.
+		 * 
+		 * @param tag -
+		 *            tag to size
+		 * @return record size or -1 if dynamic, -2 if unknown tag
+		 */
+		private int getRecordSize(int tag) {
+			int recordLength = 0;
+
+			switch (tag) {
+
+			case 0xFF: // unknown root
+
+				recordLength = idSize;
+				break;
+
+			case 0x01: // jni global root
+
+				recordLength = idSize * 2;
+				break;
+
+			case 0x02: // jni local
+				recordLength = idSize + 8;
+				break;
+
+			case 0x03: // java frame
+				recordLength = idSize + 8;
+				break;
+
+			case 0x04: // native stack root
+				recordLength = idSize + 4;
+				break;
+
+			case 0x05: // stick class root
+				recordLength = idSize;
+				break;
+
+			case 0x06: // thread block root
+				recordLength = idSize + 4;
+				break;
+
+			case 0x07: // monitor used
+				recordLength = idSize;
+				break;
+
+			case 0x08: // thread obj root
+				recordLength = idSize + 8;
+				break;
+
+			case 0x20: // class dump
+			case 0x21: // instance
+			case 0x22: // obj array
+			case 0x23: // primitive array
+				recordLength = -1;
+				break;
+			default:
+				// don't know what this is
+				recordLength = -2;
+
+			}
+			return recordLength;
+		}
+	}
+
+	private final class HPROFRecordProvider implements IArrayEntryProvider {
+
+		private IDataProvider recordProvider = null;
+
+		public HPROFRecordProvider(IDataProvider provider) {
+			this.recordProvider = provider;
+		}
+
+		@Override
+		public IHProfRecord getCurrentElement() {
+
+			// read tag
+			try {
+
+				short tag = recordProvider.readByte();
+				int ms = recordProvider.readU4();
+				int left = recordProvider.readU4();
+				byte[] data = null;
+
+				switch (tag) {
+				case 0x0c:
+					break;
+				default:
+
+					data = recordProvider.readBytes(left);
+
+				}
+
+				switch (tag) {
+
+				case 0x01:
+
+					return new UTF8HProfRecordImpl(tag, data);
+				case 0x02:
+					return new LoadClassHProfRecord(tag, data);
+				case 0x03:
+					return new UnloadClassHProfRecord(tag, data);
+				case 0x04:
+					return new FrameHProfRecord(tag, data);
+				case 0x05:
+					return new TraceHProfRecord(tag, data);
+				case 0x0e:
+					return new ControlSettingsHProfRecord(tag, data);
+
+				case 0x0a:
+					return new StartThreadHProfRecord(tag, data);
+				case 0x0b:
+					return new EndThreadHProfRecord(tag, data);
+
+				case 0x0c:
+					IHeapDumpHProfRecord rec = new HeapDumpHProfRecord(tag,
+							new SubsetDataProvider(recordProvider, left));
+					recordProvider.moveBy(left);
+					return rec;
+				default:
+					// don't know what the thing is - return an unknown
+					// type.
+
+					return new UnknownHProfRecord(tag, data);
+				}
+
+			} catch (IOException e) {
+				return null;
+			}
+
+		}
+
+		@Override
+		public long getCurrentLocation() {
+
+			try {
+				return recordProvider.getCurrentLocation();
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			return -1;
+		}
+
+		@Override
+		public void getState(List state) {
+
+			state.add("HProfRecordProvider");
+			recordProvider.addState(state);
+
+		}
+
+		@Override
+		public boolean moveRelativeElement(int seekNo) {
+
+			while (seekNo > 0) {
+				Object o = getCurrentElement();
+				if (o == null)
+					return false;
+				seekNo--;
+			}
+			return true;
+		}
+
+		@Override
+		public boolean moveToLocation(long l) {
+
+			try {
+				recordProvider.moveTo(l);
+				return true;
+			} catch (IOException e) {
+				return false;
+			}
+		}
+	}
+
+	class LoadClassHProfRecord extends HProfRecord implements
+			ILoadClassHProfRecord {
+
+		public LoadClassHProfRecord(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+		public long getClassNameID() {
+			return readNumber(8 + idSize, idSize);
+		}
+
+		public long getClassObjectID() {
+			return readNumber(4, idSize);
+		}
+
+		public int getClassSerialNumber() {
+			return readInt(0);
+		}
+
+		public int getStackTraceSerialNumber() {
+			return readInt(4 + idSize);
+		}
+	}
+
+	class UnloadClassHProfRecord extends HProfRecord implements
+			IUnloadClassHProfRecord {
+
+		public UnloadClassHProfRecord(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+		public int getClassSerialNumber() {
+			return readInt(0);
+		}
+	}
+
+	class StartThreadHProfRecord extends HProfRecord implements
+			IThreadActiveHProfRecord {
+
+		public StartThreadHProfRecord(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+		public int getStackTraceSerialNumber() {
+			return readInt(idSize + 4);
+		}
+
+		public long getThreadGroupNameID() {
+			return readNumber(8 + (idSize * 2), idSize);
+
+		}
+
+		public long getThreadGroupParentNameID() {
+			return readNumber(8 + (idSize * 3), idSize);
+		}
+
+		public long getThreadNameID() {
+			return readNumber(8 + idSize, idSize);
+		}
+
+		public long getThreadObjectID() {
+			return readNumber(4, idSize);
+		}
+
+		public int getThreadSerialNumber() {
+			return readInt(0);
+		}
+	}
+
+	class TraceHProfRecord extends HProfRecord implements
+			IJavaStackTraceHProfRecord {
+
+		public TraceHProfRecord(short tag, byte[] data) {
+			super(tag, data);
+		}
+
+		public int getFrameCount() {
+			return readInt(8);
+		}
+
+		public int getSerialNumber() {
+			return readInt(0);
+		}
+
+		public long getStackFrameID(int elementNo) {
+			return readNumber((idSize * elementNo) + 12, idSize);
+		}
+
+		public int getThreadSerialNumber() {
+			return readInt(4);
+		}
+	}
+
+	class UnknownHProfRecord extends HProfRecord {
+
+		public UnknownHProfRecord(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+	}
+
+	class UTF8HProfRecordImpl extends HProfRecord implements IUTF8HProfRecord {
+
+		public UTF8HProfRecordImpl(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+		@Override
+		public String getAsString() {
+
+			try {
+				return new String(getCharacters(), "UTF-8");
+			} catch (UnsupportedEncodingException e) {
+
+				return null;
+			}
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see org.apache.kato.hprof.IUTF8HProfRecord#getCharacters()
+		 */
+		public byte[] getCharacters() {
+
+			int length = ((int) getDataLength()) - idSize;
+			return readBytes(idSize, length);
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see org.apache.kato.hprof.IUTF8HProfRecord#getNameID()
+		 */
+		public long getNameID() {
+			return readNumber(0, idSize);
+		}
+	}
+
+	private BitMaskMappingArray array = null;
+
+	private String header = null;
+
+	private Integer idSize = null;
+	private HProfDataTypeSizes sizes = null;
+
+	private IDataProvider mainProvider = null;
+
+	private int records = -1;
+	private long recordsOffset = 0;
+
+	private Long timeStamp = null;
+
+	public HProfFile(IDataProvider provider) {
+		this.mainProvider = provider;
+	}
+
+	public byte[] peek(IDataProvider dumpRecordProvider, int i)
+			throws IOException {
+		long loc = dumpRecordProvider.getCurrentLocation();
+		long bytesLeft = dumpRecordProvider.getDataLength()
+				- dumpRecordProvider.getCurrentLocation();
+		if (i > bytesLeft)
+			i = (int) bytesLeft;
+		byte[] b = dumpRecordProvider.readBytes(i);
+		dumpRecordProvider.moveTo(loc);
+		return b;
+	}
+
+	private void buildHeader() throws IOException {
+
+		try {
+			header = mainProvider.readCString();
+		} catch (IOException ioe) {
+			throw new InvalidFileFormat("File is not an HPROF file", ioe);
+		}
+		if (header.equals("JAVA PROFILE 1.0.1") == false
+				&& header.equals("JAVA PROFILE 1.0.2") == false) {
+			throw new InvalidFileFormat("File is not an HPROF file");
+		}
+		try {
+			idSize = mainProvider.readU4();
+			timeStamp = mainProvider.readU8();
+		} catch (IOException ioe) {
+			throw new InvalidFileFormat("HPROF file is truncated", ioe);
+		}
+		sizes = new HProfDataTypeSizes(idSize);
+
+		recordsOffset = mainProvider.getCurrentLocation();
+		long maxOffsetLength = mainProvider.getDataLength() - recordsOffset;
+		SubsetDataProvider subset = new SubsetDataProvider(mainProvider,
+				maxOffsetLength);
+		array = new BitMaskMappingArray(1000, 25, new HPROFRecordProvider(
+				subset));
+
+	}
+
+	public void close() throws IOException {
+		mainProvider.close();
+
+	}
+
+	public String getHeader() {
+
+		return header;
+	}
+
+	public Integer getIdentifierSize() {
+
+		return idSize;
+	}
+
+	public long getRecordLocation(int index) {
+		if (index < 0)
+			throw new IllegalArgumentException("record index [" + index
+					+ "] is less than zero");
+		return array.getLocation(index) + recordsOffset + 9; // add 9 for
+		// header bytes
+		// of heap dump
+		// record
+	}
+
+	public IHProfRecord getRecord(int index) {
+
+		if (index < 0)
+			throw new IllegalArgumentException("record index [" + index
+					+ "] is less than zero");
+		return (IHProfRecord) array.get(index);
+	}
+
+	public int getRecordCount() {
+
+		if (records < 0)
+			records = readRecords();
+		return records;
+	}
+
+	public Long getTimeStamp() {
+		return timeStamp;
+	}
+
+	public void open() throws IOException {
+		mainProvider.open();
+		buildHeader();
+	}
+
+	private int readRecords() {
+		int counter = 0;
+		IHProfRecord record = null;
+
+		while (true) {
+			record = getRecord(counter);
+			if (record == null)
+				break;
+			counter++;
+
+		}
+		return counter;
+	}
+
+	class GCRoothreadBlockHeapRecord extends HProfRecord {
+
+		public GCRoothreadBlockHeapRecord(short tag, byte[] data) {
+			super(tag, data);
+		}
+
+		public long getId() {
+			return readNumber(0, idSize);
+		}
+
+		public int getThreadSerialNumber() {
+			return readInt(idSize);
+		}
+
+	}
+
+	class GCRootJavaFrameHeapRecord extends HProfRecord {
+
+		public GCRootJavaFrameHeapRecord(short tag, byte[] data) {
+			super(tag, data);
+		}
+
+		public long getId() {
+			return readNumber(0, idSize);
+		}
+
+		public int getThreadSerialNumber() {
+			return readInt(idSize);
+		}
+
+		public int getStackFrameNumber() {
+			return readInt(idSize + 4);
+		}
+
+	}
+
+	class GCRootJNIGlobalRefHeapRecord extends HProfRecord {
+
+		public GCRootJNIGlobalRefHeapRecord(short tag, byte[] data) {
+			super(tag, data);
+		}
+
+		public long getObjid() {
+			return readNumber(0, idSize);
+		}
+
+		public long getJniid() {
+			return readNumber(idSize, idSize);
+		}
+
+	}
+
+	class GCRootJNILocalHeapRecord extends HProfRecord {
+
+		public GCRootJNILocalHeapRecord(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+		public long getId() {
+			return readNumber(0, idSize);
+		}
+
+		public int getThreadSerialNumber() {
+			return readInt(idSize);
+		}
+
+		public int getStackFrameNumber() {
+			return readInt(idSize + 4);
+		}
+
+	}
+
+	public abstract class IDEntryHeapRecord extends HProfRecord {
+
+		public IDEntryHeapRecord(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+		public long getID() {
+			return readNumber(0, idSize);
+		}
+	}
+
+	class GCRootMonitorUsedHeapRecord extends IDEntryHeapRecord {
+
+		public GCRootMonitorUsedHeapRecord(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+	}
+
+	class GCRootStickyClassHeapRecord extends IDEntryHeapRecord {
+
+		public GCRootStickyClassHeapRecord(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+	}
+
+	class GCRootUnknownHeapRecord extends HProfRecord {
+
+		public GCRootUnknownHeapRecord(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+	}
+
+	class GCRootThreadObjHeapRecord extends HProfRecord {
+
+		public GCRootThreadObjHeapRecord(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+		public long getId() {
+			return readNumber(0, idSize);
+		}
+
+		public int getThreadSequenceNumber() {
+			return readInt(idSize);
+		}
+
+		public int getStackTraceSequenceNumber() {
+			return readInt(idSize + 4);
+		}
+
+	}
+
+	class GCRootNativeStackHeapRecord extends HProfRecord {
+
+		public GCRootNativeStackHeapRecord(short tag, byte[] data) {
+			super(tag, data);
+
+		}
+
+		public long getId() {
+			return readNumber(0, idSize);
+		}
+
+		public int getThreadSequenceNumber() {
+			return readInt(idSize);
+		}
+
+	}
+
+	abstract class LightHeapEntryRecord implements IHProfRecord {
+
+		private IDataProvider lightProvider = null;
+		private short tag = 0;
+
+		public LightHeapEntryRecord(short tag, IDataProvider provider) {
+			this.tag = tag;
+			this.lightProvider = provider;
+		}
+
+		@Override
+		public byte[] getData() {
+			try {
+				return peek(lightProvider, (int)Math.min(200, this.getDataLength()));
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			return null;
+		}
+
+		public short getTag() {
+			return tag;
+		}
+
+		public long getDataLength() {
+
+			try {
+				return lightProvider.getDataLength();
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			return -1;
+		}
+
+		public IDataProvider getProvider() {
+			return lightProvider;
+		}
+
+		protected long readLong(int offset) {			
+			try {
+				lightProvider.moveTo(offset);
+				return lightProvider.readU8();
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			return -1;
+
+		}
+
+		protected int readInt(int offset) {
+			try {
+				lightProvider.moveTo(offset);
+				return lightProvider.readU4();
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			return -1;
+
+		}
+
+		protected short readByte(int offset) {
+			try {
+				lightProvider.moveTo(offset);
+				return lightProvider.readByte();
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			return -1;
+
+		}
+
+		protected char readChar(int offset) {
+			try {
+				lightProvider.moveTo(offset);
+				return (char)lightProvider.readU2();
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			return (char)-1;
+
+		}
+		
+		protected short readShort(int offset) {
+			try {
+				lightProvider.moveTo(offset);
+				return lightProvider.readU2();
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			return -1;
+		}
+
+		protected long readNumber(int offset, int length) {
+			try {
+				lightProvider.moveTo(offset);
+				return DataReader.readNumber(lightProvider, length);
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			return -1;
+
+		}
+
+		protected byte[] readBytes(int offset, int length) {
+			try {
+				lightProvider.moveTo(offset);
+				return lightProvider.readBytes(length);
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			return null;
+		}
+
+	}
+
+	class GCPrimitiveArrayHeapDumpRecord extends LightHeapEntryRecord  implements IGCPrimitiveArrayHeapDumpRecord {
+
+		public GCPrimitiveArrayHeapDumpRecord(short tag, IDataProvider provider) {
+			super(tag, provider);
+
+		}
+
+		@Override
+		public long getID() {
+			return readNumber(0, idSize);
+		}
+
+		@Override
+		public int getStackTraceNumber() {
+			return readInt(idSize);
+		}
+
+		@Override
+		public int getNumberOfElements() {
+			return readInt(idSize + 4);
+		}
+
+		@Override
+		public short getElementType() {
+			return readByte(idSize + 8);
+		}
+
+		@Override
+		public boolean getBooleanElement(int index) {
+			return getByteElement(index) == 0;
+		}
+		
+		@Override
+		public short getByteElement(int index) {
+			return readByte(idSize+9+index);
+		}
+		
+		@Override
+		public short getShortElement(int index) {
+			return readShort(idSize+ 9 + index * 2);
+		}
+		
+		@Override
+		public char getCharElement(int index) {
+			return readChar(idSize+ 9 + index * 2);
+		}
+		
+		@Override
+		public int getIntElement(int index) {
+			return readInt(idSize+ 9 + index * 4);
+		}
+		
+		@Override
+		public long getLongElement(int index) {
+			return readLong(idSize+ 9 + index * 8);
+		}
+		
+		@Override
+		public float getFloatElement(int index) {
+			return Float.intBitsToFloat(getIntElement(index));
+		}
+		
+		@Override
+		public double getDoubleElement(int index) {
+			return Double.longBitsToDouble(getLongElement(index));
+		}
+	}
+
+	/**
+	 * An array of references on the heap.
+	 * 
+	 */
+	class GCObjectArrayHeapDumpRecord extends LightHeapEntryRecord implements IGCObjectArrayHeapDumpRecord {
+
+		public GCObjectArrayHeapDumpRecord(short tag, IDataProvider provider) {
+			super(tag, provider);
+
+		}
+
+		@Override
+		public long getID() {
+			return readNumber(0, idSize);
+		}
+
+		@Override
+		public int getStackTraceNumber() {
+			return readInt(idSize);
+		}
+
+		@Override
+		public int getNumberOfElements() {
+			return readInt(idSize + 4);
+		}
+
+		@Override
+		public long getElement(int index) {
+			return readNumber(idSize*2+8 + index * idSize, idSize);
+		}
+
+		@Override
+		public long getArrayClassObjectID() {
+			return readNumber(idSize + 8, idSize);
+		}
+
+	}
+
+	/**
+	 * An ordinary object instance on the heap.
+	 *
+	 */
+	class GCInstanceHeapDumpRecord extends LightHeapEntryRecord implements IGCInstanceHeapDumpRecord {
+
+		public GCInstanceHeapDumpRecord(short tag, IDataProvider provider) {
+			super(tag, provider);
+
+		}
+
+		public long getID() {
+			return readNumber(0, idSize);
+		}
+
+		public int getStackTraceNumber() {
+			return readInt(idSize);
+		}
+
+		public long getClassObjectID() {
+			return readNumber(idSize + 4, idSize);
+		}
+
+		public int getNumberOfValueBytes() {
+			return readInt((idSize * 2) + 4);
+		}
+
+		@Override
+		public byte getByteField(int offset) {
+			return (byte) readByte((idSize*2 + 8) + offset);
+		}
+
+		@Override
+		public char getCharField(int offset) {
+			return readChar((idSize*2 + 8) + offset);
+		}
+
+		@Override
+		public double getDoubleField(int offset) {
+			return Double.longBitsToDouble(readLong((idSize*2 + 8) + offset));
+		}
+
+		@Override
+		public float getFloatField(int offset) {
+			return Float.intBitsToFloat(readInt((idSize*2 + 8) + offset));
+		}
+
+		@Override
+		public long getIDField(int offset) {		
+			return readNumber((idSize*2 + 8) + offset,idSize);
+		}
+
+		@Override
+		public int getIntegerField(int offset) {
+			return readInt((idSize*2 + 8) + offset);
+		}
+
+		@Override
+		public long getLongField(int offset) {	
+			return readLong((idSize*2 + 8) + offset);
+		}
+
+		@Override
+		public short getShortField(int offset) {
+			return readShort((idSize*2 + 8) + offset);
+		}
+
+		@Override
+		public boolean getBooleanField(int offset) {
+			return !(getByteField(offset) == 0);
+		}
+
+	}
+
+	public class GCClassHeapDumpRecord extends LightHeapEntryRecord implements IGCClassHeapDumpRecord, IHeapObject {
+
+		private int staticFieldsOffset;
+		private int instFieldsOffset;
+
+		public GCClassHeapDumpRecord(byte tag, IDataProvider provider
+				, int staticFieldsOffset, int instFieldsOffset ) {
+			super(tag, provider);
+			
+			this.staticFieldsOffset = staticFieldsOffset;
+			this.instFieldsOffset = instFieldsOffset;
+		}
+
+		public long getID() {
+			return readNumber(0, idSize);
+		}
+
+		public int getStackTraceNumber() {
+			return readInt(idSize);
+		}
+
+		public long getSuperClassObjectID() {
+			return readNumber(idSize + 4, idSize);
+		}
+
+		public long getClassLoaderObjectID() {
+			return readNumber((idSize * 2) + 4, idSize);
+		}
+
+		public long getSignersObjectID() {
+			return readNumber((idSize * 3) + 4, idSize);
+		}
+
+		public long getProtectionDomainObjectID() {
+			return readNumber((idSize * 4) + 4, idSize);
+		}
+
+		public int getInstanceSize() {
+			return readInt((idSize * 7) + 4);
+		}
+
+		public int getConstantPoolSize() {
+			return readShort((idSize * 7) + 8);
+		}
+
+		public ConstantPoolEntry[] getConstantPool() {
+			return readConstantPool((idSize * 7) + 10);
+		}
+
+		private ConstantPoolEntry[] readConstantPool(int offset) {
+			int entries = getConstantPoolSize();
+			ConstantPoolEntry[] pool = new ConstantPoolEntry[entries];
+			for (int i = 0; i < entries; i++) {
+				ConstantPoolEntry cpe = new ConstantPoolEntry();
+				cpe.cpIndex = readShort(offset);
+				offset += 2;
+				cpe.type = readByte(offset);
+				offset++;
+				int valueLength = sizes.getLengthFromType(cpe.type);
+				cpe.data = readBytes(offset, valueLength);
+				offset += valueLength;
+				pool[i] = cpe;
+			}
+			return pool;
+		}
+
+		public StaticFieldEntry[] getStaticFields() {
+			return readStaticFields(staticFieldsOffset);			
+		}
+		
+		private StaticFieldEntry[] readStaticFields(int offset) {
+			short staticFields = readShort(offset-2);
+			
+			StaticFieldEntry[] fields = new StaticFieldEntry[staticFields];
+			for (int i = 0; i < staticFields; i++) {
+				long stringID = readNumber(offset,idSize);
+				offset += idSize;
+				short type = readByte(offset);
+				offset+=1;
+				int arrayLength = sizes.getLengthFromType(type);
+				long data = readNumber(offset, arrayLength);
+				offset += arrayLength;
+				
+				fields[i] = new StaticFieldEntry(stringID, type, data);
+			}
+			
+			return fields;
+		}
+		
+		public InstanceFieldEntry[] getInstanceFields() {
+			return readInstanceFields(instFieldsOffset);
+		}
+
+		private InstanceFieldEntry[] readInstanceFields(int offset) {
+			short instFields = readShort(offset-2);
+			int fieldOffset = 0;
+			InstanceFieldEntry[] fields = new InstanceFieldEntry[instFields];
+			
+			for (int i = 0; i < instFields; i++) {
+				long stringID = readNumber(offset,idSize);
+				offset += idSize;
+				
+				short type = readByte(offset);
+				offset+=1;
+								
+				fields[i] = new InstanceFieldEntry(stringID, type, fieldOffset);
+				fieldOffset += sizes.getLengthFromType(type);
+			}
+			offsetSize = fieldOffset;
+			return fields;
+		}
+
+		private int offsetSize=-1;
+		@Override
+		public int getOffsetSize() {
+			if(offsetSize == -1) {
+				getInstanceFields();
+			}
+			return offsetSize;
+		}
+		
+	}
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+import org.apache.kato.common.DataReader;
+
+public abstract class HProfRecord implements IHProfRecord {
+
+	private short tag=0;
+	private byte[] data=null;
+	public HProfRecord(short tag,byte[] data) {
+		this.tag=tag;
+		this.data=data;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.kato.hprof.datalayer.IHProfRecord#getTag()
+	 */
+	public short getTag() {
+		return tag;
+	}
+
+	
+	protected int readInt(int offset) {
+		return DataReader.read4Bytes(data,offset);
+	}
+	protected short readShort(int offset) {
+		return DataReader.read2Bytes(data,offset);
+	}
+	
+	protected long readNumber(int offset, int length) {
+		return DataReader.readNumber(data,offset,length);
+		
+	}
+	protected byte[] readBytes(int offset,int length) {
+		return DataReader.readByteArray(data,offset,length);
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.kato.hprof.datalayer.IHProfRecord#getDataLength()
+	 */
+	public long getDataLength() {
+		if(data==null) return 0;
+		return data.length;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.kato.hprof.datalayer.IHProfRecord#getData()
+	 */
+	public byte[] getData() {
+		return data;
+	}
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfRecordTypes.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfRecordTypes.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfRecordTypes.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfRecordTypes.java Thu May  7 14:50:21 2009
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+public enum HProfRecordTypes {
+
+	unknown,utf8,load_class,unload_class,frame,trace,alloc_sites,
+	heap_summary,start_thread,end_thread,heap_dump,
+	heap_dump_segment,heap_dump_end,cpu_samples,control_settings;
+	
+	
+	
+    
+	
+	public static HProfRecordTypes getRecordType(short tag) {
+	
+		switch(tag) {
+		case 0x01 : return utf8;
+		case 0x02 : return load_class;
+		case 0x03 : return unload_class;
+		case 0x04 : return frame;
+		case 0x05 : return trace;
+		case 0x06 : return alloc_sites;
+		case 0x07 : return heap_summary;
+		case 0x0A : return start_thread;
+		case 0x0B : return end_thread;
+		case 0x0C : return heap_dump;
+		case 0x1C : return heap_dump_segment;
+		case 0x2C : return heap_dump_end;
+		case 0x0E : return control_settings;
+		
+		default: return unknown;
+		}
+		
+	}
+	
+	
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IControlSettingsHProfRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IControlSettingsHProfRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IControlSettingsHProfRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IControlSettingsHProfRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+public interface IControlSettingsHProfRecord {
+
+	public abstract boolean isAllocTrace();
+
+	public abstract boolean isCpuSampling();
+
+	public abstract short getStackTraceDepth();
+
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCClassHeapDumpRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCClassHeapDumpRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCClassHeapDumpRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCClassHeapDumpRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+
+public interface IGCClassHeapDumpRecord {
+	public long getID();
+	
+	public int getStackTraceNumber();
+
+	public long getSuperClassObjectID();
+
+	public long getClassLoaderObjectID();
+
+	public long getSignersObjectID();
+
+	public long getProtectionDomainObjectID();
+
+	public int getInstanceSize();
+
+	public int getConstantPoolSize();
+
+	public ConstantPoolEntry[] getConstantPool();
+
+	public InstanceFieldEntry[] getInstanceFields();
+	
+	public StaticFieldEntry[] getStaticFields();
+
+	public int getOffsetSize();	
+
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCInstanceHeapDumpRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCInstanceHeapDumpRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCInstanceHeapDumpRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCInstanceHeapDumpRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+/**
+ * Represents a GCInstanceHeapDumpRecord.
+ * This is a plain object instance, i.e. it is not an array.
+ * 
+ * 
+ */
+public interface IGCInstanceHeapDumpRecord extends IHeapObject {
+
+
+	/**
+	 * The object id of the class this object is an instance of.
+	 * 
+	 * @return long object id
+	 */
+	public abstract long getClassObjectID();
+
+
+	/**
+	 * Retrieve a boolean field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return byte value
+	 */
+	public abstract boolean getBooleanField(int offset);
+	
+	/**
+	 * Retrieve a byte field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return byte value
+	 */
+	public abstract byte getByteField(int offset);
+	
+	/**
+	 * Retrieve a char field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return char value
+	 */
+	public abstract char getCharField(int offset);
+	
+	/**
+	 * Retrieve a short field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return short value
+	 */
+	public abstract short getShortField(int offset);
+	
+	/**
+	 * Retrieve a int field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return int value
+	 */
+	public abstract int getIntegerField(int offset);
+	
+	/**
+	 * Retrieve a long field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return long value
+	 */
+	public abstract long getLongField(int offset);
+	
+	/**
+	 * Retrieve a float field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return float value
+	 */
+	public abstract float getFloatField(int offset);
+	
+	/**
+	 * Retrieve a double field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return double value
+	 */
+	public abstract double getDoubleField(int offset);
+	
+	/**
+	 * Retrieve an object ID field from this object.
+	 * 
+	 * @param offset into instance values.
+	 * @return long value - an object ID.
+	 */
+	public abstract long getIDField(int offset);
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCObjectArrayHeapDumpRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCObjectArrayHeapDumpRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCObjectArrayHeapDumpRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCObjectArrayHeapDumpRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+public interface IGCObjectArrayHeapDumpRecord extends IHeapObject {
+
+	public int getNumberOfElements();
+	
+	/**
+	 * Retrieve the object ID at a given index.
+	 * 
+	 * @param index
+	 * @return ID of object at index.
+	 */
+	public long getElement(int index);
+	
+	public long getArrayClassObjectID();
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCPrimitiveArrayHeapDumpRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCPrimitiveArrayHeapDumpRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCPrimitiveArrayHeapDumpRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IGCPrimitiveArrayHeapDumpRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+public interface IGCPrimitiveArrayHeapDumpRecord extends IHeapObject {
+	public int getNumberOfElements();
+	public short getElementType();
+	boolean getBooleanElement(int index);
+	short getByteElement(int index);
+	short getShortElement(int index);
+	char getCharElement(int index);
+	int getIntElement(int index);
+	long getLongElement(int index);
+	float getFloatElement(int index);
+	double getDoubleElement(int index);
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IHProfRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IHProfRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IHProfRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IHProfRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+public interface IHProfRecord {
+
+	public short getTag();
+
+	public  long getDataLength();
+
+	public  byte[] getData();
+
+ 
+	
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IHeapDumpHProfRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IHeapDumpHProfRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IHeapDumpHProfRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IHeapDumpHProfRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+public interface IHeapDumpHProfRecord  extends IHProfRecord {
+
+	public abstract int getSubRecordCount();
+
+	public abstract IHProfRecord getSubRecord(int index);
+
+	public abstract long getSubRecordLocation(int index);
+
+	/**
+	 * Shortcut that reads a record directly.
+	 * 
+	 * @param fileOffset
+	 * @return IHProfRecord
+	 */
+	public abstract IHProfRecord getSubRecordByLocation(long location);
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IHeapObject.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IHeapObject.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IHeapObject.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IHeapObject.java Thu May  7 14:50:21 2009
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+/**
+ * Used for IHProfRecords on the heap that can be retrieved
+ * by their ID.
+ * 
+ */
+public interface IHeapObject {
+	/**
+	 * This object's ID
+	 * 
+	 * @return long object ID of this object
+	 */
+	public abstract long getID();
+
+	/**
+	 * Returns the stacktrace serial # where this object
+	 * was instantiated.
+	 * 
+	 * @return int
+	 */
+	public abstract int getStackTraceNumber();
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IJavaStackFrameHProfRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IJavaStackFrameHProfRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IJavaStackFrameHProfRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IJavaStackFrameHProfRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+public interface IJavaStackFrameHProfRecord {
+
+	public abstract long getStackFrameID();
+
+	public abstract long getMethodNameID();
+
+	public abstract long getMethodSignatureID();
+
+	public abstract long getSourceFileNameID();
+
+	public abstract int getClassSerialNumber();
+
+	public abstract int getLineNumber();
+
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IJavaStackTraceHProfRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IJavaStackTraceHProfRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IJavaStackTraceHProfRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IJavaStackTraceHProfRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+public interface IJavaStackTraceHProfRecord {
+
+	public  int getSerialNumber();
+	public int getThreadSerialNumber();
+	public  int getFrameCount();
+
+	public  long getStackFrameID(int elementNo);
+
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/ILoadClassHProfRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/ILoadClassHProfRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/ILoadClassHProfRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/ILoadClassHProfRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+public interface ILoadClassHProfRecord {
+
+	public abstract int getClassSerialNumber();
+
+	public abstract long getClassObjectID();
+
+	public abstract int getStackTraceSerialNumber();
+
+	public abstract long getClassNameID();
+
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IThreadActiveHProfRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IThreadActiveHProfRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IThreadActiveHProfRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IThreadActiveHProfRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+public interface IThreadActiveHProfRecord {
+
+	public abstract int getThreadSerialNumber();
+
+	public abstract long getThreadObjectID();
+
+	public abstract int getStackTraceSerialNumber();
+
+	public abstract long getThreadNameID();
+
+	public abstract long getThreadGroupNameID();
+
+	public abstract long getThreadGroupParentNameID();
+
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IThreadEndingHProfRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IThreadEndingHProfRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IThreadEndingHProfRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IThreadEndingHProfRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+public interface IThreadEndingHProfRecord {
+
+	public abstract int getThreadSerialNumber();
+
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IUTF8HProfRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IUTF8HProfRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IUTF8HProfRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IUTF8HProfRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+public interface IUTF8HProfRecord {
+
+	public abstract long getNameID();
+
+	public abstract byte[] getCharacters();
+
+	public abstract String getAsString();
+
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IUnloadClassHProfRecord.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IUnloadClassHProfRecord.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IUnloadClassHProfRecord.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/IUnloadClassHProfRecord.java Thu May  7 14:50:21 2009
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+/**
+ * Indicates when a class is unloaded.
+ * 
+ */
+public interface IUnloadClassHProfRecord {
+	public abstract int getClassSerialNumber();
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/InstanceFieldEntry.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/InstanceFieldEntry.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/InstanceFieldEntry.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/InstanceFieldEntry.java Thu May  7 14:50:21 2009
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+/**
+ *  An instance field description from a Class.
+ */
+public class InstanceFieldEntry extends FieldEntry {
+
+	private int offset;
+
+	/**
+	 * 
+	 * @param fieldNameID the ID of the name of the field.
+	 * @param type the type of the field
+	 * @param offset offset of the field within its instance.
+	 */
+	public InstanceFieldEntry(long fieldNameID, short type, int offset) {
+		this.fieldNameID = fieldNameID;
+		this.type = type;
+		this.offset = offset;
+	}
+	
+	public int getOffset() {
+		return offset;
+	}
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/RandomAccesDataProvider.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/RandomAccesDataProvider.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/RandomAccesDataProvider.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/RandomAccesDataProvider.java Thu May  7 14:50:21 2009
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.hprof.datalayer;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.List;
+
+import javax.imageio.stream.FileImageInputStream;
+
+import org.apache.kato.common.IDataProvider;
+
+public class RandomAccesDataProvider implements IDataProvider {
+
+	private FileImageInputStream raf=null;
+	private long fileLength=0;
+	private long current=0;
+	
+	private boolean moved=false;
+	
+	public RandomAccesDataProvider(File reader) throws IOException {
+		RandomAccessFile r=new RandomAccessFile(reader, "r");
+		raf=new FileImageInputStream(r);
+	}
+
+	@Override
+	public void close() throws IOException {
+		raf.close();
+		raf=null;
+		
+	}
+
+	@Override
+	public void moveTo(long l) throws IOException {
+		
+		current=l;
+		moved=true;
+		
+	}
+
+	@Override
+	public void open() throws IOException {
+		fileLength=raf.length();
+		raf.seek(0);
+		
+	}
+
+	@Override
+	public String readCString() throws IOException {
+		updateLocation();
+		
+		StringBuilder builder=new StringBuilder();
+		while(true) {
+			int b=raf.readUnsignedByte();
+			current++;
+			if(b==0) break;
+			builder.append( (char)b);
+		}
+		
+		return builder.toString();
+	}
+
+	@Override
+	public int readU4() throws IOException {
+		updateLocation();
+		current+=4;
+		return raf.readInt();
+	}
+
+	@Override
+	public long readU8() throws IOException {
+		updateLocation();
+		current+=8;
+		long high=raf.readUnsignedInt();
+		long low=raf.readUnsignedInt();
+		return high << 32 | low;
+	}
+
+	@Override
+	public long getCurrentLocation() throws IOException {
+		
+		return current;
+	}
+
+	@Override
+	public long getDataLength() throws IOException {
+		
+		return fileLength;
+	}
+
+	@Override
+	public short readByte() throws IOException {
+		updateLocation();
+		current++;
+		return (short) (raf.readByte() & 0xff);
+	}
+
+	@Override
+	public byte[] readBytes(int left) throws IOException {
+		updateLocation();
+		current+=left;
+		byte[] data=new byte[left];
+		 raf.readFully(data);
+		return data; 
+	}
+
+	@Override
+	public void moveBy(int move) throws IOException {
+		current+=move;
+		moved=true;
+		
+	}
+
+	@Override
+	public short readU2() throws IOException {
+		updateLocation();
+		current+=2;
+		return raf.readShort();
+	}
+	private void updateLocation() throws IOException {
+		if(moved) {
+			raf.seek(current);
+			moved=false;
+		}
+		
+	}
+
+	@Override
+	public void addState(List state) {
+		long realPos=-2;
+		try {
+			realPos = raf.getStreamPosition();
+		} catch (IOException e) {
+		
+		}
+		
+		state.add("RandomAccessDataProvider current="+current+",moved="+moved+",fileLength="+fileLength+",realpos="+realPos);
+		
+	}
+
+	@Override
+	public long dataRemaining() {
+		
+		return fileLength-current;
+	}
+	
+}