incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From monte...@apache.org
Subject svn commit: r827732 - in /incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti: javaruntime/ javaruntime/model/ process/ reader/
Date Tue, 20 Oct 2009 16:56:01 GMT
Author: monteith
Date: Tue Oct 20 16:56:00 2009
New Revision: 827732

URL: http://svn.apache.org/viewvc?rev=827732&view=rev
Log:
Fixed code to throw DataUnavailable where appropriate, put generics in place, wrap some public
fields.

Modified:
    incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/JavaRuntimeImpl.java
    incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClassLoader.java
    incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JLocation.java
    incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JMethod.java
    incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JMonitor.java
    incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JObject.java
    incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JStackFrame.java
    incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JThread.java
    incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/Model.java
    incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/process/ImageImpl.java
    incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/reader/CJVMTIBinReader.java

Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/JavaRuntimeImpl.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/JavaRuntimeImpl.java?rev=827732&r1=827731&r2=827732&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/JavaRuntimeImpl.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/JavaRuntimeImpl.java
Tue Oct 20 16:56:00 2009
@@ -24,30 +24,40 @@
 import javax.tools.diagnostics.image.DataUnavailable;
 import javax.tools.diagnostics.image.ImagePointer;
 import javax.tools.diagnostics.image.MemoryAccessException;
+import javax.tools.diagnostics.runtime.java.JavaClassLoader;
 import javax.tools.diagnostics.runtime.java.JavaHeap;
+import javax.tools.diagnostics.runtime.java.JavaMethod;
+import javax.tools.diagnostics.runtime.java.JavaMonitor;
 import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaReference;
 import javax.tools.diagnostics.runtime.java.JavaRuntime;
 import javax.tools.diagnostics.runtime.java.JavaThread;
 import javax.tools.diagnostics.runtime.java.JavaVMInitArgs;
 
+import org.apache.kato.jvmti.javaruntime.model.EmptyList;
 import org.apache.kato.jvmti.javaruntime.model.Model;
 import org.apache.kato.jvmti.reader.CLogger;
 
 public class JavaRuntimeImpl implements JavaRuntime {
+	private static final String VERSION = "0.1.0";
+	private static final String FULL_VERSION = "CJVMTI v0.1";
+	
 	private Model model=null;
+	private File source;
 	
-	public JavaRuntimeImpl(Model model) throws IOException {
+	public JavaRuntimeImpl(Model model, File source) throws IOException {
 		this.model=model;
+		this.source = source;
 	}
 	
 	@Override
-	public List getCompiledMethods() {
-		return new LinkedList();
+	public List<JavaMethod> getCompiledMethods() {
+		return new EmptyList<JavaMethod>();
 	}
 
 	@Override
-	public List getHeapRoots() {
-		return new LinkedList();
+	public List<JavaReference> getHeapRoots() {
+		return new EmptyList<JavaReference>();
 	}
 
 	private List<JavaHeap> heap = null;
@@ -61,14 +71,12 @@
 	}
 
 	@Override
-	public List getJavaClassLoaders() {
-		
+	public List<JavaClassLoader> getJavaClassLoaders() {		
 		return model.getJavaClassLoader();
 	}
 
 	@Override
 	public ImagePointer getJavaVM() throws CorruptDataException {
-		// TODO Auto-generated method stub
 		return null;
 	}
 
@@ -79,8 +87,7 @@
 	}
 
 	@Override
-	public List getMonitors() {
-		
+	public List<JavaMonitor> getMonitors() {		
 		return model.getJavaMonitors();
 	}
 
@@ -113,19 +120,17 @@
 
 	@Override
 	public String getFullVersion() throws CorruptDataException {
-
-		return "CJVMTI v0.1";
+		return FULL_VERSION;
 	}
 
 	@Override
 	public String getVersion() throws CorruptDataException {
-		return "0.1.0";
+		return VERSION;
 	}
 
 	@Override
 	public File getSource() {
-		// TODO Auto-generated method stub
-		return null;
+		return this.source;
 	}
 
 }

Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClassLoader.java?rev=827732&r1=827731&r2=827732&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClassLoader.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JClassLoader.java
Tue Oct 20 16:56:00 2009
@@ -42,12 +42,12 @@
 	}
 
 	@Override
-	public List getCachedClasses() {
-		return classes;
+	public List<JavaClass> getCachedClasses() {
+		return new EmptyList<JavaClass>();
 	}
 
 	@Override
-	public List getDefinedClasses() {
+	public List<JavaClass> getDefinedClasses() {
 		if(classes==null) classes=new LinkedList<JavaClass>();
 		return classes;
 	}

Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JLocation.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JLocation.java?rev=827732&r1=827731&r2=827732&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JLocation.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JLocation.java
Tue Oct 20 16:56:00 2009
@@ -21,8 +21,6 @@
 import javax.tools.diagnostics.runtime.java.JavaMethod;
 
 public class JLocation implements JavaLocation {
-
-	
 	public JMethod method=null;
 	public String filename=null;
 	public int linenumber=0;
@@ -30,9 +28,9 @@
 	public JLocation() {
 		
 	}
+	
 	@Override
 	public ImagePointer getAddress() throws CorruptDataException {
-		// TODO Auto-generated method stub
 		return p;
 	}
 	
@@ -42,7 +40,6 @@
 
 	@Override
 	public int getCompilationLevel() throws CorruptDataException {
-		// TODO Auto-generated method stub
 		return 0;
 	}
 

Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JMethod.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JMethod.java?rev=827732&r1=827731&r2=827732&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JMethod.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JMethod.java
Tue Oct 20 16:56:00 2009
@@ -24,6 +24,7 @@
 
 import javax.tools.diagnostics.image.CorruptDataException;
 import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.ImageSection;
 import javax.tools.diagnostics.runtime.java.JavaClass;
 import javax.tools.diagnostics.runtime.java.JavaMethod;
 
@@ -31,10 +32,7 @@
 
 public class JMethod implements JavaMethod {
 
-	
-	public String genericsignature;
-	public int nativemethod;
-	public int argumentsize;
+	private int argumentsize;
 	public int maxlocals;
 	public String name=null;
 	public String signature=null;
@@ -45,9 +43,10 @@
 	public JMethod() {
 	}
 	
-	public void setParent(JClass class1) {
-		parent=class1;	
+	public void setParent(JClass clazz) {
+		parent=clazz;	
 	}
+	
 
 	public void addLocalVariableTableEntry(JLocalVariableTableEntry entry) {
 		if(localVars==null) {
@@ -82,26 +81,23 @@
 	
 
 	@Override
-	public List getBytecodeSections() {
-	
-		return new LinkedList();
+	public List<ImageSection> getBytecodeSections() {
+		return new EmptyList<ImageSection>();
 	}
 
 	@Override
-	public List getCompiledSections() {
-		return new LinkedList();
+	public List<ImageSection> getCompiledSections() {
+		return new EmptyList<ImageSection>();
 	}
 
 	@Override
 	public JavaClass getDeclaringClass() throws CorruptDataException,
-			DataUnavailable {
-		
+			DataUnavailable {		
 		return parent;
 	}
 
 	@Override
-	public int getModifiers() throws CorruptDataException {
-		
+	public int getModifiers() throws CorruptDataException {	
 		return mods;
 	}
 
@@ -145,5 +141,25 @@
 		}
 		return null;
 	}
+
+	/** 
+	 * Store generic signature for this method.
+	 * Currently unimplemented as API doesn't require it.
+	 *  
+	 * @param signature
+	 */
+	public void setGenericsignature(String signature) {
+		// Unimplemented
+	}
+
+	/**
+	 * Returns the generic signature of this method.
+	 * Currently not implemented.
+	 * 
+	 * @return null
+	 */
+	public String getGenericsignature() {
+		return null;
+	}
 	
 }
\ No newline at end of file

Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JMonitor.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JMonitor.java?rev=827732&r1=827731&r2=827732&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JMonitor.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JMonitor.java
Tue Oct 20 16:56:00 2009
@@ -24,18 +24,19 @@
 import javax.tools.diagnostics.runtime.java.JavaThread;
 
 public class JMonitor implements JavaMonitor {
-	public static Model model;
+	private Model model;
 	private long owner=0;
-	public long monitorObject=0;
-	public long id=0;
-	List<Long> waiters=new LinkedList<Long>();
+	private long monitorObject=0;
+	private long id=0;
+	private List<Long> waiters=new LinkedList<Long>();
 	
-	public JMonitor(long monitorid) {
-		this.id=monitorid;
+	public JMonitor(long monitorid, Model model) {
+		this.id = monitorid;
+		this.model = model;
 	}
 
 	@Override
-	public List getEnterWaiters() {
+	public List<JavaThread> getEnterWaiters() {
 		List<JavaThread> waitingThreads= new LinkedList<JavaThread>();
 		for (Long l: waiters){
 			waitingThreads.add(model.getThread(l));
@@ -45,7 +46,6 @@
 
 	public void addWaiter(Long t) {
 		waiters.add(t);
-		
 	}
 
 	@Override
@@ -56,12 +56,11 @@
 
 	@Override
 	public String getName() throws CorruptDataException {
-		// TODO Auto-generated method stub
-		return "Monitor "+id;
+		return "Monitor 0x"+Long.toHexString(getId());
 	}
 
 	@Override
-	public List getNotifyWaiters() {
+	public List<JavaThread> getNotifyWaiters() {
 		List<JavaThread> waitingThreads= new LinkedList<JavaThread>();
 		for (Long l: waiters){
 			waitingThreads.add(model.getThread(l));
@@ -71,7 +70,7 @@
 
 	@Override
 	public JavaObject getObject() {
-		return model.getObjectAtAddress(monitorObject);
+		return model.getObjectAtAddress(getMonitorObject());
 	}
 
 	@Override
@@ -87,5 +86,13 @@
 		this.owner=thread;
 		
 	}
+
+	public long getId() {
+		return id;
+	}
+
+	public long getMonitorObject() {
+		return monitorObject;
+	}
 	
 }
\ No newline at end of file

Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JObject.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JObject.java?rev=827732&r1=827731&r2=827732&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JObject.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JObject.java
Tue Oct 20 16:56:00 2009
@@ -15,7 +15,6 @@
 package org.apache.kato.jvmti.javaruntime.model;
 
 import java.util.HashMap;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.logging.Level;
@@ -23,18 +22,18 @@
 import javax.tools.diagnostics.image.CorruptDataException;
 import javax.tools.diagnostics.image.DataUnavailable;
 import javax.tools.diagnostics.image.ImagePointer;
+import javax.tools.diagnostics.image.ImageSection;
 import javax.tools.diagnostics.image.MemoryAccessException;
 import javax.tools.diagnostics.runtime.java.JavaClass;
 import javax.tools.diagnostics.runtime.java.JavaHeap;
 import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaReference;
 
 import org.apache.kato.jvmti.reader.CLogger;
 
 /**
  * Represents a Java object.
  * 
- * 
- *
  */
 public class JObject implements JavaObject {
 
@@ -43,9 +42,11 @@
 	private Map<Long, Object> data = new HashMap<Long, Object>();
 	private JClass clazz = null;
 	private boolean visited = false;
-	public boolean isArray = false;
+	
+	public boolean isArray = false;	
 	public Object[] objArray;
 	public int objectSize = 0;
+	
 	private JObject superClazzObject = null;
 	private Model model;
 	
@@ -279,8 +280,7 @@
 
 	@Override
 	public long getHashcode() throws DataUnavailable, CorruptDataException {
-		// TODO Auto-generated method stub
-		return 0;
+		throw new DataUnavailable("Hashcode not available.");
 	}
 
 	@Override
@@ -303,24 +303,21 @@
 	@Override
 	public long getPersistentHashcode() throws DataUnavailable,
 			CorruptDataException {
-		// TODO Auto-generated method stub
-		return 0;
+		throw new DataUnavailable("Persistent Hashcode not available in CJVMTI.");
 	}
 
 	@Override
-	public List getReferences() {
-		return new LinkedList();
+	public List<JavaReference> getReferences() {
+		return new EmptyList<JavaReference>();
 	}
 
 	@Override
-	public List getSections() {
-
-		return new LinkedList();
+	public List<ImageSection> getSections() {
+		return new EmptyList<ImageSection>();
 	}
 
 	@Override
 	public long getSize() throws CorruptDataException {
-
 		return size;
 	}
 

Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JStackFrame.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JStackFrame.java?rev=827732&r1=827731&r2=827732&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JStackFrame.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JStackFrame.java
Tue Oct 20 16:56:00 2009
@@ -14,7 +14,6 @@
 
 package org.apache.kato.jvmti.javaruntime.model;
 
-import java.util.LinkedList;
 import java.util.List;
 import java.util.logging.Level;
 
@@ -22,6 +21,7 @@
 import javax.tools.diagnostics.image.DataUnavailable;
 import javax.tools.diagnostics.image.ImagePointer;
 import javax.tools.diagnostics.runtime.java.JavaLocation;
+import javax.tools.diagnostics.runtime.java.JavaReference;
 import javax.tools.diagnostics.runtime.java.JavaStackFrame;
 import javax.tools.diagnostics.runtime.java.JavaVariable;
 
@@ -48,8 +48,8 @@
 		this.location=loc;
 	}
 	@Override
-	public List getHeapRoots() {
-		return new LinkedList();
+	public List<JavaReference> getHeapRoots() {
+		return new EmptyList<JavaReference>();
 	}
 
 	@Override
@@ -94,4 +94,4 @@
 		addVariable(var);
 		
 	}
-}
\ No newline at end of file
+}

Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JThread.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JThread.java?rev=827732&r1=827731&r2=827732&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JThread.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/JThread.java
Tue Oct 20 16:56:00 2009
@@ -21,6 +21,7 @@
 import javax.tools.diagnostics.image.CorruptDataException;
 import javax.tools.diagnostics.image.DataUnavailable;
 import javax.tools.diagnostics.image.ImagePointer;
+import javax.tools.diagnostics.image.ImageSection;
 import javax.tools.diagnostics.image.ImageThread;
 import javax.tools.diagnostics.image.MemoryAccessException;
 import javax.tools.diagnostics.runtime.java.JavaClass;
@@ -49,17 +50,15 @@
 
 	@Override
 	public ImageThread getImageThread() throws CorruptDataException,
-			DataUnavailable {
-		
+			DataUnavailable {		
 			throw new DataUnavailable();
 	}
 	
 
 	public void addStackFrame(JStackFrame frame) {
 		frames.add(frame);
-		
-		
 	}
+	
 	@Override
 	public ImagePointer getJNIEnv() throws CorruptDataException {
 		
@@ -147,24 +146,25 @@
 		
 		
 	}
+	
 	@Override
 	public int getPriority() throws CorruptDataException {
-		
 		return priority;
 	}
+	
 	@Override
-	public List getStackFrames() {
+	public List<JavaStackFrame> getStackFrames() {
 		CLogger.logr.log(Level.FINEST,"Asked for stack frames");
 		return frames;
 	}
+	
 	@Override
-	public List getStackSections() {
-		// TODO Auto-generated method stub
-		return null;
+	public List<ImageSection> getStackSections() {
+		return new EmptyList<ImageSection>();
 	}
+	
 	@Override
-	public int getState() throws CorruptDataException {
-		
-		return 0;
+	public int getState() throws CorruptDataException {		
+		return STATE_ALIVE | STATE_RUNNABLE;
 	}
 }
\ No newline at end of file

Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/Model.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/Model.java?rev=827732&r1=827731&r2=827732&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/Model.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/javaruntime/model/Model.java
Tue Oct 20 16:56:00 2009
@@ -98,20 +98,20 @@
 	
 	public JMonitor getMonitor(long monitorid) {
 		if(monitorid==0) return null;
-		JMonitor m=(JMonitor) monitorsMap.get(monitorid);
-		if(m==null) {
-			m=new JMonitor(monitorid);
-			monitorsMap.put(monitorid,m);
+		JMonitor monitor=(JMonitor) monitorsMap.get(monitorid);
+		if(monitor==null) {
+			monitor=new JMonitor(monitorid, this);
+			monitorsMap.put(monitorid,monitor);
 		}
-		return m;
+		return monitor;
 	}
 	public List<JavaThread> getThreads() {
 		return threadMap.values();
 	}
-	public List getJavaClassLoader() {
+	public List<JavaClassLoader> getJavaClassLoader() {
 		return loadersMap.values();
 	}
-	public List getJavaMonitors() {
+	public List<JavaMonitor> getJavaMonitors() {
 		return monitorsMap.values();
 	}
 	

Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/process/ImageImpl.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/process/ImageImpl.java?rev=827732&r1=827731&r2=827732&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/process/ImageImpl.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/process/ImageImpl.java
Tue Oct 20 16:56:00 2009
@@ -16,6 +16,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.net.InetAddress;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -28,153 +29,137 @@
 import javax.tools.diagnostics.image.ImageModule;
 import javax.tools.diagnostics.image.ImagePointer;
 import javax.tools.diagnostics.image.ImageProcess;
+import javax.tools.diagnostics.image.ImageSection;
 import javax.tools.diagnostics.image.ImageThread;
 import javax.tools.diagnostics.runtime.ManagedRuntime;
 
 import org.apache.kato.jvmti.javaruntime.JavaRuntimeImpl;
+import org.apache.kato.jvmti.javaruntime.model.EmptyList;
 import org.apache.kato.jvmti.javaruntime.model.SimpleImagePointer;
-import org.apache.kato.jvmti.process.ImageImpl.ImageAddressSpaceImpl.ImageProcessImpl;
 import org.apache.kato.jvmti.reader.CJVMTIBinReader;
 
-public class ImageImpl implements Image {
+/**
+ * Implements the main Image hierarchy.
+ * There is only one instance of Image, ImageAddressSpace and ImageProcess
+ * in each dump, and data may be shared between all.
+ *
+ */
+public class ImageImpl implements Image, ImageAddressSpace, ImageProcess {
+
+	private List<ManagedRuntime> runtimes = new LinkedList<ManagedRuntime>();
+	private List<ImageAddressSpace> spaces = new LinkedList<ImageAddressSpace>();
+	private List<ImageProcess> processes = new LinkedList<ImageProcess>();
+	private File file = null;
 
-	public final class ImageAddressSpaceImpl implements ImageAddressSpace {
-		public final class ImageProcessImpl implements ImageProcess {
-			private List<ManagedRuntime> runtimes = null;
-
-			@Override
-			public String getCommandLine() throws DataUnavailable,
-					CorruptDataException {
-				return "<none>";
-			}
-
-			@Override
-			public ImageThread getCurrentThread() throws CorruptDataException {
-				// TODO Auto-generated method stub
-				return null;
-			}
-
-			@Override
-			public Properties getEnvironment() throws DataUnavailable,
-					CorruptDataException {
-
-				return new Properties();
-			}
-
-			@Override
-			public ImageModule getExecutable() throws DataUnavailable,
-					CorruptDataException {
-				throw new DataUnavailable("no env");
-			}
-
-			@Override
-			public String getID() throws DataUnavailable, CorruptDataException {
-				throw new DataUnavailable("no env");
-			}
-
-			@Override
-			public List getLibraries() throws DataUnavailable,
-					CorruptDataException {
-				throw new DataUnavailable("no env");
-			}
-
-			@Override
-			public int getPointerSize() {
-				// TODO Auto-generated method stub
-				return 0;
-			}
-
-			@Override
-			public List getRuntimes() {
-				if (runtimes == null) {
-					runtimes = new LinkedList<ManagedRuntime>();
-					// BinReader br=new BinReader(file);
-					try {
-						CJVMTIBinReader br = null;
-						br = new CJVMTIBinReader(file);
-						runtimes.add(new JavaRuntimeImpl(br.getModel()));
-					} catch (IOException e) {
-						e.printStackTrace();
-					}
-
-				}
-				return runtimes;
-			}
-
-			@Override
-			public String getSignalName() throws DataUnavailable,
-					CorruptDataException {
-				throw new DataUnavailable("no env");
-			}
-
-			@Override
-			public int getSignalNumber() throws DataUnavailable,
-					CorruptDataException {
-				throw new DataUnavailable("no env");
-			}
-
-			@Override
-			public List getThreads() {
-				// TODO Auto-generated method stub
-				return null;
-			}
-		}
-
-		private List<ImageProcess> processes = null;
-
-		@Override
-		public ImageProcess getCurrentProcess() {
-			fill();
-			return processes.get(0);
-		}
-
-		private void fill() {
-			if (processes == null) {
-				processes = new LinkedList<ImageProcess>();
-				processes.add(new ImageProcessImpl());
-			}
-
-		}
-
-		@Override
-		public List getImageSections() {
-			// TODO Auto-generated method stub
-			return null;
-		}
-
-		@Override
-		public ImagePointer getPointer(long arg0) {
-			// TODO Auto-generated method stub
-			return new SimpleImagePointer(arg0);
-		}
-
-		@Override
-		public List getProcesses() {
-			fill();
-			return processes;
-		}
+	private CJVMTIBinReader br;
+	public ImageImpl(File base) throws IOException {
+		this.file = base;
+		br = new CJVMTIBinReader(file);
+		runtimes.add(new JavaRuntimeImpl(br.getModel(), file));
+		spaces.add(this);
+		processes.add(this);
+	}
+	
+	/* ImageProcess methods */
+	
+	@Override
+	public String getCommandLine() throws DataUnavailable,
+	CorruptDataException {
+		throw new DataUnavailable("Command line not present in CJVMTI dump.");
 	}
 
-	private List<ImageAddressSpace> spaces = null;
-	private File file = null;
+	@Override
+	public ImageThread getCurrentThread() throws CorruptDataException {
+		return null;
+	}
 
-	public ImageImpl(File base) {
-		this.file = base;
+	@Override
+	public Properties getEnvironment() throws DataUnavailable,
+	CorruptDataException {
+		throw new DataUnavailable("Environment variables are not present in CJVMTI dump.");
 	}
 
 	@Override
-	public List getAddressSpaces() {
-		if (spaces == null) {
-			spaces = new LinkedList<ImageAddressSpace>();
-			spaces.add(new ImageAddressSpaceImpl());
-		}
-		return spaces;
+	public ImageModule getExecutable() throws DataUnavailable,
+	CorruptDataException {
+		throw new DataUnavailable("no env");
+	}
+
+	@Override
+	public String getID() throws DataUnavailable, CorruptDataException {
+		throw new DataUnavailable("no env");
+	}
+
+	@Override
+	public List<ImageModule> getLibraries() throws DataUnavailable,
+	CorruptDataException {
+		throw new DataUnavailable("no env");
+	}
+
+	/**
+	 * Regardless of the bittedness of the JVM the agent was run on,
+	 * the dump itself is 64 bits.
+	 * 
+	 * @return 64 
+	 */
+	@Override
+	public int getPointerSize() {
+		return 64;
+	}
+
+	@Override
+	public List<ManagedRuntime> getRuntimes() {
+		return runtimes;
+	}
 
+	/* Image methods */
+	
+	
+	@Override
+	public String getSignalName() throws DataUnavailable,
+	CorruptDataException {
+		throw new DataUnavailable("no env");
+	}
+
+	@Override
+	public int getSignalNumber() throws DataUnavailable,
+	CorruptDataException {
+		throw new DataUnavailable("no env");
+	}
+
+	@Override
+	public List<ImageThread> getThreads() {
+		return new EmptyList<ImageThread>();
+	}
+
+	@Override
+	public ImageProcess getCurrentProcess() {
+		return this;
+	}
+
+	@Override
+	public List<ImageSection> getImageSections() {
+		return new EmptyList<ImageSection>();
+	}
+
+	@Override
+	public ImagePointer getPointer(long arg0) {
+		return new SimpleImagePointer(arg0);
+	}
+
+	@Override
+	public List<ImageProcess> getProcesses() {
+		return processes;
+	}
+
+	@Override
+	public List<ImageAddressSpace> getAddressSpaces() {
+		return spaces;
 	}
 
 	@Override
 	public long getCreationTime() throws DataUnavailable {
-		return 0;
+		return br.getCreationTime();
 	}
 
 	@Override
@@ -183,41 +168,41 @@
 	}
 
 	@Override
-	public Iterator getIPAddresses() throws DataUnavailable {
+	public Iterator<InetAddress> getIPAddresses() throws DataUnavailable {
 		throw new DataUnavailable();
 	}
 
 	@Override
 	public long getInstalledMemory() throws DataUnavailable {
-		return 0;
+		throw new DataUnavailable("Installed memory not available.");
 	}
 
 	@Override
 	public int getProcessorCount() throws DataUnavailable {
-		return 1;
+		throw new DataUnavailable("Processor count not available.");
 	}
 
 	@Override
 	public String getProcessorSubType() throws DataUnavailable,
-			CorruptDataException {
-		return "sub";
+	CorruptDataException {
+		throw new DataUnavailable("Processor subtype not available.");
 	}
 
 	@Override
 	public String getProcessorType() throws DataUnavailable,
-			CorruptDataException {
-		return "proc";
+	CorruptDataException {
+		throw new DataUnavailable("Processor type not available");
 	}
 
 	@Override
 	public String getSystemSubType() throws DataUnavailable,
-			CorruptDataException {
-		return "syssub";
+	CorruptDataException {
+		throw new DataUnavailable("System subtype not available");
 	}
 
 	@Override
 	public String getSystemType() throws DataUnavailable, CorruptDataException {
-		return "sys";
+		throw new DataUnavailable("System type not available.");
 	}
 
 	@Override

Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/reader/CJVMTIBinReader.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/reader/CJVMTIBinReader.java?rev=827732&r1=827731&r2=827732&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/reader/CJVMTIBinReader.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/reader/CJVMTIBinReader.java
Tue Oct 20 16:56:00 2009
@@ -229,12 +229,11 @@
 		log.log(Level.INFO, "CJVMTI Format V0.01");
 		log.log(Level.INFO, "Starting reading in..");
 
-		Long time = variablesIn.readLong();
+		time = variablesIn.readLong();
 
 		Date creationDate = new Date((time * 1000));
 		log.log(Level.INFO, "Date of creation: " + creationDate.toString());
 
-		JMonitor.model = model;
 		generateClassLoaderForReader();
 		generatePrimitiveArrayClasses();
 
@@ -329,9 +328,9 @@
 		jm.name = mName;
 		jm.signature = mSig;
 		if (mGenSig.equals(" ")) {
-			jm.genericsignature = null; // Not currently keeping it null, left as reminder
+			jm.setGenericsignature(null); // Not currently keeping it null, left as reminder
 		}
-		jm.genericsignature = mGenSig;
+		jm.setGenericsignature(mGenSig);
 		jm.mods = modifiers;
 
 		for (int i = 0; i < count; i++) {
@@ -569,6 +568,7 @@
 	}
 
 	private List<Long> unresolvedReferences = new LinkedList<Long>();
+	private Long time;
 	
 	/**
 	 * Reads an object at the current file position
@@ -1034,7 +1034,7 @@
 			nreadReference(objID); // Follow reference
 			variablesIn.seek(cPos); // Return to read point
 			JMonitor monitor = model.getMonitor(objID);
-			monitor.setObject(monitor.id);
+			monitor.setObject(monitor.getId());
 			monitor.setOwner(t.id);
 		}
 	}
@@ -1121,4 +1121,13 @@
 		return model;
 	}
 
+
+	/**
+	 * Returns the creation time, in millis, since the epoch.
+	 * 
+	 * @return long
+	 */
+	public long getCreationTime() {
+		return time;
+	}
 }



Mime
View raw message