From kato-commits-return-109-apmail-incubator-kato-commits-archive=incubator.apache.org@incubator.apache.org Sat May 16 09:23:06 2009 Return-Path: Delivered-To: apmail-incubator-kato-commits-archive@minotaur.apache.org Received: (qmail 4717 invoked from network); 16 May 2009 09:23:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 16 May 2009 09:23:06 -0000 Received: (qmail 74395 invoked by uid 500); 16 May 2009 09:23:06 -0000 Delivered-To: apmail-incubator-kato-commits-archive@incubator.apache.org Received: (qmail 74380 invoked by uid 500); 16 May 2009 09:23:06 -0000 Mailing-List: contact kato-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: kato-dev@incubator.apache.org Delivered-To: mailing list kato-commits@incubator.apache.org Received: (qmail 74370 invoked by uid 99); 16 May 2009 09:23:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 May 2009 09:23:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 May 2009 09:23:01 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 90D0F2388895; Sat, 16 May 2009 09:22:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: kato-commits@incubator.apache.org From: spoole@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090516092239.90D0F2388895@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 interfaces=null; + private List methods=null; @Override public JavaClassLoader getClassLoader() throws CorruptDataException { return classloader; } + private void addInterface(JClass face) { + if(interfaces==null) { + interfaces=new LinkedList(); + } + interfaces.add(face); + + } + private void addMethod(JMethod m) { + if(methods==null) { + methods=new LinkedList(); + } + 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 localVars=null; public JMethod() { } + private void addLocalVariableTableEntry(JLocalVariableTableEntry entry) { + if(localVars==null) { + localVars=new LinkedList(); + } + + 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; } }