incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spo...@apache.org
Subject svn commit: r822316 - in /incubator/kato/trunk/org.apache.kato: kato.api/src/main/java/javax/tools/diagnostics/ kato.api/src/main/java/javax/tools/diagnostics/image/ kato.api/src/main/java/javax/tools/diagnostics/runtime/java/ kato.api/src/test/java/te...
Date Tue, 06 Oct 2009 15:28:10 GMT
Author: spoole
Date: Tue Oct  6 15:28:10 2009
New Revision: 822316

URL: http://svn.apache.org/viewvc?rev=822316&view=rev
Log:
updated API to allow JavaRuntime to be directly retrieved from Factory Registry

Modified:
    incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/FactoryRegistry.java
    incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/image/ImageFactory.java
    incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/runtime/java/JavaClassLoader.java
    incubator/kato/trunk/org.apache.kato/kato.api/src/test/java/test/apache/kato/TestFactoryRegistry.java
    incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/process/ImageFactoryImpl.java
    incubator/kato/trunk/org.apache.kato/kato.hprof.api/src/main/java/org/apache/kato/hprof/image/ImageFactoryImpl.java
    incubator/kato/trunk/org.apache.kato/kato.jvmti/src/main/java/org/apache/kato/jvmti/process/ImageFactoryImpl.java

Modified: incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/FactoryRegistry.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/FactoryRegistry.java?rev=822316&r1=822315&r2=822316&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/FactoryRegistry.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/FactoryRegistry.java
Tue Oct  6 15:28:10 2009
@@ -22,6 +22,7 @@
 import javax.imageio.spi.ServiceRegistry;
 import javax.tools.diagnostics.image.Image;
 import javax.tools.diagnostics.image.ImageFactory;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
 
 
 /**
@@ -181,4 +182,52 @@
 			}
 			return null; // no matches
 	}
+
+	/**
+	 * <p>
+	 * Returns an appropriate {@link javax.tools.diagnostics.image.Image} for the
+	 * provide file by locating the first registered image factory that can handle
+	 * the case insensitive file name extension of the provided file. 
+	 * If no factory can be found to handle the file then null is returned. 
+	 * <p>
+	 * File names without extension will always return null  
+	 *  
+	 * @throws IllegalArgumentException if file is null
+	 * @throws IOException if errors occur during image creation
+	 * 
+	 * @param file to create image from
+	 * @return Image or null
+	 * 
+	 */
+	public JavaRuntime getJavaRuntime(File file) throws IOException {
+			if(file==null) throw new IllegalArgumentException("file is null");
+		
+			String fileName=file.getName();
+			
+			int lastDot=fileName.lastIndexOf('.');
+			
+			if(lastDot<0) {  
+				return null; // no suffix
+			}
+			
+			if( (lastDot+1)==fileName.length()) {
+				return null;  // no suffix
+			}
+			
+			String suffix=fileName.substring(lastDot+1);
+			
+			for(ImageFactory factory:factories) {
+				String[] extensions=factory.getValidFileExtensions();
+				if(extensions==null) continue;
+				for(String value:extensions) {
+					if(suffix.equalsIgnoreCase(value)) {
+						// found match
+						return factory.getJavaRuntime(file);
+						
+					}
+				}
+				
+			}
+			return null; // no matches
+	}
 }

Modified: incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/image/ImageFactory.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/image/ImageFactory.java?rev=822316&r1=822315&r2=822316&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/image/ImageFactory.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/image/ImageFactory.java
Tue Oct  6 15:28:10 2009
@@ -16,6 +16,8 @@
 import java.io.File;
 import java.io.IOException;
 
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+
 /**
  * <p>
  * This interface is used for classes which can produce instances of Image
@@ -107,4 +109,16 @@
 	 * @return an array of case insensitive file extension names.
 	 */
 	public String[] getValidFileExtensions();
+	
+	/**
+	 * <p>
+	 * Creates a new JavaRuntime object based on the contents of the file;
+	 * <p>
+	 * Note that this method is only intended to be called by the {@link javax.tools.diagnostics.FactoryRegistry}
+	 * 
+	 * @param file a file with JavaRuntime information
+	 * @return an instance of JavaRuntime
+	 * @throws IOException if unable to create a runtime from the provided file 
+	 */
+	public JavaRuntime getJavaRuntime(File file) throws IOException;
 }

Modified: incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/runtime/java/JavaClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/runtime/java/JavaClassLoader.java?rev=822316&r1=822315&r2=822316&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/runtime/java/JavaClassLoader.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.api/src/main/java/javax/tools/diagnostics/runtime/java/JavaClassLoader.java
Tue Oct  6 15:28:10 2009
@@ -53,7 +53,7 @@
      *    
      * <p>The returned list follows the standard semantics for javax.tools.diagnostics
collections.</p>
      * <p>The returned value is never null but can be an empty list.</p>
-     *  
+     *   
      * @return an list of classes which are defined in this JavaClassLoader 
      * @see JavaClass
      */

Modified: incubator/kato/trunk/org.apache.kato/kato.api/src/test/java/test/apache/kato/TestFactoryRegistry.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.api/src/test/java/test/apache/kato/TestFactoryRegistry.java?rev=822316&r1=822315&r2=822316&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.api/src/test/java/test/apache/kato/TestFactoryRegistry.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.api/src/test/java/test/apache/kato/TestFactoryRegistry.java
Tue Oct  6 15:28:10 2009
@@ -23,6 +23,17 @@
 import javax.tools.diagnostics.image.DataUnavailable;
 import javax.tools.diagnostics.image.Image;
 import javax.tools.diagnostics.image.ImageFactory;
+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 junit.framework.TestCase;
 
@@ -67,8 +78,91 @@
 		
 			return suffixes;
 		}
+		@Override
+		public JavaRuntime getJavaRuntime(File file) {
+			
+			return new MockRuntime();
+		}
 	}
+	private final class MockRuntime implements JavaRuntime {
+
+		@Override
+		public List<JavaMethod> getCompiledMethods() {
+			// TODO Auto-generated method stub
+			return null;
+		}
+
+		@Override
+		public List<JavaReference> getHeapRoots() {
+			// TODO Auto-generated method stub
+			return null;
+		}
+
+		@Override
+		public List<JavaHeap> getHeaps() {
+			// TODO Auto-generated method stub
+			return null;
+		}
+
+		@Override
+		public List<JavaClassLoader> getJavaClassLoaders() {
+			// TODO Auto-generated method stub
+			return null;
+		}
+
+		@Override
+		public ImagePointer getJavaVM() throws CorruptDataException {
+			// TODO Auto-generated method stub
+			return null;
+		}
+
+		@Override
+		public JavaVMInitArgs getJavaVMInitArgs() throws DataUnavailable,
+				CorruptDataException {
+			// TODO Auto-generated method stub
+			return null;
+		}
+
+		@Override
+		public List<JavaMonitor> getMonitors() {
+			// TODO Auto-generated method stub
+			return null;
+		}
+
+		@Override
+		public JavaObject getObjectAtAddress(ImagePointer address)
+				throws CorruptDataException, IllegalArgumentException,
+				MemoryAccessException, DataUnavailable {
+			// TODO Auto-generated method stub
+			return null;
+		}
+
+		@Override
+		public List<JavaThread> getThreads() {
+			// TODO Auto-generated method stub
+			return null;
+		}
+
+		@Override
+		public Object getTraceBuffer(String bufferName, boolean formatted)
+				throws CorruptDataException {
+			// TODO Auto-generated method stub
+			return null;
+		}
 
+		@Override
+		public String getFullVersion() throws CorruptDataException {
+			// TODO Auto-generated method stub
+			return null;
+		}
+
+		@Override
+		public String getVersion() throws CorruptDataException {
+			// TODO Auto-generated method stub
+			return null;
+		}
+		
+	}
 	private final class MockImage implements Image {
 		public List getAddressSpaces() {
 			
@@ -140,7 +234,7 @@
 		
 	}
 	
-	public void testNullFileNameThrowsError() throws IOException {
+	public void testNullImageFileNameThrowsError() throws IOException {
 		
 		FactoryRegistry reg=new FactoryRegistry();
 		try {
@@ -153,7 +247,19 @@
 		
 	}
 	
-	public void testNoSuffixFileNameReturnsNull() throws IOException {
+	public void testNullRutimeFileNameThrowsError() throws IOException {
+		
+		FactoryRegistry reg=new FactoryRegistry();
+		try {
+		reg.getJavaRuntime(null);
+		fail("Expected illegal argument exception");
+		
+		} catch(IllegalArgumentException e) {
+			; // ok
+		}
+		
+	}
+	public void testNoSuffixImageFileNameReturnsNull() throws IOException {
 		
 		FactoryRegistry reg=new FactoryRegistry();
 		File f=new File("testfile");
@@ -162,7 +268,15 @@
 		assertNull(result);
 		
 	}
-	
+public void testNoSuffixRuntimeFileNameReturnsNull() throws IOException {
+		
+		FactoryRegistry reg=new FactoryRegistry();
+		File f=new File("testfile");
+		
+		JavaRuntime result=reg.getJavaRuntime(f);
+		assertNull(result);
+		
+	}
 	public void testDotSuffixFileNameReturnsNull() throws IOException {
 		
 		FactoryRegistry reg=new FactoryRegistry();

Modified: incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/process/ImageFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/process/ImageFactoryImpl.java?rev=822316&r1=822315&r2=822316&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/process/ImageFactoryImpl.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.cjvmti/src/main/java/org/apache/kato/jvmti/process/ImageFactoryImpl.java
Tue Oct  6 15:28:10 2009
@@ -18,7 +18,11 @@
 import java.io.IOException;
 
 import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImageAddressSpace;
 import javax.tools.diagnostics.image.ImageFactory;
+import javax.tools.diagnostics.image.ImageProcess;
+import javax.tools.diagnostics.runtime.ManagedRuntime;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
 
 public class ImageFactoryImpl implements ImageFactory{
 
@@ -57,4 +61,18 @@
 		return 0;
 	}
 
+	@Override
+	public JavaRuntime getJavaRuntime(File file) throws IOException {
+		 Image i=getImage(file);
+		 if(i==null) return null;
+		 
+		for(ImageAddressSpace space:i.getAddressSpaces()) {
+			ImageProcess process=space.getCurrentProcess();
+			for(ManagedRuntime r : process.getRuntimes()) {
+				if(r instanceof JavaRuntime) return (JavaRuntime) r;
+			}
+		}
+		return null;
+	}
+
 }

Modified: incubator/kato/trunk/org.apache.kato/kato.hprof.api/src/main/java/org/apache/kato/hprof/image/ImageFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.hprof.api/src/main/java/org/apache/kato/hprof/image/ImageFactoryImpl.java?rev=822316&r1=822315&r2=822316&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.hprof.api/src/main/java/org/apache/kato/hprof/image/ImageFactoryImpl.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.hprof.api/src/main/java/org/apache/kato/hprof/image/ImageFactoryImpl.java
Tue Oct  6 15:28:10 2009
@@ -17,7 +17,11 @@
 import java.io.IOException;
 
 import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImageAddressSpace;
 import javax.tools.diagnostics.image.ImageFactory;
+import javax.tools.diagnostics.image.ImageProcess;
+import javax.tools.diagnostics.runtime.ManagedRuntime;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
 
 import org.apache.kato.hprof.datalayer.HProfFactory;
 import org.apache.kato.hprof.datalayer.HProfFile;
@@ -66,5 +70,18 @@
 	public String[] getValidFileExtensions() {
 		return suffixes;
 	}
+	@Override
+	public JavaRuntime getJavaRuntime(File file) throws IOException {
+		 Image i=getImage(file);
+		 if(i==null) return null;
+		 
+		for(ImageAddressSpace space:i.getAddressSpaces()) {
+			ImageProcess process=space.getCurrentProcess();
+			for(ManagedRuntime r : process.getRuntimes()) {
+				if(r instanceof JavaRuntime) return (JavaRuntime) r;
+			}
+		}
+		return null;
+	}
 
 }

Modified: incubator/kato/trunk/org.apache.kato/kato.jvmti/src/main/java/org/apache/kato/jvmti/process/ImageFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.jvmti/src/main/java/org/apache/kato/jvmti/process/ImageFactoryImpl.java?rev=822316&r1=822315&r2=822316&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.jvmti/src/main/java/org/apache/kato/jvmti/process/ImageFactoryImpl.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.jvmti/src/main/java/org/apache/kato/jvmti/process/ImageFactoryImpl.java
Tue Oct  6 15:28:10 2009
@@ -18,7 +18,11 @@
 import java.io.IOException;
 
 import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImageAddressSpace;
 import javax.tools.diagnostics.image.ImageFactory;
+import javax.tools.diagnostics.image.ImageProcess;
+import javax.tools.diagnostics.runtime.ManagedRuntime;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
 
 
 public class ImageFactoryImpl implements ImageFactory{
@@ -58,5 +62,18 @@
 	public String[] getValidFileExtensions() {
 		return suffixes;
 	}
+	@Override
+	public JavaRuntime getJavaRuntime(File file) throws IOException {
+		 Image i=getImage(file);
+		 if(i==null) return null;
+		 
+		for(ImageAddressSpace space:i.getAddressSpaces()) {
+			ImageProcess process=space.getCurrentProcess();
+			for(ManagedRuntime r : process.getRuntimes()) {
+				if(r instanceof JavaRuntime) return (JavaRuntime) r;
+			}
+		}
+		return null;
+	}
 
 }



Mime
View raw message