incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spo...@apache.org
Subject svn commit: r772117 - in /incubator/kato/branches/experimental/PyJVMTI: .project README.TXT build.sh kato/ kato/Dump.py kato/JClassLoader.py kato/JThread.py kato/JThreadGroup.py kato/PauseJVM.java kato/__init__.py pyjvmti.c pyjvmti.h run.sh setup.py
Date Wed, 06 May 2009 09:41:53 GMT
Author: spoole
Date: Wed May  6 09:41:52 2009
New Revision: 772117

URL: http://svn.apache.org/viewvc?rev=772117&view=rev
Log:
first drop of experimental python frontend to jvmti

Added:
    incubator/kato/branches/experimental/PyJVMTI/.project   (with props)
    incubator/kato/branches/experimental/PyJVMTI/README.TXT
    incubator/kato/branches/experimental/PyJVMTI/build.sh   (with props)
    incubator/kato/branches/experimental/PyJVMTI/kato/
    incubator/kato/branches/experimental/PyJVMTI/kato/Dump.py   (with props)
    incubator/kato/branches/experimental/PyJVMTI/kato/JClassLoader.py   (with props)
    incubator/kato/branches/experimental/PyJVMTI/kato/JThread.py   (with props)
    incubator/kato/branches/experimental/PyJVMTI/kato/JThreadGroup.py   (with props)
    incubator/kato/branches/experimental/PyJVMTI/kato/PauseJVM.java   (with props)
    incubator/kato/branches/experimental/PyJVMTI/kato/__init__.py   (with props)
    incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c   (with props)
    incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h   (with props)
    incubator/kato/branches/experimental/PyJVMTI/run.sh   (with props)
    incubator/kato/branches/experimental/PyJVMTI/setup.py   (with props)

Added: incubator/kato/branches/experimental/PyJVMTI/.project
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/.project?rev=772117&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/.project (added)
+++ incubator/kato/branches/experimental/PyJVMTI/.project Wed May  6 09:41:52 2009
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>PyJVMTI</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+	</buildSpec>
+	<natures>
+	</natures>
+</projectDescription>

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

Added: incubator/kato/branches/experimental/PyJVMTI/README.TXT
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/README.TXT?rev=772117&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/README.TXT (added)
+++ incubator/kato/branches/experimental/PyJVMTI/README.TXT Wed May  6 09:41:52 2009
@@ -0,0 +1,27 @@
+This is an experimental project looking at using python and a jvmti extention to create a
jvmti agent.
+This agent should be able to provide basic jvmti interactions from a python console AND
+be able to produce a dump that can be read elsewhere.   Probably using python pickle to do
all
+the work.   FInally, the unpickled file needs somehow to be fronted by the Kato JavaRuntime
API
+
+To build and run:
+
+Dependencies 
+
+python 2,6  
+Sun Java 6 SDK
+gcc
+
+Steps:
+
+1 - Update setup.py to point to your Java sdk include directories
+2 - run build.sh from the PyJVMTI directory to compile and build the java and c code.
+
+3 - run the run.sh script to launch and pause a JVM with the agent attached.
+4 - Initiate a dump  ( ctl-\ on linux)  and you should drop into a python interactive shell
+5 - try the following...
+
+d=Dump()
+d.getThreads()
+
+
+

Added: incubator/kato/branches/experimental/PyJVMTI/build.sh
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/build.sh?rev=772117&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/build.sh (added)
+++ incubator/kato/branches/experimental/PyJVMTI/build.sh Wed May  6 09:41:52 2009
@@ -0,0 +1,3 @@
+javac ./kato/PauseJVM.java
+python -u ./setup.py build
+

Propchange: incubator/kato/branches/experimental/PyJVMTI/build.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/kato/branches/experimental/PyJVMTI/kato/Dump.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/Dump.py?rev=772117&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/Dump.py (added)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/Dump.py Wed May  6 09:41:52 2009
@@ -0,0 +1,68 @@
+
+#*******************************************************************************
+ #* 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.
+ #******************************************************************************"
+
+
+'''
+Created on 2 May 2009
+
+'''
+import jvmti
+import kato.JThread as JThread
+
+class Dump(object):
+    '''
+    classdocs
+    '''
+    
+
+    def __init__(selfparams):
+        '''
+        Constructor
+        '''
+        
+    
+    def getThreads(self):
+        '''
+        List Threads
+        '''  
+        
+        results=[ ]
+        
+        for t in jvmti.getAllThreads() :
+            q=JThread.JThread(t)
+            results.append(q) 
+            
+        return results
+    
+    def properties(self):
+        '''
+        List system properties
+        '''
+        print "listing properties"
+        for k, v in jvmti.getsystemproperties().iteritems():
+            print k,"=", v
+
+    @property
+    def threads(self):
+        '''
+        List system properties
+        '''
+        print "listing properties"
+        for k in jvmti.getAllThreads():
+            print k ,  jvmti.getThread(k)
+    
+        
+        
+        
\ No newline at end of file

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

Added: incubator/kato/branches/experimental/PyJVMTI/kato/JClassLoader.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/JClassLoader.py?rev=772117&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/JClassLoader.py (added)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/JClassLoader.py Wed May  6 09:41:52
2009
@@ -0,0 +1,20 @@
+#*******************************************************************************
+ #* 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.
+ #******************************************************************************"
+
+class JClassLoader(object):
+    
+    def __init__(self,loader=0):
+        '''
+        Constructor
+        '''
\ No newline at end of file

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

Added: incubator/kato/branches/experimental/PyJVMTI/kato/JThread.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/JThread.py?rev=772117&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/JThread.py (added)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/JThread.py Wed May  6 09:41:52 2009
@@ -0,0 +1,67 @@
+#*******************************************************************************
+ #* 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
+'''
+Created on 2 May 2009
+
+'''
+
+class JThread(object):
+    '''
+    classdocs
+    '''
+    info=None
+    threadid=0;
+    
+    def __init__(self,tid=0):
+        '''
+        Constructor
+        '''
+        self.threadid=tid
+    def fill(self):
+        if self.info==None :
+            self.info=jvmti.getThread(self.threadid);
+
+    @property
+    def name(self):
+        self.fill()
+        return self.info[0]
+    
+    @property
+    def priority(self):
+        self.fill()
+        return self.info[1]
+    
+    @property
+    def isDaemon(self):
+        self.fill()
+        return self.info[2]
+    
+    @property
+    def threadGroup(self):
+        self.fill()
+        return JThreadGroup(self.info[3])
+    
+    @property
+    def  contextClassLoader(self):
+        self.fill()
+        if self.info[4]==None:
+            return None
+        
+        return JClassLoader(self.info[4])                         
+    
+    def __repr__(self):
+        return "JThread id=%i name=%s" % (self.threadid , self.name)
+        
\ No newline at end of file

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

Added: incubator/kato/branches/experimental/PyJVMTI/kato/JThreadGroup.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/JThreadGroup.py?rev=772117&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/JThreadGroup.py (added)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/JThreadGroup.py Wed May  6 09:41:52
2009
@@ -0,0 +1,23 @@
+#*******************************************************************************
+ #* 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 JThreadGroup(object):
+    
+    def __init__(self,threadid=0):
+        '''
+        Constructor
+        '''
+        info=jvmti.getThreadInfo(threadid);
\ No newline at end of file

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

Added: incubator/kato/branches/experimental/PyJVMTI/kato/PauseJVM.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/PauseJVM.java?rev=772117&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/PauseJVM.java (added)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/PauseJVM.java Wed May  6 09:41:52 2009
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
+
+package kato;
+
+
+public class PauseJVM {
+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+	
+		
+		try {
+			Thread.sleep(1000000);
+		} catch (InterruptedException e) {
+
+			e.printStackTrace();
+		}
+		
+
+	}
+
+}

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

Added: incubator/kato/branches/experimental/PyJVMTI/kato/__init__.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/__init__.py?rev=772117&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/kato/__init__.py (added)
+++ incubator/kato/branches/experimental/PyJVMTI/kato/__init__.py Wed May  6 09:41:52 2009
@@ -0,0 +1 @@
+print "in init for org.kato.jvmti"
\ No newline at end of file

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

Added: incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c?rev=772117&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c (added)
+++ incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c Wed May  6 09:41:52 2009
@@ -0,0 +1,503 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
+
+#include <Python.h>
+#include "jni.h"
+#include "jvmti.h"
+#include "pyjvmti.h"
+
+
+static char *scriptname=NULL;
+static jvmtiEnv *jvmtiptr = NULL;
+static JavaVM *vmptr=NULL;
+static JNIEnv *jniptr=NULL;
+
+
+
+static char * getErrorMessage(jvmtiError err,char *usrmsg) {
+
+		char *msg=NULL;
+		if(jvmtiptr==NULL) {
+				msg="UNABLE TO RESOLVE";
+		}
+		else {
+		jvmtiError e=(*jvmtiptr)->GetErrorName(jvmtiptr,err,&msg);
+		if(e!=JNI_OK) msg="unknown message";
+		}
+
+		int length=strlen(msg)+50+strlen(usrmsg);
+		char *result=malloc(length);
+
+		sprintf(result,"failed %s (%i) %s",usrmsg,err,msg);
+
+		return result;
+}
+
+
+static PyObject *  jvmti_getStackTrace(PyObject *self, PyObject *args) {
+
+
+			int threadID=0;
+			int start_depth=0;
+			int max_frame_count=0;
+
+			PyArg_ParseTuple(args, "iii", &threadID,&start_depth,&max_frame_count);
+
+			jthread thread=(jthread)threadID;
+			jint count=0;
+			jint jstart=start_depth;
+			jint jmax=max_frame_count;
+
+			if(max_frame_count<1) max_frame_count=1;
+
+			jvmtiFrameInfo *info=malloc(sizeof(jvmtiFrameInfo)*max_frame_count);
+
+
+	jvmtiError err=(*jvmtiptr)->GetStackTrace(jvmtiptr,thread,jstart,jmax,info,&count);
+
+
+	CHECK_OK("get  stack trace")
+
+
+
+	PyObject* list= PyList_New(count);
+
+			int i=0;
+			for( i=0;i<count;i++) {
+				PyList_SetItem(list,i,Py_BuildValue("ii",info[i].method,info[i].location));
+			}
+
+			free(info);
+	return list;
+
+}
+
+static PyObject *  jvmti_getFrameCount(PyObject *self, PyObject *args) {
+
+	CHECK_VALID()
+
+		// get required thread...
+		int threadID=0;
+
+		PyArg_ParseTuple(args, "i", &threadID);
+
+		jthread thread=(jthread)threadID;
+		jint count=0;
+
+		jvmtiError err=(*jvmtiptr)->GetFrameCount(jvmtiptr,thread,&count);
+
+		CHECK_OK("get  frame count")
+
+		 return Py_BuildValue("i", count);
+
+
+}
+
+static PyObject *  jvmti_getOwnedMonitorInfo(PyObject *self, PyObject *args) {
+
+	CHECK_VALID()
+
+		// get required thread...
+		int threadID=0;
+
+		PyArg_ParseTuple(args, "i", &threadID);
+
+		jthread thread=(jthread)threadID;
+		jint count=0;
+		jobject *monitors=NULL;
+
+		jvmtiError err=(*jvmtiptr)->GetOwnedMonitorInfo(jvmtiptr,thread,&count,&monitors);
+
+		CHECK_OK("get  owned monitor info")
+
+		PyObject* list= PyList_New(count);
+
+			int i=0;
+			for( i=0;i<count;i++) {
+				PyList_SetItem(list,i,Py_BuildValue("i",monitors[i]));
+			}
+
+
+		DEALLOC(monitors); // allocated by jvmti
+
+		return list;
+}
+
+static PyObject *  jvmti_getThreadGroupInfo(PyObject *self, PyObject *args) {
+
+	CHECK_VALID()
+
+		// get required threadgroup
+		int ID=0;
+
+		PyArg_ParseTuple(args, "i", &ID);
+
+		jvmtiThreadGroupInfo info;
+		jthreadGroup threadGroup=(jthreadGroup)ID;
+
+
+		jvmtiError err=(*jvmtiptr)->GetThreadGroupInfo(jvmtiptr,threadGroup,&info);
+
+		CHECK_OK("get  threadGroup info")
+
+		PyObject *result=Py_BuildValue("s", info.name);
+
+		DEALLOC(info.name); // allocated by jvmti
+
+		return result;
+}
+static PyObject *  jvmti_getTopThreadGroups(PyObject *self, PyObject *args) {
+
+	CHECK_VALID()
+
+
+
+		jint count=0;
+		jthreadGroup *groups=NULL;
+
+		jvmtiError err=(*jvmtiptr)->GetTopThreadGroups(jvmtiptr,&count,&groups);
+
+		CHECK_OK("get  Top Thread Groups")
+
+		PyObject* list= PyList_New(count);
+
+			int i=0;
+			for( i=0;i<count;i++) {
+				PyList_SetItem(list,i,Py_BuildValue("i",groups[i]));
+			}
+
+
+		DEALLOC(groups); // allocated by jvmti
+
+		return list;
+}
+
+
+/**
+ * Get Capabilities
+ */
+
+static PyObject *  jvmti_getcapabilities(PyObject *self, PyObject *args) {
+
+
+	CHECK_VALID()
+
+		jvmtiCapabilities capabilities;
+
+		jvmtiError err=(*jvmtiptr)->GetPotentialCapabilities(jvmtiptr,
+	            &capabilities);
+
+		CHECK_OK("get capabilities")
+
+		return 0;
+
+
+}
+ static PyObject *
+jvmti_getThread(PyObject *self, PyObject *args)
+{
+	CHECK_VALID()
+	// get required thread...
+	int threadID=0;
+
+	PyArg_ParseTuple(args, "i", &threadID);
+
+	jvmtiThreadInfo info;
+	jthread thread=(jthread)threadID;
+
+
+	jvmtiError err=(*jvmtiptr)->GetThreadInfo(jvmtiptr,thread,&info);
+
+	CHECK_OK("get  thread info")
+
+	PyObject *result=Py_BuildValue("siiii", info.name,info.priority,info.is_daemon,info.thread_group,info.context_class_loader);
+
+	DEALLOC(info.name); // allocated by jvmti
+
+	return result;
+}
+
+ 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;
+
+
+	jvmtiError err=(*jvmtiptr)->GetAllThreads(jvmtiptr,&count,&threads);
+
+	CHECK_OK("get all threads")
+
+	PyObject* list= PyList_New(count);
+
+		int i=0;
+
+
+		for( i=0;i<count;i++) {
+			PyList_SetItem(list,i,Py_BuildValue("i",threads[i]));
+		}
+
+
+	DEALLOC(threads)
+
+	return list;
+
+}
+
+
+
+static PyObject *
+jvmti_getsystemproperties(PyObject *self, PyObject *args)
+{
+	CHECK_VALID()
+
+	jint count=0;
+	char **ptr=NULL;
+
+	jvmtiError err=(*jvmtiptr)->GetSystemProperties(jvmtiptr,&count,&ptr);
+
+	CHECK_OK("get system properties")
+
+	PyObject *pDict = PyDict_New(); // new reference
+
+	int i=0;
+	for( i=0;i<count;i++) {
+
+		char *name=ptr[i];
+		char *value=NULL;
+
+		// get property value
+
+		err=(*jvmtiptr)->GetSystemProperty(jvmtiptr,name,&value);
+
+		CHECK_OK("get system property")
+
+		// add to dictionary
+
+		PyDict_SetItemString(pDict,  name,Py_BuildValue("s", value));
+
+
+		// release storage
+
+		err=(*jvmtiptr)->Deallocate(jvmtiptr,value);
+
+		CHECK_OK("jvmti dealloc failed for system property value")
+
+
+	}
+
+	// release property names storage
+
+	err=(*jvmtiptr)->Deallocate(jvmtiptr,ptr);
+
+	CHECK_OK("jvmti dealloc failed")
+
+
+	return pDict;
+}
+static PyObject *
+jvmti_gettime(PyObject *self, PyObject *args)
+{
+
+
+CHECK_VALID()
+
+	jlong result=0;
+
+	jvmtiError err=(*jvmtiptr)->GetTime(jvmtiptr,&result);
+
+	CHECK_OK("GetTime")
+
+    return Py_BuildValue("l", result);
+}
+
+
+
+static PyMethodDef  JvmtiMethods[] = {
+
+    {"getTime",  jvmti_gettime, METH_VARARGS, "Get JVMTI Time."},
+
+     {"getSystemProperties",  jvmti_getsystemproperties, METH_VARARGS, "Get JVMTI System
Properties."},
+
+       {"getThread",  jvmti_getThread, METH_VARARGS,  "Get JVMTI Thread."},
+     {"getAllThreads",  jvmti_getAllThreads, METH_VARARGS,       "Get JVMTI Threads."},
+
+          {"getTopThreadGroups",  jvmti_getTopThreadGroups, METH_VARARGS,   "Get Top Thread
Groups."},
+
+          {"getThreadGroupInfo",  jvmti_getThreadGroupInfo, METH_VARARGS,  "Get Thread Group
Info."},
+
+           {"getFrameCount",  jvmti_getFrameCount, METH_VARARGS,    "Get Frame Count"},
+           {"getStackTrace",  jvmti_getStackTrace, METH_VARARGS, "Get Stack Trace"},
+     {"getOwnedMonitorInfo",  jvmti_getOwnedMonitorInfo, METH_VARARGS,  "Get Owned Monitor
Info."},
+    {NULL, NULL, 0, NULL}        /* Sentinel */
+};
+
+
+PyMODINIT_FUNC
+initjvmti(void)
+{
+	printf("initilising...");
+    (void) Py_InitModule("jvmti", JvmtiMethods);
+
+
+
+
+}
+
+
+
+
+
+ void createObject(JNIEnv *env) {
+jclass threadClass;
+jmethodID constructor;
+
+
+printf("\ncreating thread");
+
+threadClass = (*env)->FindClass(env, "test/MyDump");
+constructor = (*env)->GetMethodID(env, threadClass, "<init>", "()V");
+ (*env)->NewObject(env, threadClass, constructor);
+
+
+}
+
+
+
+
+
+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() {
+
+		printf("running script %s",scriptname);
+
+		 // Python code in separate environments
+		 FILE* file_1 = fopen(scriptname, "r");
+		 PyRun_SimpleFile(file_1, scriptname);
+
+		 fclose(file_1);
+
+
+
+
+}
+
+JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm) {
+
+		report("unloaded");
+}
+
+JNIEXPORT void JNICALL Java_test_MyDump_doit
+  (JNIEnv *env, jobject obj) {
+
+	startPython();
+}
+void startPython() {
+	char *names[]={scriptname,scriptname};
+
+		 exec_interactive_interpreter(1,names);
+		//	runScript();
+}
+
+static void JNICALL
+dataDumpRequest(jvmtiEnv *jvmti)
+{
+	jvmtiptr=jvmti;
+
+	 jint rc = (*vmptr)->GetEnv(vmptr, (void **)&jniptr, JNI_VERSION_1_6);
+
+		  	if (rc != JNI_OK) {
+		  		report("unable to load jni environment");
+		  		return rc;
+		 	}
+
+		startPython();
+}
+
+
+
+
+JNIEXPORT jint JNICALL
+Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
+{
+
+	report(" jvmti is active");
+
+	vmptr=vm;
+
+
+
+	 jint rc = (*vm)->GetEnv(vm, (void **)&jvmtiptr, JVMTI_VERSION);
+
+	  	if (rc != JNI_OK) {
+	  		report("unable to load jvm environment");
+	    	return rc;
+	 	}
+
+
+	    jvmtiEventCallbacks callbacks;
+
+	    memset(&callbacks, 0, sizeof(callbacks));
+	    callbacks.DataDumpRequest = &dataDumpRequest;
+	    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");
+
+	    // turn on ability get the monitors...
+	     jvmtiCapabilities caps;
+	     caps.can_get_owned_monitor_info=1;
+
+	    err=(*jvmtiptr)->AddCapabilities(jvmtiptr, &caps);
+	    WARN("can't turn on get monitor info");
+
+	    report("dumprequest agent registered\n");
+	    scriptname=options;
+	    report(scriptname);
+
+    return 0;
+}
+
+
+

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

Added: incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h?rev=772117&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h (added)
+++ incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h Wed May  6 09:41:52 2009
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
+
+#ifndef __PY_JVMTI_H
+#define __PY_JVMTI_H
+
+#define CHECK_VALID()   \
+	if(jvmtiptr==NULL) {  \
+			 PyErr_SetString(PyExc_TypeError, "jvmti environment  pointer not present");  \
+			            return NULL; \
+		} \
+
+#define CHECK_OK(error_msg) \
+if(err!=JNI_OK) { \
+		char *msg=getErrorMessage(err,error_msg); \
+		 PyErr_SetString(PyExc_TypeError, msg); \
+		 free(msg); \
+		 return NULL; \
+	}
+
+#define WARN(error_msg) \
+if(err!=JNI_OK) { \
+		char *msg=getErrorMessage(err,error_msg); \
+		printf("warning %s\n",msg); \
+	}
+#define DEALLOC(ptr) \
+err=(*jvmtiptr)->Deallocate(jvmtiptr,ptr); \
+		if(err!=JNI_OK) { \
+			 PyErr_SetString(PyExc_TypeError, "jvmti dealloc"); \
+            return NULL; \
+		}
+
+#define report(s)  printf("\nkato: %s",s)
+
+
+
+PyMODINIT_FUNC initjvmti(void);
+
+static PyObject *jvmti_getThread(PyObject *self, PyObject *args);
+static PyObject *jvmti_getAllThreads(PyObject *self, PyObject *args);
+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);
+void runScript(void);
+void startPython(void);
+void createObject(JNIEnv *env);
+static char * getErrorMessage(jvmtiError err,char *usrmsg);
+
+#endif

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

Added: incubator/kato/branches/experimental/PyJVMTI/run.sh
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/run.sh?rev=772117&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/run.sh (added)
+++ incubator/kato/branches/experimental/PyJVMTI/run.sh Wed May  6 09:41:52 2009
@@ -0,0 +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 PYTHONPATH=$PYTHONPATH:.
+/home/spoole/javasdks/sun/jdk1.6.0_12/bin/java  -agentlib:pyjvmti  -cp .  kato.PauseJVM

Propchange: incubator/kato/branches/experimental/PyJVMTI/run.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/kato/branches/experimental/PyJVMTI/setup.py
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/setup.py?rev=772117&view=auto
==============================================================================
--- incubator/kato/branches/experimental/PyJVMTI/setup.py (added)
+++ incubator/kato/branches/experimental/PyJVMTI/setup.py Wed May  6 09:41:52 2009
@@ -0,0 +1,28 @@
+#*******************************************************************************
+ #* 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.
+ #******************************************************************************"
+
+from distutils.core import setup, Extension
+
+module1 = Extension('libpyjvmti',
+                    sources = ['pyjvmti.c'])
+
+
+setup (name = 'jvmti',
+       version = '1.0',
+       description = 'JVMTI Wrapper',
+       include_dirs = ['/home/spoole/javasdks/sun/jdk1.6.0_12/include',
+                              '/home/spoole/javasdks/sun/jdk1.6.0_12/include/linux'],
+      packages=['kato'],
+       ext_modules = [module1]
+       ) 
\ No newline at end of file

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



Mime
View raw message