incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccris...@apache.org
Subject svn commit: r754949 [3/5] - in /incubator/kato/trunk/import/org.apache.kato.tools.katoview: ./ .settings/ src/ src/com/ src/com/ibm/ src/com/ibm/dtfj/ src/com/ibm/dtfj/dtfjview/ src/com/ibm/dtfj/dtfjview/commands/ src/com/ibm/dtfj/dtfjview/commands/hel...
Date Mon, 16 Mar 2009 16:43:31 GMT
Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/Exceptions.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/Exceptions.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/Exceptions.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/Exceptions.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands.helpers;
+
+public class Exceptions {
+
+	public static String getDataUnavailableString()
+	{
+		return "<data unavailable>";
+	}
+
+	public static String getDataUnavailableByte()
+	{
+		return "!";
+	}
+
+	public static String getDataUnavailableDoubleByte()
+	{
+		return "--";
+	}
+	
+	public static String getCorruptDataExceptionString()
+	{
+		return "<corrupt data encountered>";
+	}
+
+	public static String getCorruptDataExceptionByte()
+	{
+		return "!";
+	}
+
+	public static String getCorruptDataExceptionDoubleByte()
+	{
+		return "--";
+	}
+	
+	public static String getMemoryAccessExceptionString()
+	{
+		return "<cannot access memory>";
+	}
+
+	public static String getMemoryAccessExceptionByte()
+	{
+		return "!";
+	}
+
+	public static String getMemoryAccessExceptionDoubleByte()
+	{
+		return "--";
+	}
+	
+	public static String getIOExceptionString()
+	{
+		return "<I/O exception encountered>";
+	}
+
+	public static String getIOExceptionByte()
+	{
+		return "!";
+	}
+
+	public static String getIOExceptionDoubleByte()
+	{
+		return "--";
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/MonitorNode.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/MonitorNode.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/MonitorNode.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/MonitorNode.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands.helpers;
+
+import com.ibm.dtfj.java.JavaMonitor;
+
+public class MonitorNode {
+
+	public static final int UNKNOWN = 0;
+	public static final int NO_DEADLOCK = 1;
+	public static final int LOOP_DEADLOCK = 2;
+	public static final int BRANCH_DEADLOCK = 3;
+	
+	private JavaMonitor monitor;
+	public int visit;
+	public MonitorNode waitingOn;
+	public int deadlock;
+	public NodeList inList;
+	
+	public MonitorNode(JavaMonitor _monitor)
+	{
+		monitor = _monitor;
+		visit = 0;
+		waitingOn = null;
+		deadlock = UNKNOWN;
+		inList = null;
+	}
+
+	public JavaMonitor getMonitor()
+	{
+		return monitor;
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/MonitorState.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/MonitorState.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/MonitorState.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/MonitorState.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands.helpers;
+
+import com.ibm.dtfj.java.JavaMonitor;
+
+public class MonitorState {
+	
+	public static int WAITING_TO_ENTER = 1;
+	public static int WAITING_TO_BE_NOTIFIED_ON = 2;
+
+	private JavaMonitor jm;
+	private int status;
+	
+	public MonitorState(JavaMonitor _jm, int _status)
+	{
+		jm = _jm;
+		status = _status;
+	}
+	
+	public JavaMonitor getMonitor()
+	{
+		return jm;
+	}
+	
+	public int getStatus()
+	{
+		return status;
+	}
+	
+	public String getStatusString()
+	{
+		if (status == WAITING_TO_ENTER) {
+			return "waiting to enter";
+		} else if (status == WAITING_TO_BE_NOTIFIED_ON) {
+			return "waiting to be notified on";
+		} else {
+			return "<unknown status>";
+		}
+	}
+	
+	public static String getStatusString(int statusToGet)
+	{
+		if (statusToGet == WAITING_TO_ENTER) {
+			return "waiting to enter";
+		} else if (statusToGet == WAITING_TO_BE_NOTIFIED_ON) {
+			return "waiting to be notified on";
+		} else {
+			return "<unknown status>";
+		}
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/NodeList.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/NodeList.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/NodeList.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/NodeList.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands.helpers;
+
+import com.ibm.dtfj.java.JavaThread;
+import com.ibm.dtfj.java.JavaObject;
+import com.ibm.dtfj.image.CorruptDataException;
+
+public class NodeList {
+
+	private MonitorNode head;
+	private MonitorNode tail;
+	private int id;
+	
+	public NodeList(MonitorNode node, int _id)
+	{
+		head = node;
+		tail = node;
+		node.inList = this;
+		id = _id;
+	}
+	
+	public int getID()
+	{
+		return id;
+	}
+	
+	public boolean equals(Object other)
+	{
+		return ((NodeList)other).getID() == id;
+	}
+
+	// returns null if attached; a NodeList representing the part split off from
+	//  this NodeList if a split was required
+	public NodeList attachOrSplit(NodeList other, int nodeListNum)
+	{
+		MonitorNode headToAttach = other.getHead();
+
+		if (tail == headToAttach)
+		{
+			tail = other.getTail();
+			MonitorNode currNode = tail;
+			currNode.inList = this;
+			if (currNode != headToAttach) {
+				do {
+					currNode = currNode.waitingOn;
+					currNode.inList = this;
+				} while (currNode != headToAttach);
+			}
+			return null;
+		}
+		else
+		{
+			MonitorNode currNode = tail;
+			NodeList split = new NodeList(tail, nodeListNum);
+			do
+			{
+				if (currNode == headToAttach)
+				{
+					tail = currNode;
+					return split;
+				}
+				currNode = currNode.waitingOn;
+				split.add(currNode);
+				if (currNode != head)
+					currNode.inList = split;
+			} while (currNode != head);
+			return null;
+		}
+	}
+	
+	public void add(MonitorNode node)
+	{
+		head = node;
+	}
+	
+	public MonitorNode getHead()
+	{
+		return head;
+	}
+	
+	public MonitorNode getTail()
+	{
+		return tail;
+	}
+	
+	public boolean isLoop()
+	{
+		return tail == head;
+	}
+	
+	// Print this list of monitor nodes (ie the owning threads and there object addresses)
+	public String toString()
+	{
+		String retval = "";
+		MonitorNode currNode = tail;
+		MonitorNode lastNode = null;
+		boolean firstTime = true;
+		boolean done = false;
+		
+		do {
+			String name = "";
+			String objAddr = "";
+			JavaObject object = null;
+			JavaThread owner = null;
+			
+			try {
+				owner = currNode.getMonitor().getOwner();
+			} catch (CorruptDataException e) {
+				name = Exceptions.getCorruptDataExceptionString() + " in owner";
+			}
+
+			if (name.equals("")) {
+				try {
+					name = owner.getName();
+				} catch (CorruptDataException e) {
+					name = Exceptions.getCorruptDataExceptionString() + " in owner's ID";
+				}
+			}
+			
+			object = currNode.getMonitor().getObject();
+			if (null == object) {
+				objAddr = "raw";
+			} else {
+				objAddr = Utils.toHex(object.getID().getAddress());
+			}
+			
+			retval += "thread: " + name + " (monitor object: " + objAddr + ") waiting for =>\n\t  ";
+			
+			lastNode = currNode;
+			currNode = currNode.waitingOn;
+
+			if (head == lastNode)
+			{
+				if (firstTime && head == tail)
+					done = false;
+				else
+					done = true;
+			}
+			firstTime = false;
+			
+		} while (!done);
+		
+		retval = retval.substring(0, retval.length() - 18); // removes the tail of the last entry
+		return retval;
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/StateToString.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/StateToString.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/StateToString.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/StateToString.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands.helpers;
+
+public class StateToString {
+	
+	private static int JVMTI_THREAD_STATE_ALIVE						=     0x0001;
+	private static int JVMTI_THREAD_STATE_TERMINATED				=     0x0002;
+	private static int JVMTI_THREAD_STATE_RUNNABLE					=     0x0004;
+	private static int JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER	=     0x0400;
+	private static int JVMTI_THREAD_STATE_WAITING					=     0x0080;
+	private static int JVMTI_THREAD_STATE_WAITING_INDEFINITELY		=     0x0010;
+	private static int JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT		=     0x0020;
+	private static int JVMTI_THREAD_STATE_SLEEPING					=     0x0040;
+	private static int JVMTI_THREAD_STATE_IN_OBJECT_WAIT			=     0x0100;
+	private static int JVMTI_THREAD_STATE_PARKED					=     0x0200;
+	private static int JVMTI_THREAD_STATE_SUSPENDED					=   0x100000;
+	private static int JVMTI_THREAD_STATE_INTERRUPTED				=   0x200000;
+	private static int JVMTI_THREAD_STATE_IN_NATIVE					=   0x400000;
+	private static int JVMTI_THREAD_STATE_VENDOR_1					= 0x10000000;
+	private static int JVMTI_THREAD_STATE_VENDOR_2					= 0x20000000;
+	private static int JVMTI_THREAD_STATE_VENDOR_3					= 0x40000000;
+	
+	private static int JVMTI_JAVA_LANG_THREAD_STATE_MASK =
+		JVMTI_THREAD_STATE_TERMINATED |
+		JVMTI_THREAD_STATE_ALIVE |
+		JVMTI_THREAD_STATE_RUNNABLE |
+		JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER |
+		JVMTI_THREAD_STATE_WAITING |
+		JVMTI_THREAD_STATE_WAITING_INDEFINITELY |
+		JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;
+	private static int JVMTI_JAVA_LANG_THREAD_STATE_NEW =
+		0;
+	private static int JVMTI_JAVA_LANG_THREAD_STATE_TERMINATED =
+		JVMTI_THREAD_STATE_TERMINATED;
+	private static int JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE =
+		JVMTI_THREAD_STATE_ALIVE |
+		JVMTI_THREAD_STATE_RUNNABLE;
+	private static int JVMTI_JAVA_LANG_THREAD_STATE_BLOCKED =
+		JVMTI_THREAD_STATE_ALIVE |
+		JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
+	private static int JVMTI_JAVA_LANG_THREAD_STATE_WAITING =
+		JVMTI_THREAD_STATE_ALIVE |
+		JVMTI_THREAD_STATE_WAITING |
+		JVMTI_THREAD_STATE_WAITING_INDEFINITELY;
+	private static int JVMTI_JAVA_LANG_THREAD_STATE_TIMED_WAITING =
+		JVMTI_THREAD_STATE_ALIVE |
+		JVMTI_THREAD_STATE_WAITING |
+		JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;
+
+	public static String getJVMTIStateString(int state)
+	{
+		String retval = "";
+		
+		if (0 == state) {
+			return "<new or terminated> ";
+		}
+		
+		if ((state & JVMTI_THREAD_STATE_ALIVE) == JVMTI_THREAD_STATE_ALIVE) {
+			retval += "ALIVE ";
+		}
+		if ((state & JVMTI_THREAD_STATE_TERMINATED) == JVMTI_THREAD_STATE_TERMINATED) {
+			retval += "TERMINATED ";
+		}
+		if ((state & JVMTI_THREAD_STATE_RUNNABLE) == JVMTI_THREAD_STATE_RUNNABLE) {
+			retval += "RUNNABLE ";
+		}
+		if ((state & JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER) == JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER) {
+			retval += "BLOCKED_ON_MONITOR_ENTER ";
+		}
+		if ((state & JVMTI_THREAD_STATE_WAITING) == JVMTI_THREAD_STATE_WAITING) {
+			retval += "WAITING ";
+		}
+		if ((state & JVMTI_THREAD_STATE_WAITING_INDEFINITELY) == JVMTI_THREAD_STATE_WAITING_INDEFINITELY) {
+			retval += "WAITING_INDEFINITELY ";
+		}
+		if ((state & JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT) == JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT) {
+			retval += "WAITING_WITH_TIMEOUT ";
+		}
+		if ((state & JVMTI_THREAD_STATE_SLEEPING) == JVMTI_THREAD_STATE_SLEEPING) {
+			retval += "SLEEPING ";
+		}
+		if ((state & JVMTI_THREAD_STATE_IN_OBJECT_WAIT) == JVMTI_THREAD_STATE_IN_OBJECT_WAIT) {
+			retval += "IN_OBJECT_WAIT ";
+		}
+		if ((state & JVMTI_THREAD_STATE_PARKED) == JVMTI_THREAD_STATE_PARKED) {
+			retval += "PARKED ";
+		}
+		if ((state & JVMTI_THREAD_STATE_SUSPENDED) == JVMTI_THREAD_STATE_SUSPENDED) {
+			retval += "SUSPENDED ";
+		}
+		if ((state & JVMTI_THREAD_STATE_INTERRUPTED) == JVMTI_THREAD_STATE_INTERRUPTED) {
+			retval += "INTERRUPTED ";
+		}
+		if ((state & JVMTI_THREAD_STATE_IN_NATIVE) == JVMTI_THREAD_STATE_IN_NATIVE) {
+			retval += "IN_NATIVE ";
+		}
+		if ((state & JVMTI_THREAD_STATE_VENDOR_1) == JVMTI_THREAD_STATE_VENDOR_1) {
+			retval += "VENDOR_1 ";
+		}
+		if ((state & JVMTI_THREAD_STATE_VENDOR_2) == JVMTI_THREAD_STATE_VENDOR_2) {
+			retval += "VENDOR_2 ";
+		}
+		if ((state & JVMTI_THREAD_STATE_VENDOR_3) == JVMTI_THREAD_STATE_VENDOR_3) {
+			retval += "VENDOR_3 ";
+		}
+		
+		if (retval.equals("")) {
+			retval = "<no matching state> ";
+		}
+		
+		return retval;
+	}
+	
+	public static String getThreadStateString(int state)
+	{
+		String retval = "";
+		
+		state &= JVMTI_JAVA_LANG_THREAD_STATE_MASK;
+		
+		if (state ==  JVMTI_JAVA_LANG_THREAD_STATE_NEW) {
+			return "NEW ";
+		}
+		if ((state & JVMTI_JAVA_LANG_THREAD_STATE_TERMINATED) == JVMTI_JAVA_LANG_THREAD_STATE_TERMINATED) {
+			retval += "TERMINATED ";
+		}
+		if ((state & JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE) == JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE) {
+			retval += "RUNNABLE ";
+		}
+		if ((state & JVMTI_JAVA_LANG_THREAD_STATE_BLOCKED) == JVMTI_JAVA_LANG_THREAD_STATE_BLOCKED) {
+			retval += "BLOCKED ";
+		}
+		if ((state & JVMTI_JAVA_LANG_THREAD_STATE_WAITING) == JVMTI_JAVA_LANG_THREAD_STATE_WAITING) {
+			retval += "WAITING ";
+		}
+		if ((state & JVMTI_JAVA_LANG_THREAD_STATE_TIMED_WAITING) == JVMTI_JAVA_LANG_THREAD_STATE_TIMED_WAITING) {
+			retval += "TIMED_WAITING ";
+		}
+		
+		if (retval.equals("")) {
+			retval = "<no matching state> ";
+		}
+		
+		return retval;
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/ThreadData.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/ThreadData.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/ThreadData.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/ThreadData.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.ibm.dtfj.dtfjview.commands.helpers;
+
+import com.ibm.dtfj.java.JavaRuntime;
+import com.ibm.dtfj.java.JavaThread;
+
+public class ThreadData {
+	
+	private JavaThread jt;
+	private JavaRuntime jr;
+
+	public ThreadData(JavaThread _jt, JavaRuntime _jr) {
+		jt = _jt;
+		jr = _jr;
+	}
+	
+	public JavaThread getThread() {
+		return jt;
+	}
+	
+	public JavaRuntime getRuntime() {
+		return jr;
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/Utils.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/Utils.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/Utils.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/Utils.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,818 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands.helpers;
+
+import java.util.HashMap;
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Vector;
+import java.util.Stack;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+import java.lang.reflect.Modifier;
+
+import com.ibm.dtfj.dtfjview.Output;
+import com.ibm.dtfj.image.CorruptData;
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.image.Image;
+import com.ibm.dtfj.image.ImageAddressSpace;
+import com.ibm.dtfj.image.ImageProcess;
+import com.ibm.dtfj.image.MemoryAccessException;
+import com.ibm.dtfj.java.JavaClass;
+import com.ibm.dtfj.java.JavaClassLoader;
+import com.ibm.dtfj.java.JavaObject;
+import com.ibm.dtfj.java.JavaField;
+import com.ibm.dtfj.java.JavaRuntime;
+import com.ibm.dtfj.runtime.ManagedRuntime;
+
+public class Utils {
+
+	public static final String byteToAscii =
+		  "................" +
+		  "................" +
+		  " !\"#$%&'()*+'-./" +
+		  "0123456789:;<=>?" +
+		  "@ABCDEFGHIJKLMNO" +
+		  "PQRSTUVWXYZ[\\]^_"+
+		  "`abcdefghijklmno" +
+		  "pqrstuvwxyz{|}~." +
+		  "................" +
+		  "................" +
+		  "................" +
+		  "................" +
+		  "................" +
+		  "................" +
+		  "................" +
+		  "................"
+		 ;
+	
+	//List of keys used by HashMap object associated with each session 
+	public static final String CURRENT_MEM_ADDRESS = "currentMemPtrAddress";
+	public static final String CURRENT_NUM_BYTES_TO_PRINT = "currentNumBytes";
+	public static final String RootCommand_OBJECT = "RootCommandObject";
+	public static final String FIND_ATTRIBUTES = "FindAttributes";
+	
+	public static Iterator getRuntimes(Image loadedImage)
+	{
+		Vector runtimes = new Vector();
+		Iterator itAddressSpace;
+		Iterator itProcess;
+		Iterator itRuntime;
+		ManagedRuntime mr;
+		ImageAddressSpace ias;
+		ImageProcess ip;
+		
+		itAddressSpace = loadedImage.getAddressSpaces();
+		while (itAddressSpace.hasNext()) {
+			ias = (ImageAddressSpace)itAddressSpace.next();
+			itProcess = ias.getProcesses();
+			while (itProcess.hasNext())
+			{
+				ip = (ImageProcess)itProcess.next();
+				itRuntime = ip.getRuntimes();
+				while (itRuntime.hasNext()) {
+					// this iterator can contain ManagedRuntime or CorruptData objects
+					Object next = itRuntime.next();
+					if (next instanceof CorruptData) {
+						continue; // skip any CorruptData objects
+					} else {
+						mr = (ManagedRuntime)next;
+						if (!runtimes.contains(mr))
+							runtimes.add(mr);
+					}
+				}
+			}
+		}
+		return runtimes.iterator();
+	}
+	
+	public static String toHex(long l)
+	{
+		return "0x" + Long.toHexString(l);
+	}
+	
+	public static String toHex(int i)
+	{
+		return "0x" + Integer.toHexString(i);
+	}
+	
+	public static String toHex(short s)
+	{
+		// bit-wise AND is done to cancel the sign-extension that int casting does;
+		//  if a short's value is -1, its hex representation is 0xffff, which will be
+		//  sign-extended to 0xffffffff when cast to an int, but we want to know the hex
+		//  representation before the short is cast to an int, which the bit-wise AND does
+		return "0x" + Integer.toHexString(s & 0x0000ffff);
+	}
+	
+	public static String toHex(byte b)
+	{
+		// bit-wise AND is done to cancel the sign-extension that int casting does;
+		//  if a byte's value is -1, its hex representation is 0xff, which will be
+		//  sign-extended to 0xffffffff when cast to an int, but we want to know the hex
+		//  representation before the byte is cast to an int, which the bit-wise AND does
+		return "0x" + Integer.toHexString(b & 0x000000ff);
+	}
+	
+	public static String toFixedWidthHex(long l)
+	{
+		return Utils.padWithZeroes(Long.toHexString(l), 16);
+	}
+	
+	public static String toFixedWidthHex(int i)
+	{
+		return Utils.padWithZeroes(Integer.toHexString(i), 8);
+	}
+	
+	public static String toFixedWidthHex(short s)
+	{
+		// bit-wise AND is done to cancel the sign-extension that int casting does;
+		//  if a short's value is -1, its hex representation is 0xffff, which will be
+		//  sign-extended to 0xffffffff when cast to an int, but we want to know the hex
+		//  representation before the short is cast to an int, which the bit-wise AND does
+		return Utils.padWithZeroes(Integer.toHexString(s & 0x0000ffff), 4);
+	}
+	
+	public static String toFixedWidthHex(byte b)
+	{
+		// bit-wise AND is done to cancel the sign-extension that int casting does;
+		//  if a byte's value is -1, its hex representation is 0xff, which will be
+		//  sign-extended to 0xffffffff when cast to an int, but we want to know the hex
+		//  representation before the byte is cast to an int, which the bit-wise AND does
+		return Utils.padWithZeroes(Integer.toHexString(b & 0x000000ff), 2);
+	}
+	
+	public static Stack constructStackFromString(String args)
+	{
+		String[] argsArray = args.split("\\s+");
+		return constructStackFromStringArray(argsArray);
+	}
+	
+	public static Stack constructStackFromStringArray(String[] argsArray){
+		Stack s = new Stack();
+		for (int i = argsArray.length - 1; i >= 0; i--){
+			s.push(argsArray[i]);
+		}
+		return s;
+	}
+	
+	public static String concatArgsFromStack(Stack args){
+		String s = "";
+		while(!args.empty()){
+			s = s.concat((String)args.pop());
+		}
+		return s;
+	}
+	
+	public static ImageAddressSpace _extractAddressSpace(Image loadedImage)
+	{
+		ImageAddressSpace space = null;
+		Iterator spaces = loadedImage.getAddressSpaces();
+		
+		while ((null == space) && (spaces.hasNext())) {
+			space = (ImageAddressSpace) spaces.next();
+		}
+		return space;
+	}
+	
+	public static Long longFromString(String value)
+	{
+		Long translated = null;
+		
+		if (null != value) {
+			if (value.startsWith("0x")) {
+				value = value.substring(2);
+			}
+			try {
+				translated = new Long(Long.parseLong(value, 16));
+			} catch (NumberFormatException e) {
+				translated = null;
+			}
+		}
+		return translated;
+	}
+	
+	public static Long longFromStringWithPrefix(String value)
+	{
+		Long translated = null;
+		
+		if (value.startsWith("0x"))
+		{
+			translated = longFromString(value);
+		}
+		
+		return translated;
+	}
+	
+	public static String getSignatureName(String signature)
+	{
+		Hashtable table = new Hashtable();
+		String retval = null;
+		
+		table.put("Z", "boolean");
+		table.put("B", "byte");
+		table.put("C", "char");
+		table.put("S", "short");
+		table.put("I", "int");
+		table.put("J", "long");
+		table.put("F", "float");
+		table.put("D", "double");
+		table.put("V", "void");
+		
+		if (signature.startsWith("L"))
+		{
+			StringTokenizer st = new StringTokenizer(signature.substring(1), ";");
+			String className;
+			if (st.hasMoreTokens()) {
+				className = st.nextToken();
+				if (className.startsWith("java/lang/"))
+				{
+					className = className.substring(10);
+				}
+				retval = className.replaceAll("/", ".");
+			} else {
+				// nothing or only ";"s after opening "L"
+				return null;
+			}
+		}
+		else if (signature.startsWith("["))
+		{
+			String currSig = new String(signature);
+			String arraySuffix = "";
+			
+			while (currSig.startsWith("["))
+			{
+				arraySuffix += "[]";
+				currSig = currSig.substring(1);
+			}
+			
+			retval = Utils.getSignatureName(currSig) + arraySuffix;
+		}
+		else
+		{
+			retval = (String)table.get(signature.substring(0,1));
+		}
+		
+		return retval;
+	}
+	
+	public static String getMethodSignatureName(String signature)
+	{
+		Hashtable table = new Hashtable();
+		String retval = "";
+		
+		table.put("Z", "boolean");
+		table.put("B", "byte");
+		table.put("C", "char");
+		table.put("S", "short");
+		table.put("I", "int");
+		table.put("J", "long");
+		table.put("F", "float");
+		table.put("D", "double");
+		
+		if (signature.startsWith("("))
+		{
+			StringTokenizer st = new StringTokenizer(signature.substring(1), ")");
+			if (st.hasMoreTokens()) {
+				String parameters = st.nextToken();
+				if (st.hasMoreTokens()) {
+					retval = "(" + Utils.getMethodSignatureName(parameters) + ")";
+				} else {
+					// there is nothing between "(" and ")"
+					retval = "()";
+				}
+			} else {
+				// there is no ")" after opening "("
+				retval = null;
+			}
+		}
+		else if (signature.startsWith("L"))
+		{
+			StringTokenizer st = new StringTokenizer(signature.substring(1), ";");
+			String className;
+			if (st.hasMoreTokens()) {
+				className = st.nextToken();
+				if (className.startsWith("java/lang/"))
+				{
+					className = className.substring(10);
+				}
+				retval = className.replaceAll("/", ".");
+				if (st.hasMoreTokens()) {
+					retval += ", " + Utils.getMethodSignatureName(
+								signature.substring(signature.indexOf(';') + 1)
+							);
+				}
+			} else {
+				// nothing or only ";"s after opening "L"
+				retval = null;
+			}
+		}
+		else if (signature.startsWith("["))
+		{
+			String currSig = new String(signature);
+			String arraySuffix = "";
+			
+			while (currSig.startsWith("["))
+			{
+				arraySuffix += "[]";
+				currSig = currSig.substring(1);
+			}
+			
+			if (currSig.startsWith("L")) {
+				if (currSig.indexOf(';') + 1 == currSig.length()) {
+					retval = Utils.getSignatureName(currSig) + arraySuffix;
+				} else {
+					retval = Utils.getMethodSignatureName(
+							currSig.substring(0, currSig.indexOf(';') + 1)
+						);
+					retval += arraySuffix + ", ";
+					retval += Utils.getMethodSignatureName(
+							currSig.substring(currSig.indexOf(';') + 1)
+						);
+				}
+			} else {
+				if (1 == currSig.length()) {
+					retval = (String)table.get(currSig) + arraySuffix;
+				} else {
+					retval = (String)table.get(currSig.substring(0,1)) + arraySuffix;
+					retval += ", ";
+					retval += Utils.getMethodSignatureName(currSig.substring(1));
+				}
+			}
+		}
+		else
+		{
+			retval = (String)table.get(signature.substring(0,1));
+			if (signature.length() > 1) {
+				retval += ", " + Utils.getMethodSignatureName(signature.substring(1));
+			}
+		}
+		
+		return retval;
+	}
+	
+	public static String getReturnValueName(String signature)
+	{
+		if (signature.startsWith("("))
+		{
+			StringTokenizer st = new StringTokenizer(signature, ")");
+			if (st.hasMoreTokens()) {
+				st.nextToken();	// we don't care what's inside the brackets
+				if (st.hasMoreTokens()) {
+					String retval = st.nextToken();
+					if (st.hasMoreTokens()) {
+						// there is more than one ")"; that's one too many
+						return null;
+					} else {
+						return Utils.getSignatureName(retval);
+					}
+				} else {
+					// there is no ")" after opening "(" or the ")" is followed by nothing
+					return null;
+				}
+			}
+			else {
+				// nothing after opening "("
+				return null;
+			}
+		}
+		else
+		{
+			return null;
+		}
+	}
+	
+	public static String toString(String s)
+	{
+		if (null == s)
+			return "null";
+		else
+			return s;
+	}
+	
+	public static File absPath(HashMap properties, String path)
+	{
+		File oldPwd = (File)properties.get("pwd");
+		File newPwd = new File(path);
+
+		if (!newPwd.isAbsolute())
+			newPwd = new File(oldPwd, path);
+
+		try {
+			newPwd = newPwd.getCanonicalFile();
+		} catch (IOException e) {
+		
+		}
+		
+		return newPwd;
+	}
+	
+	public static String getVal(Object o)
+	{
+		return Utils.getVal(o, null);
+	}
+	
+/*	public static String getVal(JavaObject jo, JavaRuntime jr)
+	{
+		//try {
+		//	return "\t   object name: " + jo.getJavaClass().getName() + "\n";
+		//} catch (CorruptDataException e) {
+		//	return "\t   bad name \n";
+		//}
+		
+		//JavaField
+		return Utils.getVal(jo, Utils.getField(jo, jr));
+	}
+*/
+
+	// note: this method lets you pass in a null JavaObject, but it _will_ throw a
+	//  NullPointerException if the JavaField is not a static field when you pass it
+	//  a null JavaObject; this is the behavior of jf.get() and jf.getString()
+	public static String getVal(JavaObject jo, JavaField jf)
+	{
+		Object o;
+		String s;
+		
+		if (null == jf)
+		{
+			o = jo;
+			s = null;
+		}
+		else {
+			try {
+				o = jf.get(jo);
+			} catch (CorruptDataException e) {
+				o = null; // FIXME
+			} catch (MemoryAccessException d) {
+				o = null; // FIXME
+			} catch (NumberFormatException nfe) {
+				//out.print("<nfe>");
+				// FIXME
+				o = null;
+			}
+			
+			try {
+				s = jf.getString(jo);
+			} catch (CorruptDataException e) {
+				s = null;
+			} catch (MemoryAccessException e) {
+				s = null;
+			} catch (IllegalArgumentException e) {
+				s = null;
+			}
+		}
+		
+		return getVal(o, s);
+	}
+	
+	public static String getVal(Object o, String str)
+	{
+		String val = "";
+		Long value = null;
+		boolean object = false;
+
+		if (null == o)
+		{
+			val += "null";
+		}
+		else
+		{
+			if (o instanceof Boolean) {
+				val += ((Boolean)o).toString();
+			} else if (o instanceof Byte) {
+				byte b = ((Byte)o).byteValue();
+				val += String.valueOf(b);
+				value = new Long((new Byte(b)).longValue());
+			} else if (o instanceof Character) {
+				char c = ((Character)o).charValue();
+				val += Utils.getPrintableWithQuotes(c);
+				value = new Long((new Integer((int)c).longValue()));
+			} else if (o instanceof Double) {
+				double d = ((Double)o).doubleValue();
+				val += String.valueOf(d);
+				value = new Long(Double.doubleToRawLongBits(d));
+			} else if (o instanceof Float) {
+				float f = ((Float)o).floatValue();
+				val += String.valueOf(f);
+				value = new Long(Float.floatToRawIntBits(f));
+			} else if (o instanceof Integer) {
+				int i = ((Integer)o).intValue();
+				val += String.valueOf(i);
+				value = new Long((new Integer(i)).longValue());
+			} else if (o instanceof Long) {
+				long l = ((Long)o).longValue();
+				val += String.valueOf(l);
+				value = new Long(l);
+			} else if (o instanceof Short) {
+				short s = ((Short)o).shortValue();
+				val += String.valueOf(s);
+				value = new Long((new Short(s)).longValue());
+			} else if (o instanceof String) {
+				val += (String)o;
+			} else if (o instanceof JavaObject) {
+				if (Utils.isNull((JavaObject)o)) {
+					val += "null";
+				} else {
+					object = true;
+				}
+			} else {
+				// FIXME
+			}
+			
+			// why are we processing objects here?
+			//  because we want control over the exceptions that are thrown
+			if (object)
+			{
+				JavaObject joField = (JavaObject)o;
+				JavaClass jcField;
+				String jcName;
+				
+				try {
+					jcField = joField.getJavaClass();
+				} catch (CorruptDataException e) {
+					jcField = null;
+				}
+				
+				try {
+					if (null != jcField) {
+						jcName = jcField.getName();
+					} else {
+						jcName = null;
+					}
+				} catch (CorruptDataException e) {
+					jcName = null;
+				}
+				
+				if (null != jcName && jcName.equals("java/lang/String"))
+				{
+					if (null == str) {
+						val += getStringVal(joField);
+					} else {
+						val += "\"" + Utils.getPrintable(str) + "\"";
+					}
+				}
+				else
+				{
+					val += "<object>";
+				}
+				
+				val += " @ ";
+				val += Utils.toHex(joField.getID().getAddress());
+			}
+		}
+		
+		if (null != value)
+		{
+			val += " (";
+			val += Utils.toHex(value.longValue());
+			val += ")";
+		}
+		
+		return val;
+	}
+	
+	private static String getStringVal(JavaObject jo)
+	{
+		JavaClass jc;
+		
+		try {
+			jc = jo.getJavaClass();
+		} catch (CorruptDataException e) {
+			return "<cannot get String class from String object (" +
+				Exceptions.getCorruptDataExceptionString() + ")>";
+		}
+		
+		Iterator itJavaField = jc.getDeclaredFields();
+		JavaField jf = null;
+		while (itJavaField.hasNext())
+		{
+			jf = (JavaField)itJavaField.next();
+			try {
+				if (jf.getSignature().equals("[C") && !Modifier.isStatic(jf.getModifiers()))
+					break;
+			} catch (CorruptDataException e) {
+				// if we have an exception, do nothing and go onto the next field 
+			}
+		}
+		
+		JavaObject charArray = null;
+		try {
+			charArray = (JavaObject)jf.get(jo);
+		} catch (CorruptDataException e) {
+			return "<cannot get char array out of String (" +
+				Exceptions.getCorruptDataExceptionString() + ")>";
+		} catch (MemoryAccessException e) {
+			return "<cannot get char array out of String (" +
+				Exceptions.getMemoryAccessExceptionString() + ")>";
+		}
+		
+		int arraySize;
+		try {
+			arraySize = charArray.getArraySize();
+		} catch (CorruptDataException e) {
+			return "<cannot determine the size of the array (" +
+					Exceptions.getCorruptDataExceptionString() + ")>";
+		}
+		
+		char[] dst = new char[arraySize];
+		
+		try {
+			charArray.arraycopy(0, dst, 0, arraySize);
+		} catch (CorruptDataException e) {
+			return "<cannot copy data from the array (" +
+				Exceptions.getCorruptDataExceptionString() + ")>";
+		} catch (MemoryAccessException e) {
+			return "<cannot copy data from the array (" +
+				Exceptions.getMemoryAccessExceptionString() + ")>";
+		}
+		
+		return "\"" + Utils.getPrintable(new String(dst)) + "\"";
+	}
+	
+	public static String getPrintable(char c)
+	{
+		// for a good set of test cases for this code, try using it to print the
+		//  static char arrays of the String class; the memory addresses of these arrays
+		//  can be found by using the command "x/j java/lang/String" and looking at the
+		//  static fields printed at the top of the output
+		
+		switch (c)
+		{
+		// the following 8 cases were taken from Section 3.10.6 of the
+		//  Java Language Specification (2nd Edition), which can be found at
+		//  http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#101089
+		case '\b':
+			return "\\b";
+		case '\t':
+			return "\\t";
+		case '\n':
+			return "\\n";
+		case '\f':
+			return "\\f";
+		case '\r':
+			return "\\r";
+		case '\"':
+			return "\\\"";
+		case '\'':
+			return "\\'";
+		case '\\':
+			return "\\\\";
+		default:
+			int i = (int)c;
+			if (i <= 255) {
+				if (i >= 32 && i <= 126) {
+					// if the character is easily printable (has an integer value between
+					//  32 and 126), then just print it
+					// note: this was determined by looking at http://www.lookuptables.com/
+					return String.valueOf(c);
+				} else {
+					// if the character is not easily printable, print an octal escape;
+					//  this is done according to the Section 3.10.6 of the Java
+					//  Language Specification (see above for reference)
+					return "\\" + Utils.padWithZeroes(Integer.toOctalString(i), 3);
+				}
+			} else {
+				// if we have a character that is not between Unicode values
+				//  \u0000 and \u00ff, then print an escaped form of its Unicode value;
+				//  the format was determined from Section 3.3 of the
+				//  Java Language Specification (2nd Edition), which can be found at
+				//  http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#100850
+				return "\\u" + Utils.padWithZeroes(Integer.toHexString(i), 4);
+			}
+		}
+	}
+	
+	public static String getPrintableWithQuotes(char c)
+	{
+		return "\'" + Utils.getPrintable(c) + "\'";
+	}
+	
+	public static String getPrintable(String s)
+	{
+		String retval = "";
+		
+		for (int i = 0; i < s.length(); i++)
+		{
+			retval += Utils.getPrintable(s.charAt(i));
+		}
+		
+		return retval;
+	}
+	
+	public static String padWithZeroes(String unpadded, int desiredLength)
+	{
+		String output = new String(unpadded);
+		for (int i = unpadded.length(); i < desiredLength; i++)
+		{
+			output = "0" + output;
+		}
+		return output;
+	}
+
+	public static Iterator getAddressSapceSectionInfo(Image loadedImage){
+		Iterator itAddressSpace = loadedImage.getAddressSpaces();
+		Vector vSections = new Vector();
+		while(itAddressSpace.hasNext()){
+			ImageAddressSpace imageAddressSpace = (ImageAddressSpace)itAddressSpace.next();
+			Iterator iSections = imageAddressSpace.getImageSections();
+			while(iSections.hasNext()){
+				vSections.add(iSections.next());
+			}
+		}
+		return vSections.iterator();
+	}
+	
+	public static String getModifierString(int modifiers){
+		String retval = "";
+		if(Modifier.isPublic(modifiers)) retval += "public ";
+		if(Modifier.isPrivate(modifiers)) retval += "private ";
+		if(Modifier.isProtected(modifiers))  retval += "protected ";
+		if(Modifier.isStatic(modifiers)) retval += "static ";
+		if(Modifier.isAbstract(modifiers)) retval += "abstract ";
+		if(Modifier.isFinal(modifiers)) retval += "final ";
+		if(Modifier.isSynchronized(modifiers)) retval += "synchronized ";
+		if(Modifier.isVolatile(modifiers)) retval += "volatile ";
+		if(Modifier.isTransient(modifiers)) retval += "transient ";
+		if(Modifier.isNative(modifiers)) retval += "native ";
+		if(Modifier.isInterface(modifiers)) retval += "interface ";
+		if(Modifier.isStrict(modifiers)) retval += "strict ";
+		return retval;
+	}
+	
+	public static boolean isNull(JavaObject jo)
+	{
+		return jo.getID().getAddress() == 0;
+	}
+	
+	public static String padWithSpaces(String unpadded, int desiredLength)
+	{
+		String output = new String(unpadded);
+		for (int i = unpadded.length(); i < desiredLength; i++)
+		{
+			output += " ";
+		}
+		return output;
+	}
+	
+	public static String prePadWithSpaces(String unpadded, int desiredLength)
+	{
+		String output = "";
+		for (int i = unpadded.length(); i < desiredLength; i++)
+		{
+			output += " ";
+		}
+		output += unpadded;
+		return output;
+	}
+	
+	public static JavaClass getClassGivenName(String className, JavaRuntime jr, Output out)
+	{
+		Iterator itJavaClassLoader = jr.getJavaClassLoaders();
+		boolean found = false;
+		JavaClass jc = null;
+		
+		while (itJavaClassLoader.hasNext() && !found)
+		{
+			JavaClassLoader jcl = (JavaClassLoader)itJavaClassLoader.next();
+			Iterator itJavaClass = jcl.getDefinedClasses();
+			while (itJavaClass.hasNext() && !found)
+			{
+				jc = (JavaClass)itJavaClass.next();
+				String currClassName;
+
+				try {
+					currClassName = jc.getName();
+				} catch (CorruptDataException e) {
+					out.print("\t  <error getting class name while traversing classes: ");
+					out.print(Exceptions.getCorruptDataExceptionString());
+					out.print(">\n");
+					currClassName = null;
+					continue;
+				}
+				
+				if (currClassName.equals(className))
+				{
+					found = true;
+				}
+			}
+		}
+		
+		if (found) {
+			return jc;
+		} else {
+			return null;
+		}
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoClassCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoClassCommand.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoClassCommand.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoClassCommand.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,405 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands.infocommands;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Stack;
+import java.util.Iterator;
+
+import com.ibm.dtfj.dtfjview.Output;
+import com.ibm.dtfj.dtfjview.commands.Command;
+import com.ibm.dtfj.dtfjview.commands.helpers.ClassOutput;
+import com.ibm.dtfj.dtfjview.commands.helpers.Exceptions;
+import com.ibm.dtfj.dtfjview.commands.helpers.Utils;
+import com.ibm.dtfj.image.CorruptData;
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.image.Image;
+import com.ibm.dtfj.java.JavaClass;
+import com.ibm.dtfj.java.JavaHeap;
+import com.ibm.dtfj.java.JavaClassLoader;
+import com.ibm.dtfj.java.JavaObject;
+import com.ibm.dtfj.java.JavaRuntime;
+import com.ibm.dtfj.runtime.ManagedRuntime;
+
+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(), 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();
+		
+		// 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();
+			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();
+			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();
+		while (itHeap.hasNext()) {
+			JavaHeap jh = (JavaHeap)itHeap.next();
+			Iterator itObject = jh.getObjects();
+			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 DTFJ 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;
+		}
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoHeapCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoHeapCommand.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoHeapCommand.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoHeapCommand.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,197 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands.infocommands;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Stack;
+
+import com.ibm.dtfj.dtfjview.Output;
+import com.ibm.dtfj.dtfjview.commands.Command;
+import com.ibm.dtfj.dtfjview.commands.helpers.Utils;
+import com.ibm.dtfj.image.Image;
+import com.ibm.dtfj.image.ImageSection;
+import com.ibm.dtfj.image.DataUnavailable;
+import com.ibm.dtfj.java.JavaRuntime;
+import com.ibm.dtfj.java.JavaHeap;
+import com.ibm.dtfj.java.JavaObject;
+import com.ibm.dtfj.runtime.ManagedRuntime;
+import com.ibm.dtfj.image.CorruptDataException;
+
+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();
+		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();
+		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();
+		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();
+		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();
+		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");
+		}
+		
+	}
+	
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoJitmCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoJitmCommand.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoJitmCommand.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoJitmCommand.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.ibm.dtfj.dtfjview.commands.infocommands;
+
+import java.util.HashMap;
+import java.util.Stack;
+import java.util.Iterator;
+
+import com.ibm.dtfj.dtfjview.Output;
+import com.ibm.dtfj.dtfjview.commands.Command;
+import com.ibm.dtfj.dtfjview.commands.helpers.Exceptions;
+import com.ibm.dtfj.dtfjview.commands.helpers.Utils;
+import com.ibm.dtfj.image.Image;
+import com.ibm.dtfj.image.ImageSection;
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.java.JavaRuntime;
+import com.ibm.dtfj.java.JavaClassLoader;
+import com.ibm.dtfj.java.JavaClass;
+import com.ibm.dtfj.java.JavaMethod;
+
+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();
+				while (itJavaClassLoader.hasNext())
+				{
+					JavaClassLoader jcl = (JavaClassLoader)itJavaClassLoader.next();
+					Iterator itJavaClass = jcl.getDefinedClasses();
+					
+					while (itJavaClass.hasNext())
+					{
+						JavaClass jc = (JavaClass)itJavaClass.next();
+						Iterator itJavaMethod = jc.getDeclaredMethods();
+						
+						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().hasNext())
+							{
+								Iterator itImageSection = jm.getCompiledSections();
+								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");
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoLockCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoLockCommand.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoLockCommand.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoLockCommand.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands.infocommands;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Stack;
+import java.util.Vector;
+
+import com.ibm.dtfj.dtfjview.Output;
+import com.ibm.dtfj.dtfjview.commands.Command;
+import com.ibm.dtfj.dtfjview.commands.helpers.Exceptions;
+import com.ibm.dtfj.dtfjview.commands.helpers.Utils;
+import com.ibm.dtfj.image.DataUnavailable;
+import com.ibm.dtfj.image.Image;
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.java.JavaRuntime;
+import com.ibm.dtfj.java.JavaMonitor;
+import com.ibm.dtfj.java.JavaObject;
+import com.ibm.dtfj.java.JavaThread;
+import com.ibm.dtfj.java.JavaClass;
+
+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();
+			
+			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();
+					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();
+					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){
+			}
+		}
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoMmapCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoMmapCommand.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoMmapCommand.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoMmapCommand.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands.infocommands;
+
+import java.util.HashMap;
+import java.util.Stack;
+import java.util.Iterator;
+
+import com.ibm.dtfj.dtfjview.Output;
+import com.ibm.dtfj.dtfjview.commands.Command;
+import com.ibm.dtfj.dtfjview.commands.helpers.Utils;
+import com.ibm.dtfj.image.Image;
+import com.ibm.dtfj.image.ImageSection; 
+
+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 + ")");
+		}
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoProcCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoProcCommand.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoProcCommand.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoProcCommand.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,181 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands.infocommands;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Stack;
+import java.util.Properties;
+import java.util.Enumeration;
+
+import com.ibm.dtfj.dtfjview.Output;
+import com.ibm.dtfj.dtfjview.commands.Command;
+import com.ibm.dtfj.dtfjview.commands.helpers.Exceptions;
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.image.CorruptData;
+import com.ibm.dtfj.image.DataUnavailable;
+import com.ibm.dtfj.image.Image;
+import com.ibm.dtfj.image.ImageAddressSpace;
+import com.ibm.dtfj.image.ImageProcess;
+import com.ibm.dtfj.image.ImageThread;
+
+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();
+		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();
+		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");
+	}
+}



Mime
View raw message