incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spo...@apache.org
Subject svn commit: r779929 - in /incubator/kato/branches/experimental/PyJVMTI: build.xml init.py kato/BinDump.py pyjvmti.c pyjvmti.h run.sh tomcat.sh
Date Fri, 29 May 2009 11:05:54 GMT
Author: spoole
Date: Fri May 29 11:05:53 2009
New Revision: 779929

URL: http://svn.apache.org/viewvc?rev=779929&view=rev
Log:
intermediate updates to python jvmti experimental project to allow dump to be created on a
index out of bounds exception

Added:
    incubator/kato/branches/experimental/PyJVMTI/build.xml
    incubator/kato/branches/experimental/PyJVMTI/init.py
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/branches/experimental/PyJVMTI/run.sh
    incubator/kato/branches/experimental/PyJVMTI/tomcat.sh

Added: incubator/kato/branches/experimental/PyJVMTI/build.xml
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/build.xml?rev=779929&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/build.xml (added)
+++ incubator/kato/branches/experimental/PyJVMTI/build.xml Fri May 29 11:05:53 2009
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ====================================================================== 
+     28 May 2009 17:22:02                                                        
+
+	 Ant script to build python jvmti modules  
+                   
+                                                        
+     ====================================================================== -->
+<project name="pyjvmti" default="default">
+
+
+	<target name="default">
+		
+		
+		<javac debug="true" srcdir="." />
+
+			
+		<exec executable="python">
+			<env key="DIRS" value="${DIRS}"/>
+			<arg value="-u" />
+			<arg value="setup.py" />
+			<arg value="build" />
+			
+		</exec>
+
+
+	</target>
+
+
+</project>

Added: incubator/kato/branches/experimental/PyJVMTI/init.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/init.py?rev=779929&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/init.py (added)
+++ incubator/kato/branches/experimental/PyJVMTI/init.py Fri May 29 11:05:53 2009
@@ -0,0 +1,41 @@
+#
+# Initiation file called by pyjvmti to set callback for filtering exceptions
+#
+#
+import jvmti
+import kato.console as console
+from kato.JMethod import JMethod
+from kato.JClass import JClass
+
+def exceptionFilter(vm,env,thread,method,location,exception,catch_method,catch_location):
+    
+    #phase=jvmti.getPhase()
+    #print "phase %d  " % phase
+    #print "vm=%d env=%d thread=%d method=%d location=%d exception=%d catch=%d loc=%d" %
(vm,env,thread,method,location,exception,catch_method,catch_location)
+    
+    
+
+    if exception != 0 :
+        classid=jvmti.getObjectClass(exception);
+        clazz=JClass(classid)
+        if clazz.signature=="Ljava/lang/ArrayIndexOutOfBoundsException;" :
+            print("OOB"*20) 
+            console.save()
+    return
+        
+    if method != 0 :
+        print "method=" , method
+        m=JMethod(method);
+        print "method=" , m.name
+    else :
+        print "?"
+        
+    print "done"
+    
+def e2() :
+    print "in an empty"
+
+jvmti.registerExceptionFilter(exceptionFilter)
+
+
+

Modified: incubator/kato/branches/experimental/PyJVMTI/kato/BinDump.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/BinDump.py?rev=779929&r1=779928&r2=779929&view=diff
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/BinDump.py (original)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/BinDump.py Fri May 29 11:05:53 2009
@@ -25,6 +25,7 @@
     reporttrace=True
     tracedepth=1
     missingobjects=0
+    variables_saved=0
     
     def open(self): 
         self.traceEntry("open")
@@ -41,7 +42,7 @@
         do clean up processing 
         '''
         self.output.close()
-        self.traceExit("close (missing objects = %d)" % self.missingobjects)
+        self.traceExit("close (vars=%d missing objects = %d)" % (self.variables_saved,self.missingobjects))
   
     def startThreadSave(self,count):
         
@@ -252,7 +253,7 @@
           header=struct.pack("!hi",501,entry.slot)
           self.output.write(header)
           signature=entry.signature
-          
+          self.variables_saved+=1
           self.trace("saving %s variable at %d " % (signature,entry.slot))
 
           try :
@@ -489,7 +490,7 @@
            vartable=m.localVariableTable
            tablesize=len(vartable)
            
-           self.trace("save method %s" % m.name);
+           self.trace("save method %s %s" % (clazz.signature, m.name));
            
            header=struct.pack("!hiiiiii",204,methodid,m.modifiers,m.maxlocals,m.argumentsize,m.isnative,tablesize)
            self.output.write(header)
@@ -517,14 +518,14 @@
     def traceEntry(self,msg):
         if self.reporttrace :
              self.tracedepth+=1
-             print "."*self.tracedepth , msg
+             print "%d %s %s" % (self.tracedepth,'.'*self.tracedepth , msg)
                     
     def traceExit(self,msg):
         if self.reporttrace :
-             print "."*self.tracedepth , msg       
+             print "%d %s %s" % (self.tracedepth,'.'*self.tracedepth , msg)       
              self.tracedepth-=1
              
     def trace(self,msg):
         if self.reporttrace :
-             print "."*self.tracedepth , msg       
+             print "%d %s %s" % (self.tracedepth,'.'*self.tracedepth , msg)       
          
\ No newline at end of file

Modified: incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c?rev=779929&r1=779928&r2=779929&view=diff
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c (original)
+++ incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c Fri May 29 11:05:53 2009
@@ -20,12 +20,72 @@
 
 static char *scriptname=NULL;
 static jvmtiEnv *jvmtiptr = NULL;
+static jvmtiEnv *oldjvmtiptr = NULL;
 static JavaVM *vmptr=NULL;
 static JNIEnv *jniptr=NULL;
+static JNIEnv *oldjniptr=NULL;
 static PyObject *PYJVMTIError;
 static int objectcounter=0;
 static PyObject *my_callback = NULL;
+static PyObject *exception_callback = NULL;
+static jrawMonitorID lock=NULL;
 
+static void enterLock(jvmtiEnv *jvmti)
+
+{
+
+     jvmtiError error;
+
+     error = (*jvmti)->RawMonitorEnter(jvmti, lock);
+     if(error!=JNI_OK) {
+    	 printf("can't lock");
+     }
+
+     oldjvmtiptr=jvmtiptr;
+     jvmtiptr=jvmti;
+     oldjniptr=jniptr;
+
+     jint rc = (*vmptr)->GetEnv(vmptr, (void **)&jniptr, JNI_VERSION_1_6);
+
+     		  	if (rc != JNI_OK) {
+     		  		report("unable to load jni environment");
+     		  		return rc;
+     		 	}
+
+
+}
+
+
+
+static void exitLock(jvmtiEnv *jvmti)
+
+{
+
+    jvmtiError error;
+    jvmtiptr=oldjvmtiptr;
+    jniptr=oldjniptr;
+    error = (*jvmti)->RawMonitorExit(jvmti, lock);
+    if(error!=JNI_OK) {
+        	 printf("can't un lock");
+         }
+
+
+}
+static PyObject *  jvmti_getPhase(PyObject *self, PyObject *args) {
+
+	CHECK_VALID();
+
+	jvmtiPhase phase;
+
+	jvmtiError err=(*jvmtiptr)->GetPhase(jvmtiptr,&phase);
+
+	CHECK_OK("get phase");
+
+	int result=phase;
+	return Py_BuildValue("i", result);
+
+
+}
 JNICALL myjvmtiHeapObjectCallback(jlong class_tag,
      jlong size,
      jlong* tag_ptr,
@@ -33,6 +93,59 @@
 	printf("called...");
 }
 
+static void JNICALL myVMInit(jvmtiEnv *jvmtiptr, JNIEnv *jni, jthread thread)
+{
+
+    jvmtiError  err = (*jvmtiptr)->SetEventNotificationMode(jvmtiptr, JVMTI_ENABLE,
+	    		 JVMTI_EVENT_EXCEPTION,
+	                         (jthread)NULL);
+
+	    if(err!=JNI_OK) {
+			printf("can't set event exception");
+		}
+		else {
+			printf("\n\n\nVMINIT\n\n\n");
+		}
+
+
+
+}
+
+static void JNICALL myjvmtiEventException(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread threadj,
jmethodID methodj,
+   jlocation locationj, jobject exceptionj, jmethodID catch_methodj,
+   jlocation catch_locationj) {
+
+
+	if(exception_callback == NULL) return; // nothing to call
+
+	enterLock(jvmti_env);
+
+
+	PyObject *arglist=NULL;
+	PyObject *result=NULL;
+
+	long thread=threadj;
+	long method=methodj;
+	long location=locationj;
+	long exception=exceptionj;
+	long catch_method=catch_methodj;
+	long catch_location=locationj;
+
+	arglist = Py_BuildValue("(llllllll)",vmptr,jvmti_env,thread,method,location,exception,catch_method,catch_location);
+	result = PyObject_CallObject(exception_callback, arglist);
+	if(PyErr_Occurred()) {
+		PyErr_Print();
+		PyErr_Clear();
+	}
+
+ 	Py_DECREF(arglist);
+	if (result != NULL) {
+		Py_DECREF(result);
+
+	}
+
+	exitLock(jvmti_env);
+}
 
 static jvmtiIterationControl JNICALL
 object_ref_callback(jvmtiObjectReferenceKind reference_kind,
@@ -194,6 +307,7 @@
 
 		return result;
 }
+
 static PyObject *  jvmti_getArrayLength(PyObject *self, PyObject *args) {
 
 	CHECK_VALID();
@@ -239,6 +353,33 @@
 	getArray(Double,jdouble,double,"d")
 }
 
+static PyObject *  jvmti_registerExceptionFilter(PyObject *self, PyObject *args) {
+
+	CHECK_VALID();
+	PyObject *temp=NULL;
+    PyObject *result = NULL;
+
+    if (PyArg_ParseTuple(args, "O", &temp)) {
+			printf("\ntemp=%p\n",temp);
+	        if (!PyCallable_Check(temp)) {
+	            PyErr_SetString(PyExc_TypeError, "parameter must be callable");
+	            return NULL;
+	        }
+	        Py_XINCREF(temp);         /* Add a reference to new callback */
+	        if(exception_callback!=NULL) Py_XDECREF(exception_callback);  /* Dispose of previous
callback */
+	        exception_callback = temp;       /* Remember new callback */
+	        /* Boilerplate to return "None" */
+	        Py_INCREF(Py_None);
+	        result = Py_None;
+	        return result;
+    }
+    else {
+        PyErr_SetString(PyExc_TypeError, "can't get exception function");
+        return NULL;
+    }
+
+}
+
 static PyObject *  jvmti_iterateOverReachableObjects(PyObject *self, PyObject *args) {
 
 	CHECK_VALID();
@@ -609,6 +750,23 @@
 
     return Py_BuildValue("i", result);
 }
+static PyObject *
+jvmti_getObjectClass(PyObject *self, PyObject *args)
+{
+
+
+CHECK_VALID();
+
+	int objid=0;
+	PyArg_ParseTuple(args, "i", &objid);
+
+	jobject objectj=objid;
+
+	jclass result=(*jniptr)->GetObjectClass(jniptr,objectj);
+
+    return Py_BuildValue("i", result);
+
+}
 
 static PyObject *
 jvmti_gettime(PyObject *self, PyObject *args)
@@ -1044,6 +1202,7 @@
      {"getClassLoaderClasses",jvmti_getClassLoaderClasses, METH_VARARGS,   "Get ClassLoader
classes"},
      {"getImplementedInterfaces", jvmti_getImplementedInterfaces, METH_VARARGS,   "Get Implemented
Interfaces."},
      {"getSuperClass",        jvmti_getSuperClass, METH_VARARGS,   "Get Superclass."},
+     {"getObjectClass",       jvmti_getObjectClass, METH_VARARGS,   "Get Object Class."},
      {"getClassLoader",       jvmti_getClassLoader, METH_VARARGS,   "Get Class Loader."},
      {"getFieldName",         jvmti_getFieldName, METH_VARARGS,   "Get Field Name."},
      {"getMethodModifiers",   jvmti_getMethodModifiers, METH_VARARGS,   "Get Method Modifiers."},
@@ -1058,6 +1217,9 @@
      {"getLongArrayElements", jvmti_getLongArrayElements, METH_VARARGS,   "Get Long Array
Elements"},
      {"getFloatArrayElements",jvmti_getFloatArrayElements, METH_VARARGS,   "Get Float Array
Elements"},
      {"getDoubleArrayElements",jvmti_getDoubleArrayElements, METH_VARARGS,   "Get Double
Array Elements"},
+     {"registerExceptionFilter",jvmti_registerExceptionFilter, METH_VARARGS,   "Register
cllback for exception events"},
+     {"getPhase",              jvmti_getPhase, METH_VARARGS,   "Get JVMTI Phase"},
+
      {"iterateOverReachableObjects",       jvmti_iterateOverReachableObjects, METH_VARARGS,
  "Iterate over reachable objects"},
 
 
@@ -1107,34 +1269,26 @@
 
 void exec_interactive_interpreter(int argc, char** argv)
   {
-		printf("\ninit");
-		 Py_Initialize();
 
-		 /* Add a static module */
-		    initjvmti();
 
-		 if(scriptname!=NULL) {
-			 runScript();
-		 }
-		 else {
-		 printf("\nmain\n");
+
 		 Py_Main(argc, argv);
-		 }
-		 printf("\nclose");
+
+
 		 Py_Finalize();
 
 	}
 
 
-void runScript() {
+void runScript(char *script) {
 
-		printf("running script %s",scriptname);
+		printf("\nrunning script %s\n",script);
 
 		 // Python code in separate environments
-		 FILE* file_1 = fopen(scriptname, "r");
-		 PyRun_SimpleFile(file_1, scriptname);
+		 FILE* fd = fopen(script, "r");
+		 PyRun_SimpleFile(fd, script);
 
-		 fclose(file_1);
+		 fclose(fd);
 
 
 
@@ -1194,18 +1348,42 @@
 	    	return rc;
 	 	}
 
+		// initialise Python
+
+		Py_Initialize();
+
+		/* Add a static module */
+		 initjvmti();
+
+		// call init script if present
+		printf("\nscript options=%s",options);
+
+		if(options!=NULL) runScript(options);
 
 	    jvmtiEventCallbacks callbacks;
 
 	    memset(&callbacks, 0, sizeof(callbacks));
 	    callbacks.DataDumpRequest = &dataDumpRequest;
+	    callbacks.Exception = &myjvmtiEventException;
+		callbacks.VMInit = &myVMInit;
+
 	    jvmtiError       err = (*jvmtiptr)->SetEventCallbacks(jvmtiptr, &callbacks, sizeof(callbacks));
 
 	    err = (*jvmtiptr)->SetEventNotificationMode(jvmtiptr, JVMTI_ENABLE,
 	    		 JVMTI_EVENT_DATA_DUMP_REQUEST,
 	                         (jthread)NULL);
 
-	    CHECK_OK("unable to set callback");
+	    CHECK_OK("unable to set dump request callback");
+
+	    err = (*jvmtiptr)->SetEventNotificationMode(jvmtiptr, JVMTI_ENABLE,
+	    		 JVMTI_EVENT_VM_INIT,
+	                        (jthread)NULL);
+		if(err!=JNI_OK) {
+			printf("can't set vm init event exception");
+		}
+
+	    //CHECK_OK("unable to set exception callback");
+
 
 	    // turn on required capabilities
 
@@ -1216,14 +1394,16 @@
 	     caps.can_get_current_contended_monitor=1;
 	     caps.can_access_local_variables=1;
 	     caps.can_tag_objects=1;
+	     caps.can_generate_exception_events = 1;
 
 	    err=(*jvmtiptr)->AddCapabilities(jvmtiptr, &caps);
 
 	    WARN("can't turn on required capabilites\n");
 
 	    report("dumprequest agent registered\n");
-	    scriptname=options;
-	    report(scriptname);
+
+	    err = (*jvmtiptr)->CreateRawMonitor(jvmtiptr, "cbmonitor", &lock);
+	    WARN("can't create monitor");
 
     return JNI_OK;
 }

Modified: incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h?rev=779929&r1=779928&r2=779929&view=diff
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h (original)
+++ incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h Fri May 29 11:05:53 2009
@@ -53,13 +53,13 @@
 
 PyMODINIT_FUNC initjvmti(void);
 
-static PyObject *  jvmti_getIntArrayElements(PyObject *self, PyObject *args);
-static PyObject *  jvmti_getByteArrayElements(PyObject *self, PyObject *args);
-static PyObject *  jvmti_getCharArrayElements(PyObject *self, PyObject *args);
-static PyObject *  jvmti_getShortArrayElements(PyObject *self, PyObject *args);
-static PyObject *  jvmti_getLongArrayElements(PyObject *self, PyObject *args);
-static PyObject *  jvmti_getFloatArrayElements(PyObject *self, PyObject *args);
-static PyObject *  jvmti_getDoubleArrayElements(PyObject *self, PyObject *args);
+static PyObject *jvmti_getIntArrayElements(PyObject *self, PyObject *args);
+static PyObject *jvmti_getByteArrayElements(PyObject *self, PyObject *args);
+static PyObject *jvmti_getCharArrayElements(PyObject *self, PyObject *args);
+static PyObject *jvmti_getShortArrayElements(PyObject *self, PyObject *args);
+static PyObject *jvmti_getLongArrayElements(PyObject *self, PyObject *args);
+static PyObject *jvmti_getFloatArrayElements(PyObject *self, PyObject *args);
+static PyObject *jvmti_getDoubleArrayElements(PyObject *self, PyObject *args);
 static PyObject *jvmti_getIntArrayElements(PyObject *self, PyObject *args);
 static PyObject *jvmti_getArrayLength(PyObject *self, PyObject *args);
 static PyObject *jvmti_getThread(PyObject *self, PyObject *args);
@@ -90,7 +90,10 @@
 static PyObject *jvmti_isMethodNative(PyObject *self, PyObject *args);
 static PyObject *jvmti_iterateOverReachableObjects(PyObject *self, PyObject *args);
 static PyObject *jvmti_getLocalValue(PyObject *self, PyObject *args);
-void runScript(void);
+static PyObject *jvmti_getObjectClass(PyObject *self, PyObject *args);
+static PyObject *  jvmti_getPhase(PyObject *self, PyObject *args);
+
+void runScript(char *);
 void startPython(void);
 void createObject(JNIEnv *env);
 static char * getErrorMessage(jvmtiError err,char *usrmsg);

Modified: incubator/kato/branches/experimental/PyJVMTI/run.sh
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/run.sh?rev=779929&r1=779928&r2=779929&view=diff
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/run.sh (original)
+++ incubator/kato/branches/experimental/PyJVMTI/run.sh Fri May 29 11:05:53 2009
@@ -2,4 +2,4 @@
 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/console.py
 export PYTHONPATH=$PYTHONPATH:.
-/home/spoole/javasdks/sun/jdk1.6.0_12/bin/java   -agentlib:pyjvmti  -cp .  kato.PauseJVM
+/home/spoole/javasdks/sun/jdk1.6.0_12/bin/java   -agentlib:pyjvmti=init.py  -cp .  kato.PauseJVM

Modified: incubator/kato/branches/experimental/PyJVMTI/tomcat.sh
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/tomcat.sh?rev=779929&r1=779928&r2=779929&view=diff
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/tomcat.sh (original)
+++ incubator/kato/branches/experimental/PyJVMTI/tomcat.sh Fri May 29 11:05:53 2009
@@ -2,4 +2,4 @@
 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/console.py
 export PYTHONPATH=$PYTHONPATH:.
-/home/spoole/javasdks/sun/jdk1.6.0_12/bin/java -Dcatalina.base=/home/spoole/workspace-maven/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
-Dcatalina.home=/usr/share/tomcat5.5 -Dwtp.deploy=/home/spoole/workspace-maven/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
-Djava.endorsed.dirs=/usr/share/tomcat5.5/common/endorsed  -Dfile.encoding=UTF-8 -agentlib:pyjvmti
-classpath /usr/share/tomcat5.5/bin/bootstrap.jar:/home/spoole/javasdks/sun/jdk1.6.0_12/lib/tools.jar
org.apache.catalina.startup.Bootstrap start
+/home/spoole/javasdks/sun/jdk1.6.0_12/bin/java -Dcatalina.base=/home/spoole/workspace-maven/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
-Dcatalina.home=/usr/share/tomcat5.5 -Dwtp.deploy=/home/spoole/workspace-maven/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
-Djava.endorsed.dirs=/usr/share/tomcat5.5/common/endorsed  -Dfile.encoding=UTF-8 -agentlib:pyjvmti=init.py
-classpath /usr/share/tomcat5.5/bin/bootstrap.jar:/home/spoole/javasdks/sun/jdk1.6.0_12/lib/tools.jar
org.apache.catalina.startup.Bootstrap start



Mime
View raw message