incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spo...@apache.org
Subject svn commit: r775440 - in /incubator/kato: branches/experimental/PyJVMTI/ branches/experimental/PyJVMTI/kato/ trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/ trunk/org.apache.kato.jvmti/testsrc/test/apache/kato/jvmti/
Date Sat, 16 May 2009 09:22:36 GMT
Author: spoole
Date: Sat May 16 09:22:33 2009
New Revision: 775440

URL: http://svn.apache.org/viewvc?rev=775440&view=rev
Log:
added dumping of methods and interfaces into pyjvmti project

Added:
    incubator/kato/branches/experimental/PyJVMTI/kato/JMethod.py   (with props)
Modified:
    incubator/kato/branches/experimental/PyJVMTI/kato/BinDump.py
    incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c
    incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h
    incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinReader.java
    incubator/kato/trunk/org.apache.kato.jvmti/testsrc/test/apache/kato/jvmti/TestBinReader.java

Modified: incubator/kato/branches/experimental/PyJVMTI/kato/BinDump.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/BinDump.py?rev=775440&r1=775439&r2=775440&view=diff
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/BinDump.py (original)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/BinDump.py Sat May 16 09:22:33 2009
@@ -14,6 +14,7 @@
 import kato.Dump as Dump
 import kato.JField as JField
 import kato.JThreadGroup as JThreadGroup
+import kato.JMethod as JMethod
 
 import struct
 
@@ -136,8 +137,10 @@
         '''
         Save a single JClass
         '''
-         
-        header=struct.pack("!hiiihhhhh",201,clazz.classid,clazz.superclass,clazz.classloader,clazz.status,clazz.modifiers,len(clazz.fields),len(clazz.interfaces),len(clazz.methods))
+        interfaceCount=len(clazz.interfaces)
+        methodCount=len(clazz.methods)
+        
+        header=struct.pack("!hiiihhhhh",201,clazz.classid,clazz.superclass,clazz.classloader,clazz.status,clazz.modifiers,len(clazz.fields),interfaceCount,methodCount)
         self.output.write(header)
         namelength=struct.pack("!i",len(clazz.signature))
         self.output.write(namelength)
@@ -150,6 +153,47 @@
             field=JField.JField(clazz,fieldid)
             self.saveField(field)
     
+        # write interaces
+        
+        if interfaceCount>0 :
+            
+            header=struct.pack("!hi",203,interfaceCount)
+            self.output.write(header)
+            
+            for interfaceid in clazz.interfaces :
+                
+                header=struct.pack("!i",interfaceid)
+                self.output.write(header)
+                
+    
+       # write methods...
+        if methodCount>0 :
+            
+            self.saveMethods(clazz)
+            
+            
+        
+    def saveMethods(self,clazz):
+        
+            
+        for methodid in clazz.methods :
+           m=JMethod.JMethod(methodid)
+           vartable=m.localVariableTable
+           tablesize=len(vartable)
+           
+           header=struct.pack("!hiiiiii",204,methodid,m.modifiers,m.maxlocals,m.argumentsize,m.isnative,tablesize)
+           self.output.write(header)
+           self. writeName(m.name)
+           self. writeName(m.signature)
+           self. writeName(m.genericsignature)
+           
+           if tablesize > 0 :
+               for entry in vartable :
+                   header=struct.pack("!hiii",206,entry[0],entry[1],entry[5])
+                   self.output.write(header)
+                   self. writeName(entry[2]) # name
+                   self. writeName(entry[3]) #sig
+                   self. writeName(entry[4]) # generi sig
             
     def writeName(self,name):
         length=0

Added: incubator/kato/branches/experimental/PyJVMTI/kato/JMethod.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/JMethod.py?rev=775440&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/JMethod.py (added)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/JMethod.py Sat May 16 09:22:33 2009
@@ -0,0 +1,126 @@
+#*******************************************************************************
+ #* 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.
+ #******************************************************************************"
+
+import jvmti
+
+class JMethod(object):
+    '''
+    Representation of a method
+    '''
+    methodid=0
+    info=None
+    mods=None
+    locals=None
+    args=None
+    native=None
+    vartable=None
+    
+    def __init__(self,mid=0):
+        '''
+        Constructor
+        '''
+        self.methodid=mid
+        
+        
+    def fill(self):
+        if self.info==None :
+            self.info=jvmti.getMethodName(self.methodid)
+        
+    @property
+    def name(self):
+        '''
+        return method name
+        '''
+        self.fill()
+        return self.info[0]
+    
+    @property
+    def signature(self):
+        '''
+        return method signature
+        '''
+        self.fill()
+        return self.info[1]
+        
+    @property
+    def genericsignature(self):
+        '''
+        return methods generic signature
+        '''
+        self.fill()
+        return self.info[2]
+    
+    @property
+    def modifiers(self):
+        '''
+        Return method modifiers
+        '''
+        if self.mods==None :
+            self.mods=jvmti.getMethodModifiers(self.methodid)
+            
+        return self.mods
+            
+    @property
+    def maxlocals(self):
+        '''
+        returns the number of local variable slots in the method
+        '''
+        if self.locals==None :
+            if self.isnative > 0 :
+                self.locals=-1
+            else :
+                self.locals=jvmti.getMaxLocals(self.methodid)
+            
+        return self.locals
+        
+    @property        
+    def argumentsize(self):
+        '''
+        returns the number of slots used by the methods arguments
+        '''
+        if self.args==None :
+            if self.isnative > 0 :
+                self.args=-1
+            else :
+                self.args=jvmti.getArgumentsSize(self.methodid)
+            
+        return self.args
+    
+    @property
+    def lineNumberTable(self):
+        '''
+        '''
+        return None
+    
+    @property    
+    def localVariableTable(self):
+        '''
+        '''
+        if self.vartable == None :
+            try :
+                self.vartable=jvmti.getLocalVariableTable(self.methodid)
+            except jvmti.error :
+                self.vartable=[]
+                
+        return self.vartable;
+        
+    @property
+    def isnative(self):
+        '''
+        returns true if this is a native method
+        '''
+        if self.native==None :
+            self.native=jvmti.isMethodNative(self.methodid)
+            
+        return self.native
\ No newline at end of file

Propchange: incubator/kato/branches/experimental/PyJVMTI/kato/JMethod.py
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c?rev=775440&r1=775439&r2=775440&view=diff
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c (original)
+++ incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c Sat May 16 09:22:33 2009
@@ -789,6 +789,21 @@
 	getValue(GetClassLoader,jclass,"i","Get Class Loader")
 }
 
+static PyObject *  jvmti_getMethodModifiers(PyObject *self, PyObject *args) {
+		getValue(GetMethodModifiers,jint,"i","Get Method Modifiers")
+}
+
+static PyObject *  jvmti_getMaxLocals(PyObject *self, PyObject *args) {
+		getValue(GetMaxLocals,jint,"i","Get Max Locals")
+}
+
+static PyObject *  jvmti_getArgumentsSize(PyObject *self, PyObject *args) {
+		getValue(GetArgumentsSize,jint,"i","Get Arguments Size")
+}
+
+static PyObject *  jvmti_isMethodNative(PyObject *self, PyObject *args) {
+		getValue(IsMethodNative,jboolean,"i","Is method native")
+}
 static PyObject *  jvmti_getImplementedInterfaces(PyObject *self, PyObject *args) {
 	getList(GetImplementedInterfaces,jclass,"Get Implemented Interfaces")
 }
@@ -849,7 +864,11 @@
      {"getImplementedInterfaces", jvmti_getImplementedInterfaces, METH_VARARGS,   "Get Implemented
Interfaces."},
      {"getSuperClass",        jvmti_getSuperClass, METH_VARARGS,   "Get Superclass."},
      {"getClassLoader",       jvmti_getClassLoader, METH_VARARGS,   "Get Class Loader."},
-     {"getFieldName",        jvmti_getFieldName, METH_VARARGS,   "Get Field Name."},
+     {"getFieldName",         jvmti_getFieldName, METH_VARARGS,   "Get Field Name."},
+     {"getMethodModifiers",   jvmti_getMethodModifiers, METH_VARARGS,   "Get Method Modifiers."},
+     {"getMaxLocals",         jvmti_getMaxLocals, METH_VARARGS,   "Get Max Locas."},
+     {"getArgumentsSize",     jvmti_getArgumentsSize, METH_VARARGS,   "Get Argumens Size."},
+     {"isMethodNative",       jvmti_isMethodNative, METH_VARARGS,   "Is method native"},
 
      {NULL, NULL, 0, NULL}        /* Sentinel */
 };

Modified: incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h?rev=775440&r1=775439&r2=775440&view=diff
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h (original)
+++ incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h Sat May 16 09:22:33 2009
@@ -69,6 +69,10 @@
 static PyObject *jvmti_getSuperClass(PyObject *self, PyObject *args);
 static PyObject *jvmti_getFieldName(PyObject *self, PyObject *args);
 static PyObject *jvmti_getClassLoader(PyObject *self, PyObject *args);
+static PyObject *jvmti_getMaxLocals(PyObject *self, PyObject *args);
+static PyObject *jvmti_getArgumentsSize(PyObject *self, PyObject *args);
+static PyObject *jvmti_getMethodModifiers(PyObject *self, PyObject *args);
+static PyObject *jvmti_isMethodNative(PyObject *self, PyObject *args);
 
 void runScript(void);
 void startPython(void);

Modified: incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinReader.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinReader.java?rev=775440&r1=775439&r2=775440&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinReader.java
(original)
+++ incubator/kato/trunk/org.apache.kato.jvmti/src/org/apache/kato/jvmti/reader/BinReader.java
Sat May 16 09:22:33 2009
@@ -170,11 +170,79 @@
 			readFields(c);
 		}
 		
+		if(c.interfaceCount>0) {
+			readInterfaces(c);
+		}
+		
+		if(c.methodsCount>0) {
+			readMethods(c);
+		}
 		
 		trace("read class - name ="+c.classSig);
 		classMap.put(c.classid, c);
 	}
 	
+	private void readMethods(JClass c) throws IOException {
+		trace("reading "+c.methodsCount+" methods");
+	
+	    
+		
+		
+		for(int i=0;i<c.methodsCount;i++) {
+			
+			int rid=in.readShort();
+			if(rid!=204) error("unexpected method record id of "+rid);
+			int id=in.readInt();
+			JMethod m=getMethod(id);
+			c.addMethod(m);   
+			
+			m.mods=in.readInt();
+			m.maxlocals=in.readInt();
+			m.argumentsize=in.readInt();
+			m.nativemethod=in.readInt();
+			
+			int tableSize=in.readInt();
+			
+			m.name=readName();
+			m.signature=readName();
+			m.genericsignature=readName();
+			 
+			
+			for(int j=0;j<tableSize;j++) {
+				int tid=in.readShort();
+				if(tid!=206) error("unexpected method table record id of "+tid);
+				JLocalVariableTableEntry entry=new JLocalVariableTableEntry();
+				 entry.start=in.readInt();
+				 entry.length=in.readInt();
+				 entry.slot=in.readInt();
+				 entry.name=readName();
+				 entry.sig=readName();
+				 entry.gensig=readName();
+				 
+				 m.addLocalVariableTableEntry(entry);
+			}
+		}
+		
+		
+	}
+	private void readInterfaces(JClass c) throws IOException {
+		
+		// record form is 203,count,ints[count]
+		
+		trace("reading "+c.interfaceCount+" interfaces");
+		
+		int rid=in.readShort();
+		if(rid!=203) error("unexpected interface record id of "+rid);
+		int count=in.readInt();
+		
+		for(int i=0;i<count;i++) {
+			int id=in.readInt();
+			JClass face=getClass(id);
+			c.addInterface(face);    
+		}
+		
+	}
+	
 	private JMonitor getMonitor(int monitorid) {
 		if(monitorid==0) return null;
 		JMonitor m=(JMonitor) monitorsMap.get(monitorid);
@@ -199,6 +267,7 @@
 		JMethod m=(JMethod) methodMap.get(methodid);
 		if(m==null) {
 			m=new JMethod();
+		
 			methodMap.put(methodid,m);
 		}
 		return m;
@@ -505,11 +574,27 @@
 		    short methodsCount=0;
 		    int   nameLength=0; 
 			String classSig=null;
+			private List<JClass> interfaces=null;
+			private List<JMethod> methods=null;
 			@Override
 			public JavaClassLoader getClassLoader() throws CorruptDataException {
 				
 				return classloader;
 			}
+			private void addInterface(JClass face) {
+				if(interfaces==null) {
+					interfaces=new LinkedList<JClass>();
+				}
+				interfaces.add(face);
+				
+			}
+			private void addMethod(JMethod m) {
+				if(methods==null) {
+					methods=new LinkedList<JMethod>();
+				}
+				methods.add(m);
+				
+			}
 			@Override
 			public JavaClass getComponentType() throws CorruptDataException {
 				// TODO Auto-generated method stub
@@ -746,16 +831,28 @@
 	class JMethod implements JavaMethod {
 
 		
+		public String genericsignature;
+		public int nativemethod;
+		public int argumentsize;
+		public int maxlocals;
 		private String name=null;
 		private String signature=null;
 		private int mods=0;
 		private JClass parent=null;
 		
-		
+		private List<JLocalVariableTableEntry> localVars=null;
 		public JMethod() {
 			
 		}
 		
+		private void addLocalVariableTableEntry(JLocalVariableTableEntry entry) {
+			if(localVars==null) {
+				localVars=new LinkedList<JLocalVariableTableEntry>();
+			}
+			
+			localVars.add(entry);
+		}
+
 		@Override
 		public Iterator getBytecodeSections() {
 		
@@ -791,4 +888,15 @@
 		}
 		
 	}
+	
+	class JLocalVariableTableEntry {
+
+		public String gensig;
+		public String sig;
+		public String name;
+		public int slot;
+		public int length;
+		public int start;
+		
+	}
 }

Modified: incubator/kato/trunk/org.apache.kato.jvmti/testsrc/test/apache/kato/jvmti/TestBinReader.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.jvmti/testsrc/test/apache/kato/jvmti/TestBinReader.java?rev=775440&r1=775439&r2=775440&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.jvmti/testsrc/test/apache/kato/jvmti/TestBinReader.java
(original)
+++ incubator/kato/trunk/org.apache.kato.jvmti/testsrc/test/apache/kato/jvmti/TestBinReader.java
Sat May 16 09:22:33 2009
@@ -27,5 +27,6 @@
 	public void testOpenFile() throws IOException {
 		File f=new File("/home/spoole/workspace-javaone/PyJVMTI/kato.dump");
 		BinReader br=new BinReader(f);
+		int a=1;
 	}
 }



Mime
View raw message