incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From monte...@apache.org
Subject svn commit: r774694 - /incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfView.java
Date Thu, 14 May 2009 09:11:18 GMT
Author: monteith
Date: Thu May 14 09:11:18 2009
New Revision: 774694

URL: http://svn.apache.org/viewvc?rev=774694&view=rev
Log:
Fixes for unit testcases to pass. Moved opening of HProf file and view to appropriate places.

Modified:
    incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfView.java

Modified: 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=774694&r1=774693&r2=774694&view=diff
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfView.java (original)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfView.java Thu
May 14 09:11:18 2009
@@ -64,104 +64,101 @@
 	
 	// Thread ID Maps
 	private HashMap<Integer,IJavaThread> activeThreadsBySerial = new HashMap<Integer,
IJavaThread>();
-	
+
+	/**
+	 * Takes an open file.
+	 * 
+	 * @param file
+	 */
 	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) {
-					ActiveJavaThread ajt = new ActiveJavaThread(r);
-
-					threadRecordNO.add( ajt );
-					
-					// add by serial number
-					activeThreadsBySerial.put(ajt.getThreadSerialNumber(), ajt);
-				} else if (record instanceof IThreadEndingHProfRecord) {
-					InactiveJavaThread ijt = new InactiveJavaThread(r);
-					
-					threadRecordNO.add(ijt);
-					// remove thread by serial number.
-					//SRDM activeThreadsBySerial.remove(ijt.getThreadSerialNumber());
-				} else if (record instanceof IJavaStackTraceHProfRecord) {
-					// 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);
-					
-					// Attach this stack trace to its thread if the thread
-					// exists and this trace is newer.
-					int threadSerial = stackTrace.getThreadSerialNumber();				
-					IJavaThread ajt = activeThreadsBySerial.get(threadSerial);
-					
-					if(ajt != null) {
-						((ActiveJavaThread)ajt).setStackTrace(stackTrace);
-					}
-					
-				} else if (record instanceof IJavaStackFrameHProfRecord) {
-					IJavaStackFrameHProfRecord frame = (IJavaStackFrameHProfRecord) record;
-					long id = frame.getStackFrameID();
-					stackTraceFrames.put(id, r);
+		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) {
+				ActiveJavaThread ajt = new ActiveJavaThread(r);
+
+				threadRecordNO.add( ajt );
+
+				// add by serial number
+				activeThreadsBySerial.put(ajt.getThreadSerialNumber(), ajt);
+			} else if (record instanceof IThreadEndingHProfRecord) {
+				InactiveJavaThread ijt = new InactiveJavaThread(r);
+
+				threadRecordNO.add(ijt);
+				// remove thread by serial number.
+				//SRDM activeThreadsBySerial.remove(ijt.getThreadSerialNumber());
+			} else if (record instanceof IJavaStackTraceHProfRecord) {
+				// 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);
+
+				// Attach this stack trace to its thread if the thread
+				// exists and this trace is newer.
+				int threadSerial = stackTrace.getThreadSerialNumber();				
+				IJavaThread ajt = activeThreadsBySerial.get(threadSerial);
 
+				if(ajt != null) {
+					((ActiveJavaThread)ajt).setStackTrace(stackTrace);
 				}
-				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]);
+			} else if (record instanceof IJavaStackFrameHProfRecord) {
+				IJavaStackFrameHProfRecord frame = (IJavaStackFrameHProfRecord) record;
+				long id = frame.getStackFrameID();
+				stackTraceFrames.put(id, r);
 
-			threads = threadRecordNO.toArray(new IJavaThread[0]);
-			stackTraceRecords=javastacks.toArray(new Integer[0]);			
-			
-			correlateClasses();
-			
-		} catch (IOException e) {
+			}
+			else if(record instanceof IHeapDumpHProfRecord) {
+				heapRecord=(IHeapDumpHProfRecord) record;
+				heapRecordNo=r;
 
-			monitor.error(e);
+				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();
 	}
 
 	private IJavaClass[] primitiveArrayClasses = new IJavaClass[8];



Mime
View raw message