Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

iprof.cpp

00001 /*
00002  *                         Sun Public License Notice
00003  *
00004  * The contents of this file are subject to the Sun Public License
00005  * Version 1.0 (the "License"); you may not use this file except
00006  * in compliance with the License. A copy of the License is available
00007  * at http://www.sun.com/
00008  *
00009  * The Original Code is the Java Profiler module.  The Initial Developers
00010  * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
00011  * Lukas Petru and Marek Przeczek.
00012  *
00013  * Portions created by Jan Stola are Copyright (C) 2000-2001.
00014  * All Rights Reserved.
00015  *
00016  * Portions created by Pavel Vacha are Copyright (C) 2000-2001.
00017  * All Rights Reserved.
00018  *
00019  * Portions created by Michal Pise are Copyright (C) 2000-2001.
00020  * All Rights Reserved.
00021  *
00022  * Portions created by Petr Luner are Copyright (C) 2000-2001.
00023  * All Rights Reserved.
00024  *
00025  * Portions created by Lukas Petru are Copyright (C) 2000-2001.
00026  * All Rights Reserved.
00027  *
00028  * Portions created by Marek Przeczek are Copyright (C) 2000-2001.
00029  * All Rights Reserved.
00030  *
00031  * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
00032  *               Lukas Petru and Marek Przeczek.
00033  */
00034 
00035 #include "../commun/iprof.h"
00036 #include "../commun/communSocket.h"
00037 #include "../commun3/communShMem.h"
00038 #include "../delay/delay.h"
00039 #include "../prof/synchronized.h"
00040 #include "../prof/prof.h"
00041 
00042 #ifdef USE_ALLOCATOR
00043 Allocator IProf::sID::_allocator;
00044 #endif
00045 
00046 IProf::IProf( const Setup& setup, JVMPI_Interface* jvmpi) :
00047 
00048         communLock( "_commun_lock", jvmpi),
00049         conEstabl( 0) {
00050 
00051         _func[F_SHUTDOWN]      = &IProf::_shutdown;
00052         _func[F_IS_SHUTDOWNED] = &IProf::_isShutdowned;
00053         _func[F_SUSPEND_VM]    = &IProf::_suspendVM;
00054         _func[F_RESUME_VM]     = &IProf::_resumeVM;
00055         _func[F_EXIT_VM]       = &IProf::_exitVM;
00056         _func[F_GET_INFO]      = &IProf::_getInfo;
00057         _func[F_GET_DATA]      = &IProf::_getData;
00058         _func[F_GET_ALL]       = &IProf::_getAll;
00059         _func[F_GET_CHANGED]   = &IProf::_getChanged;
00060         _func[F_ENABLE_GC]     = &IProf::_enableGC;
00061         _func[F_DISABLE_GC]    = &IProf::_disableGC;
00062         _func[F_RUN_GC]        = &IProf::_runGC;
00063 
00064         if( setup.com.communType == Setup::COMMUN_SOCKET)
00065 
00066                 _commun = new CommunSocket( setup.com.connectMode,
00067                                                                         setup.com.hostname,
00068                                                                         setup.com.port);
00069 
00070         else _commun = new CommunShMem( setup.com.shmemId, setup.com.shmemSize);
00071 }
00072 
00073 IProf::~IProf() {
00074 
00075         if( _commun) delete _commun;
00076 }
00077 
00078 int IProf::run() {
00079 
00080         conEstabl = 0;
00081         if( !_commun->initialize()) {
00082 
00083                 Delay::delay( 100);
00084                 return 0;
00085         }
00086         conEstabl = 1;
00087 
00088         Buffer buf;
00089         while( 1) {
00090 
00091                 if( !_commun->isReady()) {
00092 
00093                         if( _commun->hasFailed()) return (conEstabl = 0);
00094                         continue;
00095                 }
00096 
00097                 Synchronized sync( communLock);
00098 
00099                 buf.clear();
00100 
00101                 (*_commun) >> buf;
00102                 if( _commun->hasFailed()) return (conEstabl = 0);
00103 
00104                 jint naction = *(jint*)(buf.getBuffer());
00105                 jint action = ntohl( naction); // back to host-byte-order
00106 
00107                 if( action < 0 || action >= FUNC_COUNT) return (conEstabl = 0);
00108 
00109                 (this->*(_func[action]))( buf);
00110 
00111                 (*_commun) << buf;
00112                 if( _commun->hasFailed()) return (conEstabl = 0);
00113         }
00114 
00115         return 1;
00116 }
00117 
00118 void IProf::_shutdown( Buffer& b) {
00119 
00120         shutdown();
00121         b.clear();
00122 }
00123 
00124 void IProf::_isShutdowned( Buffer& b) {
00125 
00126         jint rc = isShutdowned();
00127         
00128         b.clear();
00129         b += rc; // automatically stored in network-byte-order
00130 }
00131 
00132 void IProf::_suspendVM( Buffer& b) {
00133 
00134         suspendVM();
00135         b.clear();
00136 }
00137 
00138 void IProf::_resumeVM( Buffer& b) {
00139 
00140         resumeVM();
00141         b.clear();
00142 }
00143 
00144 void IProf::_exitVM( Buffer& b) {
00145 
00146         exitVM();
00147         b.clear();
00148 }
00149 
00150 void IProf::_getInfo( Buffer& b) {
00151 
00152         const char* buf = b.getBuffer()+sizeof( jint); // jump the "action" field
00153         
00154         jint infoId = ntohl( *(const jint*)buf);
00155         buf += sizeof( infoId);
00156         jint type = ntohl( *(const jint*)buf);
00157 
00158         InfoBinaryFormat* info;
00159         jint rc = getInfo( infoId, (eInfoType)type, info);
00160 
00161         b.clear( sizeof( InfoBinaryFormat));
00162         b += rc;
00163 
00164         if( rc != RC_OK) return;
00165 
00166         info->infoToBin( b);
00167 }
00168 
00169 void IProf::_getData( Buffer& b) {
00170 
00171         const char* buf = b.getBuffer()+sizeof( jint); // jump the "action" field
00172 
00173         jint objId = ntohl( *(const jint*)buf);
00174         buf += sizeof( objId);
00175         jint type = ntohl( *(const jint*)buf);
00176 
00177         sData data;
00178         jint rc = getData( objId, (eDataType)type, data);
00179 
00180         b.clear( sizeof( sData));
00181         b += rc;
00182 
00183         if( rc != RC_OK) return;
00184 
00185         b += data.active;
00186 
00187         if( type == ALLOC_DATA)    data.alloc.dataToBin( b);
00188         else if( type == CPU_DATA) data.cpu  .dataToBin( b);
00189         else                       data.mon  .dataToBin( b); // MON_DATA
00190 }
00191 
00192 int IProf::sToBin( sID* s, void** inout) {
00193 
00194         Buffer* buf = reinterpret_cast<Buffer*> ( *inout);
00195         Buffer& b = *buf;
00196 
00197         b += s->infoId;
00198         b += s->objId;
00199 
00200         b += s->parentLeftObjId;
00201         b += s->parentUpObjId;
00202         b += s->parentRightObjId;
00203 
00204         b += s->active;
00205         
00206         b += s->hasAllocData;
00207 
00208         if( s->hasAllocData) s->alloc.dataToBin( b);
00209 
00210         b += s->hasCpuData;
00211 
00212         if( s->hasCpuData) s->cpu.dataToBin( b);
00213 
00214         b += s->hasMonData;
00215 
00216         if( s->hasMonData) s->mon.dataToBin( b);
00217 
00218         b += s->hasInfo;
00219 
00220         if( s->hasInfo) {
00221 
00222                 b += s->infoType;
00223                 s->info->infoToBin( b);
00224         }
00225 
00226         return 0;
00227 }
00228 
00229 void IProf::_getAllOrChanged( int all, Buffer& b) {
00230 
00231         const char* buf = b.getBuffer()+sizeof( jint); // jump the "action" field
00232 
00233         jint objId = ntohl( *(const jint*)buf);
00234         buf += sizeof( objId);
00235 
00236         jint what = ntohl( *(const jint*)buf);
00237         buf += sizeof( what);
00238 
00239         jint includeInfo = ntohl( *(const jint*)buf);
00240         buf += sizeof( includeInfo);
00241 
00242         jint optionalArg = ntohl( *(const jint*)buf);   
00243 
00244         seqID seq;
00245         jint rc;
00246 
00247         if( all) rc = getAll( objId, (eSeqType)what, includeInfo, optionalArg, seq);
00248         else rc = getChanged( objId, (eSeqType)what, includeInfo, optionalArg, seq);
00249 
00250         b.clear( seq.length()*sizeof( sID));
00251         b += rc;
00252 
00253         if( rc < 0) return;
00254 
00255         void* buf2 = &b;
00256         seq.forEach( sToBin, &buf2);
00257 }
00258 
00259 void IProf::_enableGC( Buffer& b) {
00260 
00261         enableGC();
00262         b.clear();
00263 }
00264 
00265 void IProf::_disableGC( Buffer& b) {
00266 
00267         disableGC();
00268         b.clear();
00269 }
00270 
00271 void IProf::_runGC( Buffer& b) {
00272 
00273         runGC();
00274         b.clear();
00275 }

Generated on Mon Jan 28 14:53:26 2002 for Java Profiler Dynamic Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001