ij-16.png   inspectorJ -- JavaTM Profiler
sf project site browse source checkout source
SourceForge.net Logo



src/inspectorj/agent/commandset/virtualmachinecmdset.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   inspectorJ - java profiler                                            *
00003  *   Copyright (C) 2007 by James May
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00027 #include "virtualmachinecmdset.h"
00028 
00029 namespace inspectorj {
00030 namespace agent {
00031 namespace commandset {
00032 
00033 using namespace inspectorj::jdwp;
00034 
00038 VirtualMachineCmdSet::VirtualMachineCmdSet(JavaVM *vm, JNIEnv *env, jvmtiEnv *jvmti)
00039 {
00040     this->vm = vm;
00041     this->env = env;
00042     this->jvmti = jvmti;
00043 }
00044 
00048 VirtualMachineCmdSet::~VirtualMachineCmdSet()
00049 {
00050 }
00051 
00052 
00058 void VirtualMachineCmdSet::process(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00059 {
00060     int jdwpCmd = static_cast<int>(cmd->getCmd());
00061     switch (jdwpCmd) {
00062         case VM_CMD_VERSION : getVersionInfo(cmd, cbk); break;
00063         case VM_CMD_CLASSES_BY_SIGNATURE : getClassesBySignature(cmd, cbk); break;
00064         case VM_CMD_ALL_CLASSES : getAllClasses(cmd, cbk); break;
00065         case VM_CMD_ALL_THREADS : getAllThreads(cmd, cbk); break;
00066         case VM_CMD_TOP_LEVEL_THREAD_GROUPS : getTopLevelThreadGroups(cmd, cbk); break;
00067         case VM_CMD_DISPOSE : dispose(cmd, cbk); break;
00068         case VM_CMD_ID_SIZES : getIdSizes(cmd, cbk); break;
00069         case VM_CMD_SUSPEND : suspend(cmd, cbk); break;
00070         case VM_CMD_RESUME : resume(cmd, cbk); break;
00071         case VM_CMD_EXIT : exit(cmd, cbk); break;
00072         case VM_CMD_CREATE_STRING : createString(cmd, cbk); break;
00073         case VM_CMD_CAPABILITIES : capabilities(cmd, cbk); break;
00074         case VM_CMD_CLASSPATHS : classpaths(cmd, cbk); break;
00075         case VM_CMD_DISPOSE_OBJECTS : disposeObjects(cmd, cbk); break;
00076         case VM_CMD_HOLD_EVENTS : holdEvents(cmd, cbk); break;
00077         case VM_CMD_RELEASE_EVENTS : releaseEvents(cmd, cbk); break;
00078         case VM_CMD_CAPABILITIES_NEW : newCapabilities(cmd, cbk); break;
00079         case VM_CMD_REDEFINE_CLASSES : redefineClasses(cmd, cbk); break;
00080         case VM_CMD_SET_DEFAULT_STRATUM : setDefaultStratum(cmd, cbk); break;
00081         case VM_CMD_ALL_CLASSES_WITH_GENERIC : getAllClassesWithGeneric(cmd, cbk); break;     
00082         default : sendNotImplementedReply(cmd, cbk); break;
00083     }
00084     
00085 
00086 }
00087 
00093 void VirtualMachineCmdSet::getVersionInfo(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00094 {
00095     JDWPReply *reply = getJDWPReply(cmd);
00096     QString versionInfo = "Java Debug Wire Protocol - inspectorj implementation.\n";
00097     
00098     jvmtiError error;
00099         
00100     char* vmNameProperty = "java.vm.name";
00101     char* vmName = "";
00102     error = jvmti->GetSystemProperty(vmNameProperty, &vmName);
00103     QString vmNameString(vmName);
00104     versionInfo.append(vmNameString);
00105     versionInfo.append(" - version ");
00106     if (!error) {
00107         error = jvmti->Deallocate((unsigned char*)vmName);
00108         check_jvmti_error(jvmti, error, "[VirtualMachineCmdSet::getVersionInfo] Error: Could not deallocate memory for vmName.\n");
00109     }
00110         
00111     char* javaVersionProperty = "java.vm.version";
00112     char* javaVersion = "";
00113     error = jvmti->GetSystemProperty(javaVersionProperty, &javaVersion);
00114     QString javaVersionString(javaVersion);
00115     versionInfo.append(javaVersionString);
00116     versionInfo.append("\n");
00117     if (!error) {
00118         error = jvmti->Deallocate((unsigned char*)javaVersion);
00119         check_jvmti_error(jvmti, error, "[VirtualMachineCmdSet::getVersionInfo] Error: Could not deallocate memory for javaVersion.\n");
00120     }
00121     
00122     *reply << versionInfo;
00123     jint v1 = 1;
00124     jint v2 = 0;
00125     *reply << v1;
00126     *reply << v2;
00127     *reply << javaVersionString;
00128     *reply << vmNameString;
00129     cbk(reply);        
00130 }
00131 
00132 void VirtualMachineCmdSet::getClassesBySignature(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00133 {
00134     sendNotImplementedReply(cmd, cbk);
00135 }
00136 
00137 void VirtualMachineCmdSet::getAllClasses(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00138 {
00139     JDWPCommandSet::getClassMap().clear();
00140     JDWPReply *reply = getJDWPReply(cmd);
00141     jvmtiError error;
00142     jint clsNum;
00143     jclass *classes;
00144     error = jvmti->GetLoadedClasses(&clsNum, &classes);
00145     check_jvmti_error(jvmti, error, "Error getting Loaded Classes\n");
00146     qint64 referenceId = 0;
00147     // store the number of loaded classes
00148     *reply << clsNum;
00149     for (int i = 0; i < clsNum; i++) {
00150         
00151         // Store all classes in the classMap
00152         JDWPCommandSet::getClassMap().insert(++referenceId, classes[i]);
00153         
00154         // Get the reference type (array |  class | interface)
00155         jboolean type = 0; 
00156         jbyte _type;      
00157         error = jvmti->IsInterface(classes[i], &type);
00158         
00159         if (type) {
00160             jbyte _type = (jbyte) TAG_TYPE_INTERFACE;
00161             *reply << _type;
00162         } else {
00163             error = jvmti->IsArrayClass(classes[i], &type);
00164             if (type) { 
00165                 _type = (jbyte)TAG_TYPE_ARRAY;
00166                 *reply << _type;
00167             } else {
00168                 _type = (jbyte) TAG_TYPE_CLASS;
00169                 *reply << _type;
00170             }  
00171         }
00172         
00173         // store the referenceTypeId
00174         *reply << referenceId;
00175         
00176         
00177         // Get the jni signature of the class
00178         char* jniSignature;
00179         char* genericSignature;
00180         
00181         error = jvmti->GetClassSignature(classes[i], &jniSignature, &genericSignature);
00182         check_jvmti_error(jvmti, error, "Error getting class signature\n");
00183         QString signature(jniSignature);
00184         *reply << signature;
00185         error = jvmti->Deallocate((unsigned char*)jniSignature);
00186         error = jvmti->Deallocate((unsigned char*)genericSignature);
00187         
00188         // Get the class status
00189         jint status;
00190         error = jvmti->GetClassStatus(classes[i], &status);
00191         check_jvmti_error(jvmti, error, "Error getting class status\n");
00192         *reply << status;
00193     }
00194     error = jvmti->Deallocate((unsigned char*)classes);
00195     check_jvmti_error(jvmti, error, "Error Deallocating classes\n");
00196     cbk(reply);       
00197 }
00198 
00199 void VirtualMachineCmdSet::getAllThreads(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00200 {
00201     sendNotImplementedReply(cmd, cbk);
00202 }
00203 
00204 void VirtualMachineCmdSet::getTopLevelThreadGroups(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00205 {
00206     sendNotImplementedReply(cmd, cbk);
00207 }
00208 
00209 void VirtualMachineCmdSet::dispose(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00210 {
00211     sendNotImplementedReply(cmd, cbk);
00212 }
00213 
00214 void VirtualMachineCmdSet::getIdSizes(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00215 {
00216     // send id sizes
00217     JDWPReply *reply = getJDWPReply(cmd);
00218     
00219     qint32 size_four = 4;
00220     qint32 size_eight = 8;
00221     
00222     // field id size
00223     *reply << size_four;
00224     
00225     // method id size
00226     *reply << size_four;
00227     
00228     // object id size
00229     *reply << size_eight;
00230     
00231     // reference type id size
00232     *reply << size_eight;
00233     
00234     // frame id size
00235     *reply << size_eight;
00236     
00237     cbk(reply);
00238 }
00239 
00240 void VirtualMachineCmdSet::suspend(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00241 {
00242     sendNotImplementedReply(cmd, cbk);
00243 }
00244 
00245 void VirtualMachineCmdSet::resume(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00246 {
00247     sendNotImplementedReply(cmd, cbk);
00248 }
00249 
00250 void VirtualMachineCmdSet::exit(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00251 {
00252     sendNotImplementedReply(cmd, cbk);
00253 }
00254 
00255 void VirtualMachineCmdSet::createString(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00256 {
00257     sendNotImplementedReply(cmd, cbk);
00258 }
00259 
00260 void VirtualMachineCmdSet::capabilities(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00261 {
00262     sendNotImplementedReply(cmd, cbk);
00263 }
00264 
00265 void VirtualMachineCmdSet::classpaths(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00266 {
00267     sendNotImplementedReply(cmd, cbk);
00268 }
00269 
00270 void VirtualMachineCmdSet::disposeObjects(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00271 {
00272     sendNotImplementedReply(cmd, cbk);
00273 }
00274 
00275 void VirtualMachineCmdSet::holdEvents(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00276 {
00277     sendNotImplementedReply(cmd, cbk);
00278 }
00279 
00280 void VirtualMachineCmdSet::releaseEvents(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00281 {
00282     sendNotImplementedReply(cmd, cbk);
00283 }
00284 
00285 void VirtualMachineCmdSet::newCapabilities(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00286 {
00287     sendNotImplementedReply(cmd, cbk);
00288 }
00289 
00290 void VirtualMachineCmdSet::redefineClasses(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00291 {
00292     sendNotImplementedReply(cmd, cbk);
00293 }
00294 
00295 void VirtualMachineCmdSet::setDefaultStratum(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00296 {
00297     sendNotImplementedReply(cmd, cbk);
00298 }
00299 
00300 void VirtualMachineCmdSet::getAllClassesWithGeneric(JDWPCommand* cmd, boost::function< void (JDWPReply*) > cbk)
00301 {
00302     sendNotImplementedReply(cmd, cbk);
00303 }
00304 
00305 } // end namespace commandset
00306 } // end namespace agent
00307 } // end namespace inspectorj

Generated on Sun Aug 19 17:07:53 2007 for inspectorJ by  doxygen 1.5.1