incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From monte...@apache.org
Subject svn commit: r883384 [44/47] - in /incubator/kato/trunk/org.apache.kato: ./ kato.anttasks/src/main/java/org/apache/kato/anttasks/ kato.anttasks/src/main/java/org/apache/kato/anttasks/sitebuilder/ kato.anttasks/src/main/java/org/apache/kato/anttasks/tck/...
Date Mon, 23 Nov 2009 15:54:15 GMT
Modified: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoClassCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoClassCommand.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoClassCommand.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoClassCommand.java Mon Nov 23 15:53:48 2009
@@ -1,407 +1,407 @@
-/*******************************************************************************
- * 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.katoview.commands.infocommands;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Stack;
-import java.util.Iterator;
-
-import javax.tools.diagnostics.image.CorruptData;
-import javax.tools.diagnostics.image.CorruptDataException;
-import javax.tools.diagnostics.image.Image;
-import javax.tools.diagnostics.runtime.ManagedRuntime;
-import javax.tools.diagnostics.runtime.java.JavaClass;
-import javax.tools.diagnostics.runtime.java.JavaClassLoader;
-import javax.tools.diagnostics.runtime.java.JavaHeap;
-import javax.tools.diagnostics.runtime.java.JavaObject;
-import javax.tools.diagnostics.runtime.java.JavaRuntime;
-
-import org.apache.kato.katoview.Output;
-import org.apache.kato.katoview.commands.Command;
-import org.apache.kato.katoview.commands.helpers.ClassOutput;
-import org.apache.kato.katoview.commands.helpers.Exceptions;
-import org.apache.kato.katoview.commands.helpers.Utils;
-
-
-public class InfoClassCommand extends Command{
-	
-	public InfoClassCommand(Output o){
-		super(o, "class", "prints inheritance chain and other data for a given class", 
-				"parameters: none, class name\n\n" +
-				"if no parameters are passed to \"info class\", it prints the " +
-				"number of instances of each class and the total size of all " +
-				"instances of each class as well as the total number of instances " +
-				"of all classes and the total size of all objects.\n\n" +
-				"if a class name is passed to \"info class\", it prints the " +
-				"following information about that class:\n" +
-				"  - name\n" +
-				"  - ID\n" +
-				"  - superclass ID\n" +
-				"  - class loader ID\n" +
-				"  - modifiers\n" +
-				"  - number of instances and total size of instances\n" +
-				"  - inheritance chain\n" +
-				"  - fields with modifiers (and values for static fields)\n" +
-				"  - methods with modifiers\n"
-				);
-		child_commands = null;
-	}
-	
-	public void doCommand(Stack args, Image loadedImage, HashMap systemProperties){
-		if (args.isEmpty())
-		{
-			printImageClasses(loadedImage);
-			
-			return;
-		}
-
-		String className = (String)args.pop();
-		
-		if (!args.isEmpty())
-		{
-			out.error("\"info class\" takes at most one parameter, which, if " +
-					"specified, must be a class name");
-			return;
-		}
-		
-		printImageClass(loadedImage, className);
-	}
-	
-	private void printImageClass(Image loadedImage, String className)
-	{
-		ManagedRuntime mr;
-		Iterator itRuntime = Utils.getRuntimes(loadedImage);
-		int count = 1;
-
-		out.print("\n");
-		while (itRuntime.hasNext()) {
-			mr = (ManagedRuntime)itRuntime.next();
-			if (mr instanceof JavaRuntime)
-			{
-				out.print("Runtime #" + count + ": \n\n");
-				
-				printRuntimeClass((JavaRuntime)mr, className);
-			}
-			count++;
-		}
-	}
-	
-	private void printRuntimeClass(JavaRuntime jr, String className)
-	{
-		JavaClass jc = Utils.getClassGivenName(className, jr, out);
-		
-		// if we couldn't find a class of that name, return; the passed in class name could
-		//  still be an array type or it might not exist
-		if (null == jc)
-		{
-			out.print("\t  could not find class with name \"" + className + "\"\n\n");
-			return;
-		}
-
-		String spaces = "    ";
-		String cdeInfo = "N/A (CorruptDataException occurred)";
-		out.print("name = " + className);
-		out.print(spaces);
-		out.print("\n\n\t");
-		out.print("ID = 0x" + Long.toHexString(jc.getID().getAddress()));
-		
-		String superClassInfo;
-		try{
-			JavaClass superClass = jc.getSuperclass();
-			if (null == superClass) {
-				superClassInfo = "<no superclass>";
-			} else {
-				superClassInfo = "0x" + Long.toHexString(superClass.getID().getAddress());
-			}
-		}catch (CorruptDataException dce){
-			superClassInfo = cdeInfo;
-		}
-		out.print(spaces);
-		out.print("superID = " + superClassInfo);
-/*
- * Omitting size of class because that might differ between instances (ie. arrays)
- * 
-		sb.append(spaces);
-		sb.append("instance size = " + datum.getSize());
-*/
-		
-		String classLoaderInfo;
-		try{
-			JavaClassLoader jClassLoader = jc.getClassLoader();
-			classLoaderInfo = "0x" + Long.toHexString(jClassLoader.getObject().getJavaClass().getID().getAddress());
-		}catch (CorruptDataException cde){
-			classLoaderInfo = cdeInfo;
-		}
-		out.print(spaces);
-		out.print("\n\t");
-		out.print("classLoader = " + classLoaderInfo);
-		
-		String modifiersInfo;
-		try{
-			int modifiers = jc.getModifiers();
-			modifiersInfo = Utils.getModifierString(modifiers);
-		}catch (CorruptDataException cde){
-			modifiersInfo = cdeInfo;
-		}
-		out.print(spaces);
-		out.print("modifers: " + modifiersInfo);
-		out.print("\n\n");
-		
-		Map classMap = new HashMap();
-		classMap.put(jc, new Datum());
-		updateInstanceCount(jr, classMap);
-		Datum d = (Datum)classMap.get(jc);
-		
-		out.print("\tnumber of instances:     " + d.getCount() + "\n");
-		out.print("\ttotal size of instances: " + d.getSize() + " bytes");
-		
-		out.print("\n\n");
-		
-		printClassHierarchy(jc);
-		out.print("\n");
-		printFields(jc);
-		out.print("\n");
-		printMethods(jc);
-	}
-
-	private void printClassHierarchy(JavaClass jClass) {
-		Stack stack = new Stack();
-		while (null != jClass){
-			try{
-				stack.add(jClass.getName());
-				jClass = jClass.getSuperclass(); 
-			}catch(CorruptDataException cde){
-				stack.add("N/A (CorruptDataException occurred)");
-				break;
-			}
-		}
-		printStack(stack);
-	}
-	
-	private void printStack(Stack stack){
-		out.print("Inheritance chain....\n\n");
-		String tab = "\t";
-		String spaces = "";
-		while(stack.size() > 0){
-			out.print(tab + spaces + (String)stack.pop() + "\n");
-			spaces += "   ";
-		}
-	}
-	
-	private void printFields(JavaClass jClass) {
-		out.print("Fields......\n\n");
-		ClassOutput.printStaticFields(jClass, out);
-		ClassOutput.printNonStaticFields(jClass, out);
-	}
-	
-	private void printMethods(JavaClass jClass){
-		out.print("Methods......\n\n");
-		ClassOutput.printMethods(jClass.getDeclaredMethods().iterator(), out);
-		out.print("\n");
-	}
-	
-	
-	// below methods are for "info class" (with no parameters)
-	
-	private void printImageClasses(Image loadedImage) {
-		ManagedRuntime mr;
-		Iterator itRuntime = Utils.getRuntimes(loadedImage);
-		int count = 1;
-
-		out.print("\n");
-		while (itRuntime.hasNext()) {
-			mr = (ManagedRuntime)itRuntime.next();
-			if (mr instanceof JavaRuntime)
-			{
-				out.print("Runtime #" + count + ": \n\n");
-				
-				printRuntimeClasses((JavaRuntime)mr);
-				out.print("\n\n");
-			}
-			count++;
-		}
-	}
-	
-	private void printRuntimeClasses(JavaRuntime jr) {
-		Map javaClasses = new HashMap();
-		Iterator itClassLoader = jr.getJavaClassLoaders().iterator();
-		
-		// create Map of all classes in this JavaRuntime's class loaders
-		while (itClassLoader.hasNext()) {
-			JavaClassLoader jcl = (JavaClassLoader)itClassLoader.next();
-			
-			// Check for any corrupt data for this classloader
-			Iterator itCache = jcl.getCachedClasses().iterator();
-			while (itCache.hasNext()) {
-				Object next = itCache.next();
-				if (next instanceof CorruptData){
-					// Warn the user that the classloader data is corrupt
-					try {
-						long jclAddress = jcl.getObject().getID().getAddress();
-						out.print("\t classloader ID: " + Utils.toHex(jclAddress) + " " + Exceptions.getCorruptDataExceptionString() + "\n");
-					} catch (CorruptDataException e) {
-						out.print("\t classloader ID: <unknown> " + Exceptions.getCorruptDataExceptionString() + "\n");
-					}
-					break;
-				}
-			}
-			
-			Iterator itClass = jcl.getDefinedClasses().iterator();
-			while (itClass.hasNext()) {
-				javaClasses.put((JavaClass)itClass.next(), new Datum());
-			}
-		}
-		
-		// update count of objects and sizes in Map of classes
-		updateInstanceCount(jr, javaClasses);
-		
-		// print out results of object counting
-		long objCount = 0;
-		long totalSize = 0;
-		Iterator itClass = javaClasses.keySet().iterator();
-		if (itClass.hasNext()) {
-			printClassListHeader();
-		} else {
-			out.print("\n\t No information found for loaded classes\n");
-		}
-		while (itClass.hasNext()) {
-			JavaClass jc = (JavaClass)itClass.next();
-			String className;
-			
-			try {
-				className = jc.getName();
-			} catch (CorruptDataException cde) {
-				className = Exceptions.getCorruptDataExceptionString();
-			}
-			Datum d = (Datum)javaClasses.get(jc);
-			totalSize += d.getSize();
-			objCount += d.getCount();
-			printOneClass(className, d);
-		}
-		
-		out.print("\n");
-		if ( objCount > 0) {
-			out.print("\t Total number of objects: " + objCount + "\n");
-			out.print("\t Total size of objects: " + totalSize + "\n");
-		} 
-	}
-	
-	private void updateInstanceCount(JavaRuntime jr, Map javaClasses) {
-		Iterator itHeap = jr.getHeaps().iterator();
-		while (itHeap.hasNext()) {
-			JavaHeap jh = (JavaHeap)itHeap.next();
-			Iterator itObject = jh.getObjects().iterator();
-			while (itObject.hasNext()) {
-				Object next = itObject.next();
-				// Check that this is a JavaObject (there may be CorruptData objects in the 
-				// JavaHeap, we don't attempt to count these as instances of known classes). 
-				if (next instanceof JavaObject) {
-					JavaObject jo = (JavaObject)next;
-					Datum d = null;
-					JavaClass jc;
-				
-					try {
-						jc = jo.getJavaClass();
-					} catch (CorruptDataException cde) {
-						jc = null;
-					}
-				
-					if (null != jc) {
-						long size;
-					
-						d = (Datum)javaClasses.get(jc);
-						if (null == d) {
-							d = new Datum();
-							javaClasses.put(jc, d);
-							// FIXME: the below is for debugging purposes
-							//  this should not be needed when Kato reports array classes
-							//  in the class loaders
-/*							try {
-								out.print("\"" + jo.getJavaClass().getName() + "\"\n");
-							} catch (CorruptDataException cde) {
-							out.print(Exceptions.getCorruptDataExceptionString() + "\n");
-						}
-*/
-						}
-						try {
-							size = jo.getSize();
-						} catch (CorruptDataException cde) {
-							size = 0;
-						}
-						d.addToSize(size);
-						d.incrementCount();
-					} else {	// FIXME: DEBUG
-						try {
-							out.print(jo.getJavaClass().getName() + "\n");
-						} catch (CorruptDataException cde) {
-							out.print(Exceptions.getCorruptDataExceptionString() + "\n");
-						}
-					}
-				}
-			}
-		}
-	}
-
-	private void printClassListHeader() {
-		out.print("\t");
-		out.print(Utils.prePadWithSpaces("instances", 16));
-		out.print(Utils.prePadWithSpaces("total size", 16));
-		out.print("  class name");
-		out.print("\n");
-	}
-
-	private void printOneClass(String className, Datum datum){
-		out.print("\t");
-		out.print(Utils.prePadWithSpaces(String.valueOf(datum.getCount()), 16));
-		out.print(Utils.prePadWithSpaces(String.valueOf(datum.getSize()), 16));
-		out.print("  " + className);
-		out.print("\n");
-	}
-	
-/*
-	private void printOneClass(String className, Datum datum){
-		out.print("\t " + className + "\t"  
-				+ "has " + datum.getCount() + " instances "
-				+ "(total size = " + (long)datum.getSize()*datum.getCount() + ")"
-				+ "\n");
-	}
-*/
-	
-	public class Datum{
-		private int count;
-		private long size;
-		
-		public Datum(){
-			this.count = 0;
-			this.size = 0;
-		}
-		
-		public int getCount(){
-			return this.count;
-		}
-		
-		public long getSize(){
-			return this.size;
-		}
-		
-		public void incrementCount(){
-			this.count++;
-		}
-		
-		public void addToSize(long sizeToAdd){
-			this.size += sizeToAdd;
-		}
-	}
-}
+/*******************************************************************************
+ * 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.katoview.commands.infocommands;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Stack;
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.runtime.ManagedRuntime;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaClassLoader;
+import javax.tools.diagnostics.runtime.java.JavaHeap;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+
+import org.apache.kato.katoview.Output;
+import org.apache.kato.katoview.commands.Command;
+import org.apache.kato.katoview.commands.helpers.ClassOutput;
+import org.apache.kato.katoview.commands.helpers.Exceptions;
+import org.apache.kato.katoview.commands.helpers.Utils;
+
+
+public class InfoClassCommand extends Command{
+	
+	public InfoClassCommand(Output o){
+		super(o, "class", "prints inheritance chain and other data for a given class", 
+				"parameters: none, class name\n\n" +
+				"if no parameters are passed to \"info class\", it prints the " +
+				"number of instances of each class and the total size of all " +
+				"instances of each class as well as the total number of instances " +
+				"of all classes and the total size of all objects.\n\n" +
+				"if a class name is passed to \"info class\", it prints the " +
+				"following information about that class:\n" +
+				"  - name\n" +
+				"  - ID\n" +
+				"  - superclass ID\n" +
+				"  - class loader ID\n" +
+				"  - modifiers\n" +
+				"  - number of instances and total size of instances\n" +
+				"  - inheritance chain\n" +
+				"  - fields with modifiers (and values for static fields)\n" +
+				"  - methods with modifiers\n"
+				);
+		child_commands = null;
+	}
+	
+	public void doCommand(Stack args, Image loadedImage, HashMap systemProperties){
+		if (args.isEmpty())
+		{
+			printImageClasses(loadedImage);
+			
+			return;
+		}
+
+		String className = (String)args.pop();
+		
+		if (!args.isEmpty())
+		{
+			out.error("\"info class\" takes at most one parameter, which, if " +
+					"specified, must be a class name");
+			return;
+		}
+		
+		printImageClass(loadedImage, className);
+	}
+	
+	private void printImageClass(Image loadedImage, String className)
+	{
+		ManagedRuntime mr;
+		Iterator itRuntime = Utils.getRuntimes(loadedImage);
+		int count = 1;
+
+		out.print("\n");
+		while (itRuntime.hasNext()) {
+			mr = (ManagedRuntime)itRuntime.next();
+			if (mr instanceof JavaRuntime)
+			{
+				out.print("Runtime #" + count + ": \n\n");
+				
+				printRuntimeClass((JavaRuntime)mr, className);
+			}
+			count++;
+		}
+	}
+	
+	private void printRuntimeClass(JavaRuntime jr, String className)
+	{
+		JavaClass jc = Utils.getClassGivenName(className, jr, out);
+		
+		// if we couldn't find a class of that name, return; the passed in class name could
+		//  still be an array type or it might not exist
+		if (null == jc)
+		{
+			out.print("\t  could not find class with name \"" + className + "\"\n\n");
+			return;
+		}
+
+		String spaces = "    ";
+		String cdeInfo = "N/A (CorruptDataException occurred)";
+		out.print("name = " + className);
+		out.print(spaces);
+		out.print("\n\n\t");
+		out.print("ID = 0x" + Long.toHexString(jc.getID().getAddress()));
+		
+		String superClassInfo;
+		try{
+			JavaClass superClass = jc.getSuperclass();
+			if (null == superClass) {
+				superClassInfo = "<no superclass>";
+			} else {
+				superClassInfo = "0x" + Long.toHexString(superClass.getID().getAddress());
+			}
+		}catch (CorruptDataException dce){
+			superClassInfo = cdeInfo;
+		}
+		out.print(spaces);
+		out.print("superID = " + superClassInfo);
+/*
+ * Omitting size of class because that might differ between instances (ie. arrays)
+ * 
+		sb.append(spaces);
+		sb.append("instance size = " + datum.getSize());
+*/
+		
+		String classLoaderInfo;
+		try{
+			JavaClassLoader jClassLoader = jc.getClassLoader();
+			classLoaderInfo = "0x" + Long.toHexString(jClassLoader.getObject().getJavaClass().getID().getAddress());
+		}catch (CorruptDataException cde){
+			classLoaderInfo = cdeInfo;
+		}
+		out.print(spaces);
+		out.print("\n\t");
+		out.print("classLoader = " + classLoaderInfo);
+		
+		String modifiersInfo;
+		try{
+			int modifiers = jc.getModifiers();
+			modifiersInfo = Utils.getModifierString(modifiers);
+		}catch (CorruptDataException cde){
+			modifiersInfo = cdeInfo;
+		}
+		out.print(spaces);
+		out.print("modifers: " + modifiersInfo);
+		out.print("\n\n");
+		
+		Map classMap = new HashMap();
+		classMap.put(jc, new Datum());
+		updateInstanceCount(jr, classMap);
+		Datum d = (Datum)classMap.get(jc);
+		
+		out.print("\tnumber of instances:     " + d.getCount() + "\n");
+		out.print("\ttotal size of instances: " + d.getSize() + " bytes");
+		
+		out.print("\n\n");
+		
+		printClassHierarchy(jc);
+		out.print("\n");
+		printFields(jc);
+		out.print("\n");
+		printMethods(jc);
+	}
+
+	private void printClassHierarchy(JavaClass jClass) {
+		Stack stack = new Stack();
+		while (null != jClass){
+			try{
+				stack.add(jClass.getName());
+				jClass = jClass.getSuperclass(); 
+			}catch(CorruptDataException cde){
+				stack.add("N/A (CorruptDataException occurred)");
+				break;
+			}
+		}
+		printStack(stack);
+	}
+	
+	private void printStack(Stack stack){
+		out.print("Inheritance chain....\n\n");
+		String tab = "\t";
+		String spaces = "";
+		while(stack.size() > 0){
+			out.print(tab + spaces + (String)stack.pop() + "\n");
+			spaces += "   ";
+		}
+	}
+	
+	private void printFields(JavaClass jClass) {
+		out.print("Fields......\n\n");
+		ClassOutput.printStaticFields(jClass, out);
+		ClassOutput.printNonStaticFields(jClass, out);
+	}
+	
+	private void printMethods(JavaClass jClass){
+		out.print("Methods......\n\n");
+		ClassOutput.printMethods(jClass.getDeclaredMethods().iterator(), out);
+		out.print("\n");
+	}
+	
+	
+	// below methods are for "info class" (with no parameters)
+	
+	private void printImageClasses(Image loadedImage) {
+		ManagedRuntime mr;
+		Iterator itRuntime = Utils.getRuntimes(loadedImage);
+		int count = 1;
+
+		out.print("\n");
+		while (itRuntime.hasNext()) {
+			mr = (ManagedRuntime)itRuntime.next();
+			if (mr instanceof JavaRuntime)
+			{
+				out.print("Runtime #" + count + ": \n\n");
+				
+				printRuntimeClasses((JavaRuntime)mr);
+				out.print("\n\n");
+			}
+			count++;
+		}
+	}
+	
+	private void printRuntimeClasses(JavaRuntime jr) {
+		Map javaClasses = new HashMap();
+		Iterator itClassLoader = jr.getJavaClassLoaders().iterator();
+		
+		// create Map of all classes in this JavaRuntime's class loaders
+		while (itClassLoader.hasNext()) {
+			JavaClassLoader jcl = (JavaClassLoader)itClassLoader.next();
+			
+			// Check for any corrupt data for this classloader
+			Iterator itCache = jcl.getCachedClasses().iterator();
+			while (itCache.hasNext()) {
+				Object next = itCache.next();
+				if (next instanceof CorruptData){
+					// Warn the user that the classloader data is corrupt
+					try {
+						long jclAddress = jcl.getObject().getID().getAddress();
+						out.print("\t classloader ID: " + Utils.toHex(jclAddress) + " " + Exceptions.getCorruptDataExceptionString() + "\n");
+					} catch (CorruptDataException e) {
+						out.print("\t classloader ID: <unknown> " + Exceptions.getCorruptDataExceptionString() + "\n");
+					}
+					break;
+				}
+			}
+			
+			Iterator itClass = jcl.getDefinedClasses().iterator();
+			while (itClass.hasNext()) {
+				javaClasses.put((JavaClass)itClass.next(), new Datum());
+			}
+		}
+		
+		// update count of objects and sizes in Map of classes
+		updateInstanceCount(jr, javaClasses);
+		
+		// print out results of object counting
+		long objCount = 0;
+		long totalSize = 0;
+		Iterator itClass = javaClasses.keySet().iterator();
+		if (itClass.hasNext()) {
+			printClassListHeader();
+		} else {
+			out.print("\n\t No information found for loaded classes\n");
+		}
+		while (itClass.hasNext()) {
+			JavaClass jc = (JavaClass)itClass.next();
+			String className;
+			
+			try {
+				className = jc.getName();
+			} catch (CorruptDataException cde) {
+				className = Exceptions.getCorruptDataExceptionString();
+			}
+			Datum d = (Datum)javaClasses.get(jc);
+			totalSize += d.getSize();
+			objCount += d.getCount();
+			printOneClass(className, d);
+		}
+		
+		out.print("\n");
+		if ( objCount > 0) {
+			out.print("\t Total number of objects: " + objCount + "\n");
+			out.print("\t Total size of objects: " + totalSize + "\n");
+		} 
+	}
+	
+	private void updateInstanceCount(JavaRuntime jr, Map javaClasses) {
+		Iterator itHeap = jr.getHeaps().iterator();
+		while (itHeap.hasNext()) {
+			JavaHeap jh = (JavaHeap)itHeap.next();
+			Iterator itObject = jh.getObjects().iterator();
+			while (itObject.hasNext()) {
+				Object next = itObject.next();
+				// Check that this is a JavaObject (there may be CorruptData objects in the 
+				// JavaHeap, we don't attempt to count these as instances of known classes). 
+				if (next instanceof JavaObject) {
+					JavaObject jo = (JavaObject)next;
+					Datum d = null;
+					JavaClass jc;
+				
+					try {
+						jc = jo.getJavaClass();
+					} catch (CorruptDataException cde) {
+						jc = null;
+					}
+				
+					if (null != jc) {
+						long size;
+					
+						d = (Datum)javaClasses.get(jc);
+						if (null == d) {
+							d = new Datum();
+							javaClasses.put(jc, d);
+							// FIXME: the below is for debugging purposes
+							//  this should not be needed when Kato reports array classes
+							//  in the class loaders
+/*							try {
+								out.print("\"" + jo.getJavaClass().getName() + "\"\n");
+							} catch (CorruptDataException cde) {
+							out.print(Exceptions.getCorruptDataExceptionString() + "\n");
+						}
+*/
+						}
+						try {
+							size = jo.getSize();
+						} catch (CorruptDataException cde) {
+							size = 0;
+						}
+						d.addToSize(size);
+						d.incrementCount();
+					} else {	// FIXME: DEBUG
+						try {
+							out.print(jo.getJavaClass().getName() + "\n");
+						} catch (CorruptDataException cde) {
+							out.print(Exceptions.getCorruptDataExceptionString() + "\n");
+						}
+					}
+				}
+			}
+		}
+	}
+
+	private void printClassListHeader() {
+		out.print("\t");
+		out.print(Utils.prePadWithSpaces("instances", 16));
+		out.print(Utils.prePadWithSpaces("total size", 16));
+		out.print("  class name");
+		out.print("\n");
+	}
+
+	private void printOneClass(String className, Datum datum){
+		out.print("\t");
+		out.print(Utils.prePadWithSpaces(String.valueOf(datum.getCount()), 16));
+		out.print(Utils.prePadWithSpaces(String.valueOf(datum.getSize()), 16));
+		out.print("  " + className);
+		out.print("\n");
+	}
+	
+/*
+	private void printOneClass(String className, Datum datum){
+		out.print("\t " + className + "\t"  
+				+ "has " + datum.getCount() + " instances "
+				+ "(total size = " + (long)datum.getSize()*datum.getCount() + ")"
+				+ "\n");
+	}
+*/
+	
+	public class Datum{
+		private int count;
+		private long size;
+		
+		public Datum(){
+			this.count = 0;
+			this.size = 0;
+		}
+		
+		public int getCount(){
+			return this.count;
+		}
+		
+		public long getSize(){
+			return this.size;
+		}
+		
+		public void incrementCount(){
+			this.count++;
+		}
+		
+		public void addToSize(long sizeToAdd){
+			this.size += sizeToAdd;
+		}
+	}
+}

Propchange: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoClassCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoHeapCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoHeapCommand.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoHeapCommand.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoHeapCommand.java Mon Nov 23 15:53:48 2009
@@ -1,199 +1,199 @@
-/*******************************************************************************
- * 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.katoview.commands.infocommands;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Stack;
-
-import javax.tools.diagnostics.image.CorruptDataException;
-import javax.tools.diagnostics.image.DataUnavailable;
-import javax.tools.diagnostics.image.Image;
-import javax.tools.diagnostics.image.ImageSection;
-import javax.tools.diagnostics.runtime.ManagedRuntime;
-import javax.tools.diagnostics.runtime.java.JavaHeap;
-import javax.tools.diagnostics.runtime.java.JavaObject;
-import javax.tools.diagnostics.runtime.java.JavaRuntime;
-
-import org.apache.kato.katoview.Output;
-import org.apache.kato.katoview.commands.Command;
-import org.apache.kato.katoview.commands.helpers.Utils;
-
-
-public class InfoHeapCommand extends Command {
-	
-	public InfoHeapCommand(Output o){
-		super(o, "heap", "displays information about Java heaps",
-				"parameters: none, \"*\", or heap name\n\n" +
-				" none prints:\n" +
-				" - heap name\n" +
-				" - heap section\n" +
-				" \"*\" or heap name prints the following information\n" +
-				" about all heaps or the specified heap, respectively:\n" +
-				" - heap name\n" +
-				" - (heap size and occupancy)\n" +
-				" - heap sections\n" +
-				"  - section name\n" +
-				"  - section size\n" +
-				"  - whether the section is shared\n" +
-				"  - whether the section is executable\n" +
-				"  - whether the section is read only\n"
-				);
-		child_commands = null;
-	}
-	public void doCommand(Stack args, Image loadedImage, HashMap properties){
-		
-		
-		String param = null;
-		StringBuffer paramsToString = new StringBuffer(); 
-		if (!args.isEmpty()){
-			for (int i = (args.size())-1; i>=0; i--){
-				paramsToString.append(((String) args.get(i)) + " ");
-			}
-			if (paramsToString != null){
-				param = paramsToString.toString();
-				param = param.trim();
-			}
-		}
-		
-		ManagedRuntime mr;
-		Iterator itRuntime = Utils.getRuntimes(loadedImage);
-		int count = 1;
-
-		out.print("\n");
-		while (itRuntime.hasNext()) {
-			mr = (ManagedRuntime)itRuntime.next();
-			if (mr instanceof JavaRuntime)
-			{
-				out.print("\tRuntime #" + count);
-				out.print("\n");
-				
-				if (args.isEmpty()){
-					printHeapInfo(null,(JavaRuntime)mr, out);
-					out.print("\nUse \"info heap *\" or \"info heap <heap_name>\" " +
-							"for more information.\n");
-				} else if (param.indexOf("*")>=0){
-					printHeapInfo(param,(JavaRuntime)mr, out);
-				} else {
-					
-					boolean foundHeap = searchForHeap(param, (JavaRuntime)mr, out);
-					
-					if (!foundHeap){
-						out.error("Unable to locate heap: \"" + param +"\".");
-						out.print("\tAvailable heaps: \n");
-						printHeapInfo(null,(JavaRuntime)mr, out);
-					}
-				}
-			
-			}
-			count++;
-		}
-	}
-	private void printHeapInfo(String param, JavaRuntime runtime, Output out){
-		
-		Iterator itHeaps = runtime.getHeaps().iterator();
-		int countheaps = 1;
-		
-		while (itHeaps.hasNext())
-		{
-			JavaHeap theHeap = (JavaHeap)itHeaps.next();
-			out.print("\t Heap #" + countheaps + ":  " + theHeap.getName()+ "\n");
-			if (param != null){
-				printSectionInfo(theHeap, out);
-			}
-			countheaps++;
-		}
-	}
-	private void printSectionInfo(JavaHeap theHeap, Output out){
-		
-		Iterator itSections = theHeap.getSections().iterator();
-		int countSections = 1;
-		
-		while (itSections.hasNext()){
-			
-			ImageSection theSection = (ImageSection)itSections.next();
-			out.print("\t  Section #"+ countSections + ":  " + theSection.getName() + "\n");
-			out.print("\t   Size:        " + theSection.getSize() + " bytes\n");
-			try 
-			{
-				out.print("\t   Shared:      " + theSection.isShared() + "\n");
-				out.print("\t   Executable:  " + theSection.isExecutable() +"\n");
-				out.print("\t   Read Only:   " + theSection.isReadOnly() + "\n");
-			}
-			catch(DataUnavailable e){
-				out.print("\t   Shared:      <unknown>\n");
-				out.print("\t   Executable:  <unknown>\n");
-				out.print("\t   Read Only:   <unknown>\n");
-			}
-			countSections++;
-		}
-	}
-	private boolean searchForHeap(String param, JavaRuntime jr, Output out){
-		
-		boolean foundHeap = false;
-		
-		Iterator itHeaps = jr.getHeaps().iterator();
-		int countheaps = 1;
-		
-		while (itHeaps.hasNext())
-		{
-			JavaHeap theHeap = (JavaHeap)itHeaps.next();
-			if (theHeap.getName().indexOf(param)==0){
-				out.print("\t Heap #" + countheaps + ":  " + theHeap.getName()+"\n");
-				printOccupancyInfo(theHeap, out);
-				printSectionInfo(theHeap, out);
-				foundHeap = true;
-			}
-			countheaps++;
-		}
-		
-		return foundHeap;
-	}
-
-	private void printOccupancyInfo(JavaHeap theHeap, Output out){
-		/*
-		 * This method takes a lot of time and hence this information is only included 
-		 * when using "info heap <heapname>". If this method was run for every heap 
-		 * when using "info heap *" the amount of time it would take would be astronomical.
-		 */
-		long size = 0;
-		long totalObjectSize = 0;
-		
-		Iterator itSections = theHeap.getSections().iterator();
-		while (itSections.hasNext()){
-			ImageSection theSection = (ImageSection)itSections.next();
-			size = size + theSection.getSize();
-		}
-		out.print("\t  Size of heap: "+ size + " bytes\n");
-		
-		Iterator itObjects = theHeap.getObjects().iterator();
-		try{
-			while (itObjects.hasNext()){
-				JavaObject theObject = (JavaObject)itObjects.next();
-				totalObjectSize = totalObjectSize + theObject.getSize();
-			}
-			
-			float percentage = ((float)totalObjectSize/(float)size)*10000; 
-			int trimmedPercent = ((int)percentage); // Sending this float through an int gets it down to 2 decimal places.
-			percentage = ((float)trimmedPercent)/100;
-			
-			out.print("\t  Occupancy :   "+ totalObjectSize + " bytes  (" + percentage + "%)\n");
-		
-		} catch (CorruptDataException e){
-			out.print("\t  Occupancy :   <unknown>\n");
-		}
-		
-	}
-	
-}
+/*******************************************************************************
+ * 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.katoview.commands.infocommands;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Stack;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImageSection;
+import javax.tools.diagnostics.runtime.ManagedRuntime;
+import javax.tools.diagnostics.runtime.java.JavaHeap;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+
+import org.apache.kato.katoview.Output;
+import org.apache.kato.katoview.commands.Command;
+import org.apache.kato.katoview.commands.helpers.Utils;
+
+
+public class InfoHeapCommand extends Command {
+	
+	public InfoHeapCommand(Output o){
+		super(o, "heap", "displays information about Java heaps",
+				"parameters: none, \"*\", or heap name\n\n" +
+				" none prints:\n" +
+				" - heap name\n" +
+				" - heap section\n" +
+				" \"*\" or heap name prints the following information\n" +
+				" about all heaps or the specified heap, respectively:\n" +
+				" - heap name\n" +
+				" - (heap size and occupancy)\n" +
+				" - heap sections\n" +
+				"  - section name\n" +
+				"  - section size\n" +
+				"  - whether the section is shared\n" +
+				"  - whether the section is executable\n" +
+				"  - whether the section is read only\n"
+				);
+		child_commands = null;
+	}
+	public void doCommand(Stack args, Image loadedImage, HashMap properties){
+		
+		
+		String param = null;
+		StringBuffer paramsToString = new StringBuffer(); 
+		if (!args.isEmpty()){
+			for (int i = (args.size())-1; i>=0; i--){
+				paramsToString.append(((String) args.get(i)) + " ");
+			}
+			if (paramsToString != null){
+				param = paramsToString.toString();
+				param = param.trim();
+			}
+		}
+		
+		ManagedRuntime mr;
+		Iterator itRuntime = Utils.getRuntimes(loadedImage);
+		int count = 1;
+
+		out.print("\n");
+		while (itRuntime.hasNext()) {
+			mr = (ManagedRuntime)itRuntime.next();
+			if (mr instanceof JavaRuntime)
+			{
+				out.print("\tRuntime #" + count);
+				out.print("\n");
+				
+				if (args.isEmpty()){
+					printHeapInfo(null,(JavaRuntime)mr, out);
+					out.print("\nUse \"info heap *\" or \"info heap <heap_name>\" " +
+							"for more information.\n");
+				} else if (param.indexOf("*")>=0){
+					printHeapInfo(param,(JavaRuntime)mr, out);
+				} else {
+					
+					boolean foundHeap = searchForHeap(param, (JavaRuntime)mr, out);
+					
+					if (!foundHeap){
+						out.error("Unable to locate heap: \"" + param +"\".");
+						out.print("\tAvailable heaps: \n");
+						printHeapInfo(null,(JavaRuntime)mr, out);
+					}
+				}
+			
+			}
+			count++;
+		}
+	}
+	private void printHeapInfo(String param, JavaRuntime runtime, Output out){
+		
+		Iterator itHeaps = runtime.getHeaps().iterator();
+		int countheaps = 1;
+		
+		while (itHeaps.hasNext())
+		{
+			JavaHeap theHeap = (JavaHeap)itHeaps.next();
+			out.print("\t Heap #" + countheaps + ":  " + theHeap.getName()+ "\n");
+			if (param != null){
+				printSectionInfo(theHeap, out);
+			}
+			countheaps++;
+		}
+	}
+	private void printSectionInfo(JavaHeap theHeap, Output out){
+		
+		Iterator itSections = theHeap.getSections().iterator();
+		int countSections = 1;
+		
+		while (itSections.hasNext()){
+			
+			ImageSection theSection = (ImageSection)itSections.next();
+			out.print("\t  Section #"+ countSections + ":  " + theSection.getName() + "\n");
+			out.print("\t   Size:        " + theSection.getSize() + " bytes\n");
+			try 
+			{
+				out.print("\t   Shared:      " + theSection.isShared() + "\n");
+				out.print("\t   Executable:  " + theSection.isExecutable() +"\n");
+				out.print("\t   Read Only:   " + theSection.isReadOnly() + "\n");
+			}
+			catch(DataUnavailable e){
+				out.print("\t   Shared:      <unknown>\n");
+				out.print("\t   Executable:  <unknown>\n");
+				out.print("\t   Read Only:   <unknown>\n");
+			}
+			countSections++;
+		}
+	}
+	private boolean searchForHeap(String param, JavaRuntime jr, Output out){
+		
+		boolean foundHeap = false;
+		
+		Iterator itHeaps = jr.getHeaps().iterator();
+		int countheaps = 1;
+		
+		while (itHeaps.hasNext())
+		{
+			JavaHeap theHeap = (JavaHeap)itHeaps.next();
+			if (theHeap.getName().indexOf(param)==0){
+				out.print("\t Heap #" + countheaps + ":  " + theHeap.getName()+"\n");
+				printOccupancyInfo(theHeap, out);
+				printSectionInfo(theHeap, out);
+				foundHeap = true;
+			}
+			countheaps++;
+		}
+		
+		return foundHeap;
+	}
+
+	private void printOccupancyInfo(JavaHeap theHeap, Output out){
+		/*
+		 * This method takes a lot of time and hence this information is only included 
+		 * when using "info heap <heapname>". If this method was run for every heap 
+		 * when using "info heap *" the amount of time it would take would be astronomical.
+		 */
+		long size = 0;
+		long totalObjectSize = 0;
+		
+		Iterator itSections = theHeap.getSections().iterator();
+		while (itSections.hasNext()){
+			ImageSection theSection = (ImageSection)itSections.next();
+			size = size + theSection.getSize();
+		}
+		out.print("\t  Size of heap: "+ size + " bytes\n");
+		
+		Iterator itObjects = theHeap.getObjects().iterator();
+		try{
+			while (itObjects.hasNext()){
+				JavaObject theObject = (JavaObject)itObjects.next();
+				totalObjectSize = totalObjectSize + theObject.getSize();
+			}
+			
+			float percentage = ((float)totalObjectSize/(float)size)*10000; 
+			int trimmedPercent = ((int)percentage); // Sending this float through an int gets it down to 2 decimal places.
+			percentage = ((float)trimmedPercent)/100;
+			
+			out.print("\t  Occupancy :   "+ totalObjectSize + " bytes  (" + percentage + "%)\n");
+		
+		} catch (CorruptDataException e){
+			out.print("\t  Occupancy :   <unknown>\n");
+		}
+		
+	}
+	
+}

Propchange: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoHeapCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoJitmCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoJitmCommand.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoJitmCommand.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoJitmCommand.java Mon Nov 23 15:53:48 2009
@@ -1,116 +1,116 @@
-/*******************************************************************************
- * 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.katoview.commands.infocommands;
-
-import java.util.HashMap;
-import java.util.Stack;
-import java.util.Iterator;
-
-import javax.tools.diagnostics.image.CorruptDataException;
-import javax.tools.diagnostics.image.Image;
-import javax.tools.diagnostics.image.ImageSection;
-import javax.tools.diagnostics.runtime.java.JavaClass;
-import javax.tools.diagnostics.runtime.java.JavaClassLoader;
-import javax.tools.diagnostics.runtime.java.JavaMethod;
-import javax.tools.diagnostics.runtime.java.JavaRuntime;
-
-import org.apache.kato.katoview.Output;
-import org.apache.kato.katoview.commands.Command;
-import org.apache.kato.katoview.commands.helpers.Exceptions;
-import org.apache.kato.katoview.commands.helpers.Utils;
-
-
-public class InfoJitmCommand extends Command {
-
-	public InfoJitmCommand(Output o){
-		super(o, "jitm", "displays JIT'ed methods and their addresses",
-				"parameters: none\n\n" +
-				"prints the following information about each JIT'ed method\n\n" +
-				"  - method name and signature\n" +
-				"  - method start address\n" +
-				"  - method end address\n"
-		);
-		child_commands = null;
-	}
-	
-	public void doCommand(Stack args, Image loadedImage, HashMap properties){
-		if (!args.isEmpty())
-		{
-			out.error("\"info jitm\" command does not take any parameters");
-		}
-		else
-		{
-			Iterator itJavaRuntime = Utils.getRuntimes(loadedImage);
-			while (itJavaRuntime.hasNext())
-			{
-				JavaRuntime jr = (JavaRuntime)itJavaRuntime.next();
-				Iterator itJavaClassLoader = jr.getJavaClassLoaders().iterator();
-				while (itJavaClassLoader.hasNext())
-				{
-					JavaClassLoader jcl = (JavaClassLoader)itJavaClassLoader.next();
-					Iterator itJavaClass = jcl.getDefinedClasses().iterator();
-					
-					while (itJavaClass.hasNext())
-					{
-						JavaClass jc = (JavaClass)itJavaClass.next();
-						Iterator itJavaMethod = jc.getDeclaredMethods().iterator();
-						
-						String jcName;
-						try {
-							jcName = jc.getName();
-						} catch (CorruptDataException e) {
-							jcName = Exceptions.getCorruptDataExceptionString();
-						}
-						
-						while (itJavaMethod.hasNext())
-						{
-							JavaMethod jm = (JavaMethod)itJavaMethod.next();
-							String name;
-							String sig;
-							
-							try {
-								name = jm.getName();
-							} catch (CorruptDataException e) {
-								name = Exceptions.getCorruptDataExceptionString();
-							}
-							
-							try {
-								sig = jm.getSignature();
-							} catch (CorruptDataException e) {
-								sig = Exceptions.getCorruptDataExceptionString();
-							}
-
-							if (jm.getCompiledSections().isEmpty()==false)
-							{
-								Iterator itImageSection = jm.getCompiledSections().iterator();
-								while (itImageSection.hasNext())
-								{
-									ImageSection is = (ImageSection)itImageSection.next();
-									long startAddr = is.getBaseAddress().getAddress();
-									long size = is.getSize();
-									long endAddr = startAddr + size;
-									
-									out.print("\n\t" + "start=" + Utils.toHex(startAddr) +
-											"  " + "end=" + Utils.toHex(endAddr) +
-											"   " + jcName + "::" + name + sig);
-								}
-							}
-						}
-					}
-				}
-			}
-		}
-		out.print("\n");
-	}
-}
+/*******************************************************************************
+ * 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.katoview.commands.infocommands;
+
+import java.util.HashMap;
+import java.util.Stack;
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImageSection;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaClassLoader;
+import javax.tools.diagnostics.runtime.java.JavaMethod;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+
+import org.apache.kato.katoview.Output;
+import org.apache.kato.katoview.commands.Command;
+import org.apache.kato.katoview.commands.helpers.Exceptions;
+import org.apache.kato.katoview.commands.helpers.Utils;
+
+
+public class InfoJitmCommand extends Command {
+
+	public InfoJitmCommand(Output o){
+		super(o, "jitm", "displays JIT'ed methods and their addresses",
+				"parameters: none\n\n" +
+				"prints the following information about each JIT'ed method\n\n" +
+				"  - method name and signature\n" +
+				"  - method start address\n" +
+				"  - method end address\n"
+		);
+		child_commands = null;
+	}
+	
+	public void doCommand(Stack args, Image loadedImage, HashMap properties){
+		if (!args.isEmpty())
+		{
+			out.error("\"info jitm\" command does not take any parameters");
+		}
+		else
+		{
+			Iterator itJavaRuntime = Utils.getRuntimes(loadedImage);
+			while (itJavaRuntime.hasNext())
+			{
+				JavaRuntime jr = (JavaRuntime)itJavaRuntime.next();
+				Iterator itJavaClassLoader = jr.getJavaClassLoaders().iterator();
+				while (itJavaClassLoader.hasNext())
+				{
+					JavaClassLoader jcl = (JavaClassLoader)itJavaClassLoader.next();
+					Iterator itJavaClass = jcl.getDefinedClasses().iterator();
+					
+					while (itJavaClass.hasNext())
+					{
+						JavaClass jc = (JavaClass)itJavaClass.next();
+						Iterator itJavaMethod = jc.getDeclaredMethods().iterator();
+						
+						String jcName;
+						try {
+							jcName = jc.getName();
+						} catch (CorruptDataException e) {
+							jcName = Exceptions.getCorruptDataExceptionString();
+						}
+						
+						while (itJavaMethod.hasNext())
+						{
+							JavaMethod jm = (JavaMethod)itJavaMethod.next();
+							String name;
+							String sig;
+							
+							try {
+								name = jm.getName();
+							} catch (CorruptDataException e) {
+								name = Exceptions.getCorruptDataExceptionString();
+							}
+							
+							try {
+								sig = jm.getSignature();
+							} catch (CorruptDataException e) {
+								sig = Exceptions.getCorruptDataExceptionString();
+							}
+
+							if (jm.getCompiledSections().isEmpty()==false)
+							{
+								Iterator itImageSection = jm.getCompiledSections().iterator();
+								while (itImageSection.hasNext())
+								{
+									ImageSection is = (ImageSection)itImageSection.next();
+									long startAddr = is.getBaseAddress().getAddress();
+									long size = is.getSize();
+									long endAddr = startAddr + size;
+									
+									out.print("\n\t" + "start=" + Utils.toHex(startAddr) +
+											"  " + "end=" + Utils.toHex(endAddr) +
+											"   " + jcName + "::" + name + sig);
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+		out.print("\n");
+	}
+}

Propchange: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoJitmCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoLockCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoLockCommand.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoLockCommand.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoLockCommand.java Mon Nov 23 15:53:48 2009
@@ -1,139 +1,139 @@
-/*******************************************************************************
- * 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.katoview.commands.infocommands;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Stack;
-import java.util.Vector;
-
-import javax.tools.diagnostics.image.CorruptDataException;
-import javax.tools.diagnostics.image.DataUnavailable;
-import javax.tools.diagnostics.image.Image;
-import javax.tools.diagnostics.runtime.java.JavaClass;
-import javax.tools.diagnostics.runtime.java.JavaMonitor;
-import javax.tools.diagnostics.runtime.java.JavaObject;
-import javax.tools.diagnostics.runtime.java.JavaRuntime;
-import javax.tools.diagnostics.runtime.java.JavaThread;
-
-import org.apache.kato.katoview.Output;
-import org.apache.kato.katoview.commands.Command;
-import org.apache.kato.katoview.commands.helpers.Exceptions;
-import org.apache.kato.katoview.commands.helpers.Utils;
-
-
-public class InfoLockCommand extends Command{
-	
-	public InfoLockCommand(Output o){
-		super(o, "lock", "outputs a list of system monitors and locked objects",
-				"parameters: none\n\n" +
-				"The info lock command outputs a list of system monitors and locked objects.");
-		child_commands = null;
-	}
-	
-	public void doCommand(Stack args, Image loadedImage, HashMap properties){
-		Vector vMonitorsWithLockedObjects = new Vector();
-		Iterator runtimes = Utils.getRuntimes(loadedImage);
-		
-		while(runtimes.hasNext()){
-			JavaRuntime jRuntime = (JavaRuntime)runtimes.next();
-			Iterator monitors = jRuntime.getMonitors().iterator();
-			
-			out.println("\nSystem locks...");
-			while (monitors.hasNext()){
-				JavaMonitor jMonitor = (JavaMonitor)monitors.next();
-				JavaObject jObject = jMonitor.getObject();
-				try {
-					String monitorName = jMonitor.getName().trim();
-					if (monitorName.equalsIgnoreCase("")) {
-						monitorName = "<un-named monitor>";
-					}
-					out.println("id: 0x" + jMonitor.getID() + " name: " + jMonitor.getName());
-
-					JavaThread owner = jMonitor.getOwner();
-					if (null != owner) {
-						try {
-							out.println("\towner thread id: " + owner.getImageThread().getID()
-									+ " name: " + owner.getName());
-						} catch (DataUnavailable e) {
-							out.println("\towner thread id: " + Exceptions.getDataUnavailableString());
-						}
-					}
-					
-					// List any threads waiting on enter or notify for this monitor
-					Iterator itEnterWaiter = jMonitor.getEnterWaiters().iterator();
-					while (itEnterWaiter.hasNext()) {
-						JavaThread jThread = (JavaThread)itEnterWaiter.next();
-						try {
-							out.println("\twaiting thread id: " + jThread.getImageThread().getID() 
-									+ " name: " + jThread.getName());
-						} catch (DataUnavailable dae) {
-							out.println("\twaiting thread id: <unknown>");
-						}
-					}
-					Iterator itNotifyWaiter = jMonitor.getNotifyWaiters().iterator();
-					while (itNotifyWaiter.hasNext()) {
-						JavaThread jThread = (JavaThread)itNotifyWaiter.next();
-						try {
-							out.println("\twaiting thread id: " + jThread.getImageThread().getID() 
-									+ " name: " + jThread.getName());
-						} catch (DataUnavailable dae) {
-							out.println("\twaiting thread id: <unknown>");
-						}
-					}
-					
-				} catch(CorruptDataException cde) {
-					out.println("\nwarning, corrupt data encountered during scan for system locks...");
-				}
-				if (null != jObject) {
-					// Remember object monitors (flat or inflated) for later
-					vMonitorsWithLockedObjects.add(jMonitor);
-				}
-			}
-		}
-		
-		out.println("\nLocked objects...");
-		if (0 == vMonitorsWithLockedObjects.size()){
-			out.println("\t...None.");
-			return;
-		}
-		Iterator lockedObjects = vMonitorsWithLockedObjects.iterator();
-		while(lockedObjects.hasNext()){
-			JavaMonitor jMonitor = (JavaMonitor)lockedObjects.next();
-			JavaObject jObject = jMonitor.getObject();
-			try{
-				JavaThread owner = jMonitor.getOwner();
-				String className = "<unknown class>";
-				JavaClass jClass = jObject.getJavaClass();	
-				if (null != jClass) {
-				    className = jClass.getName();
-				}
-				String jObjectID = Long.toHexString(jObject.getID().getAddress());
-				if (null == owner) {
-					out.println(className + "@0x" + jObjectID + " locked by an unknown thread");
-				} else {
-					String owningThreadID = null;
-					try {
-						owningThreadID = owner.getImageThread().getID();
-					} catch (DataUnavailable e) {
-						owningThreadID = Exceptions.getDataUnavailableString();
-					}
-					out.println(className + "@0x" + jObjectID + "\n\tlocked by thread id: "
-								+ owningThreadID + " name: " + owner.getName());
-				}
-			}catch(CorruptDataException cde){
-			}
-		}
-	}
-}
+/*******************************************************************************
+ * 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.katoview.commands.infocommands;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Stack;
+import java.util.Vector;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaMonitor;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+import javax.tools.diagnostics.runtime.java.JavaThread;
+
+import org.apache.kato.katoview.Output;
+import org.apache.kato.katoview.commands.Command;
+import org.apache.kato.katoview.commands.helpers.Exceptions;
+import org.apache.kato.katoview.commands.helpers.Utils;
+
+
+public class InfoLockCommand extends Command{
+	
+	public InfoLockCommand(Output o){
+		super(o, "lock", "outputs a list of system monitors and locked objects",
+				"parameters: none\n\n" +
+				"The info lock command outputs a list of system monitors and locked objects.");
+		child_commands = null;
+	}
+	
+	public void doCommand(Stack args, Image loadedImage, HashMap properties){
+		Vector vMonitorsWithLockedObjects = new Vector();
+		Iterator runtimes = Utils.getRuntimes(loadedImage);
+		
+		while(runtimes.hasNext()){
+			JavaRuntime jRuntime = (JavaRuntime)runtimes.next();
+			Iterator monitors = jRuntime.getMonitors().iterator();
+			
+			out.println("\nSystem locks...");
+			while (monitors.hasNext()){
+				JavaMonitor jMonitor = (JavaMonitor)monitors.next();
+				JavaObject jObject = jMonitor.getObject();
+				try {
+					String monitorName = jMonitor.getName().trim();
+					if (monitorName.equalsIgnoreCase("")) {
+						monitorName = "<un-named monitor>";
+					}
+					out.println("id: 0x" + jMonitor.getID() + " name: " + jMonitor.getName());
+
+					JavaThread owner = jMonitor.getOwner();
+					if (null != owner) {
+						try {
+							out.println("\towner thread id: " + owner.getImageThread().getID()
+									+ " name: " + owner.getName());
+						} catch (DataUnavailable e) {
+							out.println("\towner thread id: " + Exceptions.getDataUnavailableString());
+						}
+					}
+					
+					// List any threads waiting on enter or notify for this monitor
+					Iterator itEnterWaiter = jMonitor.getEnterWaiters().iterator();
+					while (itEnterWaiter.hasNext()) {
+						JavaThread jThread = (JavaThread)itEnterWaiter.next();
+						try {
+							out.println("\twaiting thread id: " + jThread.getImageThread().getID() 
+									+ " name: " + jThread.getName());
+						} catch (DataUnavailable dae) {
+							out.println("\twaiting thread id: <unknown>");
+						}
+					}
+					Iterator itNotifyWaiter = jMonitor.getNotifyWaiters().iterator();
+					while (itNotifyWaiter.hasNext()) {
+						JavaThread jThread = (JavaThread)itNotifyWaiter.next();
+						try {
+							out.println("\twaiting thread id: " + jThread.getImageThread().getID() 
+									+ " name: " + jThread.getName());
+						} catch (DataUnavailable dae) {
+							out.println("\twaiting thread id: <unknown>");
+						}
+					}
+					
+				} catch(CorruptDataException cde) {
+					out.println("\nwarning, corrupt data encountered during scan for system locks...");
+				}
+				if (null != jObject) {
+					// Remember object monitors (flat or inflated) for later
+					vMonitorsWithLockedObjects.add(jMonitor);
+				}
+			}
+		}
+		
+		out.println("\nLocked objects...");
+		if (0 == vMonitorsWithLockedObjects.size()){
+			out.println("\t...None.");
+			return;
+		}
+		Iterator lockedObjects = vMonitorsWithLockedObjects.iterator();
+		while(lockedObjects.hasNext()){
+			JavaMonitor jMonitor = (JavaMonitor)lockedObjects.next();
+			JavaObject jObject = jMonitor.getObject();
+			try{
+				JavaThread owner = jMonitor.getOwner();
+				String className = "<unknown class>";
+				JavaClass jClass = jObject.getJavaClass();	
+				if (null != jClass) {
+				    className = jClass.getName();
+				}
+				String jObjectID = Long.toHexString(jObject.getID().getAddress());
+				if (null == owner) {
+					out.println(className + "@0x" + jObjectID + " locked by an unknown thread");
+				} else {
+					String owningThreadID = null;
+					try {
+						owningThreadID = owner.getImageThread().getID();
+					} catch (DataUnavailable e) {
+						owningThreadID = Exceptions.getDataUnavailableString();
+					}
+					out.println(className + "@0x" + jObjectID + "\n\tlocked by thread id: "
+								+ owningThreadID + " name: " + owner.getName());
+				}
+			}catch(CorruptDataException cde){
+			}
+		}
+	}
+}

Propchange: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoLockCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoMmapCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoMmapCommand.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoMmapCommand.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoMmapCommand.java Mon Nov 23 15:53:48 2009
@@ -1,50 +1,50 @@
-/*******************************************************************************
- * 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.katoview.commands.infocommands;
-
-import java.util.HashMap;
-import java.util.Stack;
-import java.util.Iterator;
-
-import javax.tools.diagnostics.image.Image;
-import javax.tools.diagnostics.image.ImageSection;
-
-import org.apache.kato.katoview.Output;
-import org.apache.kato.katoview.commands.Command;
-import org.apache.kato.katoview.commands.helpers.Utils;
-
-
-public class InfoMmapCommand extends Command{
-	
-	public InfoMmapCommand(Output o){
-		super(o, "mmap", "outputs a list of all memory segments in the address space", 
-				"parameters: none\n\n" +
-				"outputs a list all memory segments (ImageSections) " +
-				"in the address space: " +
-				"start address and size"
-				 );
-		child_commands = null;
-	}
-	
-	public void doCommand(Stack args, Image loadedImage, HashMap properties){
-		Iterator imageSections = Utils.getAddressSapceSectionInfo(loadedImage);
-		while(imageSections.hasNext()){
-			ImageSection imageSection = (ImageSection)imageSections.next();
-			long startAddress = imageSection.getBaseAddress().getAddress();
-			long size = imageSection.getSize();
-			out.println("Address: 0x" + Long.toHexString(startAddress) + "   size: 0x" + 
-					Long.toHexString(size) + " (" + size + ")");
-		}
-	}
-}
+/*******************************************************************************
+ * 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.katoview.commands.infocommands;
+
+import java.util.HashMap;
+import java.util.Stack;
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImageSection;
+
+import org.apache.kato.katoview.Output;
+import org.apache.kato.katoview.commands.Command;
+import org.apache.kato.katoview.commands.helpers.Utils;
+
+
+public class InfoMmapCommand extends Command{
+	
+	public InfoMmapCommand(Output o){
+		super(o, "mmap", "outputs a list of all memory segments in the address space", 
+				"parameters: none\n\n" +
+				"outputs a list all memory segments (ImageSections) " +
+				"in the address space: " +
+				"start address and size"
+				 );
+		child_commands = null;
+	}
+	
+	public void doCommand(Stack args, Image loadedImage, HashMap properties){
+		Iterator imageSections = Utils.getAddressSapceSectionInfo(loadedImage);
+		while(imageSections.hasNext()){
+			ImageSection imageSection = (ImageSection)imageSections.next();
+			long startAddress = imageSection.getBaseAddress().getAddress();
+			long size = imageSection.getSize();
+			out.println("Address: 0x" + Long.toHexString(startAddress) + "   size: 0x" + 
+					Long.toHexString(size) + " (" + size + ")");
+		}
+	}
+}

Propchange: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoMmapCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoProcCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoProcCommand.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoProcCommand.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoProcCommand.java Mon Nov 23 15:53:48 2009
@@ -1,183 +1,183 @@
-/*******************************************************************************
- * 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.katoview.commands.infocommands;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Stack;
-import java.util.Properties;
-import java.util.Enumeration;
-
-import javax.tools.diagnostics.image.CorruptData;
-import javax.tools.diagnostics.image.CorruptDataException;
-import javax.tools.diagnostics.image.DataUnavailable;
-import javax.tools.diagnostics.image.Image;
-import javax.tools.diagnostics.image.ImageAddressSpace;
-import javax.tools.diagnostics.image.ImageProcess;
-import javax.tools.diagnostics.image.ImageThread;
-
-import org.apache.kato.katoview.Output;
-import org.apache.kato.katoview.commands.Command;
-import org.apache.kato.katoview.commands.helpers.Exceptions;
-
-
-public class InfoProcCommand extends Command {
-
-	public InfoProcCommand(Output o){
-		super(o, "proc", "displays threads, command line arguments, environment " +
-				"variables, and shared modules of current process",
-				
-				"parameters: none\n\n" +
-				"prints the following information about the current process\n\n" +
-				"  - thread IDs for all its threads\n" +
-				"  - the command line arguments it's using\n" +
-				"  - its environment variables\n\n" +
-				"note: to view the shared modules used by a process, use the " +
-				"\"info sym\" command\n"
-		);
-		child_commands = null;
-	}
-	
-	public void doCommand(Stack args, Image loadedImage, HashMap properties){
-		if (args.isEmpty())
-		{
-			out.print("\n");
-			printAddressSpaceInfo(loadedImage, out);
-			out.print("\n");
-		}
-		else
-		{
-			out.error("\"info proc\" does not take any parameters");
-			return;
-		}
-	}
-	
-	private void printAddressSpaceInfo(Image loadedImage, Output out)
-	{
-		Iterator itAddressSpace;
-		ImageAddressSpace ias;
-		int asnum = 0;
-		
-		itAddressSpace = loadedImage.getAddressSpaces().iterator();
-		while (itAddressSpace.hasNext()) 
-		{
-			ias = (ImageAddressSpace)itAddressSpace.next();
-			out.print("\taddress space # " + asnum + "\n");
-			
-			ImageProcess ip = ias.getCurrentProcess();
-			if (ip == null) 
-			{
-				out.print("\t(No current process in this address space)\n");
-			} 
-			else 
-			{
-					printProcessInfo(ip, out);
-			}
-			asnum++;
-		}
-	}
-	
-	private void printProcessInfo(ImageProcess ip, Output out)
-	{
-		out.print("\n");
-		printThreads(ip, out);
-		out.print("\n");
-		printCommandLine(ip, out);
-		out.print("\n");
-		printEnvironmentVariables(ip, out);
-		out.print("\n");
-	}
-	
-	private void printThreads(ImageProcess ip, Output out)
-	{
-		out.print("\t Native thread IDs for current process:");
-		out.print("\n\t  ");
-		int lineLength = 10; // normal tab plus 2 spaces
-
-		// FIXME: should output architecture (32/64-bit), endianness before threads
-
-		Iterator itThread = ip.getThreads().iterator();
-		while (itThread.hasNext())
-		{
-			Object next = itThread.next();
-			if (next instanceof CorruptData)
-		        continue;
-			ImageThread it = (ImageThread)next;
-
-			try {
-				String threadID = it.getID();
-				if (threadID != null) {
-					if (lineLength + threadID.length() > 80) {
-						out.print("\n\t  ");
-						lineLength = 10;
-					}
-					out.print(it.getID() + " ");
-					lineLength += threadID.length() + 1;
-				}
-			} catch (CorruptDataException e) {
-				out.print(Exceptions.getCorruptDataExceptionString());
-			}
-		}
-	out.print("\n");
-	}
-
-	private void printCommandLine(ImageProcess ip, Output out)
-	{
-		out.print("\t Command line arguments used for current process:");
-		out.print("\n");
-		out.print("\t  ");
-		
-		try {
-			String commandLine = ip.getCommandLine();
-			if (null == commandLine)
-				out.print("<null>");
-			else
-				out.print(commandLine);
-		} catch (CorruptDataException e) {
-			out.print(Exceptions.getCorruptDataExceptionString());
-		} catch (DataUnavailable e) {
-			out.print(Exceptions.getDataUnavailableString());
-		}
-		out.print("\n");
-	}
-	
-	private void printEnvironmentVariables(ImageProcess ip, Output out)
-	{
-		out.print("\t Environment variables for current process:");
-		out.print("\n");
-		
-		Properties variables;
-		try {
-			variables = ip.getEnvironment();
-		} catch (CorruptDataException e) {
-			out.print("\t  " + Exceptions.getCorruptDataExceptionString() + "\n");
-			return;
-		} catch (DataUnavailable e) {
-			out.print("\t  " + Exceptions.getDataUnavailableString() + "\n");
-			return;
-		}
-		
-		Enumeration keys = variables.propertyNames();
-		while (keys.hasMoreElements())
-		{
-			String key = (String)keys.nextElement();
-			printVariableInfo(key, variables.getProperty(key), out);
-		}
-	}
-	
-	private void printVariableInfo(String key, String value, Output out)
-	{
-		out.print("\t  " + key + "=" + value + "\n");
-	}
-}
+/*******************************************************************************
+ * 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.katoview.commands.infocommands;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Stack;
+import java.util.Properties;
+import java.util.Enumeration;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImageAddressSpace;
+import javax.tools.diagnostics.image.ImageProcess;
+import javax.tools.diagnostics.image.ImageThread;
+
+import org.apache.kato.katoview.Output;
+import org.apache.kato.katoview.commands.Command;
+import org.apache.kato.katoview.commands.helpers.Exceptions;
+
+
+public class InfoProcCommand extends Command {
+
+	public InfoProcCommand(Output o){
+		super(o, "proc", "displays threads, command line arguments, environment " +
+				"variables, and shared modules of current process",
+				
+				"parameters: none\n\n" +
+				"prints the following information about the current process\n\n" +
+				"  - thread IDs for all its threads\n" +
+				"  - the command line arguments it's using\n" +
+				"  - its environment variables\n\n" +
+				"note: to view the shared modules used by a process, use the " +
+				"\"info sym\" command\n"
+		);
+		child_commands = null;
+	}
+	
+	public void doCommand(Stack args, Image loadedImage, HashMap properties){
+		if (args.isEmpty())
+		{
+			out.print("\n");
+			printAddressSpaceInfo(loadedImage, out);
+			out.print("\n");
+		}
+		else
+		{
+			out.error("\"info proc\" does not take any parameters");
+			return;
+		}
+	}
+	
+	private void printAddressSpaceInfo(Image loadedImage, Output out)
+	{
+		Iterator itAddressSpace;
+		ImageAddressSpace ias;
+		int asnum = 0;
+		
+		itAddressSpace = loadedImage.getAddressSpaces().iterator();
+		while (itAddressSpace.hasNext()) 
+		{
+			ias = (ImageAddressSpace)itAddressSpace.next();
+			out.print("\taddress space # " + asnum + "\n");
+			
+			ImageProcess ip = ias.getCurrentProcess();
+			if (ip == null) 
+			{
+				out.print("\t(No current process in this address space)\n");
+			} 
+			else 
+			{
+					printProcessInfo(ip, out);
+			}
+			asnum++;
+		}
+	}
+	
+	private void printProcessInfo(ImageProcess ip, Output out)
+	{
+		out.print("\n");
+		printThreads(ip, out);
+		out.print("\n");
+		printCommandLine(ip, out);
+		out.print("\n");
+		printEnvironmentVariables(ip, out);
+		out.print("\n");
+	}
+	
+	private void printThreads(ImageProcess ip, Output out)
+	{
+		out.print("\t Native thread IDs for current process:");
+		out.print("\n\t  ");
+		int lineLength = 10; // normal tab plus 2 spaces
+
+		// FIXME: should output architecture (32/64-bit), endianness before threads
+
+		Iterator itThread = ip.getThreads().iterator();
+		while (itThread.hasNext())
+		{
+			Object next = itThread.next();
+			if (next instanceof CorruptData)
+		        continue;
+			ImageThread it = (ImageThread)next;
+
+			try {
+				String threadID = it.getID();
+				if (threadID != null) {
+					if (lineLength + threadID.length() > 80) {
+						out.print("\n\t  ");
+						lineLength = 10;
+					}
+					out.print(it.getID() + " ");
+					lineLength += threadID.length() + 1;
+				}
+			} catch (CorruptDataException e) {
+				out.print(Exceptions.getCorruptDataExceptionString());
+			}
+		}
+	out.print("\n");
+	}
+
+	private void printCommandLine(ImageProcess ip, Output out)
+	{
+		out.print("\t Command line arguments used for current process:");
+		out.print("\n");
+		out.print("\t  ");
+		
+		try {
+			String commandLine = ip.getCommandLine();
+			if (null == commandLine)
+				out.print("<null>");
+			else
+				out.print(commandLine);
+		} catch (CorruptDataException e) {
+			out.print(Exceptions.getCorruptDataExceptionString());
+		} catch (DataUnavailable e) {
+			out.print(Exceptions.getDataUnavailableString());
+		}
+		out.print("\n");
+	}
+	
+	private void printEnvironmentVariables(ImageProcess ip, Output out)
+	{
+		out.print("\t Environment variables for current process:");
+		out.print("\n");
+		
+		Properties variables;
+		try {
+			variables = ip.getEnvironment();
+		} catch (CorruptDataException e) {
+			out.print("\t  " + Exceptions.getCorruptDataExceptionString() + "\n");
+			return;
+		} catch (DataUnavailable e) {
+			out.print("\t  " + Exceptions.getDataUnavailableString() + "\n");
+			return;
+		}
+		
+		Enumeration keys = variables.propertyNames();
+		while (keys.hasMoreElements())
+		{
+			String key = (String)keys.nextElement();
+			printVariableInfo(key, variables.getProperty(key), out);
+		}
+	}
+	
+	private void printVariableInfo(String key, String value, Output out)
+	{
+		out.print("\t  " + key + "=" + value + "\n");
+	}
+}

Propchange: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/infocommands/InfoProcCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message