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

prof_monitor.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 #include "../prof/synchronized.h"
00037 #include "../delay/delay.h"
00038 #include "../mon/monThreadMethod.h"
00039 #include "../mon/monThreadTrace.h"
00040 #include "../mon/monTrace.h"
00041 
00042 void Prof::event_monitorContendedEnter( JVMPI_Event* event) {
00043 
00044         Synchronized sync(dataLock);
00045 
00046         Thread* t;
00047         if (!(t = getThread(event->env_id))) {
00048                 PROF_ERROR("MONITOR CONTENDED ENTER", "Thread not found");
00049                 return;
00050         }
00051 
00052         static int firstTime = 1;
00053         if( firstTime) {
00054 
00055                 jvmpiInterface->EnableEvent( JVMPI_EVENT_MONITOR_CONTENDED_ENTERED, NULL);
00056                 jvmpiInterface->EnableEvent( JVMPI_EVENT_MONITOR_WAITED,            NULL);
00057 
00058                 firstTime = 0;
00059         }
00060 
00061         t->monitorEnter = 1;
00062         t->monitorEnterObject = event->u.monitor.object;
00063         t->monitorEnterTime = Delay::getMilliticks(); 
00064 }
00065 
00066 void Prof::event_monitorContendedEntered( JVMPI_Event* event) {
00067 
00068         Synchronized sync(dataLock);
00069 
00070         Thread* t;
00071         if (!(t = getThread(event->env_id))) {
00072                 PROF_ERROR("MONITOR CONTENDED ENTERED", "Thread not found");
00073                 return;
00074         }
00075 
00076         if ((!(t->monitorEnter)) || (t->monitorEnterObject != event->u.monitor.object)) {
00077                 PROF_ERROR("MONITOR CONTENDED ENTERED", "No corresponding MONITOR CONTENDED ENTER");
00078                 t->monitorEnter = 0;
00079                 return;
00080         }
00081         t->monitorEnter = 0;
00082 
00083         unsigned long curTime = Delay::getMilliticks();
00084         if (curTime < t->monitorEnterTime) return;
00085 
00086         int numFrames = 1;
00087         if (setup.mon.level == Setup::LEVEL_TRACE) numFrames = setup.mon.traceDepth; 
00088 
00089         JVMPI_CallTrace callTrace;
00090         JVMPI_CallFrame callFrames[MAX_TRACE];
00091 
00092         callTrace.env_id     = event->env_id;
00093         callTrace.num_frames = (jint)numFrames;
00094         callTrace.frames     = callFrames;
00095 
00096         jvmpiInterface->GetCallTrace(&callTrace, (jint)numFrames);
00097         numFrames = callTrace.num_frames;
00098         if (numFrames == 0) {
00099                 PROF_ERROR("MONITOR CONTENDED ENTERED", "GetCallTrace failed");
00100                 return;
00101         }
00102 
00103         MonStatData* stat;
00104 
00105         if (setup.mon.threadsEnabled) {
00106 
00107                 if (setup.mon.level == Setup::LEVEL_METHOD) {
00108 
00109                         if (!(stat = getMonThreadMethod(event->env_id, callFrames[0].method_id))) {
00110                                 PROF_ERROR("MONITOR CONTENDED ENTERED", "Cannot get MonThreadMethod");
00111                                 return;
00112                         }
00113                 }
00114                 else {
00115 
00116                         if (!(stat = getMonThreadTrace(event->env_id, numFrames, callFrames))) {
00117                                 PROF_ERROR("MONITOR CONTENDED ENTERED", "Cannot get MonThreadTrace");
00118                                 return;
00119                         }
00120                 }
00121         }
00122         else {
00123                 if (setup.mon.level == Setup::LEVEL_METHOD) {
00124 
00125                         if (!(stat = getMethod(callFrames[0].method_id))) {
00126                                 PROF_ERROR("MONITOR CONTENDED ENTERED", "Method not found");
00127                                 return;
00128                         }
00129                 }
00130                 else {
00131 
00132                         if (!(stat = getMonTrace(numFrames, callFrames))) {
00133                                 PROF_ERROR("MONITOR CONTENDED ENTERED", "Cannot get MonTrace");
00134                                 return;
00135                         }
00136                 }
00137         } 
00138 
00139         int hits = (stat->wait) ? 0 : 1;
00140         stat->addMonStat(hits, curTime - t->monitorEnterTime);
00141 }
00142 
00143 void Prof::event_monitorWaited( JVMPI_Event* event) {
00144 
00145         Synchronized sync(dataLock);
00146 
00147         Thread* t;
00148         if (!(t = getThread(event->env_id))) {
00149                 PROF_ERROR("MONITOR WAITED", "Thread not found");
00150                 return;
00151         }
00152 
00153         int numFrames = 1;
00154         if (setup.mon.level == Setup::LEVEL_TRACE) numFrames = setup.mon.traceDepth; 
00155 
00156         JVMPI_CallTrace callTrace;
00157         JVMPI_CallFrame callFrames[MAX_TRACE];
00158 
00159         callTrace.env_id     = event->env_id;
00160         callTrace.num_frames = (jint)numFrames;
00161         callTrace.frames     = callFrames;
00162 
00163         jvmpiInterface->GetCallTrace(&callTrace, (jint)numFrames);
00164         numFrames = callTrace.num_frames;
00165         if (numFrames == 0) {
00166                 PROF_ERROR("MONITOR WAITED", "GetCallTrace failed");
00167                 return;
00168         }
00169 
00170         MonStatData* stat;
00171 
00172         if (setup.mon.threadsEnabled) {
00173 
00174                 if (setup.mon.level == Setup::LEVEL_METHOD) {
00175 
00176                         if (!(stat = getMonThreadMethod(event->env_id, callFrames[0].method_id))) {
00177                                 PROF_ERROR("MONITOR WAITED", "Cannot get MonThreadMethod");
00178                                 return;
00179                         }
00180                 }
00181                 else {
00182 
00183                         if (!(stat = getMonThreadTrace(event->env_id, numFrames, callFrames))) {
00184                                 PROF_ERROR("MONITOR WAITED", "Cannot get MonThreadTrace");
00185                                 return;
00186                         }
00187                 }
00188         }
00189         else {
00190                 if (setup.mon.level == Setup::LEVEL_METHOD) {
00191 
00192                         if (!(stat = getMethod(callFrames[0].method_id))) {
00193                                 PROF_ERROR("MONITOR WAITED", "Method not found");
00194                                 return;
00195                         }
00196                 }
00197                 else {
00198 
00199                         if (!(stat = getMonTrace(numFrames, callFrames))) {
00200                                 PROF_ERROR("MONITOR WAITED", "Cannot get MonTrace");
00201                                 return;
00202                         }
00203                 }
00204         } 
00205 
00206         stat->wait = 1;
00207         stat->addMonStat(1, event->u.monitor_wait.timeout);
00208 }

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