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

prof_get.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 "../cpu/cpuTrace.h"
00037 #include "../shared/traceFrame.h"
00038 #include "../cpu/cpuThreadMethod.h"
00039 #include "../cpu/cpuThreadTrace.h"
00040 #include "../alloc/allocTrace.h"
00041 #include "../alloc/allocObject.h"
00042 #include "../alloc/allocObjectMethod.h"
00043 #include "../alloc/allocObjectTrace.h"
00044 #include "../alloc/allocThreadMethod.h"
00045 #include "../alloc/allocThreadTrace.h"
00046 #include "../alloc/allocThreadObject.h"
00047 #include "../alloc/allocThreadObjectMethod.h"
00048 #include "../alloc/allocThreadObjectTrace.h"
00049 #include "../mon/monTrace.h"
00050 #include "../mon/monThreadMethod.h"
00051 #include "../mon/monThreadTrace.h"
00052 
00053 CpuTrace* Prof::getCpuTrace(int numFrames, JVMPI_CallFrame* frames, int create) {
00054 
00055         TraceKey key;
00056         CpuTrace* trace;
00057 
00058         key.numFrames = numFrames;
00059         key.frames = frames;
00060 
00061         if (trace = activeCpuTraces.get(key)) return trace;
00062         if (!create) return NULL;
00063 
00064         TraceFrame* traceFrames = TraceFrame::newArray(numFrames);
00065         Method *method;
00066 
00067         for (int i = 0; i < numFrames; i++) {
00068                 if (!(method = getMethod(frames[i].method_id))) {
00069                         TraceFrame::deleteArray(traceFrames, numFrames);
00070                         return NULL;
00071                 }
00072                 traceFrames[i].method = method;
00073                 traceFrames[i].lineno = frames[i].lineno;
00074         }
00075 
00076         trace = new CpuTrace;
00077 
00078         trace->method = traceFrames[0].method;
00079         trace->numFrames = numFrames;
00080         trace->frames = traceFrames;
00081 
00082         activeCpuTraces.add(trace);
00083         trace->method->cpuTraces.add(trace);
00084 
00085         return trace;
00086 }
00087 
00088 CpuThreadMethod* Prof::getCpuThreadMethod(JNIEnv* envId, jmethodID methodId, int create) {
00089 
00090         CpuThreadMethodKey key;
00091         CpuThreadMethod* threadMethod;
00092 
00093         key.envId = envId;
00094         key.methodId = methodId;
00095         
00096         if (threadMethod = activeCpuThreadMethods.get(key)) return threadMethod;
00097         if (!create) return NULL;
00098 
00099         Method* method;
00100         Thread* thread;
00101 
00102         if (!(method = getMethod(methodId))) return NULL;
00103         if (!(thread = getThread(envId))) return NULL;
00104 
00105         threadMethod = new CpuThreadMethod;
00106 
00107         threadMethod->method = method;
00108         threadMethod->thread = thread;
00109 
00110         activeCpuThreadMethods.add(threadMethod);
00111         method->cpuThreadMethods.add(threadMethod);
00112         thread->cpuThreadMethods.add(threadMethod);
00113 
00114         return threadMethod;
00115 }
00116 
00117 CpuThreadTrace* Prof::getCpuThreadTrace(JNIEnv* envId, int numFrames, JVMPI_CallFrame* frames, int create) {
00118 
00119         CpuThreadTraceKey key;
00120         CpuThreadTrace* threadTrace;
00121 
00122         key.envId = envId;
00123         key.traceKey.numFrames = numFrames;
00124         key.traceKey.frames = frames;
00125         
00126         if (threadTrace = activeCpuThreadTraces.get(key)) return threadTrace;
00127         if (!create) return NULL;
00128 
00129         CpuThreadMethod* threadMethod;
00130         CpuTrace* trace;
00131 
00132         if (!(threadMethod = getCpuThreadMethod(envId, frames[0].method_id))) return NULL;
00133         if (!(trace = getCpuTrace(numFrames, frames))) return NULL;
00134 
00135         threadTrace = new CpuThreadTrace;
00136 
00137         threadTrace->threadMethod = threadMethod;
00138         threadTrace->trace = trace;
00139 
00140         activeCpuThreadTraces.add(threadTrace);
00141         threadMethod->threadTraces.add(threadTrace);
00142         trace->threadTraces.add(threadTrace);
00143 
00144         return threadTrace;
00145 }
00146 
00147 AllocTrace* Prof::getAllocTrace(int numFrames, JVMPI_CallFrame* frames, int create) {
00148 
00149         TraceKey key;
00150         AllocTrace* trace;
00151 
00152         key.numFrames = numFrames;
00153         key.frames = frames;
00154 
00155         if (trace = activeAllocTraces.get(key)) return trace;
00156         if (!create) return NULL;
00157 
00158         TraceFrame* traceFrames = TraceFrame::newArray(numFrames);
00159         Method *method;
00160 
00161         for (int i = 0; i < numFrames; i++) {
00162                 if (!(method = getMethod(frames[i].method_id))) {
00163                         TraceFrame::deleteArray(traceFrames, numFrames);
00164                         return NULL;
00165                 }
00166                 traceFrames[i].method = method;
00167                 traceFrames[i].lineno = frames[i].lineno;
00168         }
00169 
00170         trace = new AllocTrace;
00171 
00172         trace->method = traceFrames[0].method;
00173         trace->numFrames = numFrames;
00174         trace->frames = traceFrames;
00175 
00176         activeAllocTraces.add(trace);
00177         trace->method->allocTraces.add(trace);
00178 
00179         return trace;
00180 }
00181 
00182 AllocObject* Prof::getAllocObject(jobjectID classId, jint isArray, int create) {
00183 
00184         AllocObjectKey key;
00185         AllocObject* object;
00186 
00187         key.classId = classId;
00188         key.isArray = isArray;
00189 
00190         if (object = activeAllocObjects.get(key)) return object;
00191         if (!create) return NULL;
00192 
00193         Class *clss = NULL;
00194 
00195         if ((isArray == JVMPI_NORMAL_OBJECT) || (isArray == JVMPI_CLASS))
00196                 if (!(clss = getClass(classId))) return NULL;
00197 
00198         object = new AllocObject;
00199 
00200         object->clss = clss;
00201         object->classId = classId;
00202         object->isArray = isArray;
00203 
00204         if (isArray == JVMPI_NORMAL_OBJECT) clss->allocObject = object;
00205         else if (isArray == JVMPI_CLASS) clss->allocObjectArray = object;
00206 
00207         activeAllocObjects.add(object);
00208         allocObjects.add(object);
00209 
00210         return object;
00211 }
00212 
00213 AllocObjectMethod* Prof::getAllocObjectMethod(jobjectID classId, jint isArray, jmethodID methodId, int create) {
00214 
00215         AllocObjectMethodKey key;
00216         AllocObjectMethod* objectMethod;
00217 
00218         key.objectKey.classId = classId;
00219         key.objectKey.isArray = isArray;
00220         key.methodId = methodId;
00221 
00222         if (objectMethod = activeAllocObjectMethods.get(key)) return objectMethod;
00223         if (!create) return NULL;
00224 
00225         AllocObject *object;
00226         Method* method;
00227 
00228         if (!(object = getAllocObject(classId, isArray))) return NULL;
00229         if (!(method = getMethod(methodId))) return NULL;
00230 
00231         objectMethod = new AllocObjectMethod;
00232 
00233         objectMethod->object = object;
00234         objectMethod->method = method;
00235 
00236         activeAllocObjectMethods.add(objectMethod);
00237         object->objectMethods.add(objectMethod);
00238         method->allocObjectMethods.add(objectMethod);
00239 
00240         return objectMethod;
00241 }
00242 
00243 AllocObjectTrace* Prof::getAllocObjectTrace(jobjectID classId, jint isArray, int numFrames, JVMPI_CallFrame* frames, int create) {
00244 
00245         AllocObjectTraceKey key;
00246         AllocObjectTrace* objectTrace;
00247 
00248         key.objectKey.classId = classId;
00249         key.objectKey.isArray = isArray;
00250         key.traceKey.numFrames = numFrames;
00251         key.objectKey.isArray = isArray;
00252 
00253         if (objectTrace = activeAllocObjectTraces.get(key)) return objectTrace;
00254         if (!create) return NULL;
00255 
00256         AllocObjectMethod *objectMethod;
00257         AllocTrace* trace;
00258 
00259         if (!(objectMethod = getAllocObjectMethod(classId, isArray, frames[0].method_id))) return NULL;
00260         if (!(trace = getAllocTrace(numFrames, frames))) return NULL;
00261 
00262         objectTrace = new AllocObjectTrace;
00263 
00264         objectTrace->objectMethod = objectMethod;
00265         objectTrace->trace = trace;
00266 
00267         activeAllocObjectTraces.add(objectTrace);
00268         objectMethod->objectTraces.add(objectTrace);
00269         trace->objectTraces.add(objectTrace);
00270 
00271         return objectTrace;
00272 }
00273         
00274 AllocThreadMethod* Prof::getAllocThreadMethod(JNIEnv* envId, jmethodID methodId, int create) {
00275 
00276         AllocThreadMethodKey key;
00277         AllocThreadMethod* threadMethod;
00278 
00279         key.envId = envId;
00280         key.methodId = methodId;
00281 
00282         if (threadMethod = activeAllocThreadMethods.get(key)) return threadMethod;
00283         if (!create) return NULL;
00284 
00285         Thread* thread;
00286         Method* method;
00287 
00288         if (!(thread = getThread(envId))) return NULL;
00289         if (!(method = getMethod(methodId))) return NULL;
00290 
00291         threadMethod = new AllocThreadMethod;
00292 
00293         threadMethod->thread = thread;
00294         threadMethod->method = method;
00295 
00296         activeAllocThreadMethods.add(threadMethod);
00297         thread->allocThreadMethods.add(threadMethod);
00298         method->allocThreadMethods.add(threadMethod);
00299 
00300         return  threadMethod;
00301 }
00302 
00303 AllocThreadTrace* Prof::getAllocThreadTrace(JNIEnv* envId, int numFrames, JVMPI_CallFrame* frames, int create) {
00304 
00305         AllocThreadTraceKey key;
00306         AllocThreadTrace* threadTrace;
00307 
00308         key.envId = envId;
00309         key.traceKey.numFrames = numFrames;
00310         key.traceKey.frames = frames; 
00311 
00312         if (threadTrace = activeAllocThreadTraces.get(key)) return threadTrace;
00313         if (!create) return NULL;
00314 
00315         AllocThreadMethod* threadMethod;
00316         AllocTrace* trace;
00317 
00318         if (!(threadMethod = getAllocThreadMethod(envId, frames[0].method_id))) return NULL;
00319         if (!(trace = getAllocTrace(numFrames, frames))) return NULL;
00320 
00321         threadTrace = new AllocThreadTrace;
00322 
00323         threadTrace->threadMethod = threadMethod;
00324         threadTrace->trace = trace;
00325 
00326         activeAllocThreadTraces.add(threadTrace);
00327         threadMethod->threadTraces.add(threadTrace);
00328         trace->threadTraces.add(threadTrace);
00329 
00330         return  threadTrace;
00331 }
00332 
00333 AllocThreadObject* Prof::getAllocThreadObject(JNIEnv* envId, jobjectID classId, jint isArray, int create) {
00334 
00335         AllocThreadObjectKey key;
00336         AllocThreadObject* threadObject;
00337 
00338         key.envId = envId;
00339         key.objectKey.classId = classId;
00340         key.objectKey.isArray = isArray;
00341 
00342         if (threadObject = activeAllocThreadObjects.get(key)) return threadObject;
00343         if (!create) return NULL;
00344 
00345         Thread *thread;
00346         AllocObject *object;
00347 
00348         if (!(thread = getThread(envId))) return NULL;
00349         if (!(object = getAllocObject(classId, isArray))) return NULL;
00350 
00351         threadObject = new AllocThreadObject;
00352 
00353         threadObject->thread = thread;
00354         threadObject->object = object;
00355 
00356         activeAllocThreadObjects.add(threadObject);
00357         thread->allocThreadObjects.add(threadObject);
00358         object->threadObjects.add(threadObject);
00359 
00360         return threadObject;
00361 }
00362 
00363 AllocThreadObjectMethod* Prof::getAllocThreadObjectMethod(JNIEnv* envId, jobjectID classId, jint isArray, jmethodID methodId, int create) {
00364 
00365         AllocThreadObjectMethodKey key;
00366         AllocThreadObjectMethod* threadObjectMethod;
00367 
00368         key.envId = envId;
00369         key.objectMethodKey.objectKey.classId = classId;
00370         key.objectMethodKey.objectKey.isArray = isArray;
00371         key.objectMethodKey.methodId = methodId; 
00372 
00373         if (threadObjectMethod = activeAllocThreadObjectMethods.get(key)) return threadObjectMethod;
00374         if (!create) return NULL;
00375 
00376         AllocThreadObject *threadObject;
00377         AllocObjectMethod *objectMethod;
00378         AllocThreadMethod *threadMethod;
00379 
00380         if (!(threadObject = getAllocThreadObject(envId, classId, isArray))) return NULL;
00381         if (!(objectMethod = getAllocObjectMethod(classId, isArray, methodId))) return NULL;
00382         if (!(threadMethod = getAllocThreadMethod(envId, methodId))) return NULL;
00383 
00384         threadObjectMethod = new AllocThreadObjectMethod;
00385 
00386         threadObjectMethod->threadObject = threadObject;
00387         threadObjectMethod->objectMethod = objectMethod;
00388         threadObjectMethod->threadMethod = threadMethod;
00389 
00390         activeAllocThreadObjectMethods.add(threadObjectMethod);
00391         threadObject->threadObjectMethods.add(threadObjectMethod);
00392         objectMethod->threadObjectMethods.add(threadObjectMethod);
00393         threadMethod->threadObjectMethods.add(threadObjectMethod);
00394 
00395         return threadObjectMethod;
00396 }
00397 
00398 AllocThreadObjectTrace* Prof::getAllocThreadObjectTrace(JNIEnv* envId, jobjectID classId, jint isArray, int numFrames, JVMPI_CallFrame* frames, int create) {
00399 
00400         AllocThreadObjectTraceKey key;
00401         AllocThreadObjectTrace* threadObjectTrace;
00402 
00403         key.envId = envId;
00404         key.objectTraceKey.objectKey.classId = classId;
00405         key.objectTraceKey.objectKey.isArray = isArray;
00406         key.objectTraceKey.traceKey.numFrames = numFrames; 
00407         key.objectTraceKey.traceKey.frames = frames; 
00408 
00409         if (threadObjectTrace = activeAllocThreadObjectTraces.get(key)) return threadObjectTrace;
00410         if (!create) return NULL;
00411 
00412         AllocThreadObjectMethod *threadObjectMethod;
00413         AllocObjectTrace *objectTrace;
00414         AllocThreadTrace *threadTrace;
00415 
00416         if (!(threadObjectMethod = getAllocThreadObjectMethod(envId, classId, isArray, frames[0].method_id))) return NULL;
00417         if (!(objectTrace = getAllocObjectTrace(classId, isArray, numFrames, frames))) return NULL;
00418         if (!(threadTrace = getAllocThreadTrace(envId, numFrames, frames))) return NULL;
00419 
00420         threadObjectTrace = new AllocThreadObjectTrace;
00421 
00422         threadObjectTrace->threadObjectMethod = threadObjectMethod;
00423         threadObjectTrace->objectTrace = objectTrace;
00424         threadObjectTrace->threadTrace = threadTrace;
00425 
00426         activeAllocThreadObjectTraces.add(threadObjectTrace);
00427         threadObjectMethod->threadObjectTraces.add(threadObjectTrace);
00428         objectTrace->threadObjectTraces.add(threadObjectTrace);
00429         threadTrace->threadObjectTraces.add(threadObjectTrace);
00430 
00431         return threadObjectTrace;
00432 }
00433 
00434 MonTrace* Prof::getMonTrace(int numFrames, JVMPI_CallFrame* frames, int create) {
00435 
00436         TraceKey key;
00437         MonTrace* trace;
00438 
00439         key.numFrames = numFrames;
00440         key.frames = frames;
00441 
00442         if (trace = activeMonTraces.get(key)) return trace;
00443         if (!create) return NULL;
00444 
00445         TraceFrame* traceFrames = TraceFrame::newArray(numFrames);
00446         Method *method;
00447 
00448         for (int i = 0; i < numFrames; i++) {
00449                 if (!(method = getMethod(frames[i].method_id))) {
00450                         TraceFrame::deleteArray(traceFrames, numFrames);
00451                         return NULL;
00452                 }
00453                 traceFrames[i].method = method;
00454                 traceFrames[i].lineno = frames[i].lineno;
00455         }
00456 
00457         trace = new MonTrace;
00458 
00459         trace->method = traceFrames[0].method;
00460         trace->numFrames = numFrames;
00461         trace->frames = traceFrames;
00462 
00463         activeMonTraces.add(trace);
00464         trace->method->monTraces.add(trace);
00465 
00466         return trace;
00467 }
00468 
00469 MonThreadMethod* Prof::getMonThreadMethod(JNIEnv* envId, jmethodID methodId, int create) {
00470 
00471         MonThreadMethodKey key;
00472         MonThreadMethod* threadMethod;
00473 
00474         key.envId = envId;
00475         key.methodId = methodId;
00476         
00477         if (threadMethod = activeMonThreadMethods.get(key)) return threadMethod;
00478         if (!create) return NULL;
00479 
00480         Method* method;
00481         Thread* thread;
00482 
00483         if (!(method = getMethod(methodId))) return NULL;
00484         if (!(thread = getThread(envId))) return NULL;
00485 
00486         threadMethod = new MonThreadMethod;
00487 
00488         threadMethod->method = method;
00489         threadMethod->thread = thread;
00490 
00491         activeMonThreadMethods.add(threadMethod);
00492         method->monThreadMethods.add(threadMethod);
00493         thread->monThreadMethods.add(threadMethod);
00494 
00495         return threadMethod;
00496 }
00497 
00498 MonThreadTrace* Prof::getMonThreadTrace(JNIEnv* envId, int numFrames, JVMPI_CallFrame* frames, int create) {
00499 
00500         MonThreadTraceKey key;
00501         MonThreadTrace* threadTrace;
00502 
00503         key.envId = envId;
00504         key.traceKey.numFrames = numFrames;
00505         key.traceKey.frames = frames;
00506         
00507         if (threadTrace = activeMonThreadTraces.get(key)) return threadTrace;
00508         if (!create) return NULL;
00509 
00510         MonThreadMethod* threadMethod;
00511         MonTrace* trace;
00512 
00513         if (!(threadMethod = getMonThreadMethod(envId, frames[0].method_id))) return NULL;
00514         if (!(trace = getMonTrace(numFrames, frames))) return NULL;
00515 
00516         threadTrace = new MonThreadTrace;
00517 
00518         threadTrace->threadMethod = threadMethod;
00519         threadTrace->trace = trace;
00520 
00521         activeMonThreadTraces.add(threadTrace);
00522         threadMethod->threadTraces.add(threadTrace);
00523         trace->threadTraces.add(threadTrace);
00524 
00525         return threadTrace;
00526 }

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