From kato-commits-return-90-apmail-incubator-kato-commits-archive=incubator.apache.org@incubator.apache.org Mon May 11 10:11:32 2009 Return-Path: Delivered-To: apmail-incubator-kato-commits-archive@minotaur.apache.org Received: (qmail 29151 invoked from network); 11 May 2009 10:11:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 11 May 2009 10:11:32 -0000 Received: (qmail 44287 invoked by uid 500); 11 May 2009 10:11:32 -0000 Delivered-To: apmail-incubator-kato-commits-archive@incubator.apache.org Received: (qmail 44271 invoked by uid 500); 11 May 2009 10:11:31 -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 44261 invoked by uid 99); 11 May 2009 10:11:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 May 2009 10:11:31 +0000 X-ASF-Spam-Status: No, hits=-1996.5 required=10.0 tests=ALL_TRUSTED,URIBL_BLACK 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; Mon, 11 May 2009 10:11:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 20C29238896D; Mon, 11 May 2009 10:10:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r773520 - in /incubator/kato/branches/experimental/PyJVMTI: ./ kato/JThread.py kato/JThreadGroup.py kato/__init__.py load.py pyjvmti.c pyjvmti.h run.sh Date: Mon, 11 May 2009 10:10:55 -0000 To: kato-commits@incubator.apache.org From: spoole@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090511101056.20C29238896D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: spoole Date: Mon May 11 10:10:55 2009 New Revision: 773520 URL: http://svn.apache.org/viewvc?rev=773520&view=rev Log: more updates to pyjvmti - more jvmti methods exposed. Modified: incubator/kato/branches/experimental/PyJVMTI/ (props changed) incubator/kato/branches/experimental/PyJVMTI/kato/JThread.py incubator/kato/branches/experimental/PyJVMTI/kato/JThreadGroup.py incubator/kato/branches/experimental/PyJVMTI/kato/__init__.py incubator/kato/branches/experimental/PyJVMTI/load.py incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h incubator/kato/branches/experimental/PyJVMTI/run.sh Propchange: incubator/kato/branches/experimental/PyJVMTI/ ------------------------------------------------------------------------------ --- svn:ignore (original) +++ svn:ignore Mon May 11 10:10:55 2009 @@ -1 +1,3 @@ build + +kato.dump Modified: incubator/kato/branches/experimental/PyJVMTI/kato/JThread.py URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/JThread.py?rev=773520&r1=773519&r2=773520&view=diff ============================================================================== --- incubator/kato/branches/experimental/PyJVMTI/kato/JThread.py (original) +++ incubator/kato/branches/experimental/PyJVMTI/kato/JThread.py Mon May 11 10:10:55 2009 @@ -13,6 +13,7 @@ #******************************************************************************" import jvmti +from kato.JThreadGroup import * ''' Created on 2 May 2009 @@ -24,6 +25,9 @@ ''' info=None threadid=0; + monitors=None + hasContendedMonitor=None + contendedMonitorID=None def __init__(self,tid=0): ''' @@ -50,27 +54,45 @@ return self.info[2] @property - def threadGroup(self): + def threadGroupID(self): self.fill() - return JThreadGroup(self.info[3]) + return self.info[3] @property - def contextClassLoader(self): + def contextClassLoaderID(self): self.fill() - if self.info[4]==None: - return None + return self.info[4] + + @property + def ownedMonitorIDs(self): + if self.monitors==None : + self.monitors=jvmti.getOwnedMonitorInfo(self.threadid) + return self.monitors + + @property + def contendedMonitor(self): + if self.hasContendedMonitor==None : + self.contendedMonitorID=jvmti.getCurrentContendedMonitor(self.threadid) + if self.contendedMonitorID==None : + self.hasContendedMonitor=False + else : + self.hasContendedMonitor=True + + return self.contendedMonitorID - return JClassLoader(self.info[4]) - def __getstate__(self): """Return state values to be pickled.""" self.fill() - return self.info + return [self.threadid,self.info,self.ownedMonitors,self.contendedMonitor] def __setstate__(self, state): """Restore state from the unpickled state values.""" - self.info = state + self.threadid=state[0] + self.info = state[1] + self.monitors = state[2] + self.contendedMonitorID=state[3] + self.hasContendedMonitor= self.contendedMonitorID!=None def __repr__(self): - return "JThread id=%i name=%s" % (self.threadid , self.name) + return "JThread id=%i name=%s contendedMonitor %s" % (self.threadid , self.name,self.contendedMonitor) \ No newline at end of file Modified: incubator/kato/branches/experimental/PyJVMTI/kato/JThreadGroup.py URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/JThreadGroup.py?rev=773520&r1=773519&r2=773520&view=diff ============================================================================== --- incubator/kato/branches/experimental/PyJVMTI/kato/JThreadGroup.py (original) +++ incubator/kato/branches/experimental/PyJVMTI/kato/JThreadGroup.py Mon May 11 10:10:55 2009 @@ -16,8 +16,33 @@ class JThreadGroup(object): - def __init__(self,threadid=0): + threadid=0 + info=None + + def __init__(self,tid=0): ''' Constructor ''' - info=jvmti.getThreadInfo(threadid); \ No newline at end of file + self.threadid=tid; + + + def fill(self): + + if info==None : + info=jvmti.getThreadGroupInfo(threadid) + + def parentThreadGroupID(self): + fill() + return info[0] + + def name(self): + fill() + return info[1] + + def maxpriority(self): + fill() + return info[2] + + def isdaemon(self): + fill() + return info[3] Modified: incubator/kato/branches/experimental/PyJVMTI/kato/__init__.py URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/kato/__init__.py?rev=773520&r1=773519&r2=773520&view=diff ============================================================================== --- incubator/kato/branches/experimental/PyJVMTI/kato/__init__.py (original) +++ incubator/kato/branches/experimental/PyJVMTI/kato/__init__.py Mon May 11 10:10:55 2009 @@ -1 +1,3 @@ -print "in init for org.kato.jvmti" \ No newline at end of file + + + Modified: incubator/kato/branches/experimental/PyJVMTI/load.py URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/load.py?rev=773520&r1=773519&r2=773520&view=diff ============================================================================== --- incubator/kato/branches/experimental/PyJVMTI/load.py (original) +++ incubator/kato/branches/experimental/PyJVMTI/load.py Mon May 11 10:10:55 2009 @@ -9,5 +9,12 @@ print d print "loaded" -print d.getThreads() +for t in d.getThreads() : + print "name=" ,t.name + print "priority=" , t.priority + print "thread id=",t.threadid + print "contendedMonitor=",t.contendedMonitorID + print "thread group=", t.threadGroup + + \ 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=773520&r1=773519&r2=773520&view=diff ============================================================================== --- incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c (original) +++ incubator/kato/branches/experimental/PyJVMTI/pyjvmti.c Mon May 11 10:10:55 2009 @@ -45,6 +45,8 @@ } + + static PyObject * jvmti_getStackTrace(PyObject *self, PyObject *args) { @@ -67,7 +69,7 @@ jvmtiError err=(*jvmtiptr)->GetStackTrace(jvmtiptr,thread,jstart,jmax,info,&count); - CHECK_OK("get stack trace") + CHECK_OK("get stack trace"); @@ -85,7 +87,7 @@ static PyObject * jvmti_getFrameCount(PyObject *self, PyObject *args) { - CHECK_VALID() + CHECK_VALID(); // get required thread... int threadID=0; @@ -97,16 +99,43 @@ jvmtiError err=(*jvmtiptr)->GetFrameCount(jvmtiptr,thread,&count); - CHECK_OK("get frame count") + CHECK_OK("get frame count"); return Py_BuildValue("i", count); } +/** + * Takes threadid and returns a python list of object ids + */ +static PyObject * jvmti_getCurrentContendedMonitor(PyObject *self, PyObject *args) { + + + CHECK_VALID(); + + // get required thread... + int threadID=0; + + PyArg_ParseTuple(args, "i", &threadID); + + jthread thread=(jthread)threadID; + jobject monitor; + + jvmtiError err=(*jvmtiptr)->GetCurrentContendedMonitor(jvmtiptr,thread,&monitor); + + CHECK_OK("get contended monitor"); + + return Py_BuildValue("i",monitor); + +} + +/** + * Takes threadid and returns a python list of object ids + */ static PyObject * jvmti_getOwnedMonitorInfo(PyObject *self, PyObject *args) { - CHECK_VALID() + CHECK_VALID(); // get required thread... int threadID=0; @@ -119,7 +148,7 @@ jvmtiError err=(*jvmtiptr)->GetOwnedMonitorInfo(jvmtiptr,thread,&count,&monitors); - CHECK_OK("get owned monitor info") + CHECK_OK("get owned monitor info"); PyObject* list= PyList_New(count); @@ -136,7 +165,7 @@ static PyObject * jvmti_getThreadGroupInfo(PyObject *self, PyObject *args) { - CHECK_VALID() + CHECK_VALID(); // get required threadgroup int ID=0; @@ -149,9 +178,9 @@ jvmtiError err=(*jvmtiptr)->GetThreadGroupInfo(jvmtiptr,threadGroup,&info); - CHECK_OK("get threadGroup info") + CHECK_OK("get threadGroup info"); - PyObject *result=Py_BuildValue("s", info.name); + PyObject *result=Py_BuildValue("isiiii", info.parent,info.name,info.max_priority,info.is_daemon); DEALLOC(info.name); // allocated by jvmti @@ -159,7 +188,7 @@ } static PyObject * jvmti_getTopThreadGroups(PyObject *self, PyObject *args) { - CHECK_VALID() + CHECK_VALID(); @@ -168,7 +197,7 @@ jvmtiError err=(*jvmtiptr)->GetTopThreadGroups(jvmtiptr,&count,&groups); - CHECK_OK("get Top Thread Groups") + CHECK_OK("get Top Thread Groups"); PyObject* list= PyList_New(count); @@ -191,14 +220,14 @@ static PyObject * jvmti_getcapabilities(PyObject *self, PyObject *args) { - CHECK_VALID() + CHECK_VALID(); jvmtiCapabilities capabilities; jvmtiError err=(*jvmtiptr)->GetPotentialCapabilities(jvmtiptr, &capabilities); - CHECK_OK("get capabilities") + CHECK_OK("get capabilities"); return 0; @@ -207,7 +236,7 @@ static PyObject * jvmti_getThread(PyObject *self, PyObject *args) { - CHECK_VALID() + CHECK_VALID(); // get required thread... int threadID=0; @@ -219,7 +248,7 @@ jvmtiError err=(*jvmtiptr)->GetThreadInfo(jvmtiptr,thread,&info); - CHECK_OK("get 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); @@ -232,7 +261,7 @@ jvmti_getAllThreads(PyObject *self, PyObject *args) { - CHECK_VALID() + CHECK_VALID(); if(jniptr==NULL) { PyErr_SetString(PyExc_TypeError, "jni environment not present"); @@ -245,7 +274,7 @@ jvmtiError err=(*jvmtiptr)->GetAllThreads(jvmtiptr,&count,&threads); - CHECK_OK("get all threads") + CHECK_OK("get all threads"); PyObject* list= PyList_New(count); @@ -257,7 +286,7 @@ } - DEALLOC(threads) + DEALLOC(threads); return list; @@ -268,14 +297,16 @@ static PyObject * jvmti_getsystemproperties(PyObject *self, PyObject *args) { - CHECK_VALID() + CHECK_VALID(); - jint count=0; + jint countj=0; char **ptr=NULL; - jvmtiError err=(*jvmtiptr)->GetSystemProperties(jvmtiptr,&count,&ptr); + jvmtiError err=(*jvmtiptr)->GetSystemProperties(jvmtiptr,&countj,&ptr); + + CHECK_OK("get system properties"); - CHECK_OK("get system properties") + int count=count; PyObject *pDict = PyDict_New(); // new reference @@ -289,7 +320,7 @@ err=(*jvmtiptr)->GetSystemProperty(jvmtiptr,name,&value); - CHECK_OK("get system property") + CHECK_OK("get system property"); // add to dictionary @@ -297,19 +328,13 @@ // release storage - - err=(*jvmtiptr)->Deallocate(jvmtiptr,value); - - CHECK_OK("jvmti dealloc failed for system property value") + DEALLOC(value); } // release property names storage - - err=(*jvmtiptr)->Deallocate(jvmtiptr,ptr); - - CHECK_OK("jvmti dealloc failed") + DEALLOC(ptr); return pDict; @@ -319,35 +344,204 @@ { -CHECK_VALID() +CHECK_VALID(); jlong result=0; jvmtiError err=(*jvmtiptr)->GetTime(jvmtiptr,&result); - CHECK_OK("GetTime") + CHECK_OK("GetTime"); return Py_BuildValue("l", result); } +/** + * Get Local Variable that is an Object + */ + +static PyObject * +jvmti_getLocalObject(PyObject *self, PyObject *args) +{ + + +CHECK_VALID(); + + int threadID=0; + int depth=0; + int slot=0; + + PyArg_ParseTuple(args, "iii", &threadID,&depth,&slot); + + jthread threadj=(jthread)threadID; + jint depthj=depth; + jint slotj=slot; + jobject result; + + jvmtiError err=(*jvmtiptr)->GetLocalObject(jvmtiptr,threadj,depthj,slotj,&result); + + CHECK_OK("GetLocalObject"); + + return Py_BuildValue("l", result); +} + +/** + * Get Local Variable that is an Integer + */ +static PyObject * +jvmti_getLocalInt(PyObject *self, PyObject *args) +{ -static PyMethodDef JvmtiMethods[] = { +CHECK_VALID(); - {"getTime", jvmti_gettime, METH_VARARGS, "Get JVMTI Time."}, + int threadID=0; + int depth=0; + int slot=0; - {"getSystemProperties", jvmti_getsystemproperties, METH_VARARGS, "Get JVMTI System Properties."}, + PyArg_ParseTuple(args, "iii", &threadID,&depth,&slot); + + jthread threadj=(jthread)threadID; + jint depthj=depth; + jint slotj=slot; + jint result; + + jvmtiError err=(*jvmtiptr)->GetLocalInt(jvmtiptr,threadj,depthj,slotj,&result); + + CHECK_OK("GetLocalInt"); + + return Py_BuildValue("l", result); +} +/** + * Get Local Variable that is an Integer + */ + +static PyObject * +jvmti_getLocalLong(PyObject *self, PyObject *args) +{ + + +CHECK_VALID(); + + int threadID=0; + int depth=0; + int slot=0; + + PyArg_ParseTuple(args, "iii", &threadID,&depth,&slot); + + jthread threadj=(jthread)threadID; + jint depthj=depth; + jint slotj=slot; + jlong result; + + jvmtiError err=(*jvmtiptr)->GetLocalLong(jvmtiptr,threadj,depthj,slotj,&result); + + CHECK_OK("GetLocalLong"); + + return Py_BuildValue("l", result); +} + +/** + * Get method name , signature and generic signature + * returned as typle of strings + */ + +static PyObject * +jvmti_getMethodName(PyObject *self, PyObject *args) +{ + + + + CHECK_VALID(); + + int methodID=0; + + PyArg_ParseTuple(args, "i", &methodID); + + jmethodID method=(jmethodID)methodID; + + char *name=NULL; + char *sig=NULL; + char *generic=NULL; + + jvmtiError err=(*jvmtiptr)->GetMethodName(jvmtiptr,method,&name,&sig,&generic); + + CHECK_OK("GetMethodName"); + + PyObject *value= Py_BuildValue("sss", name,sig,generic); + DEALLOC(name); + DEALLOC(sig); + DEALLOC(generic); - {"getThread", jvmti_getThread, METH_VARARGS, "Get JVMTI Thread."}, - {"getAllThreads", jvmti_getAllThreads, METH_VARARGS, "Get JVMTI Threads."}, + return value; +} + +static PyObject * +jvmti_getLocalVariableTable(PyObject *self, PyObject *args) +{ + + + + CHECK_VALID(); + + int methodID=0; + + PyArg_ParseTuple(args, "i", &methodID); + + jmethodID method=(jmethodID)methodID; + + jint countj=0; + + jvmtiLocalVariableEntry *entries=NULL; + + jvmtiError err=(*jvmtiptr)->GetLocalVariableTable(jvmtiptr,method,&countj,&entries); + + CHECK_OK("GetLocalVariableTable"); - {"getTopThreadGroups", jvmti_getTopThreadGroups, METH_VARARGS, "Get Top Thread Groups."}, + // turn table into python data... + int count=countj; + PyObject* list= PyList_New(count); + + int i=0; + for(i=0;iSetEventNotificationMode(jvmtiptr, JVMTI_ENABLE, JVMTI_EVENT_DATA_DUMP_REQUEST, (jthread)NULL); + CHECK_OK("unable to set callback"); - // turn on ability get the monitors... + // turn on required capabilities + jvmtiCapabilities caps; + memset(&caps, 0, sizeof(jvmtiCapabilities)); + caps.can_get_owned_monitor_info=1; + caps.can_get_current_contended_monitor=1; + caps.can_access_local_variables=1; err=(*jvmtiptr)->AddCapabilities(jvmtiptr, &caps); - WARN("can't turn on get monitor info"); + + WARN("can't turn on required capabilites\n"); report("dumprequest agent registered\n"); scriptname=options; report(scriptname); - return 0; + 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=773520&r1=773519&r2=773520&view=diff ============================================================================== --- incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h (original) +++ incubator/kato/branches/experimental/PyJVMTI/pyjvmti.h Mon May 11 10:10:55 2009 @@ -35,12 +35,13 @@ printf("warning %s\n",msg); \ } #define DEALLOC(ptr) \ -err=(*jvmtiptr)->Deallocate(jvmtiptr,ptr); \ + if(ptr!=NULL) { \ + err=(*jvmtiptr)->Deallocate(jvmtiptr,( unsigned char*)ptr); \ if(err!=JNI_OK) { \ PyErr_SetString(PyExc_TypeError, "jvmti dealloc"); \ return NULL; \ - } - + } \ + } #define report(s) printf("\nkato: %s",s) Modified: incubator/kato/branches/experimental/PyJVMTI/run.sh URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/PyJVMTI/run.sh?rev=773520&r1=773519&r2=773520&view=diff ============================================================================== --- incubator/kato/branches/experimental/PyJVMTI/run.sh (original) +++ incubator/kato/branches/experimental/PyJVMTI/run.sh Mon May 11 10:10:55 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/Dump.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 -cp . kato.PauseJVM