incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spo...@apache.org
Subject svn commit: r777071 - in /incubator/kato/trunk/org.apache.kato.jvmti: src/org/apache/kato/jvmti/javaruntime/ src/org/apache/kato/jvmti/process/ src/org/apache/kato/jvmti/reader/ testsrc/test/apache/kato/jvmti/
Date Thu, 21 May 2009 11:23:24 GMT
Author: spoole
Date: Thu May 21 11:23:24 2009
New Revision: 777071

URL: http://svn.apache.org/viewvc?rev=777071&view=rev
Log:
updates to jvmti dump reader project to accomodate new experimental api structure

Added:
    incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinPrinter.java
  (with props)
Modified:
    incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/javaruntime/JavaRuntimeImpl.java
    incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/process/ImageImpl.java
    incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinReader.java
    incubator/kato/trunk/org.apache.kato.jvmti/testsrc/test/apache/kato/jvmti/TestBinReader.java

Modified: incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/javaruntime/JavaRuntimeImpl.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/javaruntime/JavaRuntimeImpl.java?rev=777071&r1=777070&r2=777071&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/javaruntime/JavaRuntimeImpl.java
(original)
+++ incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/javaruntime/JavaRuntimeImpl.java
Thu May 21 11:23:24 2009
@@ -16,7 +16,7 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.Iterator;
+import java.util.List;
 
 import org.apache.kato.image.CorruptDataException;
 import org.apache.kato.image.DataUnavailable;
@@ -38,27 +38,27 @@
 	}
 	
 	@Override
-	public Iterator getCompiledMethods() {
+	public List getCompiledMethods() {
 		// TODO Auto-generated method stub
 		return null;
 	}
 
 	@Override
-	public Iterator getHeapRoots() {
+	public List getHeapRoots() {
 		// TODO Auto-generated method stub
 		return null;
 	}
 
 	@Override
-	public Iterator getHeaps() {
+	public List getHeaps() {
 		// TODO Auto-generated method stub
 		return null;
 	}
 
 	@Override
-	public Iterator getJavaClassLoaders() {
+	public List getJavaClassLoaders() {
 		
-		return base.getJavaClassLoaderIterator();
+		return base.getJavaClassLoader();
 	}
 
 	@Override
@@ -74,9 +74,9 @@
 	}
 
 	@Override
-	public Iterator getMonitors() {
+	public List getMonitors() {
 		
-		return base.getJavaMonitorIterator();
+		return base.getJavaMonitors();
 	}
 
 	@Override
@@ -87,9 +87,9 @@
 	}
 
 	@Override
-	public Iterator getThreads() {
+	public List getThreads() {
 		
-		return base.getThreadIterator();
+		return base.getThreads();
 	}
 
 	@Override

Modified: incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/process/ImageImpl.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/process/ImageImpl.java?rev=777071&r1=777070&r2=777071&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/process/ImageImpl.java
(original)
+++ incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/process/ImageImpl.java
Thu May 21 11:23:24 2009
@@ -74,7 +74,7 @@
 			}
 
 			@Override
-			public Iterator getLibraries()
+			public List getLibraries()
 					throws DataUnavailable,
 					CorruptDataException {
 				throw new DataUnavailable("no env");
@@ -87,7 +87,7 @@
 			}
 
 			@Override
-			public Iterator getRuntimes() {
+			public List getRuntimes() {
 				if(runtimes==null) {
 					runtimes=new LinkedList<ManagedRuntime>();
 					try {
@@ -97,7 +97,7 @@
 						
 					}
 				}
-				return runtimes.iterator();
+				return runtimes;
 			}
 
 			@Override
@@ -115,7 +115,7 @@
 			}
 
 			@Override
-			public Iterator getThreads() {
+			public List getThreads() {
 				// TODO Auto-generated method stub
 				return null;
 			}
@@ -138,7 +138,7 @@
 		}
 
 		@Override
-		public Iterator getImageSections() {
+		public List getImageSections() {
 			// TODO Auto-generated method stub
 			return null;
 		}
@@ -150,9 +150,9 @@
 		}
 
 		@Override
-		public Iterator getProcesses() {
+		public List getProcesses() {
 			fill();
-			return processes.iterator();
+			return processes;
 		}
 	}
 
@@ -163,12 +163,12 @@
 		this.file=base;
 	}
 	@Override
-	public Iterator getAddressSpaces() {
+	public List getAddressSpaces() {
 		if(spaces==null) {
 			spaces=new LinkedList<ImageAddressSpace>();
 			spaces.add(new ImageAddressSpaceImpl());
 		}
-		return spaces.iterator();
+		return spaces;
 		
 	}
 

Added: incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinPrinter.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinPrinter.java?rev=777071&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinPrinter.java
(added)
+++ incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinPrinter.java
Thu May 21 11:23:24 2009
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * 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.jvmti.reader;
+
+import java.io.PrintStream;
+import java.util.Iterator;
+
+import org.apache.kato.image.CorruptDataException;
+import org.apache.kato.image.DataUnavailable;
+import org.apache.kato.java.JavaStackFrame;
+import org.apache.kato.java.JavaThread;
+
+public class BinPrinter {
+
+	private PrintStream out=System.out;
+	
+	public void print(BinReader reader) {
+	
+		out.println("--- Printing Binary Dump --");
+	
+		printThreads(reader);
+	}
+
+	private void printThreads(BinReader reader)  {
+		
+		Iterator i=reader.getThreads().iterator();
+		while(i.hasNext()) {
+			JavaThread thread=(JavaThread) i.next();
+			
+			try {
+				out.println("Thread Name: "+thread.getName());
+			} catch (CorruptDataException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			try {
+				out.println("Thread Priority: "+thread.getPriority());
+			} catch (CorruptDataException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			try {
+				out.println("Thread State: "+thread.getState());
+			} catch (CorruptDataException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			
+			printStackFrames(thread);
+			
+		}
+		
+	}
+
+	private void printStackFrames(JavaThread thread) {
+		
+		out.println("--- Stack Frames --");
+		Iterator i=thread.getStackFrames().iterator();
+		while(i.hasNext()) {
+			JavaStackFrame frame=(JavaStackFrame) i.next();
+			try {
+				out.println("frame: "+frame.getLocation());
+			} catch (CorruptDataException e) {
+				out.println("frame: n/a");
+			}
+			for(int slot=0;slot<100;slot++) {
+				Object obj=null;
+				try {
+					obj = frame.getVariable(slot);
+				} catch (CorruptDataException e) {
+					
+				} catch (DataUnavailable e) {
+					
+				} catch (IndexOutOfBoundsException e) {
+					
+				}
+				if(obj!=null) {
+					out.println("slot "+slot+" = "+obj);
+				}
+			}
+		}
+		
+	}
+}

Propchange: incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinPrinter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinReader.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinReader.java?rev=777071&r1=777070&r2=777071&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinReader.java
(original)
+++ incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinReader.java
Thu May 21 11:23:24 2009
@@ -19,13 +19,13 @@
 import java.io.IOException;
 import java.io.RandomAccessFile;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
 import javax.imageio.stream.FileImageInputStream;
 
+import org.apache.kato.ObjectMapList;
 import org.apache.kato.image.CorruptDataException;
 import org.apache.kato.image.DataUnavailable;
 import org.apache.kato.image.ImagePointer;
@@ -40,6 +40,7 @@
 import org.apache.kato.java.JavaObject;
 import org.apache.kato.java.JavaStackFrame;
 import org.apache.kato.java.JavaThread;
+import org.apache.kato.java.JavaVariable;
 
 public class BinReader {
 
@@ -48,11 +49,11 @@
 	private static final int MAX_MOD=1;
 	
 	
-	private Map<Integer,JavaThread> threadMap=new HashMap<Integer,JavaThread>();
+	private ObjectMapList<Integer,JavaThread> threadMap=new ObjectMapList<Integer,JavaThread>();
 	private Map<Integer,JavaClass>  classMap=new HashMap<Integer,JavaClass>();
-	private Map<Integer,JavaClassLoader> loadersMap=new HashMap<Integer,JavaClassLoader>();
-	private Map<Integer,JavaMonitor> monitorsMap=new HashMap<Integer,JavaMonitor>();
-	private Map<Integer,JavaMethod>  methodMap=new HashMap<Integer,JavaMethod>();
+	private ObjectMapList<Integer,JavaClassLoader> loadersMap=new ObjectMapList<Integer,JavaClassLoader>();
+	private ObjectMapList<Integer,JavaMonitor> monitorsMap=new ObjectMapList<Integer,JavaMonitor>();
+	private ObjectMapList<Integer,JavaMethod>  methodMap=new ObjectMapList<Integer,JavaMethod>();
 	FileImageInputStream in=null;
 	
 	 
@@ -85,10 +86,14 @@
 			error("version of file is not supportable");
 		}
 		
-		try {
+		
 		while(true) {
-			
-			int recordGroup=in.readShort();
+			int recordGroup=0;
+			try {
+			 recordGroup=in.readShort();
+			} catch(EOFException ee) {
+				break;
+			}	
 			switch(recordGroup) {
 			case 100 :  // thead list
 				readThreads();
@@ -102,9 +107,7 @@
 			default  :  error("record group "+recordGroup+" is not understood");
 			}
 		}
-		} catch(EOFException ee) {
-			;
-		}
+		
 	}
 	private void readThreadGroups() throws IOException {
 		// start of assuming at byte 2 of the record group
@@ -317,6 +320,10 @@
 		trace("reading "+count+" thread records");
 		
 		for(int i=0;i<count;i++) {
+			trace("reading thread "+i);
+			if(i==1) {
+				int a=1;
+			}
 			readThread();
 		}
 		 
@@ -369,6 +376,7 @@
 		
 		int methodid=in.readInt();
 		int location=in.readInt();
+		int vars=in.readInt();
 		
 		JLocation loc=new JLocation();
 		loc.method=getMethod(methodid);
@@ -377,6 +385,160 @@
 		frame.location=loc;
 		t.addStackFrame(frame);
 		
+		if(vars>0) {
+			readLocalVariables(frame,vars);
+		}
+	}
+	private void readLocalVariables(JStackFrame frame, int vars) throws IOException {
+		
+		for(int i=0;i<vars;i++) {
+			readLocalVariable(frame);
+		}
+		
+	}
+	private void readLocalVariable(JStackFrame frame) throws IOException {
+		
+		int id=in.readShort();
+		if(id!=501) error("unexpected localvariable record id of "+id);
+		
+		int slot=in.readInt();
+		String sig=readName();
+		
+		trace("read "+slot+","+sig);
+		if(sig.charAt(0)=='!') {
+			// data not available
+			frame.addVariable(slot,sig);
+			return;
+		}
+		if(sig.equals("Z")) { // boolean primitive
+			short b=in.readShort();
+			frame.addVariable(slot, b!=0);
+			return;
+		}
+		
+		if(sig.equals("C")) { // char primitive
+			char b=(char) in.readByte();
+			frame.addVariable(slot, b);
+			return;
+		}
+		if(sig.equals("I")) { // integer
+			int b=in.readInt();
+			frame.addVariable(slot, b);
+			return;
+		}
+		if(sig.equals("B")) { // byte
+			byte b=(byte) in.readShort();
+			frame.addVariable(slot, b);
+			return;
+		}     
+		if(sig.equals("S")) { // short
+			short b=in.readShort();
+			frame.addVariable(slot, b);
+			return;
+		}      
+		if(sig.equals("J")) { // long
+			long b=in.readLong();
+			frame.addVariable(slot, b);
+			return;
+		}  
+		if(sig.equals("[C")) { // char array
+			int length=in.readInt();
+			
+			char[] data=new char[length];
+			for(int i=0;i<data.length;i++) {
+				data[i]=(char) in.readByte();
+			}
+			trace(data);
+			trace("[c="+length);
+		
+			frame.addVariable(slot, data);
+			return;
+		}
+			
+		if(sig.equals("[I")) { // int array
+			int length=in.readInt();
+			int[] data=new int[length];
+			for(int i=0;i<data.length;i++) {
+				data[i]=in.readInt();
+			}
+			frame.addVariable(slot, data);
+			return;
+		} 
+          
+		if(sig.equals("[B")) { // byte array
+			int length=in.readInt();
+			byte[] data=new byte[length];
+			for(int b=0;b<data.length;b++) {
+				data[b]=(byte) in.readShort();
+			}
+			trace("bytes",data);
+			frame.addVariable(slot, data);
+			return;
+		} 
+           
+		if(sig.equals("[S")) { // short array
+			int length=in.readInt();
+			short[] data=new short[length];
+			for(int i=0;i<data.length;i++) {
+				data[i]=in.readShort();
+			}
+			frame.addVariable(slot, data);
+			return;
+		} 
+           
+		if(sig.equals("[J")) { // long array
+			int length=in.readInt();
+			long[] data=new long[length];
+			for(int i=0;i<data.length;i++) {
+				data[i]=in.readLong();
+			}
+			frame.addVariable(slot, data);
+			return;
+		} 
+		
+		if(sig.equals("[F")) { // float array
+			int length=in.readInt();
+			float[] data=new float[length];
+			for(int i=0;i<data.length;i++) {
+				data[i]=in.readFloat();
+			}
+			frame.addVariable(slot, data);
+			return;
+		} 
+		if(sig.equals("[D")) { // double array
+			int length=in.readInt();
+			double[] data=new double[length];
+			for(int i=0;i<data.length;i++) {
+				data[i]=in.readDouble();
+			}
+			frame.addVariable(slot, data);
+			return;
+		}
+		if(sig.equals("[")) { // obj array
+			int length=in.readInt();
+			frame.addVariable(slot, length);
+			return;
+		} 
+		
+		// finally - an object...
+		
+        int objectid=in.readInt();
+    	frame.addVariable(slot, objectid);
+         
+		
+	}
+	private void trace(String msg, byte[] data) {
+		System.out.print(msg+" : ");
+		for(int i=0;i<data.length;i++) {
+			System.out.print(data[i]+" ");
+		}
+		System.out.println("");
+	}
+	private void trace(char[] data) {
+		for(int i=0;i<data.length;i++) {
+			System.out.print(data[i]);
+		}
+		
 	}
 	private void readMonitors(JThread t, int monitorCount) throws IOException {
 		int id=in.readShort();
@@ -408,8 +570,8 @@
 		
 	}
 	
-	public Iterator getThreadIterator() {
-		return threadMap.values().iterator();
+	public List getThreads() {
+		return threadMap.values();
 	}
 	
 	
@@ -417,9 +579,9 @@
 
 		List<JavaThread> waiters=new LinkedList<JavaThread>();
 		@Override
-		public Iterator getEnterWaiters() {
+		public List getEnterWaiters() {
 			
-			return waiters.iterator();
+			return waiters;
 		}
 
 		private void addWaiter(JThread t) {
@@ -440,7 +602,7 @@
 		}
 
 		@Override
-		public Iterator getNotifyWaiters() {
+		public List getNotifyWaiters() {
 			// TODO Auto-generated method stub
 			return null;
 		}
@@ -513,11 +675,11 @@
 			return priority;
 		}
 		@Override
-		public Iterator getStackFrames() {
-			return frames.iterator();
+		public List getStackFrames() {
+			return frames;
 		}
 		@Override
-		public Iterator getStackSections() {
+		public List getStackSections() {
 			// TODO Auto-generated method stub
 			return null;
 		}
@@ -545,15 +707,15 @@
 		}
 
 		@Override
-		public Iterator getCachedClasses() {
+		public List getCachedClasses() {
 			// TODO Auto-generated method stub
 			return null;
 		}
 
 		@Override
-		public Iterator getDefinedClasses() {
+		public List getDefinedClasses() {
 			if(classes==null) classes=new LinkedList<JavaClass>();
-			return classes.iterator();
+			return classes;
 		}
 
 		@Override
@@ -601,17 +763,17 @@
 				return null;
 			}
 			@Override
-			public Iterator getConstantPoolReferences() {
+			public List getConstantPoolReferences() {
 				// TODO Auto-generated method stub
 				return null;
 			}
 			@Override
-			public Iterator getDeclaredFields() {
+			public List getDeclaredFields() {
 				// TODO Auto-generated method stub
 				return null;
 			}
 			@Override
-			public Iterator getDeclaredMethods() {
+			public List getDeclaredMethods() {
 				// TODO Auto-generated method stub
 				return null;
 			}
@@ -621,7 +783,7 @@
 				return null;
 			}
 			@Override
-			public Iterator getInterfaces() {
+			public List getInterfaces() {
 				
 				return null;
 			}
@@ -641,7 +803,7 @@
 				return null;
 			}
 			@Override
-			public Iterator getReferences() {
+			public List getReferences() {
 				// TODO Auto-generated method stub
 				return null;
 			}
@@ -771,6 +933,7 @@
 	class JStackFrame implements JavaStackFrame {
 
 		private JLocation location=null;
+		private Map<Integer,Object> vars=new HashMap<Integer, Object>();
 		@Override
 		public ImagePointer getBasePointer() throws CorruptDataException {
 			// TODO Auto-generated method stub
@@ -778,7 +941,7 @@
 		}
 
 		@Override
-		public Iterator getHeapRoots() {
+		public List getHeapRoots() {
 			// TODO Auto-generated method stub
 			return null;
 		}
@@ -788,7 +951,19 @@
 			
 				return location;
 		}
+
+		@Override
+		public Object getVariable(int slot) throws CorruptDataException,
+				DataUnavailable, IndexOutOfBoundsException {
+			if(vars.containsKey(slot)==false) throw new DataUnavailable("slot "+slot+" is not available");
+			
+			return vars.get(slot);
+			
+		}
 		
+		private void addVariable(int slot,Object value) {
+			vars.put(slot, value);
+		}
 	}
 	
 	class JLocation implements JavaLocation {
@@ -854,13 +1029,13 @@
 		}
 
 		@Override
-		public Iterator getBytecodeSections() {
+		public List getBytecodeSections() {
 		
 			return null;
 		}
 
 		@Override
-		public Iterator getCompiledSections() {
+		public List getCompiledSections() {
 			return null;
 		}
 
@@ -886,10 +1061,15 @@
 		public String getSignature() throws CorruptDataException {
 			return signature;
 		}
+
+		@Override
+		public List getVariables() throws DataUnavailable {
+			return localVars;
+		}
 		
 	}
 	
-	class JLocalVariableTableEntry {
+	class JLocalVariableTableEntry implements JavaVariable {
 
 		public String gensig;
 		public String sig;
@@ -897,14 +1077,38 @@
 		public int slot;
 		public int length;
 		public int start;
+		@Override
+		public int getLength() {
+			return length;
+		}
+		@Override
+		public String getName() throws DataUnavailable {
+			return name;
+		}
+		@Override
+		public String getSignature() {
+			return sig;
+		}
+		@Override
+		public int getSlot() {
+			return slot;
+		}
+		@Override
+		public int getStart() {
+			return start;
+		}
 		
 	}
 
-	public Iterator getJavaClassLoaderIterator() {
+	class VariableValue {
+		String signature=null;
+	}
+	
+	public List getJavaClassLoader() {
 		
-		return loadersMap.values().iterator();
+		return loadersMap.values();
 	}
-	public Iterator getJavaMonitorIterator() {
-		return monitorsMap.values().iterator();
+	public List getJavaMonitors() {
+		return monitorsMap.values();
 	}
 }

Modified: incubator/kato/trunk/org.apache.kato.jvmti/testsrc/test/apache/kato/jvmti/TestBinReader.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.jvmti/testsrc/test/apache/kato/jvmti/TestBinReader.java?rev=777071&r1=777070&r2=777071&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.jvmti/testsrc/test/apache/kato/jvmti/TestBinReader.java
(original)
+++ incubator/kato/trunk/org.apache.kato.jvmti/testsrc/test/apache/kato/jvmti/TestBinReader.java
Thu May 21 11:23:24 2009
@@ -17,6 +17,7 @@
 import java.io.File;
 import java.io.IOException;
 
+import org.apache.kato.jvmti.reader.BinPrinter;
 import org.apache.kato.jvmti.reader.BinReader;
 
 import junit.framework.TestCase;
@@ -29,4 +30,11 @@
 		BinReader br=new BinReader(f);
 		int a=1;
 	}
+	
+	public void testPrint() throws IOException {
+		File f=new File("/home/spoole/workspace-javaone/PyJVMTI/kato.dump");
+		BinReader br=new BinReader(f);
+		BinPrinter p=new BinPrinter();
+		p.print(br);
+	}
 }



Mime
View raw message