incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From monte...@apache.org
Subject svn commit: r772669 [2/7] - in /incubator/kato/trunk: HprofBinaryReaderPOC/ HprofBinaryReaderPOC/.settings/ HprofBinaryReaderPOC/META-INF/ HprofBinaryReaderPOC/bin/ HprofBinaryReaderPOC/bin/org/ HprofBinaryReaderPOC/bin/org/apache/ HprofBinaryReaderPOC...
Date Thu, 07 May 2009 14:50:35 GMT
Added: incubator/kato/trunk/HprofBinaryReaderPOC/bin/org/apache/kato/hprof/datalayer/IUnloadClassHProfRecord.class
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/bin/org/apache/kato/hprof/datalayer/IUnloadClassHProfRecord.class?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/bin/org/apache/kato/hprof/datalayer/IUnloadClassHProfRecord.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/bin/org/apache/kato/hprof/datalayer/InstanceFieldEntry.class
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/bin/org/apache/kato/hprof/datalayer/InstanceFieldEntry.class?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/bin/org/apache/kato/hprof/datalayer/InstanceFieldEntry.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/bin/org/apache/kato/hprof/datalayer/RandomAccesDataProvider.class
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/bin/org/apache/kato/hprof/datalayer/RandomAccesDataProvider.class?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/bin/org/apache/kato/hprof/datalayer/RandomAccesDataProvider.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/bin/org/apache/kato/hprof/datalayer/StaticFieldEntry.class
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/bin/org/apache/kato/hprof/datalayer/StaticFieldEntry.class?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/bin/org/apache/kato/hprof/datalayer/StaticFieldEntry.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/AllTests.class
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/AllTests.class?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/AllTests.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestArrayBitMaskMappingStrategy.class
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestArrayBitMaskMappingStrategy.class?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestArrayBitMaskMappingStrategy.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestArrayCompactor.class
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestArrayCompactor.class?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestArrayCompactor.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestBitMaskMappingArray$MockArrayEntryProvider.class
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestBitMaskMappingArray%24MockArrayEntryProvider.class?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestBitMaskMappingArray$MockArrayEntryProvider.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestBitMaskMappingArray.class
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestBitMaskMappingArray.class?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestBitMaskMappingArray.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestDataReader.class
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestDataReader.class?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestDataReader.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestSubsetDataProvider$MockDataProvider.class
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestSubsetDataProvider%24MockDataProvider.class?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestSubsetDataProvider$MockDataProvider.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestSubsetDataProvider.class
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestSubsetDataProvider.class?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/common/TestSubsetDataProvider.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/hprof/TestHProf.class
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/hprof/TestHProf.class?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/hprof/TestHProf.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/hprof/TestSetup.class
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/hprof/TestSetup.class?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/bin/test/apache/kato/hprof/TestSetup.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/data/dumpall.hprof
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/data/dumpall.hprof?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/data/dumpall.hprof
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/data/gen.txt
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/data/gen.txt?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/data/gen.txt (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/data/gen.txt Thu May  7 14:50:21 2009
@@ -0,0 +1 @@
+ java -agentlib:hprof=heap=dump,format=b
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/data/java.hprof
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/data/java.hprof?rev=772669&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/HprofBinaryReaderPOC/data/java.hprof
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/ArrayBitMaskMappingStrategy.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/ArrayBitMaskMappingStrategy.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/ArrayBitMaskMappingStrategy.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/ArrayBitMaskMappingStrategy.java Thu May  7 14:50:21 2009
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * 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.common;
+
+public class  ArrayBitMaskMappingStrategy {
+	
+	private int arraySize=0;
+	private int bitshift=0;
+	private int bucketSize=0; 
+	private int mask=0;
+	
+	public ArrayBitMaskMappingStrategy(int arraySize,int bucketSize) {
+		
+		this.arraySize=arraySize;
+		bitshift=(int) (Math.log10(bucketSize-1)/Math.log10(2));
+		mask   = (1 << (bitshift+1))-1;
+		this.bucketSize = mask+1;
+	}
+
+	
+	public ArrayBitMaskMappingStrategy  doubleCapacity() {
+		
+		if(bucketSize*2<2) return null;
+		
+		return new ArrayBitMaskMappingStrategy(arraySize,bucketSize*2);
+	}
+	
+	public int getArraySize() {
+		return arraySize;
+	}
+
+	public int getBitshift() {
+		return bitshift;
+	}
+
+	public int getBucketSize() {
+		return bucketSize;
+	}
+
+	
+	/**
+	 * Returns -1 if index does not map to an array element 
+	 * 
+	 * @param index
+	 * @return element array no or -1
+	 */
+	public int getIndexArrayElement(int index) {
+		
+		int loc= index >> (bitshift+1);
+		if(loc>=arraySize) return -1;
+		return loc;
+	}
+
+	/**
+	 * Returns -1 if index does not map to an array element 
+	 * 
+	 * @param index
+	 * @return element seek no or -1
+	 */
+	public int getSeekCount(int index) {
+		if(getIndexArrayElement(index)== -1 ) return -1;
+		return index & mask;
+	}
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/ArrayCompactor.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/ArrayCompactor.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/ArrayCompactor.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/ArrayCompactor.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.common;
+
+public class  ArrayCompactor {
+	
+	public static int compact(long[] array,int lastEntry) {
+		
+		
+		int target=-1;
+		for(int i=0;i<=lastEntry;i+=2) {
+			 target++;
+			  array[target]=array[i];
+			 
+		}
+		return target;
+	}
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/BasicType.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/BasicType.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/BasicType.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/BasicType.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.common;
+
+/**
+ * The basic types of the HProf format.
+ * Identifies the types of fields within classes, object instances
+ * and primitive types.
+ */
+public interface BasicType {
+	public static final int OBJECT = 2;
+	public static final int BOOLEAN = 4;
+	public static final int CHAR = 5;
+	public static final int FLOAT = 6;
+	public static final int DOUBLE = 7;
+	public static final int BYTE = 8;
+	public static final int SHORT = 9;
+	public static final int INT = 10;
+	public static final int LONG = 11;
+}
\ No newline at end of file

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/BitMaskMappingArray.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/BitMaskMappingArray.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/BitMaskMappingArray.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/BitMaskMappingArray.java Thu May  7 14:50:21 2009
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * 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.common;
+
+import java.util.LinkedList;
+import java.util.List;
+
+
+
+public class BitMaskMappingArray {
+
+	private ArrayBitMaskMappingStrategy strategy=null;
+	private long[] data=null;
+	private int    maxEntry=0;
+	private IArrayEntryProvider provider=null;
+	
+	
+	
+	public BitMaskMappingArray(int entries,int bucketSize,IArrayEntryProvider provider) {
+	
+			strategy=new ArrayBitMaskMappingStrategy(entries,bucketSize);
+			data=new long[entries];
+			this.provider=provider;
+	}
+	
+	/**
+	 * Retrive element from index
+	 * Returns null if element cannot be located
+	 * 
+	 * @param index 
+	 * @return object at index or null
+	 */
+	public Object get(int index) {
+		
+		
+//		List<String> state=new LinkedList<String>();
+//		state.add("Get "+index);
+//		provider.getState(state);
+//		printState(state);
+//		// ask strategy for element entry
+		
+		if(moveToLocation(index)==false) return null;
+	
+		
+		return provider.getCurrentElement();
+		
+	}
+
+	/**
+	 * Return a record location at a particular location,
+	 * rather than by index.
+	 * 
+	 * @param location within data provider
+	 * @return Object
+	 */
+	public Object getAtLocation(long location) {
+		if(provider.moveToLocation(location)==false) return null;
+		
+		return provider.getCurrentElement();
+	}
+
+	private boolean moveToLocation(int index) {
+		
+		int arraySlot=strategy.getIndexArrayElement(index);
+		if(arraySlot<0) {
+			
+			// array too small
+			// grow it...
+			increaseCapacity(index);
+			arraySlot=strategy.getIndexArrayElement(index);
+		}
+		
+		// is target slot outside current known element?
+		// if so fill array until slot reached
+		if(arraySlot>maxEntry) {
+			if(growArray(arraySlot)==false) return false;
+		}
+		
+		// move provider to the required location
+	
+		if(provider.moveToLocation(data[arraySlot])==false) return false;
+		
+		int seekNo=strategy.getSeekCount(index);
+		if(provider.moveRelativeElement(seekNo)==false) return false;
+		
+		return true;
+	}
+
+	private void printState(List<String> state) {
+		int c=1;
+		for(String s:state) {
+			System.out.println(c+":"+s);
+			c++;
+		}
+		
+	}
+
+	private boolean growArray(int arraySlot) {
+	
+		// move to last know slot
+		long loc=data[maxEntry];
+		provider.moveToLocation(loc);
+		int bucketSize=strategy.getBucketSize();
+		
+		// slots to fill in 
+		int slots=arraySlot-maxEntry;
+		
+		for(int i=0;i<slots;i++) {
+			if(provider.moveRelativeElement(bucketSize)==false) return false;
+			maxEntry++;
+			data[maxEntry]=provider.getCurrentLocation();
+		}
+		return true;
+	}
+
+	private void increaseCapacity(int index) {
+		
+		do {
+			maxEntry=ArrayCompactor.compact(data, maxEntry);
+			strategy=strategy.doubleCapacity();
+		}
+		while (strategy.getIndexArrayElement(index)<0);
+		
+		
+		
+	}
+
+	public long getLocation(int index) {
+		if(moveToLocation(index)==false) return -1;
+		
+		return provider.getCurrentLocation();
+	}
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/ClassSummary.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/ClassSummary.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/ClassSummary.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/ClassSummary.java Thu May  7 14:50:21 2009
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * 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.common;
+
+import java.util.Iterator;
+import java.util.TreeMap;
+
+public class ClassSummary implements Iterable<String>{
+
+	private TreeMap<String,Counter> map=new TreeMap<String,Counter>();
+	
+	private class Counter {
+		int count=0;
+	}
+
+	public void record(Object record) {
+		record(record.getClass());
+		
+	}
+	
+	public void record(Class clazz) {
+		String name=clazz.getCanonicalName();
+		Counter counter=null;
+		
+		if(map.containsKey(name)) {
+			counter=map.get(name);
+		}
+		else {
+			counter=new Counter();
+			map.put(name, counter);
+		}
+		counter.count++;
+	
+	}
+
+	@Override
+	public Iterator<String> iterator() {
+
+		return map.keySet().iterator();
+	}
+
+	public Integer getCount(String tag) {
+		if(map.containsKey(tag)) return map.get(tag).count;
+		else return null;
+	}
+	
+	
+	
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/DataProviderBackedArrayProvider.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/DataProviderBackedArrayProvider.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/DataProviderBackedArrayProvider.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/DataProviderBackedArrayProvider.java Thu May  7 14:50:21 2009
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * 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.common;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.kato.hprof.datalayer.IHeapDumpHProfRecord;
+
+public abstract class DataProviderBackedArrayProvider  implements IArrayEntryProvider{
+
+	private IDataProvider provider=null;
+	
+	public DataProviderBackedArrayProvider(IDataProvider provider) {
+		this.provider=provider;
+	}
+	
+	@Override
+	public long getCurrentLocation() {
+
+		try {
+			return provider.getCurrentLocation();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		return -1;
+	}
+
+	@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 {
+		 	provider.moveTo(l);
+		 	return true;
+		} catch(IOException e) {
+			return false;
+		}
+	}
+	@Override
+	public void getState(List state) {
+		
+		state.add("DataProviderBackedarrayProvider");
+		provider.addState(state);
+		
+		
+	}
+
+	public IDataProvider getProvider() {
+		return provider;
+	}
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/DataReader.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/DataReader.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/DataReader.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/DataReader.java Thu May  7 14:50:21 2009
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.common;
+
+import java.io.IOException;
+
+
+
+public class DataReader {
+
+	
+	public static int read4Bytes(byte[] data) {
+		
+		return read4Bytes(data,0);
+	}
+
+	public static int read4Bytes(byte[] data, int i) {
+		
+		byte b1=data[i+0];
+		byte b2=data[i+1];
+		byte b3=data[i+2];
+		byte b4=data[i+3];
+		return  (b1 << 24 ) + (b2 << 16) + (b3 << 8) + b4;
+		
+		 
+
+	}
+
+	public static short read2Bytes(byte[] data, int i) {
+		byte b1=data[i+0];
+		byte b2=data[i+1];
+		return   (short) ((b1 << 8) + b2);
+		
+	}
+
+	public static long readNumber(byte[] data, int offset, int length) {
+	
+		long value=0;
+		for(int i=0;i<length;i++) {
+			value = value << 8;
+			byte b=data[offset+i];
+			value = value + (b & 0xff);
+		}
+		return value;
+	}
+	
+	public static long readNumber(IDataProvider provider, int length) throws IOException {
+		
+		long value=0;
+		for(int i=0;i<length;i++) {
+			value = value << 8;
+			short b=provider.readByte();
+			value = value + (b &0xff);
+		}
+		return value;
+	}
+
+	public static byte[] readByteArray(byte[] data, int offset, int length) {
+		byte[] results=new byte[length];
+		System.arraycopy(data,offset,results,0,length);
+		return results;
+	}
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IArrayEntryProvider.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IArrayEntryProvider.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IArrayEntryProvider.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IArrayEntryProvider.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.common;
+
+import java.util.List;
+
+
+public interface IArrayEntryProvider {
+
+	boolean moveToLocation(long l);
+
+	Object getCurrentElement();
+
+	boolean moveRelativeElement(int seekNo);
+	long getCurrentLocation();
+
+	void getState(List state);
+
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IDLocationMap.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IDLocationMap.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IDLocationMap.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IDLocationMap.java Thu May  7 14:50:21 2009
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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.common;
+
+
+/**
+ * 
+ * Interface for various implementations that map from an ID to a location.
+ * 
+ *
+ */
+public interface IDLocationMap {
+	/** 
+	 * Extract a location by ID.
+	 * 
+	 * @param id
+	 * @return
+	 */
+	public abstract Long getLocation(Long id);
+	
+	/**
+	 * Add a mapping from an ID to a location in the IHeapDumpHProfRecord.
+	 * 
+	 * @param ID
+	 * @param location
+	 */
+	public void put(Long ID, Long location);
+
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IDToLocationHashMapper.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IDToLocationHashMapper.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IDToLocationHashMapper.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IDToLocationHashMapper.java Thu May  7 14:50:21 2009
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * 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.common;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Maps from ID's to locations on the heap.
+ * Uses a HashMap to do this in memory.
+ * This will not scale, but will work as a trivial implementation.
+ * 
+ */
+public class IDToLocationHashMapper implements IDLocationMap {	
+	private Map<Long,Long>  idToLocation = new HashMap<Long,Long>();
+		
+	/**
+	 * Retrieves a location by it ID.
+	 * 
+	 * @param ID
+	 * @return
+	 */
+	public Long getLocation(Long ID) {
+		Long location = idToLocation.get(ID);
+		if (location == null) {
+			return null;
+		}
+		
+		return location;
+	}
+	
+	/**
+	 * Add a mapping from an ID to a location.
+	 * 
+	 * @param ID
+	 * @param location
+	 */
+	public void put(Long ID, Long location) {
+		if (idToLocation.containsKey(ID)) {
+			System.err.println("Map already contains 0x"+Long.toHexString(ID));
+		}
+		idToLocation.put(ID, location);
+	}
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IDataProvider.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IDataProvider.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IDataProvider.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IDataProvider.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.common;
+
+import java.io.IOException;
+import java.util.List;
+
+public interface IDataProvider {
+
+	void close() throws IOException;
+
+	void open() throws IOException;
+
+	void moveTo(long l) throws IOException;
+
+	String readCString() throws IOException;
+
+	int readU4() throws IOException;
+
+	long readU8() throws IOException;
+
+	long getCurrentLocation() throws IOException;
+
+	long getDataLength() throws IOException;
+
+	short readByte()throws IOException;
+
+	byte[] readBytes(int left) throws IOException;
+
+	void moveBy(int left) throws IOException;
+
+	short readU2() throws IOException;
+	
+	void addState(List state);
+
+	long dataRemaining();
+
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IViewMonitor.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IViewMonitor.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IViewMonitor.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/IViewMonitor.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.common;
+
+import java.io.IOException;
+
+public interface IViewMonitor {
+
+	void error(IOException e);
+
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/InvalidFileFormat.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/InvalidFileFormat.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/InvalidFileFormat.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/InvalidFileFormat.java Thu May  7 14:50:21 2009
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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.common;
+
+import java.io.IOException;
+
+public class InvalidFileFormat extends IOException {
+
+	public InvalidFileFormat(String string) {
+		// TODO Auto-generated constructor stub
+	}
+
+	public InvalidFileFormat(String msg, Exception exception) {
+		super(msg,exception);
+	}
+
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/SubsetDataProvider.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/SubsetDataProvider.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/SubsetDataProvider.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/common/SubsetDataProvider.java Thu May  7 14:50:21 2009
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * 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.common;
+
+import java.io.IOException;
+import java.util.List;
+
+public class SubsetDataProvider implements IDataProvider {
+
+	private IDataProvider provider=null;
+	private boolean moved=true;
+	private long startPoint=0;
+	private long scope=0;
+	private long current=0;
+	
+	public SubsetDataProvider(IDataProvider provider, long range) throws IOException {
+		if(provider==null) throw new IllegalArgumentException("Provider is null");
+		if(range<0) throw new IllegalArgumentException("range "+range+" is less than 0");
+		this.provider=provider;
+		startPoint=provider.getCurrentLocation();
+		scope=range;
+	}
+	public SubsetDataProvider(IDataProvider provider,long offsetm, long range) throws IOException {
+		if(provider==null) throw new IllegalArgumentException("Provider is null");
+		if(range<0) throw new IllegalArgumentException("range "+range+" is less than 0");
+		this.provider=provider;
+		startPoint=offsetm;
+		scope=range;
+	}
+	public long getCurrentLocation() throws IOException {
+		return current;
+	}
+
+	public long getDataLength() throws IOException {
+		return scope;
+	}
+
+	public void moveBy(int left) throws IOException {
+		current+=left;
+		moved=true;
+		if(current>scope) throw new IOException("moving "+left+" is out of range "+scope);
+		
+	}
+
+	public void moveTo(long l) throws IOException {
+		if(current==l) return; // nothing to do
+		current=l;
+		moved=true;
+		if(current>scope) throw new IOException("moving "+l+" is out of range "+scope);
+		
+	}
+
+	public short readByte() throws IOException {
+		updateLocation();
+		current+=1;
+		if(current>scope) throw new IOException("reading is out of range "+scope);
+		return provider.readByte();
+		
+		
+	}
+
+	public byte[] readBytes(int left) throws IOException {
+		updateLocation();
+		current+=left;
+		if(current>scope) throw new IOException("reading "+left+" is out of range "+scope);
+		return provider.readBytes(left);
+	}
+
+	public String readCString() throws IOException {
+		updateLocation();
+		String string=provider.readCString();
+		current=provider.getCurrentLocation();
+		if(provider.getCurrentLocation()-startPoint>scope) throw new IOException("reading is out of range "+scope);
+		return string;
+	}
+
+	public int readU4() throws IOException {
+		updateLocation();
+		current+=4;
+		if(current>scope) throw new IOException("reading is out of range "+scope);
+		return provider.readU4();
+	}
+
+	public long readU8() throws IOException {
+		updateLocation();
+		current+=8;
+		if(current>scope) throw new IOException("reading is out of range "+scope);
+	
+		return provider.readU8();
+	}
+
+	@Override
+	public void close() throws IOException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void open() throws IOException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public short readU2() throws IOException {
+		updateLocation();
+		current+=2;
+		if(current>scope) throw new IOException("reading is out of range "+scope);
+		return provider.readU2();
+	}
+
+	private void updateLocation() throws IOException {
+		if(moved) {
+			provider.moveTo(current+startPoint);
+			moved=false;
+		}
+		
+	}
+
+	@Override
+	public void addState(List state) {
+		
+		state.add("SubsetProvider moved="+moved+",startPoint="+startPoint+",scope="+scope+",current="+current);
+		provider.addState(state);
+	}
+	@Override
+	public long dataRemaining() {
+		
+		return scope-current;
+	}
+	
+	
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HPROFFormattedReporter.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HPROFFormattedReporter.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HPROFFormattedReporter.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HPROFFormattedReporter.java Thu May  7 14:50:21 2009
@@ -0,0 +1,215 @@
+/*******************************************************************************
+ * 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;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.apache.kato.hprof.datalayer.HProfFactory;
+import org.apache.kato.hprof.datalayer.HProfFile;
+import org.apache.kato.hprof.datalayer.IControlSettingsHProfRecord;
+import org.apache.kato.hprof.datalayer.IHProfRecord;
+import org.apache.kato.hprof.datalayer.IHeapDumpHProfRecord;
+import org.apache.kato.hprof.datalayer.IJavaStackFrameHProfRecord;
+import org.apache.kato.hprof.datalayer.IJavaStackTraceHProfRecord;
+import org.apache.kato.hprof.datalayer.ILoadClassHProfRecord;
+import org.apache.kato.hprof.datalayer.IUTF8HProfRecord;
+
+
+public class HPROFFormattedReporter {
+
+	
+	private PrintStream out=System.out;
+	private Map<Integer,Counter> stats=new TreeMap<Integer,Counter>();
+	private TreeSet<String> labels=new TreeSet<String>();
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		
+		//File dump=new File("C:/Documents and Settings/spoole/workspace/HProf Binary Format Reader/data/java.hprof");
+		HPROFFormattedReporter reporter=new HPROFFormattedReporter();
+		File hprofFile=new File(args[0]);
+		
+		try {
+			reporter.report(hprofFile);
+		} catch (IOException e) {
+			
+			e.printStackTrace();
+		}
+		
+		
+	}
+
+	public void report(File dump) throws IOException {
+		
+		HProfFile h=HProfFactory.createReader(dump);
+		
+		h.open();
+		
+		String header=h.getHeader();
+		int    idSize=h.getIdentifierSize();
+		long   timeStamp=h.getTimeStamp();
+		
+		out.println("HPROF     : "+header);
+		out.println("ID SIZE  : "+idSize);
+		out.println("TIMESTAMP: "+timeStamp);
+		
+		int counter=0;
+		while(true) {
+			
+			IHProfRecord record=h.getRecord(counter); 
+			if(record==null) break;
+			report(record);
+			counter++;
+		}
+		
+		reportStats();
+		out.println("Report completed.  "+counter+" records");
+		
+		h.close();
+
+		
+	}
+
+	private void reportStats() {
+		for(Integer i:stats.keySet()) {
+			Counter c=stats.get(i);
+			out.println("tag "+Integer.toHexString(i)+" occurs "+c.count+" time(s)");
+		}
+		
+	}
+
+	private void report(IHProfRecord record) {
+		int tag=record.getTag();
+		accumulateStatistics(tag);
+		out.println("----------------------------------------- "+toHex(tag)+":"+record.getDataLength());		
+		switch(tag) {
+		
+		case 0x01:   IUTF8HProfRecord utf8Record=(IUTF8HProfRecord)record;
+					 reportUTF8(utf8Record);
+					 break;
+					 
+		case 0x02:   ILoadClassHProfRecord loadClass=(ILoadClassHProfRecord)record;
+		 			 reportLoadClass(loadClass);
+		 			 break;
+		 			 
+		case 0x04:   IJavaStackFrameHProfRecord frameRecord=(IJavaStackFrameHProfRecord)record;
+					 reportFrameRecord(frameRecord);
+					 break;
+					 
+		case 0x05:   IJavaStackTraceHProfRecord traceRecord=(IJavaStackTraceHProfRecord)record;
+					 reportTraceRecord(traceRecord);
+					 break;
+					 
+		case 0x0C:   IHeapDumpHProfRecord dumpRecord = (IHeapDumpHProfRecord)record;
+					 reportHeapDump(dumpRecord);
+					 break;
+		case 0x0E:   IControlSettingsHProfRecord settings=(IControlSettingsHProfRecord) record;
+					 reportSettings(settings);
+					 break;
+			
+		}
+		
+	}
+
+	private void reportFrameRecord(IJavaStackFrameHProfRecord record) {
+		
+		out.println("frame - stack frame id :"+toHex(record.getStackFrameID()));
+		out.println("frame - method name id :"+toHex(record.getMethodNameID()));
+		out.println("frame - method signature id :"+toHex(record.getMethodSignatureID()));
+		out.println("frame - source file name id :"+toHex(record.getSourceFileNameID()));
+		out.println("frame - class serial number :"+record.getClassSerialNumber());
+		out.println("frame - line number :"+record.getLineNumber());
+	}
+
+	
+	private String toHex(long h) {
+		return HProfRecordFormatter.toHex(h);
+	}
+
+	private void reportLoadClass(ILoadClassHProfRecord loadClass) {
+		out.println("load class - class serial number : "+loadClass.getClassSerialNumber());
+		out.println("load class - object ID : "+toHex(loadClass.getClassObjectID()));
+		out.println("load class - stack trace serial number : "+loadClass.getStackTraceSerialNumber());
+		out.println("load class - class Name ID : "+toHex(loadClass.getClassNameID()));
+	}
+
+	private void reportUTF8(IUTF8HProfRecord utf8Record) {
+		
+		try {
+			String label=new String(utf8Record.getCharacters(),"UTF-8");
+			if(labels.contains(label)) {
+				int a=1;
+			}
+			out.println("utf8 record id: "+toHex(utf8Record.getNameID())+" data: ["+label+"]");
+		} catch (UnsupportedEncodingException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		
+	}
+
+	private void reportTraceRecord(IJavaStackTraceHProfRecord traceRecord) {
+		out.println("stack trace serial number: "+traceRecord.getSerialNumber());
+		out.println("frame count: "+traceRecord.getFrameCount());
+		
+	}
+
+	private void reportHeapDump(IHeapDumpHProfRecord dumpRecord) {
+		out.println("dump record");
+		int index=0;
+		while(true) {
+			Object record=dumpRecord.getSubRecord(index);
+			if(record==null) break;
+			out.println(">>"+record);
+			index++;
+		}
+		
+	}
+
+	private void accumulateStatistics(int tag) {
+		
+		Counter c=null;
+		if(stats.containsKey(tag)) {
+			c=stats.get(tag);
+		}
+		else {
+			c=new Counter();
+			stats.put(tag,c);
+		}
+		c.count++;
+	}
+
+	private void reportSettings(IControlSettingsHProfRecord settings) {
+		
+		out.println("Is AllocTrace:"+settings.isAllocTrace());
+		out.println("Is CPUSampling:"+settings.isCpuSampling());
+		out.println("Stack Trace Depth:"+settings.getStackTraceDepth());
+		
+	}
+
+	public HPROFFormattedReporter() {
+		
+	}
+	
+	class Counter {
+		int count=0;
+	}
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HPROFUTF8Reporter.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HPROFUTF8Reporter.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HPROFUTF8Reporter.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HPROFUTF8Reporter.java Thu May  7 14:50:21 2009
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * 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;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.apache.kato.hprof.datalayer.HProfFactory;
+import org.apache.kato.hprof.datalayer.HProfFile;
+import org.apache.kato.hprof.datalayer.IHProfRecord;
+import org.apache.kato.hprof.datalayer.IUTF8HProfRecord;
+
+public class HPROFUTF8Reporter {
+
+	
+	private PrintStream out=System.out;
+	private Map<Integer,Counter> stats=new TreeMap<Integer,Counter>();
+	private TreeSet<String> labels=new TreeSet<String>();
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		
+		//File dump=new File("C:/Documents and Settings/spoole/workspace/HProf Binary Format Reader/data/java.hprof");
+		HPROFUTF8Reporter reporter=new HPROFUTF8Reporter();
+		File hprofFile=new File(args[0]);
+		
+		try {
+			reporter.report(hprofFile);
+		} catch (IOException e) {
+			
+			e.printStackTrace();
+		}
+		
+		
+	}
+
+	public void report(File dump) throws IOException {
+		
+		HProfFile h=HProfFactory.createReader(dump);
+		
+		h.open();
+		
+		
+		int counter=0;
+		while(true) {
+			IHProfRecord record=h.getRecord(counter); 
+			if(record==null) break;
+			report(record);
+			counter++;
+		}
+		
+	
+		h.close();
+
+		
+	}
+
+	private void report(IHProfRecord record) {
+		int tag=record.getTag();
+		
+		switch(tag) {
+		
+		case 0x01:   IUTF8HProfRecord utf8Record=(IUTF8HProfRecord)record;
+					 reportUTF8(utf8Record);
+					 break;
+					 
+					
+		}
+		
+	}
+
+	private static String toHex(long v) {
+		return "0x"+Long.toHexString(v);
+	}
+	private void reportUTF8(IUTF8HProfRecord utf8Record) {
+		
+		try {
+			String label=new String(utf8Record.getCharacters(),"UTF-8");
+			if(labels.contains(label)) {
+				int a=1;
+			}
+			out.println(label);
+		} catch (UnsupportedEncodingException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		
+	}
+
+	public HPROFUTF8Reporter() {
+		
+	}
+	
+	class Counter {
+		int count=0;
+	}
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfRecordFormatter.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfRecordFormatter.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfRecordFormatter.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfRecordFormatter.java Thu May  7 14:50:21 2009
@@ -0,0 +1,182 @@
+/*******************************************************************************
+ * 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;
+
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+
+import org.apache.kato.hprof.datalayer.HProfFile;
+import org.apache.kato.hprof.datalayer.IHProfRecord;
+import org.apache.kato.hprof.datalayer.ILoadClassHProfRecord;
+import org.apache.kato.hprof.datalayer.IUTF8HProfRecord;
+
+public class HProfRecordFormatter {
+
+	private static final String hexChars="0123456789ABCDEF";
+	private HProfFile prof=null;
+	HashMap<Long, Integer> utf8s=null;
+
+	
+	public HProfRecordFormatter(HProfFile prof, HashMap<Long, Integer> utf8s) {
+		this.prof=prof;
+		this.utf8s=utf8s;
+	}
+	public  String formatData(IHProfRecord o) {
+		
+		int tag=o.getTag();
+		
+		switch(tag) {
+		
+		case 0x01 :   return formatUTF8Data((IUTF8HProfRecord)o);
+		case 0x02:    return formatLoadCLass((ILoadClassHProfRecord)o);
+		case 0x04:   return "Frame";
+		case 0x05:   return "Trace";
+		case 0x0A:   return "Thread Start";
+		case 0x0B:   return "Thread End";
+		case 0x0C:   return "HeapDump";
+		case 0x0E:   return "Settings";
+		
+		}
+		
+		return "";
+	}
+	
+	public   String formatLoadCLass(ILoadClassHProfRecord o) {
+		
+		long id=o.getClassNameID();
+		long classID=o.getClassObjectID();
+		long serialNo=o.getClassSerialNumber();
+		long stackSerial=o.getStackTraceSerialNumber();
+		
+		String className="";
+		if(utf8s.containsKey(id)) {
+			int ref=utf8s.get(id);
+			className=getName(ref);
+			if(className==null) className="";
+			else className="("+className+")";
+		}
+		return "classNameID="+toHex(id)+className+" objectid="+toHex(classID)+" serialNo="+toHex(serialNo)+" stackSerial="+toHex(stackSerial);
+	}
+
+	public String getName(Long id) {
+		if(utf8s.containsKey(id)==false) return null;
+		int ref=utf8s.get(id);
+		return getName(ref);
+	}
+	private String getName(int ref) {
+		IHProfRecord record=prof.getRecord(ref);
+		
+		if(record instanceof IUTF8HProfRecord) {
+			IUTF8HProfRecord  utf8rec=(IUTF8HProfRecord) record;
+			return utf8rec.getAsString();
+		}
+		return null;
+	}
+	public static String toHex(long v) {
+		return "0x"+Long.toHexString(v);
+	}
+	public  static String formatUTF8Data(IUTF8HProfRecord utf8Record) {
+		
+		try {
+			return new String(utf8Record.getCharacters(),"UTF-8");
+		} catch (UnsupportedEncodingException e) {
+		
+			return "Error converting data "+e.toString();
+		
+	}
+		
+	
+}
+
+	public static String getTagName(IHProfRecord o) {
+		
+		int tag=o.getTag();
+		
+		switch(tag) {
+		
+		case 0x01 :   return "UTF8";
+		case 0x02:    return "LoadClass";
+		case 0x04:   return "Frame";
+		case 0x05:   return "Trace";
+		case 0x0A:   return "Thread started";
+		case 0x0B:   return "Thread ending";
+		case 0x0C:   return "HeapDump";
+		case 0x0E:   return "Settings";
+		}
+		
+		return o.getClass().getName();
+	}
+	public static String toHex(byte[] bytes) {
+		if(bytes==null) return "<no data>";
+		return toHex(bytes,0,bytes.length);
+	}
+	public static String toHex(byte[] bytes, int start, int length) {
+		
+		if(bytes==null) return "<no data>";
+		if(bytes.length<start) return "<bad start>";
+		
+		StringBuilder builder=new StringBuilder();
+		for(int i=0;i<length;i++) {
+			int index=i+start;
+			if(index>=bytes.length) break;
+			builder.append(toHex(bytes[index]));
+			builder.append(" ");
+		}
+		return new String(builder);
+	}
+
+	private static String toHex(byte b) {
+		 int value= (int) b & 0xFF;
+		int top=value >> 4;
+		int bottom= value & 0x0F;
+		
+		return ""+hexChars.charAt(top)+hexChars.charAt(bottom);
+		
+	}
+	public static String toHex(byte[] bytes, int start, int length, int packet) {
+		if(bytes==null) return "<no data>";
+		if(bytes.length<start) return "<bad start>";
+		
+		StringBuilder builder=new StringBuilder();
+		int c=packet;
+		for(int i=0;i<length;i++) {
+			int index=i+start;
+			if(index>=bytes.length) break;
+			builder.append(toHex(bytes[index]));
+			builder.append(" ");
+			c--;
+			if(c==0) {
+				builder.append("\n");
+				c=packet;
+			}
+		}
+		return new String(builder);
+	}
+	public static String toPrintableText(byte[] bytes) {
+		if(bytes==null) return "<no data>";
+		
+		StringBuilder builder=new StringBuilder();
+		for(int i=0;i<bytes.length;i++) {
+			char c=(char) bytes[i];
+			if(Character.isLetterOrDigit(c)) {
+				builder.append(c);
+	
+			}
+			else {
+				builder.append('.');
+			}
+		}
+		return new String(builder);
+	}
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfView.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfView.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfView.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfView.java Thu May  7 14:50:21 2009
@@ -0,0 +1,777 @@
+/*******************************************************************************
+ * 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;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Vector;
+
+import org.apache.kato.common.BasicType;
+import org.apache.kato.common.ClassSummary;
+import org.apache.kato.common.IDLocationMap;
+import org.apache.kato.common.IDToLocationHashMapper;
+import org.apache.kato.common.IViewMonitor;
+import org.apache.kato.hprof.datalayer.ConstantPoolEntry;
+import org.apache.kato.hprof.datalayer.HProfFile;
+import org.apache.kato.hprof.datalayer.IGCClassHeapDumpRecord;
+import org.apache.kato.hprof.datalayer.IHProfRecord;
+import org.apache.kato.hprof.datalayer.IHeapDumpHProfRecord;
+import org.apache.kato.hprof.datalayer.IHeapObject;
+import org.apache.kato.hprof.datalayer.IJavaStackFrameHProfRecord;
+import org.apache.kato.hprof.datalayer.IJavaStackTraceHProfRecord;
+import org.apache.kato.hprof.datalayer.ILoadClassHProfRecord;
+import org.apache.kato.hprof.datalayer.IThreadActiveHProfRecord;
+import org.apache.kato.hprof.datalayer.IThreadEndingHProfRecord;
+import org.apache.kato.hprof.datalayer.IUTF8HProfRecord;
+import org.apache.kato.hprof.datalayer.IUnloadClassHProfRecord;
+import org.apache.kato.hprof.datalayer.InstanceFieldEntry;
+import org.apache.kato.hprof.datalayer.StaticFieldEntry;
+
+public class HProfView {
+
+	private HProfFile file = null;
+	private HashMap<Long, Integer> utf8s = new HashMap<Long, Integer>();
+	private Long[] utf8ids = null;
+	private IJavaClass[] loadedClassRecordNumbers = null;
+	private IJavaThread[] threads = null;
+	private HashMap<Integer, Integer> stackTraces = new HashMap<Integer, Integer>();
+	private Integer[] stackTraceRecords=null;
+	private HashMap<Long, Integer> stackTraceFrames = new HashMap<Long, Integer>();
+	private ClassSummary recordSummary=null;
+	private IHeapDumpHProfRecord heapRecord=null;
+	private long heapRecordLocation=0;
+//	private HashMap<Long,JavaClassLoader> = new HashMap<Long,JavaClassLoader>();
+	private IDLocationMap idToLocationMap;
+	
+	// Class maps
+	private HashMap<Long,IJavaClassLoader> javaClassLoaders = new HashMap<Long,IJavaClassLoader>();
+	private HashMap<Integer,IJavaClass>  loadedClassesBySerial=new HashMap<Integer,IJavaClass>();
+	private HashMap<Long,IJavaClass>  loadedClassesByID=new HashMap<Long,IJavaClass>();
+	
+	public HProfView(HProfFile file) {
+		this.file = file;
+	}
+
+	public void open(IViewMonitor monitor) {
+
+		try {
+			file.open();
+
+			int r = 0;
+			LinkedList<IJavaClass> loadedClassesRecordNO = new LinkedList<IJavaClass>();
+			LinkedList<IJavaThread> threadRecordNO = new LinkedList<IJavaThread>();
+			LinkedList<Integer> javastacks = new LinkedList<Integer>();
+			recordSummary=new ClassSummary();
+			
+			int heapRecordNo=0;
+			while (true) {
+				IHProfRecord record = file.getRecord(r);
+				if (record == null)
+					break;
+
+				String tagName=HProfRecordFormatter.getTagName(record);
+				recordSummary.record(record);
+				if (record instanceof IUTF8HProfRecord) {
+					IUTF8HProfRecord utf8 = (IUTF8HProfRecord) record;
+					Long id = utf8.getNameID();
+					utf8s.put(id, r);
+
+				} else if (record instanceof ILoadClassHProfRecord) {
+					JavaClass c=new JavaClass(r);					
+					loadedClassesBySerial.put(c.getClassSerialNumber(),c);
+				} else if (record instanceof IUnloadClassHProfRecord) {					
+					// Remove a loaded class if it is subsequently unloaded.
+					loadedClassesBySerial.remove(((IUnloadClassHProfRecord)record).getClassSerialNumber());
+				} else if (record instanceof IThreadActiveHProfRecord) {
+					// SRDM add by serial number
+					threadRecordNO.add(new ActiveJavaThread(r));
+				} else if (record instanceof IThreadEndingHProfRecord) {
+					// SRDM remove thread by serial number.
+					
+					threadRecordNO.add(new InactiveJavaThread(r));
+
+				} else if (record instanceof IJavaStackTraceHProfRecord) {
+					// SRDM Stack traces should be attached to threads
+					// keep the most recent. Attach to thread so that when thread removed,
+					// stacktrace is removed too.
+					IJavaStackTraceHProfRecord stackTrace = (IJavaStackTraceHProfRecord) record;
+					int sn = stackTrace.getSerialNumber();
+					stackTraces.put(sn, r);
+					javastacks.add(r);
+
+				} else if (record instanceof IJavaStackFrameHProfRecord) {
+					IJavaStackFrameHProfRecord frame = (IJavaStackFrameHProfRecord) record;
+					long id = frame.getStackFrameID();
+					stackTraceFrames.put(id, r);
+
+				}
+				else if(record instanceof IHeapDumpHProfRecord) {
+					heapRecord=(IHeapDumpHProfRecord) record;
+					heapRecordNo=r;
+
+					idToLocationMap = new IDToLocationHashMapper();
+					summariseHeap(heapRecord);
+				}
+				r++;
+			}
+			
+			heapRecordLocation=file.getRecordLocation(heapRecordNo);
+			
+			utf8ids = utf8s.keySet().toArray(new Long[0]);
+			loadedClassRecordNumbers = loadedClassesRecordNO
+					.toArray(new IJavaClass[0]);
+
+			threads = threadRecordNO.toArray(new IJavaThread[0]);
+			stackTraceRecords=javastacks.toArray(new Integer[0]);			
+			
+			correlateClasses();
+			
+		} catch (IOException e) {
+
+			monitor.error(e);
+		}
+	}
+
+	private IJavaClass[] primitiveArrayClasses = new IJavaClass[8];
+	/**
+	 * Called once during processing.
+	 * Iterates over all of the classes loaded and never unloaded.
+	 * Creates the JavaClassLoaders, and creates map from object IDs to JavaClasses.
+	 * 
+	 */
+	private void correlateClasses() {
+
+		Iterator<Integer> classes = loadedClassesBySerial.keySet().iterator();
+	
+		while (classes.hasNext()) {
+			int classSerialNo = classes.next();
+			IJavaClass clazz = loadedClassesBySerial.get(classSerialNo);
+			
+			Long location =  idToLocationMap.getLocation(clazz.getClassObjectID());
+			
+			if (location == null) {
+				continue;
+			}
+			
+			IHProfRecord record =  heapRecord.getSubRecordByLocation(location);
+			long classLoaderObjectID = 0L;
+			long classObjectID = 0L;
+			if (record instanceof IGCClassHeapDumpRecord) {
+				IGCClassHeapDumpRecord classRecord = (IGCClassHeapDumpRecord) record;
+				
+				classLoaderObjectID = classRecord.getClassLoaderObjectID();
+				
+				classObjectID = classRecord.getID();
+				
+				String name = clazz.getClassName();
+				
+				if ("boolean[]".equals(name)) {
+					primitiveArrayClasses[BasicType.BOOLEAN-4] = clazz;
+				} else if ("byte[]".equals(name)) {
+					primitiveArrayClasses[BasicType.BYTE-4] = clazz;
+				} else if ("char[]".equals(name)) {
+					primitiveArrayClasses[BasicType.CHAR-4] = clazz;
+				} else if ("short[]".equals(name)) {
+					primitiveArrayClasses[BasicType.SHORT-4] = clazz;
+				} else if ("int[]".equals(name)) {
+					primitiveArrayClasses[BasicType.INT-4] = clazz;
+				} else if ("long[]".equals(name)) {
+					primitiveArrayClasses[BasicType.LONG-4] = clazz;
+				} else if ("float[]".equals(name)) {
+					primitiveArrayClasses[BasicType.FLOAT-4] = clazz;
+				} else if ("double[]".equals(name)) {
+					primitiveArrayClasses[BasicType.DOUBLE-4] = clazz;
+				}
+				
+				// Create map of classes loaded by ID.
+				loadedClassesByID.put(classObjectID, clazz);
+			} else {
+				// If the record wasn't pointing to a class, then don't do anything with this class.
+				continue;
+			}
+			
+			// retrieve classloader by ID. If it doesn't match, create one.
+			// then add this class object ID.
+			JavaClassLoader loader = (JavaClassLoader) javaClassLoaders.get(classLoaderObjectID);
+			
+			if (loader == null) {
+				loader = new JavaClassLoader(classLoaderObjectID);
+				javaClassLoaders.put(classLoaderObjectID, loader);
+			}
+			
+			loader.addClass(classObjectID);
+		}
+		
+	}
+	
+	/**
+	 * Primitive
+	 * @param type
+	 * @return
+	 */
+	public IJavaClass getPrimitiveArrayClass(int type) {
+		 if(type <4 || type >11) {
+			 throw new IllegalArgumentException("Invalid basic type for primitive array " + type);
+		 }
+		 
+		 return primitiveArrayClasses[type-4];
+	}
+	
+	/**
+	 * Returns a collection of all of the JavaClassLoaders.
+	 * 
+	 * @return Collection<JavaClassLoader>
+	 */
+	public Collection<IJavaClassLoader> getJavaClassLoaders() {
+		return javaClassLoaders.values();
+	}
+	
+	/**
+	 * Given the Object ID of a JavaClassLoader, return a JavaClassLoader
+	 * of it's ID.
+	 * 
+	 * @param id
+	 * @return
+	 */
+	public IJavaClassLoader getJavaClassLoader(long id) {
+		return javaClassLoaders.get(id);
+	}
+
+	/**
+	 * Return a JavaClass by its serial number.
+	 * 
+	 * @param serial
+	 * @return IJavaClass instance or null.
+	 */
+	public IJavaClass getJavaClassBySerial(int serial) {
+		return loadedClassesBySerial.get(serial);
+	}
+	
+	/**
+	 * Return a IJavaClass instance referenced by its ID.
+	 * @param id object ID of class
+	 * @return IJavaClass or null
+	 */
+	public IJavaClass getJavaClassByID(long id) {		
+		IJavaClass clazz = loadedClassesByID.get(id);
+		
+		if (clazz == null) {
+			System.err.println("Failed class lookup : 0x" +
+					Long.toHexString(id));
+		}
+		//assert(clazz != null);
+		
+		return clazz;
+	}
+	
+	/**
+	 * Return an IHeapObject instance with the passed object ID.
+	 * 
+	 * @param id
+	 * @return IJavaObject with passed ID
+	 */
+	public IHeapObject getJavaObjectByID(long id) {
+		Long loc = idToLocationMap.getLocation(id);
+		if (loc == null) {
+			return null;
+		}
+		
+		IHProfRecord record =  heapRecord.getSubRecordByLocation(loc);
+		
+		if (record == null) {
+			return null;
+		}
+		
+		if (record instanceof IHeapObject) {
+			return (IHeapObject) record;
+		}
+		
+		return null;
+	}
+	
+	private void summariseHeap(IHeapDumpHProfRecord heapRecord) {
+		
+		int index=0;
+		
+		while(true) {
+			IHProfRecord rec=heapRecord.getSubRecord(index);
+			
+			/* Record the ID of this record and location in ID to record map
+			 * if this record is of an appropriate type.
+			 */
+			if (rec instanceof IHeapObject) {
+				long location = heapRecord.getSubRecordLocation(index);
+				idToLocationMap.put(((IHeapObject)rec).getID(), location);
+			} 
+						
+			if(rec==null) break;
+			recordSummary.record(rec);
+			index++;
+		}
+		
+	}
+
+	public IJavaStackFrameHProfRecord getStackFrameRecordFromID(long id) {
+		int record=stackTraceFrames.get(id);
+		return (IJavaStackFrameHProfRecord) file.getRecord(record);
+	}
+	public String getName(long id) {
+		return getUTF8String(id);
+
+	}
+
+	public String getUTF8String(long id) {
+
+		int record = getUTF8RecordID(id);
+		if (record < 0)
+			return "";
+		IHProfRecord rec = file.getRecord(record);
+		if (rec == null)
+			return null;
+		if (rec instanceof IUTF8HProfRecord) {
+			IUTF8HProfRecord utf8record = (IUTF8HProfRecord) rec;
+			return utf8record.getAsString();
+		}
+
+		return null;
+	}
+
+	public int getUTF8RecordID(long id) {
+		if (utf8s.containsKey(id)) {
+			int record = utf8s.get(id);
+			return record;
+		}
+		return -1;
+	}
+
+	public int getThreadCount() {
+		return threads.length;
+	}
+
+	public IJavaThread getThread(int ref) {
+		return threads[ref];
+	}
+
+	public int getStackTraceCount() {
+		return stackTraceRecords.length;
+	}
+	public IJavaStackTraceHProfRecord getStackTraceRecord(int ref) {
+		return (IJavaStackTraceHProfRecord) file.getRecord(stackTraceRecords[ref]);
+	}
+
+	/**
+	 * Represents a JavaClass - pulls together the LoadClass hprofrecord
+	 * and it corresponding GCClassHeapDumpRecord.
+	 *
+	 */
+	public class JavaClass implements IJavaClass {
+
+		private int ref = 0;
+
+		private JavaClass(int r) {
+			this.ref = r;
+		}
+
+		@Override
+		public String getClassName() {
+			ILoadClassHProfRecord record = getLoadedClassHProfRecord(ref);
+			return getName(record.getClassNameID());
+		}
+
+		@Override
+		public long getClassObjectID() {
+			return getLoadedClassHProfRecord(ref).getClassObjectID();
+
+		}
+
+		@Override
+		public int getClassSerialNumber() {
+
+			return getLoadedClassHProfRecord(ref).getClassSerialNumber();
+		}
+
+		@Override
+		public int getStackTraceSerialNumber() {
+
+			return getLoadedClassHProfRecord(ref).getStackTraceSerialNumber();
+		}
+
+		@Override
+		public long getClassLoaderObjectID() {
+			return getHProfRecord().getClassLoaderObjectID(); 
+		}
+		
+		
+		private IGCClassHeapDumpRecord getHProfRecord() {
+			return (IGCClassHeapDumpRecord) heapRecord.getSubRecordByLocation(idToLocationMap.getLocation(getClassObjectID()));
+		}
+
+		@Override
+		public long getSuperClassObjectID() {
+			return getHProfRecord().getSuperClassObjectID();
+		}
+		
+		@Override
+		public int getInstanceSize() {
+			return getHProfRecord().getInstanceSize();
+		}
+		
+
+		/**
+		 * Check for equality
+		 */
+		@Override
+		public boolean equals(Object obj) {
+			if (obj == null) {
+				return false;
+			} else if (!(obj instanceof JavaClass)) {
+				return false;
+			}
+			return ((JavaClass)obj).getClassSerialNumber() == getClassSerialNumber();
+		}
+
+		@Override
+		public long getProtectionDomainObjectID() {
+			return getHProfRecord().getProtectionDomainObjectID();
+		}
+
+		@Override
+		public long getSignersObjectID() {
+			return getHProfRecord().getSignersObjectID();
+		}
+
+		@Override
+		public StaticFieldEntry[] getStaticFields() {
+			return getHProfRecord().getStaticFields();
+		}
+
+		@Override
+		public ConstantPoolEntry[] getConstantPoolEntries() {
+			return getHProfRecord().getConstantPool();
+		}
+
+		@Override
+		public InstanceFieldEntry[] getInstanceFields() {
+			return getHProfRecord().getInstanceFields();
+		}
+
+		@Override
+		public int getOffsetSize() {
+			return getHProfRecord().getOffsetSize();
+		}
+	}
+
+	/**
+	 * Holds the IDs of classes loaded by this classloader.
+	 * 
+	 */
+	private class JavaClassLoader implements IJavaClassLoader {
+		private Long id;
+		private Vector<Long> classes = new Vector<Long>();
+		
+		/**
+		 * Creates a JavaClassLoader.
+		 * This identifying object ID is passed.
+		 * 
+		 * @param id Object ID of the class loader.
+		 */
+		private JavaClassLoader(Long id) {
+			this.id = id;
+		}
+		
+		/**
+		 * Returns the Object ID of this classloader.
+		 * @return long
+		 */
+		public long getID() {
+			return this.id;
+		}
+		
+		/**
+		 * Add a class to the classloader.
+		 * Private as only the 
+		 * @param ID
+		 */
+		private void addClass(Long ID) {
+			this.classes.add(ID);
+		}
+		
+		public Vector<Long> getClasses() {
+			return classes;
+		}
+	}
+		
+	public class InactiveJavaThread implements IJavaThread {
+		private int ref = 0;
+
+		private InactiveJavaThread(int ref) {
+			this.ref = ref;
+
+		}
+
+		@Override
+		public int getStackTraceSerialNumber() {
+
+			return 0;
+
+		}
+
+		@Override
+		public String getThreadGroupName() {
+
+			return "";
+		}
+
+		@Override
+		public String getThreadGroupParentName() {
+			return "";
+		}
+
+		@Override
+		public String getThreadName() {
+			return "";
+		}
+
+		@Override
+		public long getThreadObjectID() {
+
+			return 0;
+		}
+
+		@Override
+		public int getThreadSerialNumber() {
+
+			return getEndingJavaThreadRecord(ref).getThreadSerialNumber();
+		}
+
+		@Override
+		public boolean isActive() {
+
+			return false;
+		}
+
+		@Override
+		public IJavaStack getStack() {
+			
+			return null;
+		}
+	}
+
+	public class ActiveJavaThread implements IJavaThread {
+
+		private final class JavaStackFrame implements IJavaStackFrame {
+			private int frameRecord=0;
+			public JavaStackFrame(int stackRecord) {
+				this.frameRecord=stackRecord;
+			}
+
+			@Override
+			public Long getID() {
+				IJavaStackFrameHProfRecord record=(IJavaStackFrameHProfRecord) file.getRecord(frameRecord);
+				return record.getStackFrameID();
+			}
+
+			@Override
+			public int getLineNumber() {
+				IJavaStackFrameHProfRecord record=(IJavaStackFrameHProfRecord) file.getRecord(frameRecord);
+				return record.getLineNumber();
+			}
+
+			@Override
+			public IJavaClass getMethodClass() {
+				IJavaStackFrameHProfRecord record=(IJavaStackFrameHProfRecord) file.getRecord(frameRecord);
+				int sn=record.getClassSerialNumber();
+				return loadedClassesBySerial.get(sn);
+			}
+
+			@Override
+			public String getMethodName() {
+				IJavaStackFrameHProfRecord record=(IJavaStackFrameHProfRecord) file.getRecord(frameRecord);
+				long id=record.getMethodNameID();
+				return getName(id);
+			}
+
+			@Override
+			public String getMethodSignature() {
+				IJavaStackFrameHProfRecord record=(IJavaStackFrameHProfRecord) file.getRecord(frameRecord);
+				long id=record.getMethodSignatureID();
+				return getName(id);
+			}
+
+			@Override
+			public String getSourceFileName() {
+				IJavaStackFrameHProfRecord record=(IJavaStackFrameHProfRecord) file.getRecord(frameRecord);
+				long id=record.getSourceFileNameID();
+				return getName(id);
+			}
+		}
+
+		private int ref = 0;
+
+		private ActiveJavaThread(int ref) {
+			this.ref = ref;
+
+		}
+
+		@Override
+		public boolean isActive() {
+
+			return true;
+		}
+
+		@Override
+		public int getStackTraceSerialNumber() {
+
+			return getActiveJavaThreadRecord(ref).getStackTraceSerialNumber();
+		}
+
+		@Override
+		public String getThreadGroupName() {
+
+			long id = getActiveJavaThreadRecord(ref).getThreadGroupNameID();
+			return getName(id);
+		}
+
+		@Override
+		public String getThreadGroupParentName() {
+			long id = getActiveJavaThreadRecord(ref)
+					.getThreadGroupParentNameID();
+			return getName(id);
+		}
+
+		@Override
+		public String getThreadName() {
+			long id = getActiveJavaThreadRecord(ref).getThreadNameID();
+			return getName(id);
+		}
+
+		@Override
+		public long getThreadObjectID() {
+			return getActiveJavaThreadRecord(ref).getThreadObjectID();
+		}
+
+		@Override
+		public int getThreadSerialNumber() {
+			return getActiveJavaThreadRecord(ref).getThreadSerialNumber();
+		}
+
+		@Override
+		public IJavaStack getStack() {
+			// stack trace record no
+			int sn = getStackTraceSerialNumber();
+			int recordId = stackTraces.get(sn);
+			IJavaStackTraceHProfRecord record = (IJavaStackTraceHProfRecord) file
+					.getRecord(recordId);
+			int stackElements = record.getFrameCount();
+			final IJavaStackFrame[] data = new IJavaStackFrame[stackElements];
+			for (int i = 0; i < stackElements; i++) {
+				long stackFrameElementID = record.getStackFrameID(i);
+				int stackRecord=stackTraceFrames.get(stackFrameElementID);
+				data[i]=new JavaStackFrame(stackRecord);
+			}
+			IJavaStack stack = new IJavaStack() {
+
+				@Override
+				public IJavaStackFrame[] getStack() {
+
+					return data;
+				}
+
+				@Override
+				public IJavaThread getThread() {
+					return ActiveJavaThread.this;
+				}
+			};
+
+			return stack;
+		}
+
+	}
+
+	private IThreadEndingHProfRecord getEndingJavaThreadRecord(int ref) {
+
+		return (IThreadEndingHProfRecord) file.getRecord(ref);
+	}
+
+	private IThreadActiveHProfRecord getActiveJavaThreadRecord(int ref) {
+
+		return (IThreadActiveHProfRecord) file.getRecord(ref);
+	}
+
+	private ILoadClassHProfRecord getLoadedClassHProfRecord(int ref) {
+		return (ILoadClassHProfRecord) file.getRecord(ref);
+	}
+
+	public int getUTF8Count() {
+		return utf8ids.length;
+	}
+
+	public long getUTF8IDFromIndex(int index) {
+
+		return utf8ids[index];
+	}
+
+	public int getLoadedClassCount() {
+		return loadedClassRecordNumbers.length;
+	}
+
+	public IJavaClass getLoadedClass(int index) {
+		return loadedClassRecordNumbers[index];
+	}
+
+	public HProfFile getFile() {
+		return file;
+	}
+
+	public int getUTF8Length(long id) {
+
+		int record = getUTF8RecordID(id);
+		if (record < 0)
+			return record;
+		IHProfRecord rec = file.getRecord(record);
+		if (rec == null)
+			return -2;
+		if (rec instanceof IUTF8HProfRecord) {
+			IUTF8HProfRecord utf8record = (IUTF8HProfRecord) rec;
+			return utf8record.getCharacters().length;
+		}
+
+		return -3;
+
+	}
+
+	public ClassSummary getRecordSummary() {
+		return recordSummary;
+	}
+
+	
+
+	public IHeapDumpHProfRecord getHeapRecord() {
+		
+			return heapRecord;
+		
+	}
+
+	/**
+	 * Return the record number for the heap record 
+	 * @return
+	 */
+	public long getHeapRecordLocation() {
+		
+		return heapRecordLocation;
+	}
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IConstantPoolEntry.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IConstantPoolEntry.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IConstantPoolEntry.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IConstantPoolEntry.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;
+
+import org.apache.kato.common.BasicType;
+
+public interface IConstantPoolEntry {
+	public int getIndex();
+	
+	public BasicType getType();
+
+	public Object getValue();
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaClass.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaClass.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaClass.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaClass.java Thu May  7 14:50:21 2009
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * 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;
+
+import org.apache.kato.hprof.datalayer.ConstantPoolEntry;
+import org.apache.kato.hprof.datalayer.InstanceFieldEntry;
+import org.apache.kato.hprof.datalayer.StaticFieldEntry;
+
+/**
+ * Allows JavaClass information to be pulled from HProf records.
+ * 
+ *
+ */
+public interface IJavaClass {
+	/**
+	 * @return
+	 */
+	public long getClassObjectID();
+
+	public int getStackTraceSerialNumber();
+
+	public String getClassName();
+
+	public int getClassSerialNumber();
+	public long getClassLoaderObjectID();
+	public long getProtectionDomainObjectID();
+	public long getSignersObjectID();
+	
+	/**
+	 * Get the object ID of the superclass.
+	 * 
+	 * @return long object id.
+	 */
+	public long getSuperClassObjectID();
+
+	public int getInstanceSize();
+
+	public ConstantPoolEntry[] getConstantPoolEntries();
+	
+	public StaticFieldEntry[] getStaticFields();
+	
+	public InstanceFieldEntry[] getInstanceFields();
+
+	public int getOffsetSize();
+}

Added: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaClassLoader.java?rev=772669&view=auto
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaClassLoader.java (added)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/IJavaClassLoader.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;
+
+import java.util.Collection;
+
+/**
+ * Represents a class loader. Is created by HProfView.
+ *
+ */
+public interface IJavaClassLoader {	
+	/**
+	 * The ID of the Object this class loader is identified by.
+	 * 
+	 * @return long object id.
+	 */
+	public abstract long getID();
+	
+	/**
+	 * The collection of java class loaders
+	 * 
+	 * @return Collection<IJavaClass> classes defined by this class loader.
+	 */
+	public abstract Collection<Long> getClasses();
+}



Mime
View raw message