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

prof.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 "../prof/prof.h"
00036 
00037 #define tF( i, a, b) tabFunc[i].event = a; tabFunc[i].func = b
00038 
00039 Prof::Prof( Setup& msetup, JVMPI_Interface* jvmpi) :
00040 
00041         IProf( msetup, jvmpi),
00042 
00043         dataLock( "_data_lock", jvmpi),
00044         shutdownLock( "_shutdown_lock", jvmpi),
00045         gcLock( "_gc_lock", jvmpi),
00046 
00047         jvmpiInterface( jvmpi),
00048 
00049         setup( msetup),
00050         sampling( jvmpi),
00051 
00052         shuttingDown( 0),
00053         threadsSuspended( 0) {
00054 
00055         tF(  0, JVMPI_EVENT_ARENA_DELETE,                  &Prof::event_arenaDelete);
00056         tF(  1, JVMPI_EVENT_ARENA_NEW,                     &Prof::event_arenaNew);
00057         tF(  2, JVMPI_EVENT_CLASS_LOAD,                    &Prof::event_classLoad);
00058         tF(  3, JVMPI_EVENT_CLASS_LOAD_HOOK,               NULL);
00059         tF(  4, JVMPI_EVENT_CLASS_UNLOAD,                  &Prof::event_classUnload);
00060         tF(  5, JVMPI_EVENT_COMPILED_METHOD_LOAD,          NULL);
00061         tF(  6, JVMPI_EVENT_COMPILED_METHOD_UNLOAD,        NULL);
00062         tF(  7, JVMPI_EVENT_DATA_DUMP_REQUEST,             NULL);
00063         tF(  8, JVMPI_EVENT_DATA_RESET_REQUEST,            NULL);
00064         tF(  9, JVMPI_EVENT_GC_FINISH,                     &Prof::event_gcFinish);
00065         tF( 10, JVMPI_EVENT_GC_START,                      &Prof::event_gcStart);
00066         tF( 11, JVMPI_EVENT_HEAP_DUMP,                     NULL);
00067         tF( 12, JVMPI_EVENT_JNI_GLOBALREF_ALLOC,           &Prof::event_jniGlobalrefAlloc);
00068         tF( 13, JVMPI_EVENT_JNI_GLOBALREF_FREE,            &Prof::event_jniGlobalrefFree);
00069         tF( 14, JVMPI_EVENT_JNI_WEAK_GLOBALREF_ALLOC,      &Prof::event_jniWeakGlobalrefAlloc);
00070         tF( 15, JVMPI_EVENT_JNI_WEAK_GLOBALREF_FREE,       &Prof::event_jniWeakGlobalrefFree);
00071         tF( 16, JVMPI_EVENT_JVM_INIT_DONE,                 &Prof::event_jvmInitDone);
00072         tF( 17, JVMPI_EVENT_JVM_SHUT_DOWN,                 &Prof::event_jvmShutDown);
00073         tF( 18, JVMPI_EVENT_METHOD_ENTRY,                  &Prof::event_methodEntry);
00074         tF( 19, JVMPI_EVENT_METHOD_ENTRY2,                 NULL);
00075         tF( 20, JVMPI_EVENT_METHOD_EXIT,                   &Prof::event_methodExit);
00076         tF( 21, JVMPI_EVENT_MONITOR_CONTENDED_ENTER,       &Prof::event_monitorContendedEnter);
00077         tF( 22, JVMPI_EVENT_MONITOR_CONTENDED_ENTERED,     &Prof::event_monitorContendedEntered);
00078         tF( 23, JVMPI_EVENT_MONITOR_CONTENDED_EXIT,        NULL);
00079         tF( 24, JVMPI_EVENT_MONITOR_DUMP,                  NULL);
00080         tF( 25, JVMPI_EVENT_MONITOR_WAIT,                  NULL);
00081         tF( 26, JVMPI_EVENT_MONITOR_WAITED,                &Prof::event_monitorWaited);
00082         tF( 27, JVMPI_EVENT_OBJECT_ALLOC,                  &Prof::event_objectAlloc);
00083         tF( 28, JVMPI_EVENT_OBJECT_DUMP,                   NULL);
00084         tF( 29, JVMPI_EVENT_OBJECT_FREE,                   &Prof::event_objectFree);
00085         tF( 30, JVMPI_EVENT_OBJECT_MOVE,                   &Prof::event_objectMove);
00086         tF( 31, JVMPI_EVENT_RAW_MONITOR_CONTENDED_ENTER,   NULL);
00087         tF( 32, JVMPI_EVENT_RAW_MONITOR_CONTENDED_ENTERED, NULL);
00088         tF( 33, JVMPI_EVENT_RAW_MONITOR_CONTENDED_EXIT,    NULL);
00089         tF( 34, JVMPI_EVENT_THREAD_END,                    &Prof::event_threadEnd);
00090         tF( 35, JVMPI_EVENT_THREAD_START,                  &Prof::event_threadStart);
00091         tF( 36, JVMPI_EVENT_INSTRUCTION_START,             NULL);
00092         
00093         tF( 37, JVMPI_EVENT_CLASS_LOAD   | JVMPI_REQUESTED_EVENT, &Prof::event_classLoad);
00094         tF( 38, JVMPI_EVENT_THREAD_START | JVMPI_REQUESTED_EVENT, &Prof::event_threadStart);
00095         tF( 39, JVMPI_EVENT_OBJECT_ALLOC | JVMPI_REQUESTED_EVENT, &Prof::event_objectAlloc);
00096 }
00097 
00098 Prof::~Prof() {
00099 
00100         delete &setup;
00101 }
00102 
00103 void Prof::runEvent( JVMPI_Event* event) {
00104 
00105         sF* p = tabFunc;
00106         
00107         for( int i = 0; i < TAB_FUNC_SIZE; i++, p++) {
00108         
00109                 if( event->event_type == p->event) {
00110 
00111                         if( p->func) (this->*(p->func))( event);
00112                         break;
00113                 }
00114         }
00115 }
00116 
00117 int Prof::communThreadEnd = 0;
00118 
00119 void Prof::communThreadRoutine( void*) {
00120 
00121         _prof->shutdownLock.wait();
00122         while( !communThreadEnd) _prof->run();
00123 }
00124 
00125 void Prof::dumpError(const char* context, const char* error, const char* file, int line) {
00126 
00127         cerr << "PROF ERROR (" << file << ", " << line << ") : " << context << " - " << error << endl;
00128 }
00129 
00130 Prof* Prof::_prof = NULL;
00131 
00132 Prof* Prof::create( char* options, JVMPI_Interface* jvmpi) {
00133 
00134         return (_prof = new Prof( *(new Setup( options)), jvmpi));
00135 }
00136 
00137 void Prof::destroy() {
00138 
00139         static int destroying = 0;
00140 
00141         if( destroying) return;
00142         destroying = 1;
00143 
00144         if( _prof) delete _prof;
00145         _prof = NULL;
00146 }

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