00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _PROF_H_
00036 #define _PROF_H_
00037
00038 #include "../main/includes.h"
00039 #include "../commun/iprof.h"
00040 #include "../hash/hash.h"
00041 #include "../cpu/sampling.h"
00042 #include "../cpu/cpuThreadMethodKey.h"
00043 #include "../shared/class.h"
00044 #include "../shared/method.h"
00045 #include "../shared/thread.h"
00046 #include "../shared/groupThread.h"
00047 #include "../alloc/allocArena.h"
00048 #include "../alloc/allocObject.h"
00049 #include "../alloc/allocGlobalRef.h"
00050 #include "../gc/gc.h"
00051
00061 class Prof: public IProf {
00062
00064 struct sF {
00065
00067 jint event;
00068
00070 void (Prof::*func)( JVMPI_Event*);
00071 };
00072
00074 enum e {
00075
00077 TAB_FUNC_SIZE = 40
00078 };
00079
00080 private:
00081
00083 sF tabFunc[TAB_FUNC_SIZE];
00084
00085 public:
00086
00088 JVMPI_Interface* jvmpiInterface;
00089
00090 public:
00091
00093 Setup& setup;
00094
00101 Lock gcLock;
00102
00104 Lock dataLock;
00105
00107 List<GroupThread,LI1> groupsOfThreads;
00108
00110 List<Thread,LI4> threads;
00111
00113 List<Class,LI2> classes;
00114
00116 List<AllocObject,LI2> allocObjects;
00117
00119 List<AllocArena,LI1> arenas;
00120
00122 Hash<AllocInstance,jobjectID,LI1> instances;
00123
00125 List<AllocInstance,LI1> unusedInstances;
00126
00128 Hash<AllocGlobalRef,jobject,LI1> jniGlobalRefs;
00129
00131 Hash<AllocGlobalRef,jobject,LI1> jniWeakGlobalRefs;
00132
00134 List<GC,LI1> gcStat;
00135
00137 Sampling sampling;
00138
00140 List<Thread,LI5> sampledThreads;
00141
00142 public:
00143
00145 Hash<Class,jobjectID,LI1> activeClasses;
00146
00148 Hash<Method,jmethodID,LI1> activeMethods;
00149
00151 Hash<Thread,JNIEnv*,LI1> activeThreads;
00152
00154 Hash<AllocObject,AllocObjectKey,LI1> activeAllocObjects;
00155
00157 Hash<AllocTrace,TraceKey,LI1> activeAllocTraces;
00158
00160 Hash<AllocObjectMethod,AllocObjectMethodKey,LI3> activeAllocObjectMethods;
00161
00163 Hash<AllocObjectTrace,AllocObjectTraceKey,LI3> activeAllocObjectTraces;
00164
00166 Hash<AllocThreadMethod,AllocThreadMethodKey,LI2> activeAllocThreadMethods;
00167
00169 Hash<AllocThreadTrace,AllocThreadTraceKey,LI2> activeAllocThreadTraces;
00170
00172 Hash<AllocThreadObject,AllocThreadObjectKey,LI3> activeAllocThreadObjects;
00173
00175 Hash<AllocThreadObjectMethod,AllocThreadObjectMethodKey,LI4> activeAllocThreadObjectMethods;
00176
00178 Hash<AllocThreadObjectTrace,AllocThreadObjectTraceKey,LI4> activeAllocThreadObjectTraces;
00179
00181 Hash<CpuTrace,TraceKey,LI1> activeCpuTraces;
00182
00184 Hash<CpuThreadMethod,CpuThreadMethodKey,LI1> activeCpuThreadMethods;
00185
00187 Hash<CpuThreadTrace,CpuThreadTraceKey,LI1> activeCpuThreadTraces;
00188
00190 Hash<MonTrace,TraceKey,LI1> activeMonTraces;
00191
00193 Hash<MonThreadMethod,MonThreadMethodKey,LI1> activeMonThreadMethods;
00194
00196 Hash<MonThreadTrace,MonThreadTraceKey,LI1> activeMonThreadTraces;
00197
00198 protected:
00199
00206 Prof( Setup& msetup, JVMPI_Interface* jvmpi);
00207
00208 public:
00209
00211 virtual ~Prof();
00212
00222 void runEvent( JVMPI_Event* event);
00223
00224 public:
00225
00236 Class* getClass( jobjectID classId, int create = 1) {
00237
00238 return activeClasses.get( classId);
00239 }
00240
00251 Method* getMethod( jmethodID methodId, int create = 1) {
00252
00253 return activeMethods.get( methodId);
00254 }
00255
00266 Thread* getThread( JNIEnv* envId, int create = 1) {
00267
00268 return activeThreads.get( envId);
00269 }
00270
00282 AllocTrace* getAllocTrace( int numFrames, JVMPI_CallFrame* frames, int create = 1);
00283
00295 AllocObject* getAllocObject( jobjectID classId, jint isArray, int create = 1);
00296
00309 AllocObjectMethod* getAllocObjectMethod( jobjectID classId, jint isArray, jmethodID methodId, int create = 1);
00310
00324 AllocObjectTrace* getAllocObjectTrace( jobjectID classId, jint isArray, int numFrames, JVMPI_CallFrame* frames, int create = 1);
00325
00337 AllocThreadMethod* getAllocThreadMethod( JNIEnv* envId, jmethodID methodId, int create = 1);
00338
00351 AllocThreadTrace* getAllocThreadTrace( JNIEnv* envId, int numFrames, JVMPI_CallFrame* frames, int create = 1);
00352
00365 AllocThreadObject* getAllocThreadObject( JNIEnv* envId, jobjectID classId, jint isArray, int create = 1);
00366
00380 AllocThreadObjectMethod* getAllocThreadObjectMethod( JNIEnv* envId, jobjectID classId, jint isArray, jmethodID methodId, int create = 1);
00381
00396 AllocThreadObjectTrace* getAllocThreadObjectTrace( JNIEnv* envId, jobjectID classId, jint isArray, int numFrames, JVMPI_CallFrame* frames, int create = 1);
00397
00409 CpuTrace* getCpuTrace( int numFrames, JVMPI_CallFrame* frames, int create = 1);
00410
00422 CpuThreadMethod* getCpuThreadMethod( JNIEnv* envId, jmethodID methodId, int create = 1);
00423
00436 CpuThreadTrace* getCpuThreadTrace( JNIEnv* envId, int numFrames, JVMPI_CallFrame* frames, int create = 1);
00437
00449 MonTrace* getMonTrace( int numFrames, JVMPI_CallFrame* frames, int create = 1);
00450
00462 MonThreadMethod* getMonThreadMethod( JNIEnv* envId, jmethodID methodId, int create = 1);
00463
00476 MonThreadTrace* getMonThreadTrace( JNIEnv* envId, int numFrames, JVMPI_CallFrame* frames, int create = 1);
00477
00478 private:
00479
00493 void event_arenaDelete( JVMPI_Event* event);
00494
00505 void event_arenaNew( JVMPI_Event* event);
00506
00517 void event_classLoad( JVMPI_Event* event);
00518
00530 void event_classUnload( JVMPI_Event* event);
00531
00542 void event_gcStart( JVMPI_Event* event);
00543
00553 void event_gcFinish( JVMPI_Event* event);
00554
00565 void event_jniGlobalrefAlloc( JVMPI_Event* event);
00566
00576 void event_jniGlobalrefFree( JVMPI_Event* event);
00577
00588 void event_jniWeakGlobalrefAlloc( JVMPI_Event* event);
00589
00599 void event_jniWeakGlobalrefFree( JVMPI_Event* event);
00600
00610 void event_jvmInitDone( JVMPI_Event* event);
00611
00620 void event_jvmShutDown( JVMPI_Event* event);
00621
00631 void event_methodEntry( JVMPI_Event* event);
00632
00642 void event_methodExit ( JVMPI_Event* event);
00643
00658 void event_monitorContendedEnter( JVMPI_Event* event);
00659
00675 void event_monitorContendedEntered( JVMPI_Event* event);
00676
00690 void event_monitorWaited( JVMPI_Event* event);
00691
00702 void event_objectAlloc( JVMPI_Event* event);
00703
00715 void event_objectFree( JVMPI_Event* event);
00716
00728 void event_objectMove( JVMPI_Event* event);
00729
00740 void event_threadStart( JVMPI_Event* event);
00741
00751 void event_threadEnd( JVMPI_Event* event);
00752
00753 private:
00754
00756 int shuttingDown;
00757
00759 int threadsSuspended;
00760
00761 public:
00762
00764 Lock shutdownLock;
00765
00766 private:
00767
00769 static int communThreadEnd;
00770
00775 static void communThreadRoutine( void*);
00776
00777 public:
00778
00792 virtual void shutdown();
00793
00806 virtual jint isShutdowned();
00807
00813 virtual void suspendVM();
00814
00821 virtual void resumeVM();
00822
00829 virtual void exitVM();
00830
00845 virtual jint getInfo( objectID infoId,
00846 eInfoType type,
00847 InfoBinaryFormat*& info);
00848
00862 virtual jint getData( objectID objId,
00863 eDataType type,
00864 sData& data);
00865
00887 virtual jint getAll( objectID objId,
00888 eSeqType what,
00889 jint includeInfo,
00890 jint optionalArg,
00891 seqID& seq) {
00892
00893 return getAllOrChanged( objId, what, includeInfo, optionalArg, seq, 1);
00894 }
00895
00914 virtual jint getChanged( objectID objId,
00915 eSeqType what,
00916 jint includeInfo,
00917 jint optionalArg,
00918 seqID& seq) {
00919
00920 return getAllOrChanged( objId, what, includeInfo, optionalArg, seq, 0);
00921 }
00922
00929 virtual void enableGC();
00930
00938 virtual void disableGC();
00939
00945 virtual void runGC();
00946
00947 private:
00948
00949
00950
00951
00952 jint getAllOrChanged( objectID objId,
00953 eSeqType what,
00954 jint includeInfo,
00955 jint optionalArg,
00956 seqID& seq,
00957 int all);
00958
00959 private:
00960
00972 objectID getInfoId( IdObject* o, eSeqType seqType);
00973
00985 sID* copy( sID* dest, IdObject* src, objectID infoId, jint includeInfo);
00986
01001 template<class T, class L>
01002 void getDataFromList( List<T,L>& list,
01003 seqID& seq,
01004 int all,
01005 eSeqType st,
01006 jint includeInfo,
01007 jint optionalArg) {
01008
01009 T* a = list.first();
01010 while( a) {
01011
01012 if( (all || a->isChanged()) && getDataFromList_filter( a, optionalArg)) {
01013
01014 seq.add( copy( new sID, a, getInfoId( a, st), includeInfo));
01015 a->setUnchanged();
01016 }
01017
01018 a = list.next( a);
01019 }
01020 }
01021
01038 int getDataFromList_filter( IdObject* o, jint optionalArg);
01039
01051 jint getInfoBinaryFormat( objectID infoId,
01052 InfoBinaryFormat*& info,
01053 jint& infoType);
01054
01055 public:
01056
01064 static void dumpError( const char* context,
01065 const char* error,
01066 const char* file,
01067 int line);
01068
01069 private:
01070
01072 static Prof* _prof;
01073
01074 public:
01075
01080 static Prof& prof() { return *_prof;}
01081
01089 static Prof* create( char* options, JVMPI_Interface* jvmpi);
01090
01094 static void destroy();
01095
01105 static void notifyEvent( JVMPI_Event* event) {
01106
01107 if( _prof) _prof->runEvent( event);
01108 }
01109
01110 private:
01111
01112
01113
01114
01115 static int findParent( Thread* t, void** inout);
01116 static int findGroup( GroupThread* g, void** inout);
01117 };
01118
01119 #endif // _PROF_H_