incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spo...@apache.org
Subject svn commit: r774671 - in /incubator/kato/branches/experimental/PyJVMTI: build.sh kato/BinDump.py kato/Dump.py kato/JClass.py kato/PauseJVM.java kato/PrintDump.py kato/console.py pyjvmti.c pyjvmti.h run.sh
Date Thu, 14 May 2009 07:41:29 GMT
Author: spoole
Date: Thu May 14 07:41:28 2009
New Revision: 774671

URL: http://svn.apache.org/viewvc?rev=774671&view=rev
Log:
major updates to the pyjvmti experimental code

Added:
    incubator/kato/branches/experimental/PyJVMTI/kato/BinDump.py   (with props)
    incubator/kato/branches/experimental/PyJVMTI/kato/JClass.py   (with props)
    incubator/kato/branches/experimental/PyJVMTI/kato/PrintDump.py   (with props)
    incubator/kato/branches/experimental/PyJVMTI/kato/console.py   (with props)
Modified:
    incubator/kato/branches/experimental/PyJVMTI/build.sh
    incubator/kato/branches/experimental/PyJVMTI/kato/Dump.py
    incubator/kato/branches/experimental/PyJVMTI/kato/PauseJVM.java
    incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c
    incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h
    incubator/kato/branches/experimental/PyJVMTI/run.sh

Modified: incubator/kato/branches/experimental/PyJVMTI/build.sh
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/build.sh?rev=774671&r1=774670&r2=774671&view=diff
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/build.sh (original)
+++ incubator/kato/branches/experimental/PyJVMTI/build.sh Thu May 14 07:41:28 2009
@@ -1,3 +1,3 @@
-javac ./kato/PauseJVM.java
+javac -g ./kato/PauseJVM.java
 python -u ./setup.py build
 

Added: incubator/kato/branches/experimental/PyJVMTI/kato/BinDump.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/BinDump.py?rev=774671&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/BinDump.py (added)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/BinDump.py Thu May 14 07:41:28 2009
@@ -0,0 +1,48 @@
+import kato.Dump as Dump
+import struct
+
+class BinDump(Dump.Dump):
+    
+    output=None
+      
+    def open(self): 
+        self.output=open("kato.dump","wb")
+
+        
+    def close(self): 
+        '''
+        Called at end of save process
+        provides an opportunity for subclasses do
+        do clean up processing 
+        '''
+        self.output.close()
+        
+  
+    def startThreadSave(self,count):
+        
+        # write a threads meta record
+        recordType=struct.pack("!hi",100,count)
+        self.output.write(recordType)
+        
+        
+    def saveThread(self,thread):
+        '''
+        Save a single Jthread
+        '''
+        header=struct.pack("!hhhi",101,thread.priority,thread.isDaemon,thread.threadGroupID)
+        self.output.write(header)
+        namelength=struct.pack("!i",len(thread.name))
+        self.output.write(namelength)
+        self.output.write(thread.name)
+       
+        print "saved " , thread.name 
+       
+        
+    def saveClass(self,clazz):
+        '''
+        Save a single JClass
+        '''
+        
+       # print "saving " , clazz.signature
+        
+       
\ No newline at end of file

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

Modified: incubator/kato/branches/experimental/PyJVMTI/kato/Dump.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/Dump.py?rev=774671&r1=774670&r2=774671&view=diff
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/Dump.py (original)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/Dump.py Thu May 14 07:41:28 2009
@@ -20,62 +20,114 @@
 '''
 import jvmti
 import kato.JThread as JThread
-import cPickle as pickle
+import kato.JClass as JClass
 
 class Dump(object):
+    
+    includeThreads=True
+    includeClasses=True
+    
     '''
-    classdocs
+    Abstract class that walks the required data and calls dump methods
+    that are expected to be overloaded by concrete dump instances
     '''
     results=None
     
-    def __getstate__(self):
-       """Return state values to be pickled."""
-       return self.getThreads()
-       
-
-    def __setstate__(self, state):
-        """Restore state from the unpickled state values."""
-        self.results=state
-
     def __init__(selfparams):
         '''
         Constructor
         '''
         
+    def open(self): 
+        '''
+        Called at start of save process
+        provides an opportunity for subclasses do
+        do initial processing 
+        '''
+        
+    def close(self): 
+        '''
+        Called at end of save process
+        provides an opportunity for subclasses do
+        do clean up processing 
+        '''
+        
+    def saveThread(self,thread):
+        '''
+        Save a single Jthread
+        '''
+       
+    def saveClass(self,clazz):
+        '''
+        Save a single JClass
+        '''
     
-    def getThreads(self):
+        
+    def saveClasses(self,classes):
+         
         '''
-        List Threads
-        '''  
-        if self.results==None:
-            self.results=[] 
-            for t in jvmti.getAllThreads() :
-                 q=JThread.JThread(t)
-                 self.results.append(q) 
+        Save Classes - given a list of class ids 
+        will call saveClass repeatedly with a newly constructed
+        JClass instance
+        ''' 
+         
+        for c in classes :
+            q=JClass.JClass(c)
+            self.saveClass(q) 
             
-        return self.results
+    def startThreadSave(self,count):
+        '''
+        called before threads are saved
+        '''   
     
-    def properties(self):
+    def endThreadSave(self):
         '''
-        List system properties
+        called just after threads are saved
+        '''   
+    
+    def saveThreads(self,threads):
         '''
-        print "listing properties"
-        for k, v in jvmti.getsystemproperties().iteritems():
-            print k,"=", v
-
-    @property
-    def threads(self):
+        Save Threads - given a list of thread ids 
+        will call saveThread repeatedly with a newly constructed
+        JThread instance
+        ''' 
+        self.startThreadSave(len(threads))
+        
+        for t in threads :
+           q=JThread.JThread(t)
+           self.saveThread(q) 
+            
+        self.endThreadSave()
+    
+   
+    def save(self):
         '''
-        List system properties
+        root method for saving a dump
+        calls the saveAll* methods in turn depending
+        on configuration
+        '''
+        self.open()
+        self.saveAllThreads()
+        self.saveAllClasses()
+        self.close()
+    
+    def saveAllThreads(self):
+        '''
+        Save threads to dump if includeThreads is true
         '''
-        print "listing properties"
-        for k in jvmti.getAllThreads():
-            print k ,  jvmti.getThread(k)
+        if self.includeThreads==False :  return
+        
+        threads=jvmti.getAllThreads()
+        self.saveThreads(threads);
     
+                
+    def saveAllClasses(self):
+        '''
+        Save class to dump if includeClasses is true
+        '''
         
-    def save(self):
+        if self.includeClasses==False :  return
+        
+        classes=jvmti.getLoadedClasses()
         
-            output=open("kato.dump","w")
-            pickle.dump(self,output)
-            output.close()
-            
\ No newline at end of file
+        self.saveClasses(classes);        
\ No newline at end of file

Added: incubator/kato/branches/experimental/PyJVMTI/kato/JClass.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/JClass.py?rev=774671&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/JClass.py (added)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/JClass.py Thu May 14 07:41:28 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.
+ #******************************************************************************"
+
+import jvmti
+
+class JClass(object):
+    '''
+    Representation of a loaded class
+    '''
+    classid=0
+    sig=None
+
+    def __init__(self,cid=0):
+        '''
+        Constructor
+        '''
+        self.classid=cid
+        self.fill()
+        
+    def fill(self):
+        if self.sig==None :
+          self.sig=jvmti.getClassSignature(self.classid)
+       
+    @property
+    def signature(self):
+        self.fill();
+        return self.sig[0]
+    
+    @property
+    def genericSignature(self):
+        self.fill();
+        return self.sig[1]
+    
\ No newline at end of file

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

Modified: incubator/kato/branches/experimental/PyJVMTI/kato/PauseJVM.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/PauseJVM.java?rev=774671&r1=774670&r2=774671&view=diff
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/PauseJVM.java (original)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/PauseJVM.java Thu May 14 07:41:28 2009
@@ -17,14 +17,16 @@
 
 public class PauseJVM {
 
+	private static int classint=100;
+	public static final int constantint=200;
 	/**
 	 * @param args
 	 */
 	public static void main(String[] args) {
 	
-		
+		long me=1000000;
 		try {
-			Thread.sleep(1000000);
+			Thread.sleep(me);
 		} catch (InterruptedException e) {
 
 			e.printStackTrace();

Added: incubator/kato/branches/experimental/PyJVMTI/kato/PrintDump.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/PrintDump.py?rev=774671&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/PrintDump.py (added)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/PrintDump.py Thu May 14 07:41:28 2009
@@ -0,0 +1,20 @@
+import kato.Dump as Dump
+
+class PrintDump(Dump.Dump):
+    
+     
+         
+     def saveThread(self,thread):
+        '''
+        Save a single Jthread
+        '''
+        print "saving " , thread.name
+        
+     def saveClass(self,clazz):
+        '''
+        Save a single JClass
+        '''
+        
+        print "saving " , clazz.signature
+        
+       
\ No newline at end of file

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

Added: incubator/kato/branches/experimental/PyJVMTI/kato/console.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/console.py?rev=774671&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/console.py (added)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/console.py Thu May 14 07:41:28 2009
@@ -0,0 +1,118 @@
+print "JVMTI Interactive Session started"
+
+import jvmti 
+#import kato.Dump as Dump
+from  kato.BinDump import BinDump
+saveclasses=False
+saveThreads=False
+
+
+class MyError(Exception):
+
+    def __init__(self, value):
+        self.value = value
+    def __str__(self):
+        return repr(self.value)
+
+def getSize(thread,depth,sig,slot):
+
+    if sig=="J" :
+        return 0
+    if sig=="I" :
+        return 0
+    try :   
+        value=jvmti.getLocalObject(thread,depth,slot) 
+        return jvmti.getObjectSize(value)
+    
+    except TypeError as (errno):
+        return -1
+        
+
+
+def getValue(thread,depth,sig,slot):
+    try :
+        if sig=="J" :
+            return jvmti.getLocalLong(thread,depth,slot)
+        if sig=="I" :
+            return jvmti.getLocalInt(thread,depth,slot)
+    
+        return jvmti.getLocalObject(thread,depth,slot)
+    
+    except TypeError as (errno):
+        return "don't know"
+    
+def save():
+    print "saving..."
+    print "save classes = ", saveclasses
+    print "save Threads = ", saveThreads
+    d=BinDump()
+    d.save()
+    
+    print "saved"
+
+def classes() :
+    print "list classes"
+    for foo in jvmti.getLoadedClasses() :
+        details=jvmti.getClassSignature(foo)
+        print "class id ",foo,details
+    
+    
+def saveAllThreads(output):
+    json.dump("threads",output)
+    threads=jvmti.getAllThreads() 
+    for thread in threads :
+        frame_count=jvmti.getFrameCount(thread)
+        json.dump([thread,frame_count],output)
+        depth=-1
+        for frame in jvmti.getStackTrace(thread,0,frame_count) :
+            depth=depth+1
+            methodName=jvmti.getMethodName(frame[0])
+            json.dump(methodName,output)
+            try :
+                for variable in jvmti.getLocalVariableTable(frame[0]):
+                    length=variable[1]
+                    name=variable[2]
+                    sig=variable[3]
+                    slot=variable[5]
+                    value=getValue(thread,depth,sig,slot)
+                    size=getSize(thread,depth,sig,slot)
+                    json.dump([depth,variable,value,size],output)
+                    
+            except TypeError as (errno):
+                    json.dump([depth,"n/a"],output) 
+       
+    
+def threads():
+    """
+        List all JVMTI Threads
+    """
+    print "list threads"
+    for foo in jvmti.getAllThreads() :
+        print "thread id ",foo
+        print "\t--- stack ----"
+        frame_count=jvmti.getFrameCount(foo)
+        depth=-1
+        for frame in jvmti.getStackTrace(foo,0,frame_count) :
+            depth=depth+1
+            methodName=jvmti.getMethodName(frame[0])
+            print  "\t" , depth,frame[0] ,methodName
+            try :
+                print "\t\t--- vars ----"
+                for variable in jvmti.getLocalVariableTable(frame[0]):
+                    #"iisssi",start,length, name,sig,generic,slot);
+                    length=variable[1]
+                    name=variable[2]
+                    sig=variable[3]
+                    slot=variable[5]
+                    
+                    value=getValue(foo,depth,sig,slot)
+                    size=getSize(foo,depth,sig,slot)
+                    print "\t\t" ,slot,sig,name,value,"size=",size
+                   
+                   
+                    
+            except TypeError as (errno):
+                print "\t\t error",errno 
+
+    
+ 
\ No newline at end of file

Propchange: incubator/kato/branches/experimental/PyJVMTI/kato/console.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=774671&r1=774670&r2=774671&view=diff
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c (original)
+++ incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c Thu May 14 07:41:28 2009
@@ -257,16 +257,45 @@
 	return result;
 }
 
+ /**
+  * Returns a list of loaded class ids
+  */
+ static PyObject *
+ jvmti_getLoadedClasses(PyObject *self, PyObject *args)
+ {
+
+ 	CHECK_VALID();
+
+ 	jint count=0;
+ 	jclass* classes=NULL;
+
+
+ 	jvmtiError err=(*jvmtiptr)->GetLoadedClasses(jvmtiptr,&count,&classes);
+
+ 	CHECK_OK("get all classes");
+
+ 	PyObject* list= PyList_New(count);
+
+ 		int i=0;
+
+
+ 		for( i=0;i<count;i++) {
+ 			PyList_SetItem(list,i,Py_BuildValue("i",classes[i]));
+ 		}
+
+
+ 	DEALLOC(classes);
+
+ 	return list;
+
+ }
+
  static PyObject *
 jvmti_getAllThreads(PyObject *self, PyObject *args)
 {
 
 	CHECK_VALID();
 
-	if(jniptr==NULL) {
-		 PyErr_SetString(PyExc_TypeError, "jni environment not present");
-					            return NULL;
-	}
 
 	jint count=0;
 	jthread* threads=NULL;
@@ -441,10 +470,39 @@
 }
 
 /**
+ * Get method bytecode
+ */
+static PyObject *
+jvmti_getBytecodes(PyObject *self, PyObject *args)
+{
+	CHECK_VALID();
+
+			int methodID=0;
+			jint size=0;
+			unsigned char* bytes=NULL;
+
+			PyArg_ParseTuple(args, "i", &methodID);
+
+			jmethodID method=(jmethodID)methodID;
+
+			jvmtiError err=(*jvmtiptr)->GetBytecodes(jvmtiptr,method,&size,&bytes);
+
+			CHECK_OK("Getbytecodes");
+
+
+			PyObject *value= Py_BuildValue("s",bytes);
+
+			DEALLOC(bytes);
+
+
+			return value;
+}
+/**
  * Get method name , signature and generic signature
  * returned as typle of strings
  */
 
+
 static PyObject *
 jvmti_getMethodName(PyObject *self, PyObject *args)
 {
@@ -475,6 +533,43 @@
 		return value;
 }
 
+/**
+ * Get class signature and generic signature
+ * returned as typle of strings
+ */
+
+static PyObject *
+jvmti_getClassSignature(PyObject *self, PyObject *args)
+{
+
+
+
+	CHECK_VALID();
+
+		int classID=0;
+
+		PyArg_ParseTuple(args, "i", &classID);
+
+		jclass class=(jclass)classID;
+
+
+		char  *sig=NULL;
+		char  *generic=NULL;
+
+		jvmtiError err=(*jvmtiptr)->GetClassSignature(jvmtiptr,class,&sig,&generic);
+
+		CHECK_OK("GetClassSignature");
+
+		PyObject *value= Py_BuildValue("ss",sig,generic);
+
+		DEALLOC(sig);
+		DEALLOC(generic);
+
+		return value;
+}
+
+
+
 static PyObject *
 jvmti_getLocalVariableTable(PyObject *self, PyObject *args)
 {
@@ -495,6 +590,14 @@
 
 		jvmtiError err=(*jvmtiptr)->GetLocalVariableTable(jvmtiptr,method,&countj,&entries);
 
+		/*
+		if(err==JVMTI_ERROR_NATIVE_METHOD) {
+			return Py_BuildValue("is",err,"native method");
+		}
+		if(err==JVMTI_ERROR_ABSENT_INFORMATION) {
+					return Py_BuildValue("is",err,"missing");
+		}
+	*/
 		CHECK_OK("GetLocalVariableTable");
 
 		// turn table into python data...
@@ -525,6 +628,31 @@
 		return list;
 }
 
+/**
+ * Returns the size of the object
+ */
+static PyObject *  jvmti_getObjectSize(PyObject *self, PyObject *args) {
+
+	CHECK_VALID();
+
+		// get required object
+		int objectID=0;
+
+		PyArg_ParseTuple(args, "i", &objectID);
+
+		jobject object=(jobject)objectID;
+		jlong size=0;
+
+		jvmtiError err=(*jvmtiptr)->GetObjectSize(jvmtiptr,object,&size);
+
+		CHECK_OK("get Object Size");
+
+		 return Py_BuildValue("i", size);
+
+
+}
+
+
 static PyMethodDef  JvmtiMethods[] = {
 
      {"getTime",              jvmti_gettime, METH_VARARGS,             "Get JVMTI Time."},
@@ -542,6 +670,10 @@
      {"getLocalLong",         jvmti_getLocalLong, METH_VARARGS,        "Get Local Long."},
      {"getMethodName",        jvmti_getMethodName, METH_VARARGS,      "Get method name and
sig."},
      {"getLocalVariableTable",jvmti_getLocalVariableTable, METH_VARARGS,"Get Local Variable
Table."},
+     {"getObjectSize",        jvmti_getObjectSize, METH_VARARGS,       "Get Object Size"},
+     {"getLoadedClasses",     jvmti_getLoadedClasses, METH_VARARGS,    "Get Loaded Classes."},
+     {"getClassSignature",    jvmti_getClassSignature, METH_VARARGS,   "Get Class Signature."},
+
     {NULL, NULL, 0, NULL}        /* Sentinel */
 };
 
@@ -615,6 +747,7 @@
 
 }
 
+
 JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm) {
 
 		report("unloaded");

Modified: incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h?rev=774671&r1=774670&r2=774671&view=diff
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h (original)
+++ incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h Thu May 14 07:41:28 2009
@@ -53,9 +53,14 @@
 static PyObject *jvmti_getsystemproperties(PyObject *self, PyObject *args);
 static PyObject *jvmti_gettime(PyObject *self, PyObject *args);
 static PyObject *jvmti_getTopThreadGroups(PyObject *self, PyObject *args);
-static PyObject *  jvmti_getThreadGroupInfo(PyObject *self, PyObject *args);
-static PyObject *  jvmti_getFrameCount(PyObject *self, PyObject *args);
-static PyObject *  jvmti_getStackTrace(PyObject *self, PyObject *args);
+static PyObject *jvmti_getThreadGroupInfo(PyObject *self, PyObject *args);
+static PyObject *jvmti_getFrameCount(PyObject *self, PyObject *args);
+static PyObject *jvmti_getStackTrace(PyObject *self, PyObject *args);
+static PyObject *jvmti_getBytecodes(PyObject *self, PyObject *args);
+static PyObject *jvmti_getLocalLong(PyObject *self, PyObject *args);
+static PyObject *jvmti_getLocalInt(PyObject *self, PyObject *args);
+static PyObject *jvmti_getLocalObject(PyObject *self, PyObject *args);
+
 void runScript(void);
 void startPython(void);
 void createObject(JNIEnv *env);

Modified: incubator/kato/branches/experimental/PyJVMTI/run.sh
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/run.sh?rev=774671&r1=774670&r2=774671&view=diff
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/run.sh (original)
+++ incubator/kato/branches/experimental/PyJVMTI/run.sh Thu May 14 07:41:28 2009
@@ -1,5 +1,5 @@
 export LD_PRELOAD=/usr/lib/python2.6/config/libpython2.6.so
 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./build/lib.linux-i686-2.6:/usr/lib/python2.6:/usr/lib/python2.6/config
-#export PYTHONSTARTUP=./build/lib.linux-i686-2.6/kato/Dump.py
+export PYTHONSTARTUP=./build/lib.linux-i686-2.6/kato/console.py
 export PYTHONPATH=$PYTHONPATH:.
 /home/spoole/javasdks/sun/jdk1.6.0_12/bin/java   -agentlib:pyjvmti  -cp .  kato.PauseJVM



Mime
View raw message