|
Added
Link Here
|
| 1 |
/********************************************************************** |
| 2 |
* Copyright (c) 2005, 2007 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* $Id: JvmpiWriter.c,v 1.31 2007/01/22 19:14:31 nmehrega Exp $ |
| 8 |
* |
| 9 |
* Contributors: |
| 10 |
* IBM - Initial API and implementation |
| 11 |
**********************************************************************/ |
| 12 |
|
| 13 |
#include <ctype.h> |
| 14 |
#include <stddef.h> |
| 15 |
#include <time.h> |
| 16 |
#include <sys/types.h> |
| 17 |
#include <jvmpi.h> |
| 18 |
#include <stdlib.h> |
| 19 |
#include <stdio.h> |
| 20 |
#include <assert.h> |
| 21 |
#include <signal.h> |
| 22 |
#include <jni.h> |
| 23 |
#ifndef __OS400__ |
| 24 |
#include <sys/timeb.h> |
| 25 |
#endif |
| 26 |
#include <sys/types.h> |
| 27 |
#include <time.h> |
| 28 |
#include "eventmask.h" |
| 29 |
#include "hash.h" |
| 30 |
#include "JvmpiWriter.h" |
| 31 |
#include "piAgentExtension.h" |
| 32 |
#include "options.h" |
| 33 |
#include "filters.h" |
| 34 |
#include "RABindings.h" |
| 35 |
#include "JVMPIException.h" |
| 36 |
#ifndef __OS400__ |
| 37 |
#endif |
| 38 |
#include "RASocket.h" |
| 39 |
#include "print.h" |
| 40 |
#include "performance.h" |
| 41 |
#include "strings.h" |
| 42 |
#include "utility.h" |
| 43 |
|
| 44 |
#include "StatelessHeapSnapshotManager_C.h" |
| 45 |
|
| 46 |
#if defined __cplusplus && defined _HPUX |
| 47 |
#define ENV(e) e |
| 48 |
#define JOBJECT jclass |
| 49 |
#else |
| 50 |
#define ENV(e) (*e) |
| 51 |
#define JOBJECT jobject |
| 52 |
#endif |
| 53 |
|
| 54 |
#ifdef _SHOOTDEBUG |
| 55 |
#include "agentDebug.h" |
| 56 |
#endif |
| 57 |
|
| 58 |
/* |
| 59 |
* A note about agent extensions: |
| 60 |
* |
| 61 |
* Allan Pratt of the Rational software division of IBM added a feature |
| 62 |
* to this agent on March 31, 2004: a simple extensibility system |
| 63 |
* that lets people write agent extensions. Instructions for building an agent |
| 64 |
* extension can be found in piAgentExtension.h. |
| 65 |
* |
| 66 |
* The system is quite limited: it doesn't solve any of the hard problems |
| 67 |
* related to sending JVMPI events to multiple agents. It is barely adequate |
| 68 |
* for an agent extension that wants JVM_INIT_DONE and CLASS_LOAD_HOOK, |
| 69 |
* which is all we need it for right now. |
| 70 |
* |
| 71 |
* Every code segment related to this extension system has the |
| 72 |
* words "agent extension" in a comment nearby. |
| 73 |
*/ |
| 74 |
|
| 75 |
/** |
| 76 |
* MACROS |
| 77 |
* |
| 78 |
*/ |
| 79 |
/* following two undefs were added to avoid conflict from new java.h defs ... 135623 */ |
| 80 |
#undef ATTACH_THREAD |
| 81 |
#undef DETACH_THREAD |
| 82 |
|
| 83 |
#ifdef _WIN32 |
| 84 |
#define MODULE_REFERENCE HMODULE |
| 85 |
#define DLL_REFERENCE HINSTANCE |
| 86 |
#define DLL_NAME "jvm" |
| 87 |
#define RESOLVE_MODULE(name) GetModuleHandle(name) |
| 88 |
#define LOAD_LIBRARY(name) LoadLibrary(name) |
| 89 |
#define RESOLVE_ENTRY_POINT(mod, entry) GetProcAddress(mod, entry) |
| 90 |
#define ATTACH_THREAD(env) (*_jvmpiAgent_jvm)->AttachCurrentThread(_jvmpiAgent_jvm, (void**)&env, NULL) |
| 91 |
#define DETACH_THREAD() (*_jvmpiAgent_jvm)->DetachCurrentThread(_jvmpiAgent_jvm) |
| 92 |
#ifndef CDECL |
| 93 |
#define CDECL __cdecl |
| 94 |
#endif |
| 95 |
#elif MVS |
| 96 |
#include <dll.h> |
| 97 |
#define MODULE_REFERENCE dllhandle * |
| 98 |
#define DLL_REFERENCE dllhandle * |
| 99 |
#define DLL_NAME "libjava.so" |
| 100 |
#define RESOLVE_MODULE(name) dllload(name) |
| 101 |
#define LOAD_LIBRARY(name) dllload(name) |
| 102 |
#define RESOLVE_ENTRY_POINT(mod, entry) dllqueryfn(mod, entry) |
| 103 |
#define ATTACH_THREAD(env) (*_jvmpiAgent_jvm)->AttachCurrentThread(_jvmpiAgent_jvm, (void**)&env, NULL) |
| 104 |
#define DETACH_THREAD() (*_jvmpiAgent_jvm)->DetachCurrentThread(_jvmpiAgent_jvm) |
| 105 |
#ifndef CDECL |
| 106 |
#define CDECL |
| 107 |
#endif |
| 108 |
#elif _HPUX |
| 109 |
#include <dlfcn.h> |
| 110 |
#define MODULE_REFERENCE void * |
| 111 |
#define DLL_REFERENCE void * |
| 112 |
#define DLL_NAME "libjvm.sl" |
| 113 |
#define RESOLVE_MODULE(name) dlopen(name, RTLD_LAZY) |
| 114 |
#define LOAD_LIBRARY(name) dlopen(name, RTLD_LAZY) |
| 115 |
#define RESOLVE_ENTRY_POINT(mod, entry) dlsym(mod, entry) |
| 116 |
#define ATTACH_THREAD(env) (_jvmpiAgent_jvm)->AttachCurrentThread((void**)&env, NULL) |
| 117 |
#define DETACH_THREAD() (_jvmpiAgent_jvm)->DetachCurrentThread() |
| 118 |
#ifndef CDECL |
| 119 |
#define CDECL |
| 120 |
#endif |
| 121 |
#elif __OS400__ |
| 122 |
#define MODULE_REFERENCE void * |
| 123 |
#define DLL_REFERENCE void * |
| 124 |
#define DLL_NAME "libjvm" |
| 125 |
#define RESOLVE_MODULE(name) loadServicePgm(name) |
| 126 |
#define LOAD_LIBRARY(name) loadServicePgm(name) |
| 127 |
#define RESOLVE_ENTRY_POINT(mod, entry) findServicePgmEntry(mod, entry) |
| 128 |
#define ATTACH_THREAD(env) (*_jvmpiAgent_jvm)->AttachCurrentThread(_jvmpiAgent_jvm, (void**)&env, NULL) |
| 129 |
#define DETACH_THREAD() (*_jvmpiAgent_jvm)->DetachCurrentThread(_jvmpiAgent_jvm) |
| 130 |
#ifndef CDECL |
| 131 |
#define CDECL |
| 132 |
#endif |
| 133 |
#else |
| 134 |
#include <dlfcn.h> |
| 135 |
#define MODULE_REFERENCE void * |
| 136 |
#define DLL_REFERENCE void * |
| 137 |
#define DLL_NAME "libjvm.so" |
| 138 |
#define RESOLVE_MODULE(name) dlopen(name, RTLD_LAZY) |
| 139 |
#define LOAD_LIBRARY(name) dlopen(name, RTLD_LAZY) |
| 140 |
#define RESOLVE_ENTRY_POINT(mod, entry) dlsym(mod, entry) |
| 141 |
#define ATTACH_THREAD(env) (*_jvmpiAgent_jvm)->AttachCurrentThread(_jvmpiAgent_jvm, (void**)&env, NULL) |
| 142 |
#define DETACH_THREAD() (*_jvmpiAgent_jvm)->DetachCurrentThread(_jvmpiAgent_jvm) |
| 143 |
#ifndef CDECL |
| 144 |
#define CDECL |
| 145 |
#endif |
| 146 |
#endif |
| 147 |
|
| 148 |
#define IBM_VENDOR_STRING "IBM" |
| 149 |
#define IBM_VENDOR_STRING_LENGTH 3 |
| 150 |
#define SUN_VENDOR_STRING "Sun" |
| 151 |
#define SUN_VENDOR_STRING_LENGTH 3 |
| 152 |
/* we only use the first 3 characters in HP's vendor string "Hewlett-Packard Co." */ |
| 153 |
#define HP_VENDOR_STRING "Hew" |
| 154 |
#define HP_VENDOR_STRING_LENGTH 3 |
| 155 |
|
| 156 |
#define org_eclipse_hyades_collection_profiler_Profiler_PROFILER_EXECUTION_ONLY 1L |
| 157 |
#define org_eclipse_hyades_collection_profiler_Profiler_PROFILER_HEAP_ONLY 2L |
| 158 |
#define org_eclipse_hyades_collection_profiler_Profiler_PROFILER_EXECUTION_AND_HEAP 3L |
| 159 |
#define org_eclipse_hyades_collection_profiler_Profiler_PROFILER_OPTIMIZED_HEAP_ONLY 4L |
| 160 |
#define org_eclipse_hyades_collection_profiler_Profiler_EMIT_XML_SUCCESS 0L |
| 161 |
#define org_eclipse_hyades_collection_profiler_Profiler_EMIT_XML_SUSPENDED_IO 1L |
| 162 |
#define org_eclipse_hyades_collection_profiler_Profiler_EMIT_XML_FAIL 2L |
| 163 |
|
| 164 |
/** |
| 165 |
* TYPEDEFS |
| 166 |
*/ |
| 167 |
|
| 168 |
/* TraceON - turn on tracing |
| 169 |
TracePause - Pause tracing (keeping in mind that hash tables are not scrubbed) |
| 170 |
TraceOFF - Turn off tracing completely |
| 171 |
*/ |
| 172 |
enum TraceToggleType {TraceON,TracePause,TraceOFF}; |
| 173 |
typedef enum TraceToggleType TraceToggle; |
| 174 |
|
| 175 |
/* This is the signature declaration for all the event handlers from JVMPI. With a common |
| 176 |
signature we can load the functions into an array and random access the proper |
| 177 |
handler based upon the event type. |
| 178 |
*/ |
| 179 |
typedef void (*ProcessEventFunction)(JVMPI_Event *event, ThreadPrivateStorage *tps, BOOL isRequested, timestamp_t timestamp, timestamp_t cpu_timestamp); |
| 180 |
|
| 181 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 182 |
void *prevMthdTps=NULL; |
| 183 |
int meCount=0; /* methodEntryEvents count */ |
| 184 |
int mxCount=0; /* methodExitEvents count*/ |
| 185 |
|
| 186 |
void dumpMethodEventCounts(void) {/* dump MethodEvent counts */ |
| 187 |
if (meCount>0 || mxCount>0) { |
| 188 |
printf("Method entries/exits on tps %8x = %5d/%5d\n", (void *)prevMthdTps, meCount, mxCount); fflush(stdout); |
| 189 |
} |
| 190 |
meCount=mxCount=0; |
| 191 |
} |
| 192 |
#endif |
| 193 |
|
| 194 |
/* For pre-aggregation */ |
| 195 |
/* The threadsRoot list is a list of all "live" threads. |
| 196 |
I believe you could reach all the same elements using the thread hash table. |
| 197 |
This is an optimization opportunity. |
| 198 |
*/ |
| 199 |
struct ThreadListElement { |
| 200 |
ThreadPrivateStorage * data; |
| 201 |
struct ThreadListElement * next; |
| 202 |
struct ThreadListElement * prev; |
| 203 |
}; |
| 204 |
|
| 205 |
struct ThreadListElement * threadsRoot = 0; |
| 206 |
|
| 207 |
/* |
| 208 |
* Locks for pre-aggregation logic. |
| 209 |
* |
| 210 |
* threadListLock is used when you are reading or writing the list starting at threadsRoot. |
| 211 |
* |
| 212 |
* stackFrameStructureLock is used when you are changing (but not just reading) |
| 213 |
* the "next" and "child" pointers of any StackFrame object. This might seem unnecessary |
| 214 |
* since each thread has its own rooted StackFrame structure, but the killer is dumping: |
| 215 |
* during a dump, one thread reads all StackFrame structures, and having other threads |
| 216 |
* running and updating their "next" pointers could crash the dump. |
| 217 |
* |
| 218 |
* Technically, this lock could also be acquired when you update the field values |
| 219 |
* in any StackFrame, since the dump could see inconsistent data if it visits a node |
| 220 |
* at the same time you're updating it. But I don't want to do that - it's too expensive |
| 221 |
* to acquire this on every method entry and exit event. |
| 222 |
* |
| 223 |
* There is a no-lock alternative to stackFrameStructureLock: in the dumping logic, |
| 224 |
* use JNI to suspend all other Java threads. I think this will suspend them in Java, |
| 225 |
* not in the middle of a JVMPI event handler, so once they're all suspended the |
| 226 |
* thread doing the dumping will know it's safe. If you implement this, you can remove |
| 227 |
* all references to stackFrameStructureLock. |
| 228 |
* |
| 229 |
* Here's another no-lock trick: use the garbage collector instead. [Credit to Victor Havin |
| 230 |
* for this one.] If you want to do a dump, you use JNI to cause a GC. In the handler for |
| 231 |
* the "GC Started" notification from JVMPI, that's where you actually do the dump. |
| 232 |
* When you're in that handler, you know that all other Java threads are suspended in |
| 233 |
* safe states - definitely not executing handlers for other JVMPI events. |
| 234 |
*/ |
| 235 |
|
| 236 |
static ra_critsec_t * stackFrameStructureLock = 0; |
| 237 |
static ra_critsec_t * threadListLock = 0; |
| 238 |
|
| 239 |
/* For pre-aggregation */ |
| 240 |
void getStackFrameStructureLock() { |
| 241 |
if (stackFrameStructureLock == 0 ) { |
| 242 |
stackFrameStructureLock = (ra_critsec_t *)jvmpiAgent_Calloc(sizeof(ra_critsec_t)); |
| 243 |
ra_mutexCreate(stackFrameStructureLock); |
| 244 |
} |
| 245 |
|
| 246 |
ra_mutexEnter(stackFrameStructureLock); |
| 247 |
} |
| 248 |
|
| 249 |
/* For pre-aggregation */ |
| 250 |
void releaseStackFrameStructureLock() { |
| 251 |
if( stackFrameStructureLock == 0 ) { |
| 252 |
fprintf(stdout, "Error!! stackFrameStructureLock is NULL " ); |
| 253 |
fflush(stdout); |
| 254 |
} |
| 255 |
ra_mutexExit(stackFrameStructureLock); |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
/* For pre-aggregation */ |
| 260 |
void getThreadListLock() { |
| 261 |
if (threadListLock == 0 ) { |
| 262 |
threadListLock = (ra_critsec_t *)jvmpiAgent_Calloc(sizeof(ra_critsec_t)); |
| 263 |
ra_mutexCreate(threadListLock); |
| 264 |
} |
| 265 |
|
| 266 |
ra_mutexEnter(threadListLock); |
| 267 |
} |
| 268 |
|
| 269 |
/* For pre-aggregation */ |
| 270 |
void releaseThreadListLock() { |
| 271 |
if( threadListLock == 0 ) { |
| 272 |
fprintf(stdout, "Error!! threadListLock is NULL " ); |
| 273 |
fflush(stdout); |
| 274 |
} |
| 275 |
ra_mutexExit(threadListLock); |
| 276 |
} |
| 277 |
|
| 278 |
static BOOL _traceResourcesGone = FALSE; /* Trace Hash Tables were cleaned up * pre-agg: 134635 */ |
| 279 |
|
| 280 |
extern int _requestClassObj; /* used to flag when a object_alloc is being performed on a class object */ |
| 281 |
|
| 282 |
/** |
| 283 |
* File Scope Variable Definitions |
| 284 |
*/ |
| 285 |
static Jobject2jobjectID _jobject2jobjectID = 0; /* Function pointer to JVM interface function that converts JNI object handles to |
| 286 |
JVMPI object identifiers */ |
| 287 |
#ifdef __OS400__ |
| 288 |
#pragma convert(819) |
| 289 |
#endif |
| 290 |
static char _heapDefName[8] = "default"; |
| 291 |
#ifdef __OS400__ |
| 292 |
#pragma convert(0) |
| 293 |
#endif |
| 294 |
|
| 295 |
|
| 296 |
static BOOL _jvmShutDown = FALSE; /* JVM is in shut down mode*/ |
| 297 |
static BOOL _jvmpiAgent_isJVMInitDone=FALSE; /* JVM has finished initialization */ |
| 298 |
static BOOL _jvmpiAgent_isListenerUnblocked=FALSE; /* Has ra_startListener returned? */ |
| 299 |
static BOOL _jvmpiAgent_isMonitored=FALSE; /* Are we currently monitored? */ |
| 300 |
static BOOL _jvmpiAgent_isSuspended=FALSE; /* Are we currently suspended? */ |
| 301 |
static BOOL _jvmpiAgent_burstTimeoutSet=FALSE; /* Is our timout value set? */ |
| 302 |
|
| 303 |
/* In order to limit tracing to a single thread these variables are used */ |
| 304 |
static JNIEnv *_jvmpiAgent_limitingThread=NULL; |
| 305 |
static BOOL _jvmpiAgent_singleThreaded=FALSE; |
| 306 |
|
| 307 |
static unsigned int _invocationCountRemaining=0; /* Used in burst tracing to count invocations */ |
| 308 |
static timestamp_t _burstTimeout; |
| 309 |
static BOOL _triggerSqueezed=FALSE; /* Used in trigger tracing to indicate we have started */ |
| 310 |
|
| 311 |
static BOOL _stackSamplerActive=FALSE; /* Stack sampler shutoff switch */ |
| 312 |
|
| 313 |
static BOOL _xmlHeadersPrinted=FALSE; |
| 314 |
|
| 315 |
/* Piyush Agarwal */ |
| 316 |
static BOOL _analyseOptHeap = FALSE ; /* To determine if the analyse |
| 317 |
message came from the RAC */ |
| 318 |
static int _optHeapError = 0 ; /*58049 Handle Error if OptHeap files |
| 319 |
cannot be written */ |
| 320 |
static int _unknownClassSuffix = 1; |
| 321 |
static char _classNameBuffer[64]; /* "unknown" + "int" */ |
| 322 |
|
| 323 |
/* Giri: <Defect 64462> */ |
| 324 |
static BOOL _optHeapSetupDone = FALSE ; /* For tracking status of optHeap setup */ |
| 325 |
/*Bug 82214*/ |
| 326 |
static int optHeapContextId = -1 ; |
| 327 |
|
| 328 |
/*Bug 59544 SetConfig changes for opt heap dump location*/ |
| 329 |
/* Bug 64476 */ |
| 330 |
#ifdef MVS |
| 331 |
#pragma convlit(suspend) |
| 332 |
#endif |
| 333 |
static char _tempDirOptionName[21] = "LOCAL_AGENT_TEMP_DIR" ; |
| 334 |
#ifdef MVS |
| 335 |
#pragma convlit(resume) |
| 336 |
#endif |
| 337 |
|
| 338 |
/* Array of function pointers to the JVMPI event handling functions */ |
| 339 |
static ProcessEventFunction _processEventFunction[JVMPI_MAX_EVENT_TYPE_VAL + 1]; /* The defect number is 174948. */ |
| 340 |
|
| 341 |
/* Array of function pointers for our agent extension; the signature is slightly different */ |
| 342 |
static AgentExtensionEventHandler agent_extension_handlers[JVMPI_MAX_EVENT_TYPE_VAL + 1]; |
| 343 |
|
| 344 |
/* Pointer to handler function for the agent extension to handle RAC commands. */ |
| 345 |
/* Remains null unless an extension extension utilizes it. */ |
| 346 |
static void (*agent_extension_command_handler)(ra_command_t *command); |
| 347 |
|
| 348 |
/** |
| 349 |
* FUNCTION PROTOTYPES |
| 350 |
*/ |
| 351 |
static int enableJvmpiEvent(jint event_type, |
| 352 |
ProcessEventFunction eventHandler); |
| 353 |
|
| 354 |
static void processObjAllocEvent(JVMPI_Event *event, |
| 355 |
ThreadPrivateStorage *tps, |
| 356 |
BOOL isRequested, |
| 357 |
timestamp_t timestamp, |
| 358 |
timestamp_t cpu_timestamp); |
| 359 |
|
| 360 |
static void processGcStartEvent(JVMPI_Event *event, |
| 361 |
ThreadPrivateStorage *tps, |
| 362 |
BOOL isRequested, |
| 363 |
timestamp_t timestamp, |
| 364 |
timestamp_t cpu_timestamp); |
| 365 |
|
| 366 |
static void processGcFinishEvent(JVMPI_Event *event, |
| 367 |
ThreadPrivateStorage *tps, |
| 368 |
BOOL isRequested, |
| 369 |
timestamp_t timestamp, |
| 370 |
timestamp_t cpu_timestamp); |
| 371 |
|
| 372 |
static void processCountingMethodEntryEvent(JVMPI_Event *event, |
| 373 |
ThreadLocalStorage *tps, |
| 374 |
BOOL isRequested, |
| 375 |
timestamp_t timestamp, |
| 376 |
timestamp_t cpu_timestamp); |
| 377 |
|
| 378 |
static void toggleActiveJvmpiEvents(TraceToggle toggle); |
| 379 |
|
| 380 |
static void cleanUpAllTraceResources(); |
| 381 |
|
| 382 |
static void loadStack(ThreadPrivateStorage *tps); |
| 383 |
|
| 384 |
static void startTracing(BOOL standalone); |
| 385 |
|
| 386 |
static void suspendTracing(TraceToggle toggle); |
| 387 |
|
| 388 |
static void resumeTracing(); |
| 389 |
|
| 390 |
static void stopTracing(); |
| 391 |
|
| 392 |
static void jvmpiAgent_PrintStartingXMLFragments(); |
| 393 |
|
| 394 |
static void setNowTimes(ThreadLocalStorage * tps, timestamp_t * nowTime_P, timestamp_t * nowCpuTime_P); |
| 395 |
|
| 396 |
static void recordAgMethodEntry(ThreadLocalStorage * tps, StackEntry * stackEntry, StackEntry * caller); |
| 397 |
|
| 398 |
/* Piyush Agarwal */ |
| 399 |
static void sendHeapDumpInformation(char *filename) ; |
| 400 |
static void sendHeapDumpEndMessage(RA_AGENT_HANDLE handle,ra_uint_t contextId,char* filename) ; |
| 401 |
static void processRACDataDumpRequest(BOOL finalheap,ra_uint_t contextId) ; |
| 402 |
/* Added Call Back Message */ |
| 403 |
OptHeapCallBack _jvmpiAgent_optHeapCallBack = { sendHeapDumpInformation }; |
| 404 |
|
| 405 |
/* functions for agent extensions to call to enable events and command listening */ |
| 406 |
static void agentExtensionSetEventHandler(jint event_type, |
| 407 |
AgentExtensionEventHandler handler); |
| 408 |
static void agentExtensionSetCommandHandler(void (*handler)(ra_command_t *command)); |
| 409 |
|
| 410 |
|
| 411 |
static void sendOptHeapErrorMessage(RA_AGENT_HANDLE handle,ra_uint_t contextId) ; /* Piyush 58049 */ |
| 412 |
|
| 413 |
/* Giri: Defect 64462 For performing opt heap related setup */ |
| 414 |
static void jvmpiAgent_DoOptHeapSetup(); |
| 415 |
|
| 416 |
/** |
| 417 |
* GLOBALS |
| 418 |
*/ |
| 419 |
jclass _jvmpiAgent_JVMPIException = 0; /* JNI hook to JVMPIException class */ |
| 420 |
jmethodID _jvmpiAgent_setExceptionTracing = 0; /* JNI hook to JVMPIException.setExceptionTracing method */ |
| 421 |
JavaVM * _jvmpiAgent_jvm = 0; /* JVM reference (established in JVM_OnLoad) */ |
| 422 |
JVMPI_Interface * _jvmpiAgent_jvmpiInterface = 0; /* JVMPI Interface pointer (established in JVM_OnLoad */ |
| 423 |
Lock_t _jvmpiAgent_synchLock; |
| 424 |
char * _jvmpiAgent_trace_id; |
| 425 |
SegmentedValue_t _jvmpiAgent_collation; |
| 426 |
GenerationInfo_t _heapDumpInfo; /* GENERATION Index for Object reference*/ |
| 427 |
RA_AGENT_HANDLE _jvmpiAgent_bindingStorage; |
| 428 |
char _setPathDelimiter = 0; |
| 429 |
jobjectID _resolvedClassId = 0; /* Used to store the class id for the associated class of an object being dumped */ |
| 430 |
enum JavaVendor _javaVendor = VendorOther; |
| 431 |
enum JavaVersion _javaVersion = VersionOther; |
| 432 |
|
| 433 |
|
| 434 |
/** ANALYSE_HEAP ************************************************************** |
| 435 |
* This is the function that must be called to request a heap dump. |
| 436 |
* |
| 437 |
*/ |
| 438 |
jint analyseHeap(jint type) { |
| 439 |
jint result; |
| 440 |
JVMPI_HeapDumpArg arg; |
| 441 |
|
| 442 |
|
| 443 |
/* RKD: When we are stack sampling or we have been told to ignore heap information |
| 444 |
we don't want to be processing heap dump requests |
| 445 |
*/ |
| 446 |
if(_jvmpiAgent_Options.mode==TraceModeStackSampling || !jvmpiAgent_isTracingHeap()) { |
| 447 |
return -1; |
| 448 |
} |
| 449 |
|
| 450 |
/* If we get a heap dump level 0 we are marking the heap and we |
| 451 |
mark the generation to be zero. |
| 452 |
RKD: Should we scrub the table here? |
| 453 |
*/ |
| 454 |
if(type==JVMPI_DUMP_LEVEL_0) { |
| 455 |
_heapDumpInfo.index = 0; |
| 456 |
} |
| 457 |
/* Bug Number 71068*/ |
| 458 |
/*else { |
| 459 |
_heapDumpInfo.index++; |
| 460 |
|
| 461 |
}*/ |
| 462 |
|
| 463 |
/* To make sure that analyseheap is being called from TraceOptHeap methods only */ |
| 464 |
if ( _jvmpiAgent_Options.mode == TraceOptimizedHeap && _analyseOptHeap == FALSE ) { |
| 465 |
/* Bug Number 71043 required for AS400 */ |
| 466 |
if ( type == JVMPI_DUMP_LEVEL_0 ) |
| 467 |
jvmpiAgent_getCurrentTime(&_heapDumpInfo.lastGenerationTime); |
| 468 |
return (jint)0 ; |
| 469 |
} |
| 470 |
|
| 471 |
/* Bug Number 71068*/ |
| 472 |
if(type != JVMPI_DUMP_LEVEL_0) { |
| 473 |
_heapDumpInfo.index++; |
| 474 |
} |
| 475 |
|
| 476 |
arg.heap_dump_level=type; |
| 477 |
|
| 478 |
/* Because this can be invoked via JNI we need to check to |
| 479 |
ensure we have the interface. Someone may invoke the |
| 480 |
dump but JVMPI may not be enabled. |
| 481 |
*/ |
| 482 |
|
| 483 |
if(_jvmpiAgent_jvmpiInterface) { |
| 484 |
result = REQUEST_EVENT(JVMPI_EVENT_HEAP_DUMP, &arg); |
| 485 |
} |
| 486 |
|
| 487 |
/* Save the time we finished the dump at */ |
| 488 |
jvmpiAgent_getCurrentTime(&_heapDumpInfo.lastGenerationTime); |
| 489 |
|
| 490 |
return result; |
| 491 |
} |
| 492 |
|
| 493 |
|
| 494 |
jint runGC() { |
| 495 |
jint result; |
| 496 |
JVMPI_HeapDumpArg arg; |
| 497 |
ThreadPrivateStorage *tps=jvmpiAgent_getThreadLocalStorage(0); |
| 498 |
tps->scrubbingHeap=1; |
| 499 |
|
| 500 |
/* Scrub the heap */ |
| 501 |
arg.heap_dump_level=JVMPI_DUMP_LEVEL_0; |
| 502 |
if(_jvmpiAgent_jvmpiInterface) { |
| 503 |
result = REQUEST_EVENT(JVMPI_EVENT_HEAP_DUMP, &arg); |
| 504 |
} |
| 505 |
|
| 506 |
tps->scrubbingHeap=0; |
| 507 |
return result; |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
/* bugzilla 71388 start - JNI methods need to be enclosed in a conditional 'extern "C"' declaration */ |
| 512 |
#if defined __cplusplus |
| 513 |
extern "C" { |
| 514 |
#endif |
| 515 |
|
| 516 |
|
| 517 |
/* |
| 518 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 519 |
* Method: initialize0 |
| 520 |
* Signature: ()V |
| 521 |
*/ |
| 522 |
JNIEXPORT jint JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_initialize0(JNIEnv *env, |
| 523 |
JOBJECT obj) { |
| 524 |
|
| 525 |
/* We just need to check if we are running in application mode */ |
| 526 |
if(_jvmpiAgent_jvm && _jvmpiAgent_Options.application) { |
| 527 |
return (jint)0; |
| 528 |
} |
| 529 |
else { |
| 530 |
return (jint)-1; |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
/* |
| 535 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 536 |
* Method: setMode0 |
| 537 |
* Signature: (I)V |
| 538 |
*/ |
| 539 |
JNIEXPORT void JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_setMode0 |
| 540 |
(JNIEnv *env, jobject obj, jint mode) { |
| 541 |
|
| 542 |
/* call to OPTIMIZED HEAP DUMP CODE for method setMode0() goes here */ |
| 543 |
} |
| 544 |
|
| 545 |
/* |
| 546 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 547 |
* Method: startProfiling0 |
| 548 |
* Signature: (ZZ)I |
| 549 |
*/ |
| 550 |
JNIEXPORT jint JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_startProfiling0(JNIEnv *env, |
| 551 |
JOBJECT obj, |
| 552 |
jboolean currentThread, |
| 553 |
jint boundaryDepth) { |
| 554 |
|
| 555 |
if(_jvmpiAgent_jvm) { |
| 556 |
if(currentThread) { |
| 557 |
_jvmpiAgent_singleThreaded=TRUE; |
| 558 |
_jvmpiAgent_limitingThread=env; |
| 559 |
} |
| 560 |
else { |
| 561 |
_jvmpiAgent_singleThreaded=FALSE; |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
/* If we have a boundary depth we are tracing in boundary and contiguous mode. Otherwise we |
| 566 |
need to reset the stack info back to the orignal state in case this is a subsequent call |
| 567 |
to start profiling. |
| 568 |
*/ |
| 569 |
if(boundaryDepth>0) { |
| 570 |
_jvmpiAgent_Options.stackInfo=StackInfoBoundaryAndContiguous; |
| 571 |
_jvmpiAgent_Options.boundaryDepth=(unsigned short)boundaryDepth; |
| 572 |
} |
| 573 |
else { |
| 574 |
_jvmpiAgent_Options.stackInfo=StackInfoNormal; |
| 575 |
_jvmpiAgent_Options.boundaryDepth=0; |
| 576 |
} |
| 577 |
|
| 578 |
/* If someone is attached we start tracing now, otherwise we ignore this call */ |
| 579 |
if(_jvmpiAgent_isMonitored) { |
| 580 |
if(_jvmpiAgent_isSuspended) { |
| 581 |
resumeTracing(); |
| 582 |
|
| 583 |
} |
| 584 |
else { |
| 585 |
startTracing(TRUE); |
| 586 |
} |
| 587 |
|
| 588 |
/* Squeeze the trigger */ |
| 589 |
_triggerSqueezed=TRUE; |
| 590 |
|
| 591 |
return (jint)0; |
| 592 |
|
| 593 |
} |
| 594 |
} |
| 595 |
return (jint)-1; |
| 596 |
} |
| 597 |
|
| 598 |
/* |
| 599 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 600 |
* Method: stopProfiling0 |
| 601 |
* Signature: ()V |
| 602 |
*/ |
| 603 |
JNIEXPORT void JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_stopProfiling0(JNIEnv *env, |
| 604 |
JOBJECT obj) { |
| 605 |
|
| 606 |
if(_jvmpiAgent_jvm) { |
| 607 |
suspendTracing(TracePause); |
| 608 |
_jvmpiAgent_limitingThread=NULL; |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
/* |
| 613 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 614 |
* Method: markHeap0 |
| 615 |
* Signature: ()V |
| 616 |
*/ |
| 617 |
JNIEXPORT void JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_markHeap0(JNIEnv *env, |
| 618 |
JOBJECT obj) { |
| 619 |
if(_jvmpiAgent_jvm) { |
| 620 |
analyseHeap(JVMPI_DUMP_LEVEL_0); |
| 621 |
} |
| 622 |
} |
| 623 |
|
| 624 |
/* |
| 625 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 626 |
* Method: analyzeHeap0 |
| 627 |
* Signature: (Ljava/lang/String;)V |
| 628 |
*/ |
| 629 |
JNIEXPORT void JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_analyzeHeap0(JNIEnv *env, |
| 630 |
JOBJECT obj, |
| 631 |
jstring name) { |
| 632 |
if(_jvmpiAgent_jvm) { |
| 633 |
analyseHeap(JVMPI_DUMP_LEVEL_1); |
| 634 |
} |
| 635 |
} |
| 636 |
|
| 637 |
/* |
| 638 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 639 |
* Method: optimizedHeapDump0 |
| 640 |
* Signature: ()Ljava/lang/String; |
| 641 |
*/ |
| 642 |
JNIEXPORT jstring JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_optimizedHeapDump0 |
| 643 |
(JNIEnv *env, jobject obj) { |
| 644 |
|
| 645 |
/* call to OPTIMIZED HEAP DUMP CODE for method optimizedHeapDump0() goes here */ |
| 646 |
processRACDataDumpRequest(FALSE,0) ; |
| 647 |
return (jstring)0; |
| 648 |
|
| 649 |
} |
| 650 |
|
| 651 |
/* |
| 652 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 653 |
* Method: stopOptimizedHeapInfoSnapshot0 |
| 654 |
* Signature: ()Ljava/lang/String; |
| 655 |
*/ |
| 656 |
JNIEXPORT jstring JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_stopOptimizedHeapInfoSnapshot0 |
| 657 |
(JNIEnv *env, jobject obj) { |
| 658 |
|
| 659 |
|
| 660 |
/* call to OPTIMIZED HEAP DUMP CODE for method stopOptimizedHeapInfoSnapshot0() |
| 661 |
goes here */ |
| 662 |
processRACDataDumpRequest(TRUE,0) ; |
| 663 |
return (jstring)0; |
| 664 |
|
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
/* |
| 669 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 670 |
* Method: disableGC0 |
| 671 |
* Signature: ()V |
| 672 |
*/ |
| 673 |
JNIEXPORT void JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_disableGC0 |
| 674 |
(JNIEnv *env, jobject obj) { |
| 675 |
|
| 676 |
if (_jvmpiAgent_jvmpiInterface) { |
| 677 |
_jvmpiAgent_jvmpiInterface->DisableGC(); |
| 678 |
} |
| 679 |
|
| 680 |
|
| 681 |
} |
| 682 |
|
| 683 |
/* |
| 684 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 685 |
* Method: enableGC0 |
| 686 |
* Signature: ()V |
| 687 |
*/ |
| 688 |
JNIEXPORT void JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_enableGC0 |
| 689 |
(JNIEnv *env, jobject obj) { |
| 690 |
|
| 691 |
if (_jvmpiAgent_jvmpiInterface) { |
| 692 |
_jvmpiAgent_jvmpiInterface->EnableGC(); |
| 693 |
} |
| 694 |
|
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
/* |
| 699 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 700 |
* Method: runGC0 |
| 701 |
* Signature: ()V |
| 702 |
*/ |
| 703 |
JNIEXPORT void JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_runGC0(JNIEnv *env, |
| 704 |
JOBJECT obj) { |
| 705 |
if(_jvmpiAgent_jvm) { |
| 706 |
runGC(); |
| 707 |
} |
| 708 |
} |
| 709 |
|
| 710 |
|
| 711 |
/* |
| 712 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 713 |
* Method: release0 |
| 714 |
* Signature: ()V |
| 715 |
*/ |
| 716 |
JNIEXPORT void JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_release0 |
| 717 |
(JNIEnv *env, jobject obj) { |
| 718 |
|
| 719 |
/* RJD: currently the following is the body of the cleanupAndExit method. Other |
| 720 |
cleanup may be necessary -- need to discuss */ |
| 721 |
|
| 722 |
ThreadLocalStorage *tps=jvmpiAgent_getThreadLocalStorage(0); |
| 723 |
|
| 724 |
/* If the application is logging to a file */ |
| 725 |
if (_jvmpiAgent_outFile) { |
| 726 |
jvmpiAgent_printStandaloneTraceTagClose(tps); |
| 727 |
jvmpiAgent_cleanupStandaloneIO(); |
| 728 |
} else if (_jvmpiAgent_Options.application) { /*94955*/ |
| 729 |
jvmpiAgent_printStandaloneTraceTagClose(tps); |
| 730 |
} |
| 731 |
|
| 732 |
/* If this application is being controlled/moitored remotely */ |
| 733 |
if (!_jvmpiAgent_Options.standalone) { |
| 734 |
|
| 735 |
/* Wait until all the data is sent over the wire if there is a data connection */ |
| 736 |
if(!_jvmpiAgent_suspendIO) { |
| 737 |
if(_jvmpiAgent_Options.targetHdl.dtarget==RA_SOCKET && _jvmpiAgent_Options.targetHdl.dtargetHdl.socketFD>-1) { |
| 738 |
ra_closeSocket(_jvmpiAgent_Options.targetHdl.dtargetHdl.socketFD); |
| 739 |
} |
| 740 |
else if (_jvmpiAgent_Options.targetHdl.dtarget == RA_SHAREDMEMORY) { |
| 741 |
ra_stopFlushingShm(&_jvmpiAgent_Options.targetHdl.dtargetHdl.shmHdl); /* 175248 */ |
| 742 |
} |
| 743 |
|
| 744 |
_jvmpiAgent_suspendIO=1; |
| 745 |
} |
| 746 |
ra_stopListener(_jvmpiAgent_bindingStorage); |
| 747 |
} |
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
} |
| 752 |
|
| 753 |
/* |
| 754 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 755 |
* Method: emitXMLFragment0 |
| 756 |
* Signature: ([BII)I |
| 757 |
*/ |
| 758 |
JNIEXPORT jint JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_emitXMLFragment0 |
| 759 |
(JNIEnv *env, jclass clz, jbyteArray arr, jint offset, jint len) { |
| 760 |
char *carr; /* note that jbyte * is a signed char* on most platforms */ |
| 761 |
char *outputBuffer; |
| 762 |
#ifdef __OS400__ |
| 763 |
char *tmp, *tmp2; /* temporary storage used only for AS/400 */ |
| 764 |
#endif |
| 765 |
jboolean iscopy; |
| 766 |
ThreadLocalStorage *tps; |
| 767 |
iscopy = JNI_FALSE; |
| 768 |
|
| 769 |
if (_jvmpiAgent_suspendIO) { |
| 770 |
return org_eclipse_hyades_collection_profiler_Profiler_EMIT_XML_SUSPENDED_IO; |
| 771 |
} |
| 772 |
|
| 773 |
carr = (char *) ENV(env)->GetByteArrayElements(ENVPARM(env) arr,&iscopy); |
| 774 |
|
| 775 |
if (carr == NULL) { |
| 776 |
/* NULL is returned by GetByteArrayElements only when an OutOfMemoryError occurs */ |
| 777 |
return org_eclipse_hyades_collection_profiler_Profiler_EMIT_XML_FAIL; |
| 778 |
} |
| 779 |
|
| 780 |
/* get the thread private storage */ |
| 781 |
tps=jvmpiAgent_getThreadLocalStorage(env); |
| 782 |
|
| 783 |
if (tps == 0) { |
| 784 |
tps = jvmpiAgent_getThreadLocalStorage(0); |
| 785 |
} |
| 786 |
|
| 787 |
/* Ensure that the output buffer is large enough. Note, the jvmpiAgent_print |
| 788 |
method adds a '\n', and on zOS a '\0' to the buffer. We take this into account |
| 789 |
when sizing the buffer. */ |
| 790 |
if (len > (ORIGINAL_MESSAGE_BUFFER_SIZE - 2)) { |
| 791 |
outputBuffer = (char *)ra_allocateMessageBlock((unsigned short)len+2); |
| 792 |
#ifdef __OS400__ |
| 793 |
/* we need to increase the size of the etoa scratch buffer */ |
| 794 |
tmp = tps->buffer2; /* remember the normal buffer */ |
| 795 |
tps->buffer2 = ra_allocateMessageBlock((unsigned short)len+2); |
| 796 |
#endif |
| 797 |
if (!outputBuffer) { |
| 798 |
return org_eclipse_hyades_collection_profiler_Profiler_EMIT_XML_FAIL; |
| 799 |
} |
| 800 |
} |
| 801 |
else { |
| 802 |
outputBuffer = tps->buffer; |
| 803 |
} |
| 804 |
|
| 805 |
#ifdef __OS400__ |
| 806 |
/* on AS400 we assume the passed in string is in UTF-8. Convert it to EBCDIC before |
| 807 |
putting it into the output buffer. */ |
| 808 |
|
| 809 |
/* this is ugly, but it's required: the as400_atoe routines require a null terminated string, |
| 810 |
and that the 'from' buffer is not the same as the 'to' buffer */ |
| 811 |
tmp2 = ra_malloc(sizeof(char)*(len+1)); |
| 812 |
if (!tmp2) { |
| 813 |
return org_eclipse_hyades_collection_profiler_Profiler_EMIT_XML_FAIL; |
| 814 |
} |
| 815 |
memcpy(tmp2,&carr[offset],len); |
| 816 |
tmp2[len] = '\0'; |
| 817 |
outputBuffer = as400_atoe_tobuffer(tmp2,outputBuffer); |
| 818 |
ra_free(tmp2); |
| 819 |
#else |
| 820 |
/* copy the XML fragment into the tps->buffer for printing */ |
| 821 |
memcpy(outputBuffer,&carr[offset],len); |
| 822 |
#endif |
| 823 |
|
| 824 |
jvmpiAgent_print(tps,outputBuffer,(unsigned short) len); |
| 825 |
|
| 826 |
if (tps->buffer != outputBuffer) { |
| 827 |
ra_freeMessageBlock((unsigned char *)outputBuffer); |
| 828 |
#ifdef __OS400__ |
| 829 |
ra_freeMessageBlock((unsigned char *)tps->buffer2); |
| 830 |
tps->buffer2 = tmp; /* restore the normal buffer */ |
| 831 |
#endif |
| 832 |
} |
| 833 |
|
| 834 |
ENV(env)->ReleaseByteArrayElements(ENVPARM(env) arr, (signed char *) carr, JNI_ABORT); |
| 835 |
|
| 836 |
return org_eclipse_hyades_collection_profiler_Profiler_EMIT_XML_SUCCESS; |
| 837 |
|
| 838 |
} |
| 839 |
|
| 840 |
/* |
| 841 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 842 |
* Method: getCurrentTime0() |
| 843 |
* Signature: ()D |
| 844 |
*/ |
| 845 |
JNIEXPORT jdouble JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_getCurrentTime0 |
| 846 |
(JNIEnv *env, jclass clz) { |
| 847 |
timestamp_t timestamp; |
| 848 |
|
| 849 |
jvmpiAgent_getCurrentTime(×tamp); |
| 850 |
return ticksToTime2(timestamp, TRUE); |
| 851 |
} |
| 852 |
|
| 853 |
/* |
| 854 |
* Class: org_eclipse_hyades_collection_profiler_Profiler |
| 855 |
* Method: getCurrentThreadCpuTime0() |
| 856 |
* Signature: ()D |
| 857 |
*/ |
| 858 |
JNIEXPORT jdouble JNICALL Java_org_eclipse_hyades_collection_profiler_Profiler_getCurrentThreadCpuTime0 |
| 859 |
(JNIEnv *env, jclass clz) { |
| 860 |
timestamp_t cpu_timestamp; |
| 861 |
|
| 862 |
cpu_timestamp = jvmpiAgent_getCurrentThreadCPUTime(); |
| 863 |
return ((jdouble) |
| 864 |
#ifdef WIN32 |
| 865 |
(__int64) |
| 866 |
#endif |
| 867 |
cpu_timestamp)/1000000000; /* nanoseconds but very fat grain, about 10 milliseconds!!! */ |
| 868 |
} |
| 869 |
|
| 870 |
|
| 871 |
/* bugzilla 71388 end - JNI methods need to be enclosed in a conditional 'extern "C"' declaration */ |
| 872 |
#if defined __cplusplus |
| 873 |
} |
| 874 |
#endif |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
#ifndef __OS400__ |
| 879 |
/* Resolve to the jobject2jobjectID interface */ |
| 880 |
static jobjectID resolveJobject2jobjectID(jthrowable e, JNIEnv *env) |
| 881 |
{ |
| 882 |
static resolved = 0; |
| 883 |
if (_jobject2jobjectID) |
| 884 |
{ |
| 885 |
return _jobject2jobjectID(e); |
| 886 |
} |
| 887 |
else if ( resolved ) |
| 888 |
{ |
| 889 |
return 0; |
| 890 |
} |
| 891 |
else |
| 892 |
{ |
| 893 |
resolved = 1; |
| 894 |
/* jobject2jobjectID IBM JDK 1.2.2 IBM JDK1.3 Sun JDK 1.2.2 Classic Sun JDK 1.3 Classic Sun JDK 1.3 Hotspot |
| 895 |
JVM.dll entry point not available yes yes yes no |
| 896 |
JVMPI interface pointer not available yes no no yes - but no header |
| 897 |
*/ |
| 898 |
/* First attempt to resolve the entry point directly from the JVM dll */ |
| 899 |
_jobject2jobjectID = (Jobject2jobjectID)RESOLVE_ENTRY_POINT(RESOLVE_MODULE(DLL_NAME), "jobject2jobjectID"); |
| 900 |
|
| 901 |
if (!_jobject2jobjectID) |
| 902 |
{ |
| 903 |
/* We couldn't find the entry point exported from the JVM dll so now we check the JVM version |
| 904 |
to see if it is safe to retreive the entry point from the JVMPI interface structure. We assume |
| 905 |
that any JVM above version 2.1 should support this interface... */ |
| 906 |
#if defined __cplusplus && defined _HPUX |
| 907 |
jint version = ENV(env)->GetVersion(); |
| 908 |
#else |
| 909 |
jint version = (*env)->GetVersion(env); |
| 910 |
#endif |
| 911 |
unsigned short *p = (unsigned short *)&version; |
| 912 |
unsigned short major = *p; |
| 913 |
unsigned short minor = *(p+1); |
| 914 |
if (major >= 2 && minor >= 1) |
| 915 |
{ |
| 916 |
#ifndef _HPUX |
| 917 |
_jobject2jobjectID = _jvmpiAgent_jvmpiInterface->jobject2jobjectID; |
| 918 |
#endif |
| 919 |
} |
| 920 |
} |
| 921 |
return _jobject2jobjectID ? _jobject2jobjectID(e) : 0; |
| 922 |
} |
| 923 |
} |
| 924 |
#endif /* __OS400__ */ |
| 925 |
|
| 926 |
|
| 927 |
/** GET_THREAD_LOCAL_STORAGE ************************************************* |
| 928 |
* This function returns the address of the thread local storage for the |
| 929 |
* specified JNIEnv (aka thread). A special thread local storage structure is |
| 930 |
* allocated for static references and is returned when the JNIEnv parameter is |
| 931 |
* 0 or if the JVM is in Garbage Collection or Shutdown mode. Garbage Collection |
| 932 |
* and Shutdown mode must be handled in this way because some versions of the |
| 933 |
* JVM use special threads to do this processing which cause the |
| 934 |
* GetThreadLocalStorage interface function to trap. |
| 935 |
*/ |
| 936 |
ThreadPrivateStorage *jvmpiAgent_getThreadLocalStorage(JNIEnv *env_id) { |
| 937 |
HashEntry *hashEntry = jvmpiAgent_FindThreadSymbol(env_id); |
| 938 |
if (hashEntry) { |
| 939 |
if (!hashEntry->printed && env_id && THREAD_ENTRY(hashEntry)->threadStartEventSeen && _xmlHeadersPrinted) { |
| 940 |
jvmpiAgent_printThreadStartElement(env_id, hashEntry); |
| 941 |
} |
| 942 |
return (ThreadPrivateStorage *)hashEntry->entry; |
| 943 |
} |
| 944 |
else { |
| 945 |
hashEntry = jvmpiAgent_CreateStack(env_id); |
| 946 |
return (ThreadPrivateStorage *)hashEntry->entry; |
| 947 |
} |
| 948 |
} |
| 949 |
|
| 950 |
|
| 951 |
/** SEND_ERROR_MESSAGE ******************************************************************* |
| 952 |
*/ |
| 953 |
void sendErrorMessage(RA_ERROR_LEVEL severity, |
| 954 |
const char *errorId, |
| 955 |
const char *errorString) |
| 956 |
{ |
| 957 |
#ifdef MVS |
| 958 |
__atoe(errorId); |
| 959 |
__atoe(errorString); |
| 960 |
#endif |
| 961 |
if(!_jvmpiAgent_Options.standalone) |
| 962 |
{ |
| 963 |
ra_logErrorMessage(_jvmpiAgent_bindingStorage, severity, errorId, errorString); |
| 964 |
} |
| 965 |
else |
| 966 |
{ |
| 967 |
/* 60642 standalone mode - write to stderr if warning or worse */ |
| 968 |
if (severity >= RA_WARNING) |
| 969 |
{ |
| 970 |
#ifdef MVS |
| 971 |
#pragma convlit(suspend) |
| 972 |
#endif |
| 973 |
fprintf(stderr, "%s: %s\n", errorId, errorString); |
| 974 |
#ifdef MVS |
| 975 |
#pragma convlit(resume) |
| 976 |
#endif |
| 977 |
fflush(stderr); |
| 978 |
} |
| 979 |
} |
| 980 |
/* we need to undo the conversion on 390 in case this method is called with the same |
| 981 |
string more than once */ |
| 982 |
#ifdef MVS |
| 983 |
__etoa(errorId); |
| 984 |
__etoa(errorString); |
| 985 |
#endif |
| 986 |
} |
| 987 |
|
| 988 |
/** CLEANUP_AND_EXIT ********************************************************** |
| 989 |
* Flushes the I/O buffers, closes the data channel or file and shuts down the |
| 990 |
* RAC connection. |
| 991 |
*/ |
| 992 |
static void CDECL cleanupAndExit(int sig) { |
| 993 |
ThreadLocalStorage *tps=jvmpiAgent_getThreadLocalStorage(0); |
| 994 |
|
| 995 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 996 |
printf("cleanupAndExit underway\n"); fflush(stdout); |
| 997 |
#endif |
| 998 |
/* If the application is logging to a file */ |
| 999 |
if (_jvmpiAgent_outFile) { |
| 1000 |
jvmpiAgent_printStandaloneTraceTagClose(tps); |
| 1001 |
jvmpiAgent_cleanupStandaloneIO(); |
| 1002 |
} else if (_jvmpiAgent_Options.application) { /*94955*/ |
| 1003 |
jvmpiAgent_printStandaloneTraceTagClose(tps); |
| 1004 |
} |
| 1005 |
|
| 1006 |
/* If this application is being controlled/moitored remotely */ |
| 1007 |
if (!_jvmpiAgent_Options.standalone) { |
| 1008 |
|
| 1009 |
/* Wait until all the data is sent over the wire if there is a data connection */ |
| 1010 |
if(!_jvmpiAgent_suspendIO) { |
| 1011 |
if(_jvmpiAgent_Options.targetHdl.dtarget==RA_SOCKET && _jvmpiAgent_Options.targetHdl.dtargetHdl.socketFD>-1) { |
| 1012 |
ra_closeSocket(_jvmpiAgent_Options.targetHdl.dtargetHdl.socketFD); |
| 1013 |
} |
| 1014 |
else if (_jvmpiAgent_Options.targetHdl.dtarget == RA_SHAREDMEMORY) { |
| 1015 |
ra_stopFlushingShm(&_jvmpiAgent_Options.targetHdl.dtargetHdl.shmHdl); /* 175248 */ |
| 1016 |
} |
| 1017 |
|
| 1018 |
_jvmpiAgent_suspendIO=1; |
| 1019 |
} |
| 1020 |
ra_stopListener(_jvmpiAgent_bindingStorage); |
| 1021 |
} |
| 1022 |
} |
| 1023 |
|
| 1024 |
|
| 1025 |
/** OUTPUT_CLASS_DECLARATION ************************************************** |
| 1026 |
* Conditionally outputs a classLoad element if it has not already been output. |
| 1027 |
*/ |
| 1028 |
void jvmpiAgent_outputClassDeclaration(HashEntry *classEntry, |
| 1029 |
ThreadPrivateStorage *tps) { |
| 1030 |
/* RKD: The testing for printing and the marking of printed elements is |
| 1031 |
not good. We need to mark the element as printed at the same |
| 1032 |
time as we check to see if it is printed. This is the only |
| 1033 |
way to ensure we don't have a race condition and an element |
| 1034 |
gets printed. |
| 1035 |
*/ |
| 1036 |
if (!_jvmpiAgent_suspendIO && classEntry != NULL && !classEntry->printed) { |
| 1037 |
|
| 1038 |
/* Ensure that the class object and the java.lang.Class have been printed unless we are |
| 1039 |
specifically not tracing heap information or we have been specified to ignore heap information */ |
| 1040 |
if(CLASS_ENTRY(classEntry)->classObject!=NULL && jvmpiAgent_isTracingHeap()) { |
| 1041 |
if(!CLASS_ENTRY(classEntry)->classObject->printed) { |
| 1042 |
jvmpiAgent_printObjAllocElement(CLASS_ENTRY(classEntry)->classObject, tps->env, 0); |
| 1043 |
} |
| 1044 |
} |
| 1045 |
/* Have to check whether the class is printed already which is the case for java.lang.Class */ |
| 1046 |
|
| 1047 |
if (!classEntry->printed && CLASS_ENTRY(classEntry)->classId) { /* 218494 */ |
| 1048 |
jvmpiAgent_printClass(classEntry, tps); |
| 1049 |
} |
| 1050 |
/* If this is a primative class there is no class object */ |
| 1051 |
else if(CLASS_ENTRY(classEntry)->arrayClass) { |
| 1052 |
jvmpiAgent_printClass(classEntry, tps); |
| 1053 |
} |
| 1054 |
|
| 1055 |
} |
| 1056 |
} |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
/** OUTPUT_METHOD_DECLARATION ********************************************************* |
| 1061 |
* Conditionally outputs a METHOD element (and any referenced CLASS_LOAD elements) |
| 1062 |
* if it has not already been output. |
| 1063 |
* Preconditions: In order to avoid redundant testing this method does not test to |
| 1064 |
* determine if IO is suspended and hense should not be called when |
| 1065 |
* it is. |
| 1066 |
* methodEntry - the method you wish to print the declaration for. |
| 1067 |
* buffer - the buffer to flush the IO to. |
| 1068 |
*/ |
| 1069 |
void jvmpiAgent_outputMethodDeclaration(HashEntry *methodHashEntry, |
| 1070 |
ThreadPrivateStorage *tps) { |
| 1071 |
|
| 1072 |
/* RKD: The testing for printing and the marking of printed elements is |
| 1073 |
not good. We need to mark the element as printed at the same |
| 1074 |
time as we check to see if it is printed. This is the only |
| 1075 |
way to ensure we don't have a race condition and an element |
| 1076 |
gets printed. |
| 1077 |
*/ |
| 1078 |
if (!methodHashEntry->printed) { |
| 1079 |
methodHashEntry->printed=1; |
| 1080 |
jvmpiAgent_outputClassDeclaration(METHOD_ENTRY(methodHashEntry)->classHashEntry, tps); |
| 1081 |
jvmpiAgent_printMethod(METHOD_ENTRY(methodHashEntry), tps); |
| 1082 |
} |
| 1083 |
} |
| 1084 |
|
| 1085 |
|
| 1086 |
/* |
| 1087 |
This function resolves to the JAVA method JVMPIException.setExceptionTracing if not already done, and then synchronizes the |
| 1088 |
state of the traceExceptions option with the Java class. |
| 1089 |
The function returns the current state of the traceExceptions option. |
| 1090 |
*/ |
| 1091 |
static int isTracingExceptions(JNIEnv *env, jclass cls) |
| 1092 |
{ |
| 1093 |
if (!_jvmpiAgent_setExceptionTracing) |
| 1094 |
{ |
| 1095 |
#if defined __cplusplus && defined _HPUX |
| 1096 |
_jvmpiAgent_setExceptionTracing = ENV(env)->GetStaticMethodID(cls, "setExceptionTracing", "(Z)V"); |
| 1097 |
#else |
| 1098 |
_jvmpiAgent_setExceptionTracing = (*env)->GetStaticMethodID(env, cls, "setExceptionTracing", "(Z)V"); |
| 1099 |
#endif |
| 1100 |
_jvmpiAgent_JVMPIException = cls; |
| 1101 |
} |
| 1102 |
if (!_jvmpiAgent_Options.traceExceptions && _jvmpiAgent_setExceptionTracing) |
| 1103 |
{ |
| 1104 |
#if defined __cplusplus && defined _HPUX |
| 1105 |
ENV(env)->CallStaticVoidMethod(_jvmpiAgent_JVMPIException, _jvmpiAgent_setExceptionTracing, (jboolean)0 ); |
| 1106 |
#else |
| 1107 |
(*env)->CallStaticVoidMethod(env, _jvmpiAgent_JVMPIException, _jvmpiAgent_setExceptionTracing, (jboolean)0 ); |
| 1108 |
#endif |
| 1109 |
} |
| 1110 |
return _jvmpiAgent_Options.traceExceptions; |
| 1111 |
} |
| 1112 |
|
| 1113 |
|
| 1114 |
#ifndef __OS400__ |
| 1115 |
/** PROCESS_EXCEPTION_EVENT ************************************************** |
| 1116 |
*/ |
| 1117 |
static void processExceptionEvent(JNIEnv *env, ThreadPrivateStorage *tps, jclass cls, jthrowable e, enum ThrowOrCatch type) |
| 1118 |
{ |
| 1119 |
|
| 1120 |
/* RKD: We shouldn't be testing IO here. */ |
| 1121 |
if (!_jvmpiAgent_suspendIO && isTracingExceptions(env, cls)) |
| 1122 |
{ |
| 1123 |
HashEntry * methodHashEntry = 0; |
| 1124 |
methodHashEntry = jvmpiAgent_Peek(tps,2)->methodHashEntry; |
| 1125 |
if (methodHashEntry && CLASS_ENTRY(METHOD_ENTRY(methodHashEntry)->classHashEntry)->traceFlag) |
| 1126 |
{ |
| 1127 |
jobjectID objId = resolveJobject2jobjectID(e, env); |
| 1128 |
jvmpiAgent_printExceptionElement(env, tps, type, methodHashEntry, objId, e); |
| 1129 |
} |
| 1130 |
} |
| 1131 |
} |
| 1132 |
#endif /* __OS400__ */ |
| 1133 |
|
| 1134 |
/* bugzilla 71388 start - JNI methods need to be enclosed in a conditional 'extern "C"' declaration */ |
| 1135 |
#if defined __cplusplus |
| 1136 |
extern "C" { |
| 1137 |
#endif |
| 1138 |
|
| 1139 |
/* |
| 1140 |
* Class: JVMPIException |
| 1141 |
* Method: JVMPICatch |
| 1142 |
* Signature: (Ljava/lang/Throwable;)V |
| 1143 |
*/ |
| 1144 |
JNIEXPORT void JNICALL Java_com_ibm_etools_logging_tracing_agent_Callback_JVMPICatch0(JNIEnv *env, jclass cls, jthrowable e) |
| 1145 |
{ |
| 1146 |
#ifndef __OS400__ |
| 1147 |
processExceptionEvent(env, jvmpiAgent_getThreadLocalStorage(env), cls, e, Catch); |
| 1148 |
#endif /* __OS400__ */ |
| 1149 |
} |
| 1150 |
|
| 1151 |
|
| 1152 |
/* |
| 1153 |
* Class: JVMPIException |
| 1154 |
* Method: JVMPIThrow |
| 1155 |
* Signature: (Ljava/lang/Throwable;)V |
| 1156 |
*/ |
| 1157 |
JNIEXPORT void JNICALL Java_com_ibm_etools_logging_tracing_agent_Callback_JVMPIThrow0(JNIEnv *env, jclass cls, jthrowable e) |
| 1158 |
{ |
| 1159 |
#ifndef __OS400__ |
| 1160 |
processExceptionEvent(env, jvmpiAgent_getThreadLocalStorage(env), cls, e, Throw); |
| 1161 |
#endif |
| 1162 |
} |
| 1163 |
|
| 1164 |
/* bugzilla 71388 end - JNI methods need to be enclosed in a conditional 'extern "C"' declaration */ |
| 1165 |
#if defined __cplusplus |
| 1166 |
} |
| 1167 |
#endif |
| 1168 |
|
| 1169 |
/** PROCESS_METHOD_EXIT_EVENT ************************************************ |
| 1170 |
* |
| 1171 |
*/ |
| 1172 |
static void processMethodExitEvent(JVMPI_Event *event, |
| 1173 |
ThreadPrivateStorage *tps, |
| 1174 |
BOOL isRequested, |
| 1175 |
timestamp_t timestamp, |
| 1176 |
timestamp_t cpu_timestamp) { |
| 1177 |
HashEntry *methodHashEntry; |
| 1178 |
|
| 1179 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 1180 |
if (tps!=prevMthdTps) { |
| 1181 |
dumpMethodEventCounts(); prevMthdTps=tps; |
| 1182 |
} |
| 1183 |
mxCount++; |
| 1184 |
#endif |
| 1185 |
if(_jvmpiAgent_Options.mode == TraceModeNone) { |
| 1186 |
return; |
| 1187 |
} |
| 1188 |
|
| 1189 |
if (_jvmpiAgent_Options.mode == TraceOptimizedHeap) { |
| 1190 |
/* ToDo: remove. I know that, in TraceGcOptimizedHeap mode, it will never come |
| 1191 |
* here because METHOD_EXIT event is disbled, but just to make sure that it |
| 1192 |
* is not accidently causing lack of LeakCandidates. |
| 1193 |
*/ |
| 1194 |
/* do nothing */ |
| 1195 |
return; |
| 1196 |
} |
| 1197 |
|
| 1198 |
/* RKD: If we don't know the stack for this thread |
| 1199 |
we will abort this event. |
| 1200 |
*/ |
| 1201 |
if(!tps->threadStackKnown) { |
| 1202 |
return; |
| 1203 |
} |
| 1204 |
|
| 1205 |
|
| 1206 |
/* RKD: It could be possible that the stack will be empty. This happens |
| 1207 |
on various platforms with various JDK's due to bugs in the JVMPI |
| 1208 |
implementation. In order to avoid the almightly stack underflow |
| 1209 |
that would result in us bringing down the JVM, I will check and |
| 1210 |
see if the stack is empty. It this is the case I will back out |
| 1211 |
the profiler and allow the JVM to continue processing. |
| 1212 |
*/ |
| 1213 |
if(!tps->tos) { |
| 1214 |
tps->threadStackKnown=0; |
| 1215 |
return; |
| 1216 |
} |
| 1217 |
|
| 1218 |
/* Compare the current method with that on the local stack */ |
| 1219 |
methodHashEntry = tps->stackEntry[tps->tos].methodHashEntry; |
| 1220 |
/* 174190 - added check for non-NULL methodHashEntry in case there isn't one stored on the stack */ |
| 1221 |
if(methodHashEntry && ((MethodHashKey *)methodHashEntry->id)->id != event->u.method.method_id) { |
| 1222 |
/* Stack is not synched, look up the method */ |
| 1223 |
methodHashEntry = jvmpiAgent_FindMethodSymbol(event->u.method.method_id); |
| 1224 |
} |
| 1225 |
|
| 1226 |
/* 174190 - added check for non-NULL methodHashEntry in case there isn't one stored on the stack */ |
| 1227 |
if (methodHashEntry) { |
| 1228 |
/* If not pre-aggregating, print the method-exit event for those where we printed the entry. */ |
| 1229 |
if (_jvmpiAgent_Options.compressLevel==CompressNone) { |
| 1230 |
if (jvmpiAgent_Peek(tps, 0)->printed) { |
| 1231 |
jvmpiAgent_printMethodExitElement(event, tps, methodHashEntry, timestamp,cpu_timestamp); |
| 1232 |
} |
| 1233 |
} |
| 1234 |
/* If this was a trigger that started tracing, stop tracing (only if trigger tracing) */ |
| 1235 |
if(_jvmpiAgent_Options.startMode>TraceStartModeFilter && !_jvmpiAgent_Options.application && jvmpiAgent_Peek(tps, 0)->trigger) { |
| 1236 |
suspendTracing(TracePause); |
| 1237 |
} |
| 1238 |
} |
| 1239 |
|
| 1240 |
/* if pre-aggregation, accumulate time into this StackEntry (unless bad lastEntryTime), and set lastEntryTime of caller. */ |
| 1241 |
if(_jvmpiAgent_Options.compressLevel==CompressAggregate) |
| 1242 |
{ |
| 1243 |
StackEntry * top = jvmpiAgent_Peek(tps, 0); |
| 1244 |
StackEntry * caller = jvmpiAgent_Peek(tps, 1); |
| 1245 |
if( top != NULL && top->lastEntryTime!=0) { /* lastEntryTime is 0 for first stackEntry after loadstack * 139537 */ |
| 1246 |
TIMESTAMP_ADD(top->baseTime , timestamp - top->lastEntryTime); |
| 1247 |
TIMESTAMP_ADD(top->baseCPUTime, cpu_timestamp - top->lastEntryCPUTime); |
| 1248 |
DBG_CHK_AND_REPORT_TIME_OVERFLOW(top->baseTime, "Time overflowed?! (MethodExit: top->baseTime)\n"); /* 134577 */ |
| 1249 |
} |
| 1250 |
if( caller != NULL ) { |
| 1251 |
caller->lastEntryTime = timestamp; |
| 1252 |
caller->lastEntryCPUTime = cpu_timestamp; |
| 1253 |
} |
| 1254 |
/* The logic in jvmpiAgent_Pop will roll data from the StackEntry to the proper StackFrame. */ |
| 1255 |
} |
| 1256 |
jvmpiAgent_Pop(tps); |
| 1257 |
} |
| 1258 |
|
| 1259 |
/* bugzilla 71388 start - JNI methods need to be enclosed in a conditional 'extern "C"' declaration */ |
| 1260 |
#if defined __cplusplus |
| 1261 |
extern "C" { |
| 1262 |
#endif |
| 1263 |
|
| 1264 |
/* |
| 1265 |
* Class: com_ibm_etools_logging_tracing_agent_Callback |
| 1266 |
* Method: JVMPICoverage0 |
| 1267 |
* Signature: (S)V |
| 1268 |
*/ |
| 1269 |
JNIEXPORT void JNICALL Java_com_ibm_etools_logging_tracing_agent_Callback_JVMPICoverage0(JNIEnv *env, jclass cls, jshort e) |
| 1270 |
{ |
| 1271 |
|
| 1272 |
/* RKD: We shouldn't be testing IO here */ |
| 1273 |
if (!_jvmpiAgent_suspendIO && _jvmpiAgent_jvm) /* Only do this if the dll has been initialized correctly */ |
| 1274 |
{ |
| 1275 |
HashEntry * methodHashEntry = 0; |
| 1276 |
ThreadLocalStorage *tps; |
| 1277 |
tps = jvmpiAgent_getThreadLocalStorage(env); |
| 1278 |
|
| 1279 |
methodHashEntry = jvmpiAgent_Peek(tps,2)->methodHashEntry; |
| 1280 |
if (methodHashEntry && CLASS_ENTRY(METHOD_ENTRY(methodHashEntry)->classHashEntry)->traceFlag) |
| 1281 |
{ |
| 1282 |
jvmpiAgent_printLineElement(env, tps, methodHashEntry, e); |
| 1283 |
} |
| 1284 |
} |
| 1285 |
|
| 1286 |
} |
| 1287 |
|
| 1288 |
/* bugzilla 71388 end - JNI methods need to be enclosed in a conditional 'extern "C"' declaration */ |
| 1289 |
#if defined __cplusplus |
| 1290 |
} |
| 1291 |
#endif |
| 1292 |
|
| 1293 |
static int decrementInvocationCount() { |
| 1294 |
/* Decrement the burst count if necessary. |
| 1295 |
RKD: This should be atomic. |
| 1296 |
*/ |
| 1297 |
/* decrementInvocationCount() is called at the END of processMethodEntry, and so |
| 1298 |
when the invocationCountRemaining is 1, this means that we've traced the number |
| 1299 |
of methods asked for by the user */ |
| 1300 |
if(_invocationCountRemaining<=1) { |
| 1301 |
suspendTracing(TracePause); |
| 1302 |
return -1; |
| 1303 |
} |
| 1304 |
else { |
| 1305 |
_invocationCountRemaining--; |
| 1306 |
return 0; |
| 1307 |
} |
| 1308 |
} |
| 1309 |
|
| 1310 |
|
| 1311 |
static int incrementInvocationCount() { |
| 1312 |
_invocationCountRemaining--; |
| 1313 |
} |
| 1314 |
|
| 1315 |
/** PROCESS_MISSING_STACK_ENTRIES ******************************************** |
| 1316 |
* |
| 1317 |
*/ |
| 1318 |
static void processMissingStackEntries(JVMPI_Event *event, ThreadLocalStorage *tps) { |
| 1319 |
StackEntry * se = 0; |
| 1320 |
int i = 1; |
| 1321 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 1322 |
dumpMethodEventCounts(); printf("processMissingStackEntries: tps = %8x\n", (void *)tps); fflush(stdout); |
| 1323 |
#endif |
| 1324 |
if(_jvmpiAgent_Options.mode == TraceModeNone) { |
| 1325 |
return; |
| 1326 |
} |
| 1327 |
if (_jvmpiAgent_Options.mode == TraceOptimizedHeap) { |
| 1328 |
/* ToDo: remove. I know that, in TraceGcOptimizedHeap mode, it will never come |
| 1329 |
* here because it is called only from processMethodEntry() method, and |
| 1330 |
* METHOD_ENTRY events are disabled. But just to make sure that it |
| 1331 |
* is not accidently causing lack of LeakCandidates. |
| 1332 |
*/ |
| 1333 |
/* do nothing */ |
| 1334 |
return; |
| 1335 |
} |
| 1336 |
|
| 1337 |
/* Walk up the stack looking for the first non filtered out method. This loop will leave |
| 1338 |
i being the stack offset of the first unfiltered method on the stack and se points to this |
| 1339 |
stackEntry. If se is null then we walked off the beginning of the stack without finding |
| 1340 |
an unfiltered method. |
| 1341 |
*/ |
| 1342 |
for (se = jvmpiAgent_Peek(tps, i); se && !se->printed; se = jvmpiAgent_Peek(tps, ++i)); |
| 1343 |
|
| 1344 |
|
| 1345 |
/* Now we walk through the filtered out stack entries producing METHOD_ENTRYs for each entry.*/ |
| 1346 |
for (--i; se && i > 0; --i) { |
| 1347 |
se = jvmpiAgent_Peek(tps, i); |
| 1348 |
|
| 1349 |
/* If we are handling object collation we better ensure we know the object */ |
| 1350 |
if(_jvmpiAgent_Options.mode == TraceModeFull) { |
| 1351 |
/* RKD: If we know the object we should check our filter against it for inheritance reasons (only when filter tracing) */ |
| 1352 |
if (se->objectHashEntry && _jvmpiAgent_Options.startMode==TraceStartModeFilter && !se->objectHashEntry->printed) { |
| 1353 |
jvmpiAgent_printObjAllocElement(se->objectHashEntry, event->env_id, 0); |
| 1354 |
} |
| 1355 |
} |
| 1356 |
|
| 1357 |
/* Note: following if-else-if pattern repeats with variation in ProcessMethodEntry */ |
| 1358 |
/* Test pre-aggregation mode */ |
| 1359 |
if (_jvmpiAgent_Options.compressLevel==CompressNone) { |
| 1360 |
/* Full Trace: print the method entry for this stack frame */ |
| 1361 |
jvmpiAgent_printMethodEntryEvent(event, tps, se, tps->tos-i); |
| 1362 |
} |
| 1363 |
else { /* 134635C - fix contiguous mode (besides detach/attach/pause) */ |
| 1364 |
|
| 1365 |
/* pre-agg mode: print a methodDef if needed and create a stackFrame for this stackEntry. |
| 1366 |
* |
| 1367 |
* We can safely create a stackFrame after the fact here. It is later than usual (normally |
| 1368 |
* done on method entry) but still before it is needed (in the agPop invoked at method exit). |
| 1369 |
* Note that the baseTime/baseCpuTime accumulations have already been done correctly for this |
| 1370 |
* stackEntry by the normal MethodEntryEvent operations which accumulate time the same way |
| 1371 |
* regardless of whether the method is filtered or not. It is the processing of MethodExitEvents |
| 1372 |
* (specifically the jvmpiAgent_agPop) that differentiates between filtered and not. |
| 1373 |
*/ |
| 1374 |
StackEntry * caller; |
| 1375 |
caller = jvmpiAgent_Peek(tps, i+1); /* se is guaranteed to have a caller on the stack */ |
| 1376 |
/* Pre-agg: print method def if needed & create/re-use StackFrame for method * 134577 */ |
| 1377 |
/* : set lastEntryTime (& lastEntryCpuTime as needed) * 134577 */ |
| 1378 |
recordAgMethodEntry(tps, se, caller); /* 134577 */ |
| 1379 |
} |
| 1380 |
/* Deal with burst mode if we are running in that mode (ignore BurstModeSeconds here) */ |
| 1381 |
if( _jvmpiAgent_Options.burstMode == BurstModeInvocations || |
| 1382 |
_jvmpiAgent_Options.burstMode == BurstModeSecondsAndInvocations ) { |
| 1383 |
decrementInvocationCount(); /* non-zero indicates count exhausted: tracing has suspended */ |
| 1384 |
} |
| 1385 |
|
| 1386 |
} |
| 1387 |
} |
| 1388 |
|
| 1389 |
/** |
| 1390 |
* loadMethodHashEntry() |
| 1391 |
* |
| 1392 |
* Load the method hash entry for a given method_id, ensuring that a CLASS_LOAD |
| 1393 |
* is requested if the piAgent doesn't currently know about the method |
| 1394 |
*/ |
| 1395 |
static HashEntry *loadMethodHashEntry(jmethodID method_id) { |
| 1396 |
HashEntry *methodHashEntry = NULL; |
| 1397 |
/* The JVM may give us a method_id of '0' */ |
| 1398 |
if(method_id != 0) { |
| 1399 |
methodHashEntry = jvmpiAgent_FindMethodSymbol(method_id); |
| 1400 |
|
| 1401 |
/* If this is an unknown method we need to ask for the CLASS_LOAD event */ |
| 1402 |
if(!methodHashEntry) { |
| 1403 |
jobjectID clazz; |
| 1404 |
jint result; |
| 1405 |
clazz=_jvmpiAgent_jvmpiInterface->GetMethodClass(method_id); |
| 1406 |
result=!JVMPI_SUCCESS; |
| 1407 |
|
| 1408 |
if(clazz) { |
| 1409 |
result=REQUEST_EVENT2(JVMPI_EVENT_CLASS_LOAD, clazz); /* 232010 */ |
| 1410 |
/* If we found the class we should have the method */ |
| 1411 |
if(result == JVMPI_SUCCESS) { |
| 1412 |
methodHashEntry = jvmpiAgent_FindMethodSymbol(method_id); |
| 1413 |
} |
| 1414 |
} |
| 1415 |
} |
| 1416 |
} |
| 1417 |
return methodHashEntry; |
| 1418 |
} |
| 1419 |
|
| 1420 |
|
| 1421 |
/** PROCESS_COUNTING_METHOD_ENTRY_EVENT |
| 1422 |
* |
| 1423 |
* This version of processMethodEntryEvent is called when the METHOD_COUNTS_ONLY option is turned |
| 1424 |
* on. We don't want the overhead of the regular processMethodEntry event in this case. |
| 1425 |
*/ |
| 1426 |
|
| 1427 |
static void processCountingMethodEntryEvent(JVMPI_Event *event, ThreadLocalStorage *tps, BOOL isRequested, timestamp_t timestamp, |
| 1428 |
timestamp_t cpu_timestamp) { |
| 1429 |
HashEntry *methodHashEntry; |
| 1430 |
|
| 1431 |
methodHashEntry = loadMethodHashEntry(event->u.method.method_id); |
| 1432 |
if (methodHashEntry != NULL) { |
| 1433 |
METHOD_ENTRY(methodHashEntry)->methodCount++; |
| 1434 |
} |
| 1435 |
} |
| 1436 |
|
| 1437 |
/* For pre-aggregation */ |
| 1438 |
/* Recursively free stack frames. |
| 1439 |
* This function frees all children of the frame being passed in, |
| 1440 |
* then frees that frame itself. It returns the "next" (sibling) pointer |
| 1441 |
* from the frame being freed. |
| 1442 |
* |
| 1443 |
* OPTIMIZATION OPPORTUNITY HERE: use a chunky allocator for StackFrame |
| 1444 |
* objects, with one chunk chain per thread. Since the frames for a thread |
| 1445 |
* are always freed all at once, you could just free the chunks and not have |
| 1446 |
* to do this recursive descent. |
| 1447 |
*/ |
| 1448 |
void freeStackFrames(StackFrame* frame) |
| 1449 |
{ |
| 1450 |
if (frame == NULL) return; |
| 1451 |
|
| 1452 |
/* first, free children */ |
| 1453 |
freeStackFrames(frame->calledList); |
| 1454 |
|
| 1455 |
/* then, free the next sibling */ |
| 1456 |
freeStackFrames(frame->next); |
| 1457 |
|
| 1458 |
/* finally, free this frame */ |
| 1459 |
free(frame); |
| 1460 |
} |
| 1461 |
|
| 1462 |
/* For pre-aggregation */ |
| 1463 |
/* |
| 1464 |
* Add a thread to the list of live threads that the |
| 1465 |
* pre-aggregation logic is tracking. |
| 1466 |
* |
| 1467 |
* This may seem redundant - the list of live threads is also available |
| 1468 |
* in the ThreadHashTable data structure. But the timing and semantics |
| 1469 |
* adding and removing threads from that list and this one are different, |
| 1470 |
* and I didn't want to go poking around to make sure the right things would |
| 1471 |
* always happen in the right order, so I left this as a separate data |
| 1472 |
* structure just like the original prototype implementors had. |
| 1473 |
*/ |
| 1474 |
void addThreadToList( ThreadPrivateStorage * tpsLocal ) |
| 1475 |
{ |
| 1476 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 1477 |
dumpMethodEventCounts(); printf("addThreadToList (try): tpsLocal = %8x\n", (void *)tpsLocal); fflush(stdout); |
| 1478 |
#endif |
| 1479 |
/* Get the thread list lock because we're managing that list here */ |
| 1480 |
getThreadListLock(); |
| 1481 |
{ |
| 1482 |
/* It seems we are recieving duplicate events for thread starts. First, make |
| 1483 |
* sure we don't already have the thread */ |
| 1484 |
struct ThreadListElement * it = threadsRoot; |
| 1485 |
while (it) { |
| 1486 |
if (it->data == tpsLocal ) { |
| 1487 |
/* Thread already seen; exit with "it" != NULL */ |
| 1488 |
break; |
| 1489 |
} |
| 1490 |
it = it->next; |
| 1491 |
} |
| 1492 |
|
| 1493 |
if (it == NULL ) { |
| 1494 |
/* usual case: we don't already have an entry for this thread */ |
| 1495 |
struct ThreadListElement * newThreadElement = (struct ThreadListElement *)jvmpiAgent_Calloc( sizeof( struct ThreadListElement ) ); |
| 1496 |
newThreadElement->data = tpsLocal; |
| 1497 |
newThreadElement->next = threadsRoot; |
| 1498 |
newThreadElement->prev = 0; |
| 1499 |
if( threadsRoot ) |
| 1500 |
threadsRoot->prev = newThreadElement; |
| 1501 |
threadsRoot = newThreadElement; |
| 1502 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 1503 |
printf("addThreadToList (succeed)\n"); fflush(stdout); |
| 1504 |
#endif |
| 1505 |
} |
| 1506 |
} |
| 1507 |
releaseThreadListLock(); |
| 1508 |
} |
| 1509 |
|
| 1510 |
/* For pre-aggregation */ |
| 1511 |
/* |
| 1512 |
* Remove a thread from the list of live threads being maintained |
| 1513 |
* by the pre-aggregation logic. See notes above for why this |
| 1514 |
* exists in parallel with the ThreadHashTable stuff. |
| 1515 |
* |
| 1516 |
* Frees all StackFrames associated with the thread being removed. |
| 1517 |
* Does not dump any data; this function assumes you did that already or you |
| 1518 |
* don't care. |
| 1519 |
*/ |
| 1520 |
void removeThreadFromList( ThreadPrivateStorage * target_tps ) |
| 1521 |
{ |
| 1522 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 1523 |
dumpMethodEventCounts(); printf("removeThreadFromList (try): target_tps = %8x\n", (void *)target_tps); fflush(stdout); |
| 1524 |
#endif |
| 1525 |
/* get the thread list lock because we're managing that list here */ |
| 1526 |
getThreadListLock(); |
| 1527 |
{ |
| 1528 |
struct ThreadListElement * it = threadsRoot; |
| 1529 |
while (it) { |
| 1530 |
if( it->data == target_tps ) |
| 1531 |
break; |
| 1532 |
it = it->next; |
| 1533 |
} |
| 1534 |
|
| 1535 |
if (it) { /* If found */ |
| 1536 |
/* Free all the elements from calledList, recursively */ |
| 1537 |
freeStackFrames(it->data->calledList); |
| 1538 |
it->data->calledList = NULL; |
| 1539 |
|
| 1540 |
/* Now actually remove the thread from the list */ |
| 1541 |
if( it->next ) |
| 1542 |
it->next->prev = it->prev; |
| 1543 |
if( it->prev ) |
| 1544 |
it->prev->next = it->next; |
| 1545 |
if( threadsRoot == it ) |
| 1546 |
threadsRoot = it->next; |
| 1547 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 1548 |
printf("removeThreadFromList (succeed)\n"); fflush(stdout); |
| 1549 |
#endif |
| 1550 |
} |
| 1551 |
|
| 1552 |
free(it); |
| 1553 |
} |
| 1554 |
target_tps->calledList = NULL; /* 134635: frames are all gone so thread's calledList must be nulled */ |
| 1555 |
releaseThreadListLock(); |
| 1556 |
} |
| 1557 |
|
| 1558 |
/* For pre-aggregation */ |
| 1559 |
/* |
| 1560 |
* Recursively print the aggregated data for a single thread, |
| 1561 |
* starting from a given StackFrame. Called from PrintAgThreadData. |
| 1562 |
*/ |
| 1563 |
|
| 1564 |
void printAgData(ThreadPrivateStorage * tps, StackFrame * call) { |
| 1565 |
|
| 1566 |
if (call == NULL) |
| 1567 |
return; |
| 1568 |
|
| 1569 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 1570 |
dumpMethodEventCounts(); |
| 1571 |
printf("printAgData: agMethodEntry, (children), agMethodExit\n"); fflush(stdout); |
| 1572 |
printf(" : tps, &stackframe, &methodHashEntry, MethodIdRef= %8x, %8x, %8x", |
| 1573 |
(void *)tps, (void *)call, (void*)(METHOD_ENTRY(call->methodHashEntry)) ); fflush(stdout); |
| 1574 |
printf(", %5d\n", (jint)((METHOD_ENTRY(call->methodHashEntry))->static_id)); fflush(stdout); |
| 1575 |
#endif |
| 1576 |
|
| 1577 |
jvmpiAgent_printAgMethodEntryEvent(tps, call); /* 135437 */ |
| 1578 |
|
| 1579 |
/* Note: The following loop prints the call chains of the direct children of the current "call", |
| 1580 |
* depth first and then breadth. It terminates when the "next" ptr of one of the direct children |
| 1581 |
* of the current call is null. Thus it terminates after printing the call chains of the last |
| 1582 |
* direct child of the current call frame. (The loop & recursion is compact but can confuse.) |
| 1583 |
*/ |
| 1584 |
|
| 1585 |
/* Dump this call's children */ |
| 1586 |
{ |
| 1587 |
StackFrame * it = call->calledList; /* select the first direct child of the current "call" */ |
| 1588 |
while( it != NULL ) { /* stop if there are no more direct children of the current caller */ |
| 1589 |
printAgData(tps, it); /* print the call chains of this direct child of the current caller */ |
| 1590 |
it = it->next; /* select the next direct child of the current caller */ |
| 1591 |
} |
| 1592 |
} |
| 1593 |
|
| 1594 |
jvmpiAgent_printAgMethodExitElement(tps, call); /* 135457 */ |
| 1595 |
} |
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
/* For pre-aggregation */ |
| 1600 |
/* |
| 1601 |
* Send the call chain counts for the indicated thread. |
| 1602 |
* This is called from two places: when a single thread dies, |
| 1603 |
* and when you do a full-process snapshot. |
| 1604 |
* |
| 1605 |
* This function calls getStackFrameStructureLock, but |
| 1606 |
* only if it's called from a place where you didn't already have it. |
| 1607 |
* This is conveyed by a boolean argument, true if the caller |
| 1608 |
* already has the lock. That's necessary because the |
| 1609 |
* ra_critsec_t implementation isn't reentrant on Linux. |
| 1610 |
* |
| 1611 |
* The reason we need to acquire StackFrameStructureLock even though |
| 1612 |
* we're only dumping a single thread is that another dump request |
| 1613 |
* (a snapshot or JVM shutdown) could come in on another thread |
| 1614 |
* while this dump is still going on. We don't want to have |
| 1615 |
* multiple dumps happening in parallel: they would cause |
| 1616 |
* duplicate data to be sent. |
| 1617 |
* |
| 1618 |
* This does mean that one thread's death will stall any other thread that |
| 1619 |
* makes a unique call (and thus also needs StackFrameStructureLock) |
| 1620 |
* for the duration of the dump, even though they couldn't |
| 1621 |
* possibly step on each other. This makes me wish for a different |
| 1622 |
* lock implementation, one that more completely expresses the possible collisions. |
| 1623 |
*/ |
| 1624 |
void printThreadAgData ( ThreadLocalStorage * tps, int alreadyHasLock ) { |
| 1625 |
StackFrame * it; |
| 1626 |
|
| 1627 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 1628 |
dumpMethodEventCounts(); |
| 1629 |
printf("printThreadAgData: tps, tps->calledList, _traceResourcesGone = %8x, %8x, %2d\n", |
| 1630 |
(void *)tps, (void *)tps->calledList, (int)_traceResourcesGone); fflush(stdout); |
| 1631 |
#endif |
| 1632 |
/* pre-agg: 134635 |
| 1633 |
* This test is necessary because it is possible for a print of agg data |
| 1634 |
* to be attempted after the underlying trace resources (esp. method hash table) |
| 1635 |
* have been cleaned-up via cleanupAllTraceResources. This is known to occur at |
| 1636 |
* least sometimes when a processThreadEndEvent occurs after DETACH_FROM_AGENT |
| 1637 |
* has been processed. It is a harmless test for the non-pre-agg case |
| 1638 |
*/ |
| 1639 |
if (_traceResourcesGone) { |
| 1640 |
return; |
| 1641 |
} |
| 1642 |
|
| 1643 |
if (!alreadyHasLock) { |
| 1644 |
getStackFrameStructureLock(); |
| 1645 |
} |
| 1646 |
it = tps->calledList; |
| 1647 |
while( it != NULL ) { |
| 1648 |
printAgData(tps, it); |
| 1649 |
it = it->next; |
| 1650 |
} |
| 1651 |
if (!alreadyHasLock) { |
| 1652 |
releaseStackFrameStructureLock(); |
| 1653 |
} |
| 1654 |
} |
| 1655 |
|
| 1656 |
/* For pre-aggregation */ |
| 1657 |
/* |
| 1658 |
* Send the call chain counts for all threads. This is a "snapshot" |
| 1659 |
* operation that acquires the StackFrameStructureLock |
| 1660 |
* and walks the StackFrames of all threads. |
| 1661 |
*/ |
| 1662 |
void printAllThreadAgData() { |
| 1663 |
|
| 1664 |
/* Get the thread list lock because we walk the whole thread list here */ |
| 1665 |
getThreadListLock(); |
| 1666 |
{ |
| 1667 |
struct ThreadListElement * it = threadsRoot; |
| 1668 |
|
| 1669 |
/* |
| 1670 |
* Acquire this lock so we block out any other thread |
| 1671 |
* that is trying to add new callers to frames. |
| 1672 |
* See notes elsewhere about a no-lock alternative |
| 1673 |
* to stackFrameStructureLock. |
| 1674 |
*/ |
| 1675 |
getStackFrameStructureLock(); |
| 1676 |
{ |
| 1677 |
while (it) { |
| 1678 |
printThreadAgData( it->data, TRUE ); |
| 1679 |
it = it->next; |
| 1680 |
} |
| 1681 |
} |
| 1682 |
releaseStackFrameStructureLock(); |
| 1683 |
} |
| 1684 |
releaseThreadListLock(); |
| 1685 |
} |
| 1686 |
|
| 1687 |
/* |
| 1688 |
* Return current time and (if options so indicate) current cpu time. As a side-effect, |
| 1689 |
* tps->last_cpu_time is updated if cpu time is updated. This function is used in |
| 1690 |
* processMethodEntryEvent and processMissingStackEntries because they share a pattern |
| 1691 |
* of usage where latest time/cpu_time are used for both stackEntry aggregation (if applicable) |
| 1692 |
* and method entry overhead calculations. |
| 1693 |
*/ |
| 1694 |
void setNowTimes(ThreadLocalStorage * tps, timestamp_t * nowTime_P, timestamp_t * nowCpuTime_P) { /* 134577 */ |
| 1695 |
jvmpiAgent_getCurrentTime(nowTime_P); |
| 1696 |
if (_jvmpiAgent_Options.cpuTime) { |
| 1697 |
*nowCpuTime_P = jvmpiAgent_getCurrentThreadCPUTime(); |
| 1698 |
tps->last_cpu_timestamp = *nowCpuTime_P; |
| 1699 |
} |
| 1700 |
} |
| 1701 |
|
| 1702 |
/* For pre-aggregation */ |
| 1703 |
/* |
| 1704 |
* Print method def if needed and create/re-use StackFrame for method along this chain since it |
| 1705 |
* is not filtered out. Get latest time/cpuTime. Store them in stackEntry->lastEntryTime and |
| 1706 |
* lastEntryCPUTime to allow for potential suspendTracing (which references these values) from |
| 1707 |
* subsequent decrementInvocationCount calls and for later overhead calculations in the caller. |
| 1708 |
* They are purposely calculated as late in this function as possible to eliminate overhjeas from method stats. |
| 1709 |
*/ |
| 1710 |
void recordAgMethodEntry(ThreadLocalStorage * tps, StackEntry * stackEntry, StackEntry * caller) { /*134577 */ |
| 1711 |
timestamp_t nowTime; |
| 1712 |
timestamp_t nowCpuTime = 0; |
| 1713 |
|
| 1714 |
stackEntry->printed = 1; /* Indicate that this entry is "printed"=non-filtered - 134635C */ |
| 1715 |
jvmpiAgent_outputMethodDeclaration(stackEntry->methodHashEntry, tps); |
| 1716 |
jvmpiAgent_CreateStackFrame(tps, stackEntry->methodHashEntry, caller); |
| 1717 |
|
| 1718 |
setNowTimes(tps, &nowTime, &nowCpuTime); |
| 1719 |
stackEntry->lastEntryTime = nowTime; /* critical in case suspend occurs from burst mode before Method entry ends *134577 */ |
| 1720 |
stackEntry->lastEntryCPUTime = nowCpuTime; |
| 1721 |
} |
| 1722 |
|
| 1723 |
|
| 1724 |
/** PROCESS_METHOD_ENTRY_EVENT *********************************************** |
| 1725 |
* |
| 1726 |
*/ |
| 1727 |
static void processMethodEntryEvent(JVMPI_Event *event, ThreadLocalStorage *tps, BOOL isRequested, timestamp_t timestamp, |
| 1728 |
timestamp_t cpu_timestamp) { |
| 1729 |
HashEntry *methodHashEntry, *objectHashEntry; |
| 1730 |
StackEntry * stackEntry, *caller; |
| 1731 |
int isPrinting; |
| 1732 |
jmethodID method_id; |
| 1733 |
jobjectID object_id; |
| 1734 |
BOOL triggeringEvent=FALSE; |
| 1735 |
|
| 1736 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 1737 |
if (tps!=prevMthdTps) { |
| 1738 |
dumpMethodEventCounts(); prevMthdTps=tps; |
| 1739 |
} |
| 1740 |
meCount++; |
| 1741 |
#endif |
| 1742 |
|
| 1743 |
if(_jvmpiAgent_Options.mode == TraceModeNone) { |
| 1744 |
return; |
| 1745 |
} |
| 1746 |
if (_jvmpiAgent_Options.mode == TraceOptimizedHeap) { |
| 1747 |
/* ToDo: remove. I know that, in TraceGcOptimizedHeap mode, it will never come |
| 1748 |
* here because METHOD_ENTRY event is disbled, but just to make sure that it |
| 1749 |
* is not accidently causing lack of LeakCandidates. |
| 1750 |
*/ |
| 1751 |
/* do nothing */ |
| 1752 |
return; |
| 1753 |
} |
| 1754 |
|
| 1755 |
objectHashEntry=methodHashEntry=NULL; |
| 1756 |
method_id = event->u.method.method_id; |
| 1757 |
object_id=(event->event_type==JVMPI_EVENT_METHOD_ENTRY2) ? event->u.method_entry2.obj_id : 0; |
| 1758 |
|
| 1759 |
/* RKD: If we don't know the stack for this thread |
| 1760 |
we better materialize this stack now. |
| 1761 |
*/ |
| 1762 |
if(!tps->threadStackKnown) { |
| 1763 |
/* Disable GC */ |
| 1764 |
_jvmpiAgent_jvmpiInterface->DisableGC(); |
| 1765 |
loadStack(tps); |
| 1766 |
|
| 1767 |
/* Re-enable GC */ |
| 1768 |
_jvmpiAgent_jvmpiInterface->EnableGC(); |
| 1769 |
|
| 1770 |
/* We are already on the stack from the load. Pop us off */ |
| 1771 |
jvmpiAgent_Pop(tps); |
| 1772 |
|
| 1773 |
/* RKD: Do to problems we have with the JIT being enabled it may be possible that the |
| 1774 |
thread stack is still not known. If this case we abort this method |
| 1775 |
*/ |
| 1776 |
if(!tps->threadStackKnown) { |
| 1777 |
return; |
| 1778 |
} |
| 1779 |
|
| 1780 |
} |
| 1781 |
|
| 1782 |
|
| 1783 |
methodHashEntry = loadMethodHashEntry(method_id); |
| 1784 |
|
| 1785 |
/* Determine if we are supposed to print this method. Depending upon the trace start mode will determine this test */ |
| 1786 |
if(_jvmpiAgent_Options.startMode==TraceStartModeFilter) { |
| 1787 |
isPrinting = (methodHashEntry && METHOD_ENTRY(methodHashEntry)->traceFlag && _jvmpiAgent_Options.stackInfo > StackInfoNone); |
| 1788 |
} |
| 1789 |
/* Trigger tracing */ |
| 1790 |
else { |
| 1791 |
/* If the trigger hasn't been squeezed yet check to see if we are the trigger and scope to thread if neccessary */ |
| 1792 |
if(!_triggerSqueezed) { |
| 1793 |
isPrinting = (methodHashEntry |
| 1794 |
&& (METHOD_ENTRY(methodHashEntry)->trigger |
| 1795 |
== METHOD_ENTRY(methodHashEntry)->methodCount)); |
| 1796 |
|
| 1797 |
if(isPrinting) { |
| 1798 |
_triggerSqueezed=TRUE; |
| 1799 |
triggeringEvent=TRUE; |
| 1800 |
if(_jvmpiAgent_Options.startMode==TraceStartModeTriggerSingleThreaded) { |
| 1801 |
_jvmpiAgent_limitingThread=event->env_id; |
| 1802 |
_jvmpiAgent_singleThreaded=TRUE; |
| 1803 |
} |
| 1804 |
if(_jvmpiAgent_isSuspended) { |
| 1805 |
resumeTracing(); |
| 1806 |
} |
| 1807 |
} |
| 1808 |
isPrinting=isPrinting && _jvmpiAgent_Options.stackInfo > StackInfoNone; |
| 1809 |
} |
| 1810 |
else { |
| 1811 |
isPrinting = (methodHashEntry && _jvmpiAgent_Options.stackInfo > StackInfoNone); |
| 1812 |
} |
| 1813 |
} |
| 1814 |
|
| 1815 |
/* If we are handling object collation we better ensure we know the object */ |
| 1816 |
if(_jvmpiAgent_Options.mode == TraceModeFull && object_id) { |
| 1817 |
/* Look for the object */ |
| 1818 |
|
| 1819 |
/* 226233: we can safely use the "fast", non-ref counting |
| 1820 |
version here, since we'd only be here if this is an |
| 1821 |
ENTRY2 event, in which case the heap is locked */ |
| 1822 |
objectHashEntry = jvmpiAgent_FindObjectSymbolFast(object_id); |
| 1823 |
|
| 1824 |
/* If the object is not currently in the DB look it upo in the VM */ |
| 1825 |
if(!objectHashEntry || !objectHashEntry->id || |
| 1826 |
!((ObjectHashKey*)objectHashEntry->id)->id) { |
| 1827 |
int result; |
| 1828 |
/* RKD: Disable the garbage collector while we get the object */ |
| 1829 |
_jvmpiAgent_jvmpiInterface->DisableGC(); |
| 1830 |
result=REQUEST_EVENT2(JVMPI_EVENT_OBJECT_ALLOC, event->u.method_entry2.obj_id); /* 232010 */ |
| 1831 |
_jvmpiAgent_jvmpiInterface->EnableGC(); |
| 1832 |
|
| 1833 |
/* We should now find the object without incident */ |
| 1834 |
objectHashEntry = jvmpiAgent_FindObjectSymbolFast(object_id); |
| 1835 |
} |
| 1836 |
|
| 1837 |
/* RKD: If we know the object we should check our filter against it for inheritance reasons (only when filter tracing) */ |
| 1838 |
if ( objectHashEntry && _jvmpiAgent_Options.startMode==TraceStartModeFilter |
| 1839 |
&& OBJECT_ENTRY(objectHashEntry)->traceFlag && !objectHashEntry->printed ) { |
| 1840 |
jvmpiAgent_printObjAllocElement(objectHashEntry, event->env_id, 0); |
| 1841 |
isPrinting=1; |
| 1842 |
} |
| 1843 |
} |
| 1844 |
|
| 1845 |
/* pre-aggregation mode: accumulate time into the caller (unless caller was added to stack by loadstack) */ |
| 1846 |
if (_jvmpiAgent_Options.compressLevel==CompressAggregate) { |
| 1847 |
caller = jvmpiAgent_Peek(tps, 0); |
| 1848 |
if (caller != NULL && caller->lastEntryTime!=0) { /* lastEntryTime is 0 for first caller after loadstack * 139537 */ |
| 1849 |
TIMESTAMP_ADD(caller->baseTime, timestamp - caller->lastEntryTime); |
| 1850 |
TIMESTAMP_ADD(caller->baseCPUTime, cpu_timestamp - caller->lastEntryCPUTime); |
| 1851 |
DBG_CHK_AND_REPORT_TIME_OVERFLOW(caller->baseTime, "Time overflowed?! (MethodEntry: caller->baseTime)\n"); /* 134577 */ |
| 1852 |
caller->lastEntryTime = -1; /* -1 means this frame active right now */ |
| 1853 |
caller->lastEntryCPUTime = -1; |
| 1854 |
} |
| 1855 |
} |
| 1856 |
|
| 1857 |
/* Push the method on the stack. (Note: this initializes all pre-agg stackEntry fields to 0) */ |
| 1858 |
stackEntry = jvmpiAgent_Push(tps, event->env_id, methodHashEntry, objectHashEntry, timestamp,cpu_timestamp); |
| 1859 |
|
| 1860 |
/* If we are in a pure trigger mode we need to indicate whether this frame is the trigger so we stop |
| 1861 |
profiling when the frame is popped. |
| 1862 |
*/ |
| 1863 |
stackEntry->trigger=triggeringEvent; |
| 1864 |
|
| 1865 |
|
| 1866 |
if (methodHashEntry) { |
| 1867 |
if (isPrinting) { |
| 1868 |
if(_jvmpiAgent_Options.startMode==TraceStartModeFilter && (_jvmpiAgent_Options.stackInfo==StackInfoContiguous || _jvmpiAgent_Options.stackInfo==StackInfoBoundaryAndContiguous)) { |
| 1869 |
processMissingStackEntries(event, tps); |
| 1870 |
} |
| 1871 |
|
| 1872 |
/* When in filtering mode, reset the boundary depth every time we hit a traced method. */ |
| 1873 |
if(_jvmpiAgent_Options.startMode==TraceStartModeFilter) { |
| 1874 |
stackEntry->currentBoundaryDepth=_jvmpiAgent_Options.boundaryDepth+1; |
| 1875 |
} |
| 1876 |
|
| 1877 |
/* If we are in application mode we need to set the boundary depth only when we did not see |
| 1878 |
the entry event on the next frame up the stack. |
| 1879 |
*/ |
| 1880 |
if(_jvmpiAgent_Options.application && _jvmpiAgent_Options.boundaryDepth) { |
| 1881 |
StackEntry *invokerFrame=jvmpiAgent_Peek(tps,1); |
| 1882 |
if(invokerFrame && !invokerFrame->entryEventSeen) { |
| 1883 |
stackEntry->currentBoundaryDepth=_jvmpiAgent_Options.boundaryDepth; |
| 1884 |
} |
| 1885 |
|
| 1886 |
/* Application mode is a different then all the other modes in the fact that we |
| 1887 |
don't keep tracing deeper if our boundaryDepth is |
| 1888 |
*/ |
| 1889 |
if(!stackEntry->currentBoundaryDepth) { |
| 1890 |
return; |
| 1891 |
} |
| 1892 |
} |
| 1893 |
/* Note: following if-else-if pattern repeats below and with variation in ProcessMissingStackEntries */ |
| 1894 |
if (_jvmpiAgent_Options.compressLevel==CompressNone) { |
| 1895 |
/* Full trace: print the method entry for this event */ |
| 1896 |
jvmpiAgent_printMethodEntryEvent(event, tps, stackEntry, tps->tos); |
| 1897 |
} |
| 1898 |
else { |
| 1899 |
/* Pre-agg: print method def if needed & create/re-use StackFrame for method * 134577 */ |
| 1900 |
/* : set lastEntryTime (& lastEntryCpuTime as needed) * 134577 */ |
| 1901 |
recordAgMethodEntry(tps, stackEntry, caller); /* 134577 */ |
| 1902 |
} |
| 1903 |
/* Deal with burst mode if we are running in that mode (ignore BurstModeSeconds here) */ |
| 1904 |
if( _jvmpiAgent_Options.burstMode == BurstModeInvocations || |
| 1905 |
_jvmpiAgent_Options.burstMode == BurstModeSecondsAndInvocations ) { |
| 1906 |
if(decrementInvocationCount()) { /* non-zero indicates count exhausted: tracing has suspended */ |
| 1907 |
return; /* don't count suspension time in entry overhead */ |
| 1908 |
} |
| 1909 |
} |
| 1910 |
} |
| 1911 |
else if(_jvmpiAgent_Options.stackInfo>=StackInfoBoundary && stackEntry->currentBoundaryDepth) { |
| 1912 |
/* Note: following if-else-if pattern repeats above and with variation in ProcessMissingStackEntries */ |
| 1913 |
if (_jvmpiAgent_Options.compressLevel==CompressNone) { |
| 1914 |
/* Full trace: print the method entry for this event */ |
| 1915 |
jvmpiAgent_printMethodEntryEvent(event, tps, stackEntry, tps->tos); |
| 1916 |
} |
| 1917 |
else { |
| 1918 |
/* Pre-agg: print method def if needed & create/re-use StackFrame for method * 134577 */ |
| 1919 |
/* : set lastEntryTime (& lastEntryCpuTime as needed) * 134577 */ |
| 1920 |
recordAgMethodEntry(tps, stackEntry, caller); /*134577 */ |
| 1921 |
} |
| 1922 |
/* Deal with burst mode if we are running in that mode (ignore BurstModeSeconds here) */ |
| 1923 |
if( _jvmpiAgent_Options.burstMode == BurstModeInvocations || |
| 1924 |
_jvmpiAgent_Options.burstMode == BurstModeSecondsAndInvocations ) { |
| 1925 |
if(decrementInvocationCount()) { /* non-zero indicates count exhausted: tracing has suspended */ |
| 1926 |
return; /* don't count suspension time in entry overhead */ |
| 1927 |
} |
| 1928 |
} |
| 1929 |
} |
| 1930 |
} |
| 1931 |
|
| 1932 |
{ |
| 1933 |
/* NMM: here is where we accumulate the tracing overhead due |
| 1934 |
to method enter processing */ |
| 1935 |
timestamp_t now; |
| 1936 |
timestamp_t cpu_now = 0; |
| 1937 |
Uint64 enter_overhead; |
| 1938 |
Uint64 cpu_enter_overhead = 0; |
| 1939 |
|
| 1940 |
/* Get new times that include our overhead in them */ |
| 1941 |
if (_jvmpiAgent_Options.compressLevel==CompressNone) { |
| 1942 |
setNowTimes(tps, &now, &cpu_now); |
| 1943 |
} else { |
| 1944 |
/* 134577 * |
| 1945 |
* Pre-agg: only set now & cpu_now here if they were not previously set by recordAgMethodEntry. |
| 1946 |
* The difference in calculating them here and in an earlier recordAgMethod is |
| 1947 |
* negligible. The intent is to conserve getCurrentTime & getCurrentThreadCPUtime |
| 1948 |
* calls because they are expensive and would skew the overhead calculation. |
| 1949 |
*/ |
| 1950 |
if (stackEntry->lastEntryTime == 0) { /* not set by either previous recordAgMethodEntry */ |
| 1951 |
setNowTimes(tps, &now, &cpu_now); |
| 1952 |
stackEntry->lastEntryTime = now; |
| 1953 |
stackEntry->lastEntryCPUTime = cpu_now; |
| 1954 |
} else { /* set by one of the previous recordAgMethodEntry */ |
| 1955 |
now = stackEntry->lastEntryTime; |
| 1956 |
cpu_now = stackEntry->lastEntryCPUTime; |
| 1957 |
} |
| 1958 |
} |
| 1959 |
|
| 1960 |
enter_overhead = TIMESTAMP_SUB(now,timestamp); |
| 1961 |
if (_jvmpiAgent_Options.cpuTime) { |
| 1962 |
cpu_enter_overhead = TIMESTAMP_SUB(cpu_now,cpu_timestamp); |
| 1963 |
} |
| 1964 |
|
| 1965 |
stackEntry->cumulative_overhead = enter_overhead; |
| 1966 |
stackEntry->cumulative_cpu_overhead = cpu_enter_overhead; |
| 1967 |
} |
| 1968 |
} |
| 1969 |
|
| 1970 |
|
| 1971 |
/** SET_PATH_DELIMITER ******************************************************** |
| 1972 |
* Checks class name's provided by JVMPI to determine if this JVM uses the '.' |
| 1973 |
* package delimiter. If it does, we will tell the filters checker to use |
| 1974 |
* change all it's strings to the '.' delimiter. |
| 1975 |
* RKD: I hate the use of a global here. I bet we can get around this. |
| 1976 |
*/ |
| 1977 |
static void setPathDelimiter(char * str) { |
| 1978 |
#ifdef __OS400__ |
| 1979 |
#pragma convert(819) |
| 1980 |
#endif |
| 1981 |
|
| 1982 |
/* The path delimiter on IBM's JDK */ |
| 1983 |
char ibmch = '/'; |
| 1984 |
/* The path delimiter on SUN's JDK */ |
| 1985 |
char sunch = '.'; |
| 1986 |
/* The location of the delimiter */ |
| 1987 |
char *pdest; |
| 1988 |
|
| 1989 |
/* Look for the IBM delimiter in the given string */ |
| 1990 |
pdest = strchr(str, ibmch ); |
| 1991 |
|
| 1992 |
/* Set the global delimiter */ |
| 1993 |
if(pdest) { |
| 1994 |
_setPathDelimiter = ibmch; |
| 1995 |
} |
| 1996 |
else { |
| 1997 |
pdest = strchr(str, sunch ); |
| 1998 |
if(pdest) { |
| 1999 |
_setPathDelimiter = sunch; |
| 2000 |
jvmpiAgent_changeDelimiter(); |
| 2001 |
} |
| 2002 |
} |
| 2003 |
#ifdef __OS400__ |
| 2004 |
#pragma convert(0) |
| 2005 |
#endif |
| 2006 |
} |
| 2007 |
|
| 2008 |
#ifdef __OS400__ |
| 2009 |
/** PROCESS_OBJECT_DUMP_EVENT ************************************************* |
| 2010 |
* Handles the output of a OBJECT_DUMP element and attributes along with any |
| 2011 |
* @param event - the event data provided by the JVM. |
| 2012 |
* @param isRequested - whether this event is generated as a result of a specific |
| 2013 |
* RequestEvent call. If the event is requested it is assumed |
| 2014 |
* that the writelock is held for the hashtables. |
| 2015 |
*/ |
| 2016 |
static void processObjectDumpEvent(JVMPI_Event *event, |
| 2017 |
ThreadLocalStorage *tps, |
| 2018 |
BOOL isRequested, |
| 2019 |
timestamp_t timestamp, |
| 2020 |
timestamp_t cpu_timestamp) { |
| 2021 |
|
| 2022 |
if((_jvmpiAgent_Options.mode == TraceOptimizedHeap) && (event->u.object_dump.data_len > 0) && |
| 2023 |
(event->u.object_dump.data[0] == JVMPI_GC_CLASS_DUMP)) { |
| 2024 |
|
| 2025 |
StatelessHeapSnapshotManager_objectDumpCallbackMethod(event); |
| 2026 |
return; |
| 2027 |
} |
| 2028 |
|
| 2029 |
} |
| 2030 |
#endif |
| 2031 |
|
| 2032 |
/** PROCESS_CLASS_LOAD_EVENT ************************************************* |
| 2033 |
* Handles the output of a CLASS_LOAD element and attributes along with any |
| 2034 |
* associated METHOD, STATIC_FIELD and INSTANCE_FIELD elements. |
| 2035 |
* @param event - the event data provided by the JVM. |
| 2036 |
* @param isRequested - whether this event is generated as a result of a specific |
| 2037 |
* RequestEvent call. If the event is requested it is assumed |
| 2038 |
* that the writelock is held for the hashtables. |
| 2039 |
*/ |
| 2040 |
static void processClassLoadEvent(JVMPI_Event *event, |
| 2041 |
ThreadLocalStorage *tps, |
| 2042 |
BOOL isRequested, |
| 2043 |
timestamp_t timestamp, |
| 2044 |
timestamp_t cpu_timestamp) { |
| 2045 |
char * buffer; |
| 2046 |
HashEntry *classHashEntry; |
| 2047 |
|
| 2048 |
if(_jvmpiAgent_Options.mode == TraceModeNone) { |
| 2049 |
return; |
| 2050 |
} |
| 2051 |
if(_jvmpiAgent_Options.mode == TraceOptimizedHeap) { |
| 2052 |
/* ToDo: We do not track callInfo currently |
| 2053 |
if (_jvmpiAgent_Options.classInfoCallback) { |
| 2054 |
*/ |
| 2055 |
|
| 2056 |
/* Giri <Defect 78980/78981>: Sometimes, the IBM Classic VM sends |
| 2057 |
* class load events with class_name set to NULL. Other fields are set correctly. |
| 2058 |
* Handle these cases properly. |
| 2059 |
* |
| 2060 |
* Anandi Aug 2005 Fix Giri's fix, bugzilla 106779. |
| 2061 |
* Don't simply return when className is |
| 2062 |
* NULL. Not calling StatelessHeapSnapshotManager_classInfoCallback leaves stale |
| 2063 |
* values in the globals that the function sets and corrupts the parsing of |
| 2064 |
* the heap. Anoint the class with a name and call |
| 2065 |
* StatelessHeapSnapshotManager_classInfoCallback. |
| 2066 |
* Also handle the empty string case. |
| 2067 |
* |
| 2068 |
* Not thread-safe and that is OK. This code is conditional |
| 2069 |
* on mode==TraceOptimizedHeap and that always runs in a single thread. |
| 2070 |
* (JVMPI CLASS_LOAD events are not enabled from JVMPI; they only occur |
| 2071 |
* when we ask for them, and we only ask from a single thread.) |
| 2072 |
*/ |
| 2073 |
|
| 2074 |
if (event->u.class_load.class_name == NULL || |
| 2075 |
(strlen(event->u.class_load.class_name) == 0)) { |
| 2076 |
sprintf(_classNameBuffer, "unknown%d", _unknownClassSuffix++); |
| 2077 |
StatelessHeapSnapshotManager_classInfoCallback(_classNameBuffer, |
| 2078 |
event->u.class_load.num_interfaces, |
| 2079 |
event->u.class_load.num_static_fields, |
| 2080 |
event->u.class_load.statics); |
| 2081 |
} else { |
| 2082 |
|
| 2083 |
StatelessHeapSnapshotManager_classInfoCallback(event->u.class_load.class_name, |
| 2084 |
event->u.class_load.num_interfaces, |
| 2085 |
event->u.class_load.num_static_fields, |
| 2086 |
event->u.class_load.statics); |
| 2087 |
} |
| 2088 |
/* } */ |
| 2089 |
return; |
| 2090 |
} |
| 2091 |
|
| 2092 |
buffer = tps->buffer; |
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
/* If we haven't determined the path delimiter of this JVM try to use this |
| 2097 |
class name to determine the delimiter. |
| 2098 |
*/ |
| 2099 |
if(!_setPathDelimiter) { |
| 2100 |
setPathDelimiter((char*)event->u.class_load.class_name); |
| 2101 |
} |
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
/* Create the class symbol */ |
| 2106 |
classHashEntry = jvmpiAgent_CreateClassSymbol(event, tps, jvmpiAgent_getFilter((char *)event->u.class_load.class_name, "")); |
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
/* RKD: We print this class definition if we are traing this type or if we are asked |
| 2111 |
to output classes irregardless of whether the are ever used. Also, if this class |
| 2112 |
has already had its class object printed then we should also print the class definition |
| 2113 |
*/ |
| 2114 |
if (_jvmpiAgent_Options.unreferencedSymbols && CLASS_ENTRY(classHashEntry)->traceFlag) { |
| 2115 |
jvmpiAgent_outputClassDeclaration(classHashEntry, tps); |
| 2116 |
jvmpiAgent_printMethods((HashEntry **)CLASS_ENTRY(classHashEntry)->methods, CLASS_ENTRY(classHashEntry)->numMethods, tps); |
| 2117 |
} |
| 2118 |
/* DNS: 218494 - added this check back in so class is not output indiscrimantly */ |
| 2119 |
else if(CLASS_ENTRY(classHashEntry)->classObject && CLASS_ENTRY(classHashEntry)->classObject->printed) { |
| 2120 |
jvmpiAgent_outputClassDeclaration(classHashEntry, tps); |
| 2121 |
|
| 2122 |
} |
| 2123 |
|
| 2124 |
if(!isRequested) { |
| 2125 |
/* NMM: here is where we accumulate the tracing overhead due |
| 2126 |
to classload processing */ |
| 2127 |
StackEntry* tos; |
| 2128 |
if((tos=jvmpiAgent_Peek(tps, 0)) |
| 2129 |
&& tos->entryEventSeen) { |
| 2130 |
timestamp_t now; |
| 2131 |
timestamp_t cpu_now = 0; |
| 2132 |
Uint64 classload_overhead; |
| 2133 |
Uint64 cpu_classload_overhead = 0; |
| 2134 |
|
| 2135 |
if (_jvmpiAgent_Options.cpuTime) { |
| 2136 |
cpu_now = jvmpiAgent_getCurrentThreadCPUTime(); |
| 2137 |
tps->last_cpu_timestamp = cpu_timestamp; /* remember last known CPU time */ |
| 2138 |
cpu_classload_overhead = TIMESTAMP_SUB(cpu_now,cpu_timestamp); |
| 2139 |
} |
| 2140 |
jvmpiAgent_getCurrentTime(&now); |
| 2141 |
classload_overhead = TIMESTAMP_SUB(now,timestamp); |
| 2142 |
|
| 2143 |
tos->cumulative_overhead += classload_overhead; |
| 2144 |
tos->cumulative_cpu_overhead += cpu_classload_overhead; |
| 2145 |
|
| 2146 |
} |
| 2147 |
} |
| 2148 |
|
| 2149 |
} |
| 2150 |
|
| 2151 |
static void agRollUpStack(ThreadLocalStorage* tps, |
| 2152 |
timestamp_t timestamp, |
| 2153 |
timestamp_t cpu_timestamp) |
| 2154 |
{ |
| 2155 |
/* simulate an exit for the top frame - that is, |
| 2156 |
* perform the same boookkeeping that a method exit would have. |
| 2157 |
* All other frames have accurate baseTime already, |
| 2158 |
* and agPop will update their cumulative times. |
| 2159 |
*/ |
| 2160 |
int depth = 0; |
| 2161 |
StackEntry* stkentry = jvmpiAgent_Peek(tps, depth); |
| 2162 |
if (stkentry != NULL) { |
| 2163 |
TIMESTAMP_ADD(stkentry->baseTime, timestamp - stkentry->lastEntryTime); |
| 2164 |
DBG_CHK_AND_REPORT_TIME_OVERFLOW(stkentry->baseTime, "Time overflowed?! (agRollUpStack: stkentry->baseTime)\n"); /* 134577 */ |
| 2165 |
|
| 2166 |
/* Add last known CPU time on the thread to the frame's |
| 2167 |
* base CPU time, if it's greater. It might not be greater |
| 2168 |
* because it's just a guess - the last time we updated |
| 2169 |
* tps->last_cpu_timestamp for that thread. If the logic |
| 2170 |
* that updates that value isn't perfect, then we |
| 2171 |
* could be behind the times and we would add negative time. |
| 2172 |
* In that case just don't add anything. |
| 2173 |
* |
| 2174 |
* This system always under-reports the CPU time of the top |
| 2175 |
* frame on other threads, but we can't help that because we |
| 2176 |
* don't have a platform-independent "get the CPU time on |
| 2177 |
* another thread" query. |
| 2178 |
*/ |
| 2179 |
if (cpu_timestamp > stkentry->lastEntryCPUTime) { |
| 2180 |
TIMESTAMP_ADD(stkentry->baseCPUTime, cpu_timestamp - stkentry->lastEntryCPUTime); |
| 2181 |
} |
| 2182 |
} |
| 2183 |
|
| 2184 |
/* now call agPop for each active frame, to roll up data */ |
| 2185 |
while ((stkentry = jvmpiAgent_Peek(tps, depth)) != NULL) { |
| 2186 |
jvmpiAgent_agPop(stkentry); |
| 2187 |
depth++; |
| 2188 |
} |
| 2189 |
} |
| 2190 |
|
| 2191 |
/** PROCESS_THREAD_END_EVENT *********************************************** |
| 2192 |
* Handles thread end events from JVMPI. |
| 2193 |
*/ |
| 2194 |
static void processThreadEndEvent(JVMPI_Event *event, |
| 2195 |
ThreadLocalStorage *tps, |
| 2196 |
BOOL isRequested, |
| 2197 |
timestamp_t timestamp, |
| 2198 |
timestamp_t cpu_timestamp) { |
| 2199 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 2200 |
dumpMethodEventCounts(); |
| 2201 |
printf("processThreadEnd: tps, tps->calledList, _traceResourcesGone = %8x, %8x, %2d\n", |
| 2202 |
(void *)tps, (void *)tps->calledList, (int)_traceResourcesGone); fflush(stdout); |
| 2203 |
#endif |
| 2204 |
/* In TraceTraceOptimizedHeap mode, we don't need any hashing */ |
| 2205 |
if (_jvmpiAgent_Options.mode == TraceOptimizedHeap || _jvmpiAgent_Options.mode == TraceModeNone) { |
| 2206 |
/* do nothing */ |
| 2207 |
return; |
| 2208 |
} |
| 2209 |
|
| 2210 |
if (_jvmpiAgent_Options.compressLevel==CompressAggregate) { |
| 2211 |
/* We are pre-aggregating: |
| 2212 |
* Roll up this stack, then report its data. |
| 2213 |
* |
| 2214 |
* We send the data now so the thread-exit notification occurs |
| 2215 |
* in the proper sequence; if we saved up the data and sent |
| 2216 |
* it later, we'd be sending agMethodEntry events on a thread |
| 2217 |
* that had already been seen to exit. |
| 2218 |
* |
| 2219 |
* Locking note: printThreadAgData will call getStackFrameStructureLock |
| 2220 |
* because we're passing FALSE, saying we don't already have it. |
| 2221 |
* See comments at printThreadAgData for why this is a shame. |
| 2222 |
*/ |
| 2223 |
agRollUpStack(tps, timestamp, cpu_timestamp); |
| 2224 |
printThreadAgData(tps, FALSE); |
| 2225 |
removeThreadFromList(tps); |
| 2226 |
} |
| 2227 |
|
| 2228 |
jvmpiAgent_printThreadEndElement(event->env_id, tps); |
| 2229 |
jvmpiAgent_DestroyStack(event->env_id); |
| 2230 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 2231 |
printf("processThreadEnd: done!\n"); fflush(stdout); |
| 2232 |
#endif |
| 2233 |
} |
| 2234 |
|
| 2235 |
|
| 2236 |
/** PROCESS_THREAD_START_EVENT *********************************************** |
| 2237 |
* Handles thread start events from JVMPI. |
| 2238 |
*/ |
| 2239 |
static void processThreadStartEvent(JVMPI_Event *event, |
| 2240 |
ThreadLocalStorage *tps, |
| 2241 |
BOOL isRequested, |
| 2242 |
timestamp_t timestamp, |
| 2243 |
timestamp_t cpu_timestamp) { |
| 2244 |
ThreadLocalStorage *tpsLocal = 0; |
| 2245 |
HashEntry *hashEntry; |
| 2246 |
|
| 2247 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 2248 |
dumpMethodEventCounts(); |
| 2249 |
printf("processThreadStart: tps, tps->calledList, _traceResourcesGone = %8x, %8x, %2d\n", |
| 2250 |
(void *)tps, (void *)tps->calledList, (int)_traceResourcesGone); fflush(stdout); |
| 2251 |
#endif |
| 2252 |
|
| 2253 |
/* In TraceTraceOptimizedHeap mode, we don't need any hashing */ |
| 2254 |
if (_jvmpiAgent_Options.mode == TraceOptimizedHeap || _jvmpiAgent_Options.mode == TraceModeNone) { |
| 2255 |
/* do nothing */ |
| 2256 |
return; |
| 2257 |
} |
| 2258 |
|
| 2259 |
/* Find the thread to determine if it already exists. This should never happen. */ |
| 2260 |
hashEntry = jvmpiAgent_FindThreadSymbol(event->env_id); |
| 2261 |
|
| 2262 |
/* If this is a new thread create a stack for it */ |
| 2263 |
if (!hashEntry) { |
| 2264 |
hashEntry = jvmpiAgent_CreateStack(event->env_id); |
| 2265 |
} |
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
|
| 2270 |
tpsLocal = THREAD_ENTRY(hashEntry); |
| 2271 |
|
| 2272 |
/* 236501 begins */ |
| 2273 |
tpsLocal->threadName = ""; |
| 2274 |
tpsLocal->groupName = ""; |
| 2275 |
tpsLocal->parentName = "" ; |
| 2276 |
|
| 2277 |
if(event->u.thread_start.thread_name) { |
| 2278 |
STRDUP(tps->threadName, event->u.thread_start.thread_name); |
| 2279 |
} |
| 2280 |
if(event->u.thread_start.group_name) { |
| 2281 |
STRDUP(tps->groupName, event->u.thread_start.group_name); |
| 2282 |
} |
| 2283 |
if(event->u.thread_start.parent_name) { |
| 2284 |
STRDUP(tps->parentName, event->u.thread_start.parent_name); |
| 2285 |
} |
| 2286 |
/* 236501 ends */ |
| 2287 |
|
| 2288 |
tpsLocal->threadId = event->u.thread_start.thread_id; |
| 2289 |
tpsLocal->threadStartEventSeen = 1; |
| 2290 |
tpsLocal->threadStackKnown=0; |
| 2291 |
tpsLocal->disableEventsForThisThread=0; |
| 2292 |
|
| 2293 |
if(_jvmpiAgent_Options.compressLevel==CompressAggregate) { |
| 2294 |
/* we are pre-aggregating: add this thread to the list |
| 2295 |
* of threads that we will want to dump data for when requested, |
| 2296 |
* or when they die. |
| 2297 |
*/ |
| 2298 |
addThreadToList(tpsLocal); |
| 2299 |
} |
| 2300 |
|
| 2301 |
if (hashEntry) { /* bugzilla 72292 */ |
| 2302 |
if (!hashEntry->printed && event->env_id && THREAD_ENTRY(hashEntry)->threadStartEventSeen && _xmlHeadersPrinted) { |
| 2303 |
jvmpiAgent_printThreadStartElement(event->env_id, hashEntry); |
| 2304 |
} |
| 2305 |
} |
| 2306 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 2307 |
printf("processThreadStart: done!\n"); fflush(stdout); |
| 2308 |
#endif |
| 2309 |
} |
| 2310 |
|
| 2311 |
/* pre-aggregation */ |
| 2312 |
|
| 2313 |
/* rollUpAndPrintAllThreadAgData |
| 2314 |
* |
| 2315 |
* This function rolls up all threads' stacks and prints their data. |
| 2316 |
* You use this when the JVM is shutting down, or as a final data dump |
| 2317 |
* when the user asks to detach from the target process. |
| 2318 |
* |
| 2319 |
* Note: I'm not sure what happens if you do this and then keep |
| 2320 |
* running the process and collecting more data. The live frame at the |
| 2321 |
* top of each stack will probably accumulate more baseTime, and when |
| 2322 |
* that frame exits the new baseTime will roll up into its callers AGAIN, |
| 2323 |
* so the time it had run before the first snapshot will get double-counted. |
| 2324 |
*/ |
| 2325 |
void rollUpAndPrintAllThreadAgData(timestamp_t timestamp) |
| 2326 |
{ |
| 2327 |
/* Roll up stacks and emit data for living threads. |
| 2328 |
* (Data for threads that have died has already been transmitted.) |
| 2329 |
* |
| 2330 |
* Notice that the cpu_timestamp we use for rolling up is the |
| 2331 |
* last_cpu_timestamp recorded for each thread. |
| 2332 |
* That field in tps is updated for each event notification, |
| 2333 |
* so we're acting like each thread has consumed zero |
| 2334 |
* time since the last notification on that thread. |
| 2335 |
* This is the best we can do because we can't ask |
| 2336 |
* what the CPU time is on a thread other than the current thread. |
| 2337 |
* |
| 2338 |
* IMPORTANT LOCKING NOTE: the function dumpAllThreadStatistics |
| 2339 |
* calls getThreadListLock, and on some platforms the lock |
| 2340 |
* implementation we get from the RAC shared libraries is the |
| 2341 |
* kind that you can't reenter. So we have to get that lock, |
| 2342 |
* roll up the live stack frames, then release it before calling |
| 2343 |
* dumpAllThreadStatistics ... otherwise we'll deadlock on ourselves. |
| 2344 |
* (The lock impl on Windows is reentrant, but not on Linux.) |
| 2345 |
*/ |
| 2346 |
struct ThreadListElement * it; |
| 2347 |
|
| 2348 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 2349 |
dumpMethodEventCounts(); printf("rollUpAndPrintAllThreadAgData\n"); fflush(stdout); |
| 2350 |
#endif |
| 2351 |
getThreadListLock(); /* see IMPORTANT LOCKING NOTE above */ |
| 2352 |
it = threadsRoot; |
| 2353 |
while (it) { |
| 2354 |
ThreadPrivateStorage * target_tps = it->data; |
| 2355 |
if (target_tps != NULL) { |
| 2356 |
agRollUpStack(target_tps, timestamp, target_tps->last_cpu_timestamp); |
| 2357 |
} |
| 2358 |
it = it->next; |
| 2359 |
} |
| 2360 |
releaseThreadListLock(); |
| 2361 |
printAllThreadAgData(); |
| 2362 |
} |
| 2363 |
|
| 2364 |
/** PROCESSES_JVM_SHUTDOWN_EVENT ********************************************* |
| 2365 |
* |
| 2366 |
*/ |
| 2367 |
static void processesJVMShutdownEvent(JVMPI_Event *event, |
| 2368 |
ThreadLocalStorage *tps, |
| 2369 |
BOOL isRequested, |
| 2370 |
timestamp_t timestamp, |
| 2371 |
timestamp_t cpu_timestamp) { |
| 2372 |
_jvmShutDown = (enum _BOOL)1; |
| 2373 |
|
| 2374 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 2375 |
dumpMethodEventCounts(); printf("processesJVMShutdownEvent\n"); fflush(stdout); |
| 2376 |
#endif |
| 2377 |
/* If pre-aggregating, dump aggregated data for all living threads */ |
| 2378 |
if (_jvmpiAgent_Options.compressLevel==CompressAggregate) { |
| 2379 |
rollUpAndPrintAllThreadAgData(timestamp); |
| 2380 |
/* Note: we leak StackFrames here for all living threads. |
| 2381 |
* To fix this leak, call removeThreadFromList for all living threads. |
| 2382 |
* But, in general, the process is coming down anyway, |
| 2383 |
* so that would be a waste of time. |
| 2384 |
*/ |
| 2385 |
} |
| 2386 |
jvmpiAgent_printJvmShutdownElement(event); |
| 2387 |
#ifdef _DEBUG |
| 2388 |
if (_jvmpiAgent_Options.debugHash) { |
| 2389 |
jvmpiAgent_DumpHashTableStatistics(); |
| 2390 |
} |
| 2391 |
#endif |
| 2392 |
|
| 2393 |
cleanupAndExit(0); |
| 2394 |
ra_releaseVMLock(); |
| 2395 |
} |
| 2396 |
|
| 2397 |
/** PROCESS_OBJ_MOVE_EVENT *************************************************** |
| 2398 |
* Handler for object move events recieved during GC from JVMPI. |
| 2399 |
* |
| 2400 |
* The class id for the class associated with the object being moved is subject to change. |
| 2401 |
* In such cases, the hash entry for the associated class will also be moved. |
| 2402 |
*/ |
| 2403 |
static void processObjMoveEvent(JVMPI_Event *event, |
| 2404 |
ThreadLocalStorage *tps, |
| 2405 |
BOOL isRequested, |
| 2406 |
timestamp_t timestamp, |
| 2407 |
timestamp_t cpu_timestamp) { |
| 2408 |
|
| 2409 |
HashEntry *objectHashEntry; /* Hash entry of the object being moved */ |
| 2410 |
HashEntry *classHashEntry; /* Hash entry of the class associated with the object being moved */ |
| 2411 |
|
| 2412 |
if (_jvmpiAgent_Options.mode == TraceModeNone) { |
| 2413 |
return; |
| 2414 |
} |
| 2415 |
|
| 2416 |
if(_jvmpiAgent_Options.mode == TraceOptimizedHeap ) { /*58049*/ |
| 2417 |
return; |
| 2418 |
} |
| 2419 |
/* Find the object */ |
| 2420 |
objectHashEntry = jvmpiAgent_FindObjectSymbol(event->u.obj_move.obj_id); |
| 2421 |
|
| 2422 |
|
| 2423 |
if (objectHashEntry) { |
| 2424 |
void *id; |
| 2425 |
ObjectHashKey newId; |
| 2426 |
newId.id = event->u.obj_move.new_obj_id; |
| 2427 |
id = objectHashEntry->id; |
| 2428 |
|
| 2429 |
/* Move the object hash entry and determine its associated class */ |
| 2430 |
jvmpiAgent_MoveSymbol(objectHashEntry, Object_t, id, (void*)&newId); |
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
/* RJD- The following should be unnecessary. According to JVMPI spec, class id's |
| 2435 |
should also have their own object move events, and not be implicit as part of a regular |
| 2436 |
object move. |
| 2437 |
|
| 2438 |
|
| 2439 |
classHashEntry = OBJECT_ENTRY(objectHashEntry)->classHashEntry; |
| 2440 |
if (classHashEntry) |
| 2441 |
{ |
| 2442 |
// Mode 1: Resolve the class id for the object being requested. The class id for |
| 2443 |
// the object will be stored in the global variable '_resolvedClassId' |
| 2444 |
tps->mode = 1; |
| 2445 |
REQUEST_EVENT2(JVMPI_EVENT_OBJECT_ALLOC, event->u.obj_move.new_obj_id); |
| 2446 |
tps->mode = 0; |
| 2447 |
|
| 2448 |
|
| 2449 |
// Move the class hash entry if necessary |
| 2450 |
if (_resolvedClassId != CLASS_ENTRY(classHashEntry)->classId) |
| 2451 |
jvmpiAgent_MoveSymbol(classHashEntry, Class_t, (jint)_resolvedClassId); |
| 2452 |
} |
| 2453 |
*/ |
| 2454 |
|
| 2455 |
/* We will only print object move for objects which we have already declared |
| 2456 |
within the trace and if we have been asked to print object moves |
| 2457 |
*/ |
| 2458 |
|
| 2459 |
if (objectHashEntry->printed && |
| 2460 |
(_jvmpiAgent_Options.gc==GcMoves || _jvmpiAgent_Options.gc==GcDeletesAndMoves) && |
| 2461 |
!_jvmpiAgent_suspendIO) { |
| 2462 |
jvmpiAgent_printObjMoveElement(event, objectHashEntry); |
| 2463 |
} |
| 2464 |
} |
| 2465 |
|
| 2466 |
|
| 2467 |
/* The object move may be that of a java.lang.Class instance, in which |
| 2468 |
case the class table must be updated as well */ |
| 2469 |
classHashEntry = jvmpiAgent_FindClassSymbol(event->u.obj_move.obj_id); |
| 2470 |
|
| 2471 |
if (classHashEntry) { |
| 2472 |
void *id; |
| 2473 |
ClassHashKey newId; |
| 2474 |
newId.id = event->u.obj_move.new_obj_id; |
| 2475 |
id = classHashEntry->id; |
| 2476 |
jvmpiAgent_MoveSymbol(classHashEntry, Class_t, id,(void*)&newId); |
| 2477 |
} |
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
} |
| 2482 |
|
| 2483 |
/** PROCESS_OBJ_FREE_EVENT *************************************************** |
| 2484 |
* Handler for object free events recieved during GC from JVMPI. |
| 2485 |
*/ |
| 2486 |
static void processObjFreeEvent(JVMPI_Event *event, |
| 2487 |
ThreadLocalStorage *tps, |
| 2488 |
BOOL isRequested, |
| 2489 |
timestamp_t timestamp, |
| 2490 |
timestamp_t cpu_timestamp) { |
| 2491 |
HashEntry *objectHashEntry; |
| 2492 |
|
| 2493 |
if (_jvmpiAgent_Options.mode == TraceModeNone) { |
| 2494 |
return; |
| 2495 |
} |
| 2496 |
|
| 2497 |
if(_jvmpiAgent_Options.mode == TraceOptimizedHeap) { /*58049*/ |
| 2498 |
return; |
| 2499 |
} |
| 2500 |
/* Do we know of this object */ |
| 2501 |
objectHashEntry = jvmpiAgent_FindObjectSymbol(event->u.obj_free.obj_id); |
| 2502 |
if (objectHashEntry) { |
| 2503 |
/* We will only print object move for objects which we have already declared |
| 2504 |
within the trace and if we have been asked to print object free's |
| 2505 |
*/ |
| 2506 |
if (objectHashEntry->printed && |
| 2507 |
(_jvmpiAgent_Options.gc==GcDeletes || _jvmpiAgent_Options.gc==GcDeletesAndMoves) |
| 2508 |
&& !_jvmpiAgent_suspendIO) { |
| 2509 |
|
| 2510 |
jvmpiAgent_printObjFreeElement(jvmpiAgent_getThreadLocalStorage(event->env_id), objectHashEntry); |
| 2511 |
} |
| 2512 |
|
| 2513 |
/* Remove the object from the object hashtable */ |
| 2514 |
jvmpiAgent_DeleteSymbol(objectHashEntry, Object_t); |
| 2515 |
} |
| 2516 |
} |
| 2517 |
|
| 2518 |
/** PROCESS_CLASS_UNLOAD_EVENT *********************************************** |
| 2519 |
* Handle class unload events. |
| 2520 |
*/ |
| 2521 |
static void processClassUnloadEvent(JVMPI_Event *event, |
| 2522 |
ThreadLocalStorage *tps, |
| 2523 |
BOOL isRequested, |
| 2524 |
timestamp_t timestamp, |
| 2525 |
timestamp_t cpu_timestamp) { |
| 2526 |
HashEntry *classHashEntry; |
| 2527 |
if (_jvmpiAgent_Options.mode == TraceModeNone) { |
| 2528 |
return; |
| 2529 |
} |
| 2530 |
|
| 2531 |
if(_jvmpiAgent_Options.mode == TraceOptimizedHeap ) { |
| 2532 |
return; |
| 2533 |
} |
| 2534 |
|
| 2535 |
classHashEntry = jvmpiAgent_FindClassSymbol(event->u.class_unload.class_id); |
| 2536 |
|
| 2537 |
/* We will only print class unloads for classes which we have already declared |
| 2538 |
within the trace |
| 2539 |
*/ |
| 2540 |
if (classHashEntry) { |
| 2541 |
classHashEntry->deleted = 1; /* Mark as deleted */ |
| 2542 |
|
| 2543 |
if (!_jvmpiAgent_suspendIO) { |
| 2544 |
jvmpiAgent_printClassUnloadElement(event, tps, classHashEntry); |
| 2545 |
} |
| 2546 |
} |
| 2547 |
} |
| 2548 |
|
| 2549 |
/** PROCESS_GC_START_EVENT *************************************************** |
| 2550 |
* Handle GC start events. |
| 2551 |
*/ |
| 2552 |
static void processGcStartEvent(JVMPI_Event *event, |
| 2553 |
ThreadLocalStorage *tps, |
| 2554 |
BOOL isRequested, |
| 2555 |
timestamp_t timestamp, |
| 2556 |
timestamp_t cpu_timestamp) { |
| 2557 |
if (_jvmpiAgent_Options.mode == TraceModeNone) { |
| 2558 |
return; |
| 2559 |
} |
| 2560 |
|
| 2561 |
if(_jvmpiAgent_Options.mode == TraceOptimizedHeap) { |
| 2562 |
/* do nothing */ |
| 2563 |
return; |
| 2564 |
} |
| 2565 |
if (!_jvmpiAgent_suspendIO) { |
| 2566 |
jvmpiAgent_printGcStartElement(event); |
| 2567 |
} |
| 2568 |
} |
| 2569 |
|
| 2570 |
/** PROCESS_GC_FINISH_EVENT ************************************************** |
| 2571 |
* Handle GC finish events. |
| 2572 |
*/ |
| 2573 |
static void processGcFinishEvent(JVMPI_Event *event, |
| 2574 |
ThreadLocalStorage *tps, |
| 2575 |
BOOL isRequested, |
| 2576 |
timestamp_t timestamp, |
| 2577 |
timestamp_t cpu_timestamp) { |
| 2578 |
if (_jvmpiAgent_Options.mode == TraceOptimizedHeap || _jvmpiAgent_Options.mode == TraceModeNone) { |
| 2579 |
/* do nothing */ |
| 2580 |
return; |
| 2581 |
} |
| 2582 |
if (!_jvmpiAgent_suspendIO) { |
| 2583 |
jvmpiAgent_printGcFinishElement(event); |
| 2584 |
} |
| 2585 |
} |
| 2586 |
|
| 2587 |
/** PROCESS_OBJ_ALLOC_EVENT ************************************************** |
| 2588 |
* |
| 2589 |
*/ |
| 2590 |
static void processObjAllocEvent(JVMPI_Event *event, |
| 2591 |
ThreadLocalStorage *tps, |
| 2592 |
BOOL isRequested, |
| 2593 |
timestamp_t timestamp, |
| 2594 |
timestamp_t cpu_timestamp) |
| 2595 |
{ |
| 2596 |
HashEntry *classHashEntry; |
| 2597 |
HashEntry *objectHashEntry; |
| 2598 |
BOOL allocatedOnTracedStackframe=FALSE; |
| 2599 |
|
| 2600 |
if (_jvmpiAgent_Options.mode == TraceOptimizedHeap || _jvmpiAgent_Options.mode == TraceModeNone) { |
| 2601 |
/* do nothing */ |
| 2602 |
return; |
| 2603 |
} |
| 2604 |
|
| 2605 |
/* In case the mode of 'tps' is set to 1, then this handler will only need to resolve the class |
| 2606 |
* id of the object that has been dumped */ |
| 2607 |
if (tps->mode == 1) |
| 2608 |
{ |
| 2609 |
_resolvedClassId = event->u.obj_alloc.class_id; |
| 2610 |
return; |
| 2611 |
} |
| 2612 |
|
| 2613 |
|
| 2614 |
objectHashEntry = jvmpiAgent_FindObjectSymbol(event->u.obj_alloc.obj_id); |
| 2615 |
if (objectHashEntry) { |
| 2616 |
/* the object already exists, don't do anything */ |
| 2617 |
return; |
| 2618 |
} |
| 2619 |
|
| 2620 |
/* RKD: Determine if this object is being allocated on a traced stack frame |
| 2621 |
*/ |
| 2622 |
if(_jvmpiAgent_Options.stackInfo>StackInfoNone) { |
| 2623 |
StackEntry *tos; |
| 2624 |
if(tos=jvmpiAgent_Peek(tps, 0)) { |
| 2625 |
allocatedOnTracedStackframe=(BOOL)(tos->printed); |
| 2626 |
} |
| 2627 |
} |
| 2628 |
|
| 2629 |
|
| 2630 |
/* RJD We normally shouldn't receive an OBJ_ALLOC with class_id == 0 and |
| 2631 |
is_array = JVMPI_NORMAL_OBJECT; however, the Sun JVM seems to send |
| 2632 |
this for the object instance of java.lang.Class. |
| 2633 |
We handle this by assigning the class_id to the object_id (since the |
| 2634 |
object instance of java.lang.Class is clearly of type java.lang.Class). |
| 2635 |
|
| 2636 |
Only do this when _requestClassObj is set (which should only be set |
| 2637 |
from a heap dump). Further, only do this when IsRequest bit is set to true. |
| 2638 |
This is a work around that may have some subtle concurrency issues crop up (because |
| 2639 |
of bugs with different JVMs), so this should be kept in mind if examining a |
| 2640 |
future bug that seems to be a result of the following code. |
| 2641 |
bugzilla_57475 */ |
| 2642 |
|
| 2643 |
if (!event->u.obj_alloc.class_id && |
| 2644 |
event->u.obj_alloc.is_array == JVMPI_NORMAL_OBJECT && |
| 2645 |
_requestClassObj && isRequested) { |
| 2646 |
event->u.obj_alloc.class_id = event->u.obj_alloc.obj_id; |
| 2647 |
} |
| 2648 |
|
| 2649 |
|
| 2650 |
|
| 2651 |
/* ##RKD: We could have an object allocate and not know about it's class. This |
| 2652 |
is a performance hit to look up the class whenever we get an object |
| 2653 |
with unknown type..but I don't see any way around it right now. Also |
| 2654 |
don't try and lookup primitive array classes as this fries the JVM. As for |
| 2655 |
classes with a class id of "0", this is a documented limitation. It |
| 2656 |
appears that the class id of all object arrays is always NULL. If we have an |
| 2657 |
array object manually associate it with our spoofed array class objects. We |
| 2658 |
only need to do this if the array object was explicitly asked for. |
| 2659 |
*/ |
| 2660 |
if(event->u.obj_alloc.class_id && (event->u.obj_alloc.is_array==JVMPI_NORMAL_OBJECT |
| 2661 |
#if !(defined _HPUX || defined _SOLARIS) |
| 2662 |
|| event->u.obj_alloc.is_array==JVMPI_CLASS) ) { |
| 2663 |
#else |
| 2664 |
)) { |
| 2665 |
#endif |
| 2666 |
|
| 2667 |
|
| 2668 |
classHashEntry = jvmpiAgent_FindClassSymbol(event->u.obj_alloc.class_id); |
| 2669 |
if(!classHashEntry) { |
| 2670 |
jint result; |
| 2671 |
result=REQUEST_EVENT2(JVMPI_EVENT_CLASS_LOAD, event->u.obj_alloc.class_id); /* 232010 */ |
| 2672 |
/* Look up the class again*/ |
| 2673 |
if(result == JVMPI_SUCCESS) { |
| 2674 |
classHashEntry = jvmpiAgent_FindClassSymbol(event->u.obj_alloc.class_id); |
| 2675 |
} |
| 2676 |
} |
| 2677 |
|
| 2678 |
/* Always add this object if we explicitly asked for it. In filtered mode store it if |
| 2679 |
we are tracing this type. In triggered mode we will store it if it is on the stack. |
| 2680 |
*/ |
| 2681 |
if(classHashEntry) { |
| 2682 |
if(_jvmpiAgent_Options.startMode==TraceStartModeFilter) { |
| 2683 |
if(CLASS_ENTRY(classHashEntry)->traceFlag || isRequested) { |
| 2684 |
objectHashEntry = jvmpiAgent_CreateObjectSymbol(event, (BOOL)(!isRequested), (BOOL)(!isRequested)); |
| 2685 |
OBJECT_ENTRY(objectHashEntry)->classHashEntry=classHashEntry; |
| 2686 |
|
| 2687 |
/* Print this object only if we are tracing this type and we want object information */ |
| 2688 |
if(OBJECT_ENTRY(objectHashEntry)->traceFlag && jvmpiAgent_isTracingHeap()) { |
| 2689 |
jvmpiAgent_printObjAllocElement(objectHashEntry, event->env_id, 0); |
| 2690 |
} |
| 2691 |
} |
| 2692 |
} |
| 2693 |
else { |
| 2694 |
if(isRequested) { |
| 2695 |
objectHashEntry = jvmpiAgent_CreateObjectSymbol(event, FALSE, FALSE); |
| 2696 |
OBJECT_ENTRY(objectHashEntry)->classHashEntry=classHashEntry; |
| 2697 |
} |
| 2698 |
else if(allocatedOnTracedStackframe) { |
| 2699 |
objectHashEntry = jvmpiAgent_CreateObjectSymbol(event, TRUE, (BOOL)(!isRequested)); |
| 2700 |
|
| 2701 |
OBJECT_ENTRY(objectHashEntry)->classHashEntry=classHashEntry; |
| 2702 |
jvmpiAgent_printObjAllocElement(objectHashEntry, event->env_id, 0); |
| 2703 |
} |
| 2704 |
} |
| 2705 |
} |
| 2706 |
} |
| 2707 |
/* This is a primative array. If we requested it's alloc event then create it's entries. Also we print |
| 2708 |
primative array allocations if the current stack frame has been printed |
| 2709 |
*/ |
| 2710 |
else if(isRequested || allocatedOnTracedStackframe || _jvmpiAgent_Options.stackInfo==StackInfoNone) { |
| 2711 |
ObjectEntry *objectEntry; |
| 2712 |
|
| 2713 |
/* RJD. The 1.3 JVM's on Solaris and HP crash when requesting a |
| 2714 |
JVMPI_EVENT_CLASS_LOAD event on class_id of array objects due to a bug in the JVM. |
| 2715 |
Thus, do not look up the |
| 2716 |
class in those cases. |
| 2717 |
bugzilla_56189 */ |
| 2718 |
|
| 2719 |
|
| 2720 |
#if (defined _HPUX || defined _SOLARIS) |
| 2721 |
if(event->u.obj_alloc.class_id && |
| 2722 |
(_javaVersion != Version13 || event->u.obj_alloc.is_array!=JVMPI_CLASS)) { |
| 2723 |
#else |
| 2724 |
if(event->u.obj_alloc.class_id) { |
| 2725 |
#endif |
| 2726 |
|
| 2727 |
classHashEntry = jvmpiAgent_FindClassSymbol(event->u.obj_alloc.class_id); |
| 2728 |
if(!classHashEntry) { |
| 2729 |
jint result; |
| 2730 |
result=REQUEST_EVENT2(JVMPI_EVENT_CLASS_LOAD, event->u.obj_alloc.class_id); /* 232010 */ |
| 2731 |
/* Look up the class again*/ |
| 2732 |
if(result == JVMPI_SUCCESS) { |
| 2733 |
classHashEntry = jvmpiAgent_FindClassSymbol(event->u.obj_alloc.class_id); |
| 2734 |
} |
| 2735 |
|
| 2736 |
objectHashEntry = jvmpiAgent_CreateObjectSymbol(event, FALSE, FALSE); |
| 2737 |
OBJECT_ENTRY(objectHashEntry)->classHashEntry=classHashEntry; |
| 2738 |
} |
| 2739 |
} |
| 2740 |
else { |
| 2741 |
classHashEntry=jvmpiAgent_getPrimativeClassEntry(event->u.obj_alloc.is_array); |
| 2742 |
if(classHashEntry && CLASS_ENTRY(classHashEntry)->traceFlag && jvmpiAgent_isTracingHeap()) { |
| 2743 |
jvmpiAgent_outputClassDeclaration(classHashEntry, tps); |
| 2744 |
objectHashEntry = jvmpiAgent_CreateObjectSymbol(event, allocatedOnTracedStackframe, (BOOL)(!isRequested)); |
| 2745 |
objectEntry=OBJECT_ENTRY(objectHashEntry); |
| 2746 |
jvmpiAgent_printObjAllocElement(objectHashEntry, event->env_id, 0); |
| 2747 |
} |
| 2748 |
} |
| 2749 |
} |
| 2750 |
|
| 2751 |
if(!isRequested) { |
| 2752 |
/* NMM: here is where we accumulate the tracing overhead due to |
| 2753 |
object allocation processing */ |
| 2754 |
StackEntry* tos; |
| 2755 |
if(tps |
| 2756 |
&& (tos=jvmpiAgent_Peek(tps, 0)) |
| 2757 |
&& tos->entryEventSeen) { |
| 2758 |
timestamp_t now; |
| 2759 |
timestamp_t cpu_now = 0; |
| 2760 |
Uint64 objalloc_overhead; |
| 2761 |
Uint64 cpu_objalloc_overhead = 0; |
| 2762 |
|
| 2763 |
if (_jvmpiAgent_Options.cpuTime) { |
| 2764 |
cpu_now = jvmpiAgent_getCurrentThreadCPUTime(); |
| 2765 |
cpu_objalloc_overhead = TIMESTAMP_SUB(cpu_now,cpu_timestamp); |
| 2766 |
} |
| 2767 |
|
| 2768 |
jvmpiAgent_getCurrentTime(&now); |
| 2769 |
objalloc_overhead = TIMESTAMP_SUB(now,timestamp); |
| 2770 |
tos->cumulative_overhead += objalloc_overhead; |
| 2771 |
tos->cumulative_cpu_overhead += cpu_objalloc_overhead; |
| 2772 |
|
| 2773 |
} |
| 2774 |
} |
| 2775 |
} |
| 2776 |
|
| 2777 |
/** PROCESS_CLASS_LOAD_HOOK_EVENT ******************************************** |
| 2778 |
* |
| 2779 |
*/ |
| 2780 |
static void processClassLoadHookEvent(JVMPI_Event *event, |
| 2781 |
ThreadLocalStorage *tps, |
| 2782 |
BOOL isRequested, |
| 2783 |
timestamp_t timestamp, |
| 2784 |
timestamp_t cpu_timestamp) |
| 2785 |
{ |
| 2786 |
} |
| 2787 |
|
| 2788 |
/** PROCESS_DATA_DUMP_REQUEST |
| 2789 |
* This is the kill-3 handler |
| 2790 |
*/ |
| 2791 |
static void processDataDumpRequest(JVMPI_Event *event, |
| 2792 |
ThreadLocalStorage *tps, |
| 2793 |
BOOL isRequested, |
| 2794 |
timestamp_t timestamp, |
| 2795 |
timestamp_t cpu_timestamp) { |
| 2796 |
if (_jvmpiAgent_Options.mode == TraceOptimizedHeap) { |
| 2797 |
/* status(KILL3_DUMP_REQUEST); */ |
| 2798 |
_analyseOptHeap = TRUE ; |
| 2799 |
analyseHeap(JVMPI_DUMP_LEVEL_1); |
| 2800 |
|
| 2801 |
_analyseOptHeap = FALSE ; |
| 2802 |
_optHeapError = 0 ; |
| 2803 |
} |
| 2804 |
else if (_jvmpiAgent_Options.mode == TraceHeap) { |
| 2805 |
analyseHeap(JVMPI_DUMP_LEVEL_1); |
| 2806 |
} |
| 2807 |
} |
| 2808 |
|
| 2809 |
/* Piyush Agarwal */ |
| 2810 |
/* Optimized Heap Dump from RAC */ |
| 2811 |
/* We need to send the heapDumpFile Name to the RAC */ |
| 2812 |
static void sendHeapDumpInformation(char *filename){ |
| 2813 |
|
| 2814 |
/* Giri: <Defect 64462> Added the standalone mode check, instead of isControlled check */ |
| 2815 |
/* THe pring HD Start Element should be sent at the end after the heap dump is taken for optHeap */ |
| 2816 |
|
| 2817 |
if ( _jvmpiAgent_Options.mode == TraceOptimizedHeap && !_jvmpiAgent_Options.standalone ) |
| 2818 |
{ |
| 2819 |
ThreadLocalStorage *tps=jvmpiAgent_getThreadLocalStorage(0); |
| 2820 |
#ifdef __OS400__ |
| 2821 |
/* Anandi 25 May 2004: The print routines expect ascii chars in |
| 2822 |
strings */ |
| 2823 |
char *tmpname = as400_etoa(filename); |
| 2824 |
jvmpiAgent_printHDStartElement(tps,tmpname) ; |
| 2825 |
ra_free(tmpname); |
| 2826 |
#else |
| 2827 |
/* Bug 64476 Added change for converting the name to ascii from ebcdic */ |
| 2828 |
#ifdef MVS |
| 2829 |
__etoa(filename) ; |
| 2830 |
#endif |
| 2831 |
jvmpiAgent_printHDStartElement(tps,filename) ; |
| 2832 |
#ifdef MVS |
| 2833 |
__atoe(filename) ; |
| 2834 |
#endif |
| 2835 |
#endif |
| 2836 |
/*Bug 82214*/ |
| 2837 |
if (!_optHeapError && (optHeapContextId != -1)) { |
| 2838 |
sendHeapDumpEndMessage(_jvmpiAgent_bindingStorage,optHeapContextId,filename); |
| 2839 |
} |
| 2840 |
/*Bug 82214*/ |
| 2841 |
|
| 2842 |
} |
| 2843 |
} |
| 2844 |
|
| 2845 |
static void processRACDataDumpRequest(BOOL finalheap,ra_uint_t contextId) |
| 2846 |
{ |
| 2847 |
optHeapContextId = contextId ; |
| 2848 |
if (_jvmpiAgent_Options.mode == TraceOptimizedHeap) { |
| 2849 |
/* Called From client */ |
| 2850 |
/* We also need to send an empty heap dump header to the workbench */ |
| 2851 |
_analyseOptHeap = TRUE ; |
| 2852 |
|
| 2853 |
analyseHeap(JVMPI_DUMP_LEVEL_1); |
| 2854 |
/* If this application is being controlled/moitored remotely */ |
| 2855 |
if (!_jvmpiAgent_Options.standalone) { |
| 2856 |
if (_optHeapError) |
| 2857 |
{ |
| 2858 |
sendOptHeapErrorMessage(_jvmpiAgent_bindingStorage, /* Piyush 58049 */ |
| 2859 |
contextId) ; |
| 2860 |
} |
| 2861 |
_optHeapError = 0 ; |
| 2862 |
} |
| 2863 |
_analyseOptHeap = FALSE ; |
| 2864 |
} |
| 2865 |
optHeapContextId = -1 ; |
| 2866 |
} |
| 2867 |
|
| 2868 |
/* Send message to RAC which then sends it to the client */ |
| 2869 |
static void sendHeapDumpEndMessage(RA_AGENT_HANDLE handle,ra_uint_t contextId,char* filename) |
| 2870 |
{ |
| 2871 |
ra_message_t *message; |
| 2872 |
ra_command_t *command; |
| 2873 |
char *tmpMessageName ; |
| 2874 |
|
| 2875 |
message=ra_createMessage(RA_CONTROL_MESSAGE, 0); |
| 2876 |
command=ra_addCommandToMessage(message, NULL); |
| 2877 |
|
| 2878 |
/* Set the agent information */ |
| 2879 |
command->tag= RA_CUSTOM_COMMAND ; |
| 2880 |
command->info.custom_command.context= contextId ; |
| 2881 |
command->info.custom_command.processId = ra_getProcessId(); |
| 2882 |
|
| 2883 |
/*Bug 64476*/ |
| 2884 |
#ifdef MVS |
| 2885 |
#pragma convlit(suspend) |
| 2886 |
#endif |
| 2887 |
tmpMessageName = (char *)malloc(sizeof("RA_OPT_HEAP_DUMP_DONE")+strlen(filename)+(2*sizeof(char))) ; |
| 2888 |
strcpy(tmpMessageName,"RA_OPT_HEAP_DUMP_DONE:") ; |
| 2889 |
strcat(tmpMessageName,filename) ; |
| 2890 |
ra_copyRASTRING(&command->info.custom_command.agent, &handle->agentName); |
| 2891 |
ra_createRASTRING(&command->info.custom_command.message,tmpMessageName); |
| 2892 |
free(tmpMessageName) ; |
| 2893 |
#ifdef MVS |
| 2894 |
#pragma convlit(resume) |
| 2895 |
#endif |
| 2896 |
|
| 2897 |
/* Inform server about heap done */ |
| 2898 |
ra_sendMessage(handle, message); |
| 2899 |
/* Clean up the allocated memory */ |
| 2900 |
ra_destroyMessage(message, TRUE); |
| 2901 |
} |
| 2902 |
|
| 2903 |
/* Send error message to RAC which then sends it to the client */ |
| 2904 |
/* Piyush 58049 */ |
| 2905 |
static void sendOptHeapErrorMessage(RA_AGENT_HANDLE handle, |
| 2906 |
ra_uint_t contextId) |
| 2907 |
{ |
| 2908 |
ra_message_t *message; |
| 2909 |
ra_command_t *command; |
| 2910 |
|
| 2911 |
message=ra_createMessage(RA_CONTROL_MESSAGE, 0); |
| 2912 |
command=ra_addCommandToMessage(message, NULL); |
| 2913 |
|
| 2914 |
/* Set the agent information */ |
| 2915 |
command->tag= RA_CUSTOM_COMMAND ; |
| 2916 |
command->info.custom_command.context= contextId ; |
| 2917 |
command->info.custom_command.processId = ra_getProcessId(); |
| 2918 |
|
| 2919 |
/* Giri: Defect 70308 */ |
| 2920 |
#ifdef MVS |
| 2921 |
#pragma convlit(suspend) |
| 2922 |
#endif |
| 2923 |
|
| 2924 |
ra_copyRASTRING(&command->info.custom_command.agent, &handle->agentName); |
| 2925 |
switch (_optHeapError) { |
| 2926 |
case RA_OPT_HEAP_DISK_FULL : |
| 2927 |
ra_createRASTRING(&command->info.custom_command.message, "RA_OPT_HEAP_DISK_FULL"); |
| 2928 |
break ; |
| 2929 |
case RA_OPT_HEAP_COULD_NOT_CREATE_FILE : |
| 2930 |
ra_createRASTRING(&command->info.custom_command.message, "RA_OPT_HEAP_COULD_NOT_CREATE_FILE"); |
| 2931 |
break ; |
| 2932 |
} |
| 2933 |
|
| 2934 |
/* Giri: Defect 70308 */ |
| 2935 |
#ifdef MVS |
| 2936 |
#pragma convlit(resume) |
| 2937 |
#endif |
| 2938 |
|
| 2939 |
/* Inform server about heap done */ |
| 2940 |
ra_sendMessage(handle, message); |
| 2941 |
/* Clean up the allocated memory */ |
| 2942 |
ra_destroyMessage(message, TRUE); |
| 2943 |
} |
| 2944 |
|
| 2945 |
/** PROCESS_HEAP_DUMP_EVENT *************************************************** |
| 2946 |
* This is called by notify_event when we are getting a heap dump data as the |
| 2947 |
* result of a heap dump request. |
| 2948 |
*/ |
| 2949 |
static void processHeapDumpEvent(JVMPI_Event *event, |
| 2950 |
ThreadLocalStorage *tps, |
| 2951 |
BOOL isRequested, |
| 2952 |
timestamp_t timestamp, |
| 2953 |
timestamp_t cpu_timestamp) { |
| 2954 |
|
| 2955 |
if (_jvmpiAgent_Options.mode == TraceModeNone) { |
| 2956 |
return; |
| 2957 |
} |
| 2958 |
|
| 2959 |
switch (event->u.heap_dump.dump_level) { |
| 2960 |
case JVMPI_DUMP_LEVEL_0: /* we must have asked for a dump population */ |
| 2961 |
if(_jvmpiAgent_Options.mode != TraceOptimizedHeap && _jvmpiAgent_isMonitored ) |
| 2962 |
{ |
| 2963 |
jvmpiAgent_markHeap(event); |
| 2964 |
} |
| 2965 |
break; |
| 2966 |
case JVMPI_DUMP_LEVEL_1: /* we must have asked for a dump for references */ |
| 2967 |
if(_jvmpiAgent_Options.mode == TraceOptimizedHeap && !_optHeapError ) { /*58049*/ |
| 2968 |
_optHeapError = StatelessHeapSnapshotManager_handleHeapSnapshot_FromC(event->env_id, |
| 2969 |
event->u.heap_dump.dump_level, |
| 2970 |
event->u.heap_dump.begin, |
| 2971 |
event->u.heap_dump.end); |
| 2972 |
} else { |
| 2973 |
jvmpiAgent_analyseHeap(event, _heapDefName); |
| 2974 |
} |
| 2975 |
break; |
| 2976 |
default: |
| 2977 |
break; |
| 2978 |
} /* dump_level switch */ |
| 2979 |
|
| 2980 |
} |
| 2981 |
|
| 2982 |
|
| 2983 |
|
| 2984 |
|
| 2985 |
|
| 2986 |
/* long getOwnerThread(jobjectID object_id) |
| 2987 |
|
| 2988 |
Obtain the owner thread of the given monitor object |
| 2989 |
|
| 2990 |
args - |
| 2991 |
object_id - the object (monitor) whose thread owner is to be determined. |
| 2992 |
tps - thread local storage for storing monitor dump |
| 2993 |
|
| 2994 |
returns - |
| 2995 |
the thread that owns the given object |
| 2996 |
*/ |
| 2997 |
|
| 2998 |
unsigned long getOwnerThread(jobjectID object_id, ThreadLocalStorage *tps) { |
| 2999 |
|
| 3000 |
int result = JVMPI_FAIL; |
| 3001 |
|
| 3002 |
tps->monitorObj = object_id; |
| 3003 |
if (object_id != 0) { |
| 3004 |
|
| 3005 |
/* Requesting MONITOR_DUMP in IBM 1.4.x JVM's prior to 1.4.2 cause |
| 3006 |
the JVM to crash. Do not request a JVMPI_EVENT_MONITOR_DUMP in those cases */ |
| 3007 |
if (!(_javaVendor == VendorIBM && |
| 3008 |
(_javaVersion == Version140 || _javaVersion == Version141))) { |
| 3009 |
|
| 3010 |
result = REQUEST_EVENT(JVMPI_EVENT_MONITOR_DUMP,0); |
| 3011 |
} |
| 3012 |
|
| 3013 |
} |
| 3014 |
|
| 3015 |
if (result == JVMPI_SUCCESS) { |
| 3016 |
/* the owner thread is set in the tps->ownerThread variable upon return |
| 3017 |
from the monitor dump request */ |
| 3018 |
return tps->ownerThread; |
| 3019 |
} |
| 3020 |
|
| 3021 |
return 0; |
| 3022 |
|
| 3023 |
} |
| 3024 |
|
| 3025 |
|
| 3026 |
static void processMonitorDumpEvent(JVMPI_Event *event, |
| 3027 |
ThreadLocalStorage *tps, |
| 3028 |
BOOL isRequested, |
| 3029 |
timestamp_t timestamp, |
| 3030 |
timestamp_t cpu_timestamp) { |
| 3031 |
|
| 3032 |
tps->ownerThread = jvmpiAgent_analyseMonitorDump(event,tps->monitorObj); |
| 3033 |
} |
| 3034 |
|
| 3035 |
static void processMonitorContendedEnter(JVMPI_Event *event, |
| 3036 |
ThreadLocalStorage *tps, |
| 3037 |
BOOL isRequested, |
| 3038 |
timestamp_t timestamp, |
| 3039 |
timestamp_t cpu_timestamp) { |
| 3040 |
|
| 3041 |
HashEntry *objectHashEntry = 0; /* hash entry corresponding to the monitor object */ |
| 3042 |
unsigned long thread_owner = 0; |
| 3043 |
|
| 3044 |
/* determine the thread that currently owns the monitor */ |
| 3045 |
thread_owner = getOwnerThread(event->u.monitor.object,tps); |
| 3046 |
|
| 3047 |
|
| 3048 |
/* lookup monitor object, ensuring that it exists in the trace */ |
| 3049 |
objectHashEntry = jvmpiAgent_FindObjectSymbolWithAllocateAndPrint(event->env_id, |
| 3050 |
event->u.monitor.object); |
| 3051 |
|
| 3052 |
|
| 3053 |
if (objectHashEntry) { |
| 3054 |
jvmpiAgent_printMonitorContendedEnterElement(objectHashEntry, event, |
| 3055 |
thread_owner, timestamp); |
| 3056 |
} |
| 3057 |
|
| 3058 |
} |
| 3059 |
|
| 3060 |
static void processMonitorContendedEntered(JVMPI_Event *event, |
| 3061 |
ThreadLocalStorage *tps, |
| 3062 |
BOOL isRequested, |
| 3063 |
timestamp_t timestamp, |
| 3064 |
timestamp_t cpu_timestamp) { |
| 3065 |
|
| 3066 |
HashEntry *objectHashEntry = 0; /* hash entry corresponding to the monitor object */ |
| 3067 |
|
| 3068 |
/* lookup monitor object, ensuring that it exists in the trace */ |
| 3069 |
objectHashEntry = jvmpiAgent_FindObjectSymbolWithAllocateAndPrint(event->env_id, |
| 3070 |
event->u.monitor.object); |
| 3071 |
|
| 3072 |
|
| 3073 |
if (objectHashEntry) { |
| 3074 |
jvmpiAgent_printMonitorContendedEnteredElement(objectHashEntry, event, timestamp); |
| 3075 |
} |
| 3076 |
|
| 3077 |
} |
| 3078 |
|
| 3079 |
static void processMonitorContendedExit(JVMPI_Event *event, |
| 3080 |
ThreadLocalStorage *tps, |
| 3081 |
BOOL isRequested, |
| 3082 |
timestamp_t timestamp) { |
| 3083 |
/* currently not required according to BlueRat specs; stub in place since it might |
| 3084 |
be useful */ |
| 3085 |
} |
| 3086 |
|
| 3087 |
static void processMonitorWait(JVMPI_Event *event, |
| 3088 |
ThreadLocalStorage *tps, |
| 3089 |
BOOL isRequested, |
| 3090 |
timestamp_t timestamp, |
| 3091 |
timestamp_t cpu_timestamp) { |
| 3092 |
|
| 3093 |
HashEntry *objectHashEntry = 0; /* hash entry corresponding to the monitor object */ |
| 3094 |
int isThreadSleep = 0; /* boolean indicating if monitor wait occured in thread |
| 3095 |
sleep */ |
| 3096 |
|
| 3097 |
|
| 3098 |
|
| 3099 |
/* if the monitor object is NOT NULL, it is a regular object, |
| 3100 |
if it is NULL, then it indicates that the wait is in Thread.sleep() */ |
| 3101 |
|
| 3102 |
if ((void *) event->u.monitor_wait.object != NULL) { |
| 3103 |
/* lookup monitor object, ensuring that it exists in the trace */ |
| 3104 |
objectHashEntry = jvmpiAgent_FindObjectSymbolWithAllocateAndPrint(event->env_id, |
| 3105 |
event->u.monitor.object); |
| 3106 |
} |
| 3107 |
else { |
| 3108 |
isThreadSleep = 1; |
| 3109 |
} |
| 3110 |
|
| 3111 |
/* print the element only if we managed to resolve the hash entry for the monitor |
| 3112 |
object, or if the the monitor waited event was due to Thread.sleep(). */ |
| 3113 |
if (objectHashEntry || isThreadSleep) { |
| 3114 |
jvmpiAgent_printMonitorWaitElement(objectHashEntry, event, timestamp, isThreadSleep); |
| 3115 |
} |
| 3116 |
|
| 3117 |
|
| 3118 |
} |
| 3119 |
|
| 3120 |
static void processMonitorWaited(JVMPI_Event *event, |
| 3121 |
ThreadLocalStorage *tps, |
| 3122 |
BOOL isRequested, |
| 3123 |
timestamp_t timestamp, |
| 3124 |
timestamp_t cpu_timestamp) { |
| 3125 |
|
| 3126 |
|
| 3127 |
HashEntry *objectHashEntry = 0; /* hash entry corresponding to the monitor object */ |
| 3128 |
int isThreadSleep = 0; /* boolean indicating if monitor wait occured in thread |
| 3129 |
sleep */ |
| 3130 |
|
| 3131 |
/* if the monitor object is not NULL, it is a regular object, |
| 3132 |
if it is NULL, then it indicates that the wait is in Thread.sleep() */ |
| 3133 |
|
| 3134 |
if ((void *) event->u.monitor_wait.object != NULL) { |
| 3135 |
/* lookup monitor object, ensuring that it exists in the trace */ |
| 3136 |
objectHashEntry = jvmpiAgent_FindObjectSymbolWithAllocateAndPrint(event->env_id, |
| 3137 |
event->u.monitor.object); |
| 3138 |
} |
| 3139 |
else { |
| 3140 |
isThreadSleep = 1; |
| 3141 |
} |
| 3142 |
|
| 3143 |
/* print the element only if we managed to resolve the hash entry for the monitor |
| 3144 |
object, or if the the monitor waited event was due to Thread.sleep(). */ |
| 3145 |
if (objectHashEntry || isThreadSleep) { |
| 3146 |
jvmpiAgent_printMonitorWaitedElement(objectHashEntry, event, timestamp,isThreadSleep); |
| 3147 |
} |
| 3148 |
|
| 3149 |
} |
| 3150 |
|
| 3151 |
|
| 3152 |
/** NOTIFY_EVENT -- JVMPI EVENT HANDLER FUNCTION ***************************** |
| 3153 |
* This is the entry point for all events from the JVMPI interface. These |
| 3154 |
* events may be because of registered events or specific requested events. |
| 3155 |
* from here we jump to the specific handler for each event. |
| 3156 |
*/ |
| 3157 |
static void notify_event(JVMPI_Event *event) { |
| 3158 |
BOOL isRequested=FALSE; |
| 3159 |
timestamp_t timestamp; |
| 3160 |
timestamp_t cpu_timestamp = 0; |
| 3161 |
jint masked_event_type = event->event_type & (0xffffffff ^ JVMPI_REQUESTED_EVENT); |
| 3162 |
|
| 3163 |
/* Get the tps */ |
| 3164 |
ThreadPrivateStorage *tps=jvmpiAgent_getThreadLocalStorage(event->env_id); |
| 3165 |
|
| 3166 |
/* Get the timestamp */ |
| 3167 |
jvmpiAgent_getCurrentTime(×tamp); |
| 3168 |
if (_jvmpiAgent_Options.cpuTime) { |
| 3169 |
cpu_timestamp = jvmpiAgent_getCurrentThreadCPUTime(); |
| 3170 |
|
| 3171 |
/* record the last CPU timestamp on this thread; we'll need this later. |
| 3172 |
* (Actually, it's only needed if pre-aggregating (CompressAggregate), but |
| 3173 |
* testing that would slow this function down unnecessarily.) |
| 3174 |
*/ |
| 3175 |
tps->last_cpu_timestamp = cpu_timestamp; |
| 3176 |
} |
| 3177 |
|
| 3178 |
/* Check for disablement. Note: today (3/29/04) no code disables events */ |
| 3179 |
if(tps->disableEventsForThisThread) { |
| 3180 |
return; |
| 3181 |
} |
| 3182 |
|
| 3183 |
/*------------------------------------------------------------ |
| 3184 |
* Route this event to an agent extension if one is listening. |
| 3185 |
* This is a simple dispatcher system with no advanced logic |
| 3186 |
* for (e.g.) sending requested events to the requesting agent only. |
| 3187 |
* |
| 3188 |
* Agent extensions get events regardless of thread or burst timeout. |
| 3189 |
* They get the event pointer plus their own thread local storage pointer. |
| 3190 |
*/ |
| 3191 |
if (agent_extension_handlers[masked_event_type] != NULL) { |
| 3192 |
agent_extension_handlers[masked_event_type](event, &(tps->agent_extension_slot)); |
| 3193 |
} |
| 3194 |
/*------------------------------------------------------------*/ |
| 3195 |
|
| 3196 |
/* Just route the event to the appropriate event handler function */ |
| 3197 |
if(event->event_type & JVMPI_REQUESTED_EVENT) { |
| 3198 |
event->event_type=masked_event_type; |
| 3199 |
isRequested=TRUE; |
| 3200 |
} |
| 3201 |
else { |
| 3202 |
|
| 3203 |
/* If we are in burst timeout then stop tracing now */ |
| 3204 |
if(_jvmpiAgent_burstTimeoutSet) { |
| 3205 |
if(TIMESTAMP_GREATER(timestamp,_burstTimeout)) { |
| 3206 |
suspendTracing(TracePause); |
| 3207 |
} |
| 3208 |
} |
| 3209 |
|
| 3210 |
/* If we are in single threaded tracing ignore this event if it isn't on the proper thread. Can't do |
| 3211 |
this if we are insturmenting code though |
| 3212 |
*/ |
| 3213 |
if(event->event_type!=JVMPI_EVENT_CLASS_LOAD_HOOK |
| 3214 |
&& _jvmpiAgent_singleThreaded |
| 3215 |
&& _jvmpiAgent_limitingThread!=event->env_id) { |
| 3216 |
return; |
| 3217 |
} |
| 3218 |
} |
| 3219 |
|
| 3220 |
/* Check for null: maybe only an agent extension has a handler */ |
| 3221 |
if (_processEventFunction[event->event_type] != NULL) { |
| 3222 |
_processEventFunction[event->event_type](event, tps, isRequested, timestamp,cpu_timestamp); |
| 3223 |
} |
| 3224 |
} |
| 3225 |
|
| 3226 |
|
| 3227 |
/** AGENT_EXTENSION_SET_EVENT_HANDLER ******************************************************* |
| 3228 |
* Remember an agent extension's handler for an event. |
| 3229 |
* |
| 3230 |
* This function is called from agent extensions. The agent extension |
| 3231 |
* calls this function to set a handler and enable the corresponding |
| 3232 |
* JVMPI event. |
| 3233 |
* |
| 3234 |
* In stand-alone mode, this function actually calls JVMPI to enable the event. |
| 3235 |
* |
| 3236 |
* But in non-standalone mode, if isJVMInitDone is still false, |
| 3237 |
* we don't enable the event. Instead, we just record the extension's |
| 3238 |
* desire to handle the event. Later we will loop through and enable |
| 3239 |
* the events that the extension asked for. |
| 3240 |
* |
| 3241 |
* Why? Because in non-standalone mode, the agent extension's init function |
| 3242 |
* is calling us from a different thread - not the main thread that JVM_OnLoad |
| 3243 |
* was called on. If you try to enable events from this other thread, |
| 3244 |
* the JVM crashes. |
| 3245 |
* |
| 3246 |
* Rather than needlessly attaching threads to the JVM (and risk having |
| 3247 |
* them stay attached too long, or detach too soon), I decided to queue |
| 3248 |
* up the "enable" operations and process them in the main (OnLoad) thread |
| 3249 |
* after the listener gets unblocked - that is, when Workbench sends RESUME. |
| 3250 |
* |
| 3251 |
* In standalone mode, this system is not necessary because the extension |
| 3252 |
* agent init function is called from the main thread, where OnLoad is running. |
| 3253 |
* |
| 3254 |
* This system isn't used in "enabled" or "application" mode. In those |
| 3255 |
* modes, ra_startListener doesn't block, so it doesn't work to queue the |
| 3256 |
* requests and handle them when ra_startListener returns. But it's |
| 3257 |
* also not a standalone mode, meaning commands will come in on the |
| 3258 |
* listener thread (and calling enableEvent on a separate thread is bad). |
| 3259 |
* |
| 3260 |
* The agent_extension_init function gets a flag telling the extension |
| 3261 |
* whether it's safe to call enable_event_handler. It's safe in standalone |
| 3262 |
* mode, and in controlled mode, but not in application mode or enabled mode. |
| 3263 |
* |
| 3264 |
* One way to make sure it's safe is to start a new thread, attach that |
| 3265 |
* thread to the JVM, make the SetEventHandler call, detach the thread, |
| 3266 |
* then let the thread die. |
| 3267 |
*/ |
| 3268 |
static void agentExtensionSetEventHandler(jint event_type, |
| 3269 |
AgentExtensionEventHandler handler) { |
| 3270 |
agent_extension_handlers[event_type] = handler; |
| 3271 |
if (_jvmpiAgent_Options.standalone || _jvmpiAgent_isListenerUnblocked) { |
| 3272 |
_jvmpiAgent_jvmpiInterface->EnableEvent(event_type, 0); |
| 3273 |
} |
| 3274 |
} |
| 3275 |
|
| 3276 |
/** AGENT_EXTENSION_SET_COMMAND_HANDLER ******************************************************* |
| 3277 |
* Records an agent extension's handler for RAC commands. |
| 3278 |
*/ |
| 3279 |
static void agentExtensionSetCommandHandler(void (*handler)(ra_command_t *command)) { |
| 3280 |
agent_extension_command_handler = handler; |
| 3281 |
} |
| 3282 |
|
| 3283 |
|
| 3284 |
/** LOAD_STACK **************************************************************** |
| 3285 |
* The intention of this method is to materialize a single thread stack |
| 3286 |
* within the JVM. This would be used when doing stack sampling and when |
| 3287 |
* starting a trace at some arbitrary point during execution. The problem is... |
| 3288 |
* the IBM JVM often returns the wrong stack. Furthermore, it does not support |
| 3289 |
* asynchronous stack traversal so this needs to be called on the thread |
| 3290 |
* that is being loaded. |
| 3291 |
* |
| 3292 |
* The bug on IBM JDK's appears to be that information missing after a stack |
| 3293 |
* load is always at the top of the stack. Broken stack frame links due to |
| 3294 |
* the JIT is the cause. |
| 3295 |
*/ |
| 3296 |
static void loadStack(ThreadPrivateStorage *tps) |
| 3297 |
{ |
| 3298 |
int i; |
| 3299 |
JVMPI_CallTrace callTrace; |
| 3300 |
timestamp_t now; |
| 3301 |
timestamp_t cpu_now = 0; |
| 3302 |
StackFrame *it, *calledListOfCaller; /* pre-agg: 134635 */ |
| 3303 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 3304 |
dumpMethodEventCounts(); printf("LoadStack: tps = %8x\n", (void *)tps); fflush(stdout); |
| 3305 |
#endif |
| 3306 |
|
| 3307 |
/* Ignore the Global thread */ |
| 3308 |
if(!tps->env) |
| 3309 |
{ |
| 3310 |
return; |
| 3311 |
} |
| 3312 |
|
| 3313 |
|
| 3314 |
jvmpiAgent_getCurrentTime(&now); |
| 3315 |
if (_jvmpiAgent_Options.cpuTime) { |
| 3316 |
cpu_now = jvmpiAgent_getCurrentThreadCPUTime(); |
| 3317 |
tps->last_cpu_timestamp = cpu_now; /* remember last known CPU time */ |
| 3318 |
} |
| 3319 |
|
| 3320 |
callTrace.frames=(JVMPI_CallFrame*)malloc(400*sizeof(JVMPI_CallFrame)); |
| 3321 |
callTrace.env_id=tps->env; |
| 3322 |
_jvmpiAgent_jvmpiInterface->GetCallTrace(&callTrace, 400); |
| 3323 |
calledListOfCaller=tps->calledList; /* pre-agg: 134635 */ |
| 3324 |
for(i=callTrace.num_frames-1; i>=0; i--) |
| 3325 |
{ |
| 3326 |
HashEntry *methodHashEntry; |
| 3327 |
StackEntry *stackEntry; |
| 3328 |
methodHashEntry=jvmpiAgent_FindMethodSymbol((callTrace.frames[i].method_id)); |
| 3329 |
|
| 3330 |
/* If we don't know about the method we should get the class */ |
| 3331 |
if(!methodHashEntry) |
| 3332 |
{ |
| 3333 |
int result; |
| 3334 |
jobjectID clazz=_jvmpiAgent_jvmpiInterface->GetMethodClass(callTrace.frames[i].method_id); |
| 3335 |
result=REQUEST_EVENT2(JVMPI_EVENT_CLASS_LOAD, clazz); /* 232010 */ |
| 3336 |
/* If we found the class we should have the method */ |
| 3337 |
if(result == JVMPI_SUCCESS) { |
| 3338 |
methodHashEntry = jvmpiAgent_FindMethodSymbol((callTrace.frames[i].method_id)); |
| 3339 |
} |
| 3340 |
} |
| 3341 |
stackEntry=jvmpiAgent_Push(tps, tps->env, methodHashEntry ,NULL, now,cpu_now); |
| 3342 |
stackEntry->entryEventSeen=0; |
| 3343 |
|
| 3344 |
/* 134635 */ |
| 3345 |
/* Note that, before pre-agg was supported, filtering was not tested for and methodEntryEvents |
| 3346 |
* were not printed for these re-constructed method invocations. However, any |
| 3347 |
* MethodEntryEvents emitted from a previous run of this thread were still in effect and |
| 3348 |
* resumption of the thread picked-up where the last one left off. To get the same effect in |
| 3349 |
* the pre-agg case, it's necessary to determine if any of the thread's pre-existing |
| 3350 |
* calledList trees/sub-trees (from a previous run of the thread) has a record of the currrent |
| 3351 |
* call sequence being loaded (or of any starting portion thereof). If so, those stackEntries |
| 3352 |
* represented in the calledList tree will be connected to the corresponding stackFrames in |
| 3353 |
* that tree (and are marked as "realFrames" and "printed"). This occurs after a resume that |
| 3354 |
* follows a pause but *not* after an attach that follows a detach (because, in the |
| 3355 |
* detach/attach case, the calledList tree will have been cleared/freed by the detach). |
| 3356 |
*/ |
| 3357 |
if (_jvmpiAgent_Options.compressLevel==CompressAggregate) { /* pre-agg: 134635 */ |
| 3358 |
/* search for current method in calledList of Caller: if found, it will be a non-null "it" */ |
| 3359 |
for (it=calledListOfCaller; it!=NULL && it->methodHashEntry!=methodHashEntry; it=it->next); |
| 3360 |
|
| 3361 |
if (it != NULL) { /* if it!=NULL then the current method was found as a child of the caller frame */ |
| 3362 |
stackEntry->stackFrame = it; /* connect the current stack entry to the found frame */ |
| 3363 |
stackEntry->realFrame = 1; /* treat almost as a CreateStackFrame operation * 139537 */ |
| 3364 |
stackEntry->printed = 1; /* treat almost as a CreateStackFrame operation * 139537 */ |
| 3365 |
calledListOfCaller = it->calledList; /* the next stack entry's method will need to one of this frame's |
| 3366 |
* children for the repeated starting call sequence to continue */ |
| 3367 |
} else { /* 139537 */ |
| 3368 |
calledListOfCaller = NULL; /* this terminates the repeated starting call sequence * 139537 */ |
| 3369 |
} |
| 3370 |
} |
| 3371 |
} |
| 3372 |
free(callTrace.frames); |
| 3373 |
|
| 3374 |
/* RKD: Mark this thread as a valid thread only if the thread stack is depth is greater then zero. This check |
| 3375 |
needs to be here as the JIT in some IBM JDKS doesn't always give the stack information when you invoke |
| 3376 |
GetCallTrace() |
| 3377 |
*/ |
| 3378 |
if(callTrace.num_frames > 0) |
| 3379 |
{ |
| 3380 |
tps->threadStackKnown=1; |
| 3381 |
/* pre-agg: add this thread to the list of threads that we will want to |
| 3382 |
* dump data for when requested, or when they die. |
| 3383 |
*/ |
| 3384 |
if(_jvmpiAgent_Options.compressLevel==CompressAggregate) { /* pre-agg: 134635 */ |
| 3385 |
addThreadToList(tps); |
| 3386 |
} |
| 3387 |
} |
| 3388 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 3389 |
dumpMethodEventCounts(); printf("LoadStack: tps = %8x Done!\n", (void *)tps); fflush(stdout); |
| 3390 |
#endif |
| 3391 |
|
| 3392 |
|
| 3393 |
return; |
| 3394 |
} |
| 3395 |
|
| 3396 |
/** STACK_CLEANER ************************************************************ |
| 3397 |
* Walk a stack and cleanup all the memory in use. |
| 3398 |
*/ |
| 3399 |
int stackCleaner(HashEntry *hashEntry, |
| 3400 |
void *parm) { |
| 3401 |
ThreadPrivateStorage *tps; |
| 3402 |
tps=(ThreadPrivateStorage*)THREAD_ENTRY(hashEntry); |
| 3403 |
|
| 3404 |
/* Pop all the entries on the stack */ |
| 3405 |
while(tps->tos) { |
| 3406 |
jvmpiAgent_Pop(tps); |
| 3407 |
} |
| 3408 |
/* Mark this thread as an invalid thread */ |
| 3409 |
tps->threadStackKnown=0; |
| 3410 |
|
| 3411 |
return 0; |
| 3412 |
} |
| 3413 |
|
| 3414 |
|
| 3415 |
/** DELETE_HASH_ENTRY ********************************************************* |
| 3416 |
* |
| 3417 |
*/ |
| 3418 |
int deleteHashEntry(HashEntry *entry, |
| 3419 |
void *param) { |
| 3420 |
jvmpiAgent_DeleteSymbol(entry, (*(enum EntryType*)param)); |
| 3421 |
return 0; |
| 3422 |
} |
| 3423 |
|
| 3424 |
|
| 3425 |
|
| 3426 |
|
| 3427 |
/** CLEAN_UP_ALL_TRACE_ROSOURCES ********************************************** |
| 3428 |
* Cleanup all our resources that were allocated during a trace so that we have |
| 3429 |
* no history of events/objects to refer to. With this done we can start a new |
| 3430 |
* trace. |
| 3431 |
*/ |
| 3432 |
static void cleanUpAllTraceResources() { |
| 3433 |
enum EntryType type; |
| 3434 |
|
| 3435 |
_traceResourcesGone = TRUE; /* pre-agg: 134635 */ |
| 3436 |
|
| 3437 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 3438 |
printf("cleanUpAllTraceResources\n"); fflush(stdout); |
| 3439 |
#endif |
| 3440 |
/* Delete each of the objects */ |
| 3441 |
type=Object_t; |
| 3442 |
jvmpiAgent_ForAll(Object_t, deleteHashEntry, &type); |
| 3443 |
|
| 3444 |
/* 174841 - RKD: Always keep the state of threads |
| 3445 |
so that the stack can be re-materialized later if |
| 3446 |
necessary |
| 3447 |
type=Thread_t; |
| 3448 |
jvmpiAgent_ForAll(Thread_t, deleteHashEntry, &type); |
| 3449 |
174841 end */ |
| 3450 |
|
| 3451 |
/* pre-aggregation */ |
| 3452 |
/* Remove all threads from the "threadsRoot" list of live threads. |
| 3453 |
* This will free the StackFrames pointed to by the threads, |
| 3454 |
* and set all tps->callerList to NULL. |
| 3455 |
* |
| 3456 |
* Note that threadEnds sometimes occur even after Detach/cleanup. |
| 3457 |
* Thus, removeThreadFromList could be underway on multiple "threads" |
| 3458 |
* but the ThreadList lock combined with the traceResourcesGone flag |
| 3459 |
* should be sufficient to provide correct operation even in that |
| 3460 |
* scenario. |
| 3461 |
*/ |
| 3462 |
if (_jvmpiAgent_Options.compressLevel==CompressAggregate) { /* 134635 */ |
| 3463 |
while (threadsRoot != NULL) { |
| 3464 |
removeThreadFromList(threadsRoot->data); |
| 3465 |
} |
| 3466 |
} |
| 3467 |
|
| 3468 |
/* Delete each of the classes */ |
| 3469 |
type=Class_t; |
| 3470 |
jvmpiAgent_ForAll(Class_t, deleteHashEntry, &type); |
| 3471 |
|
| 3472 |
/* Delete each of the methods */ |
| 3473 |
type=Method_t; |
| 3474 |
jvmpiAgent_ForAll(Method_t, deleteHashEntry, &type); |
| 3475 |
|
| 3476 |
/* deleting the class hashtable will have also removed the primitive types; |
| 3477 |
if someone reattaches to the profiler, the primitive types will not be |
| 3478 |
regenerated automatically. Hence, we must regenerate them now. */ |
| 3479 |
|
| 3480 |
createPrimitiveTypes(); |
| 3481 |
} |
| 3482 |
|
| 3483 |
|
| 3484 |
/** START_TRACING ************************************************************* |
| 3485 |
* This is the entry point which must be called to start a trace. It takes |
| 3486 |
* care of emitting all the header information and turning the JVMPI events |
| 3487 |
* on so we will start recieving events. |
| 3488 |
*/ |
| 3489 |
static void startTracing(BOOL standalone) { |
| 3490 |
|
| 3491 |
_jvmpiAgent_suspendIO = 0; |
| 3492 |
_traceResourcesGone = FALSE; /* pre-agg: 134635 */ |
| 3493 |
|
| 3494 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 3495 |
printf("startTracing\n"); fflush(stdout); |
| 3496 |
#endif |
| 3497 |
|
| 3498 |
/** Giri: <Defect 64462> We need to do some optHeap related setup, before we can request opt Heap dumps |
| 3499 |
So we do the required set-up if the mode is TraceOptimizedHeap */ |
| 3500 |
|
| 3501 |
if (_jvmpiAgent_Options.mode == TraceOptimizedHeap ) { |
| 3502 |
jvmpiAgent_DoOptHeapSetup(); |
| 3503 |
} |
| 3504 |
|
| 3505 |
jvmpiAgent_PrintStartingXMLFragments(); |
| 3506 |
_xmlHeadersPrinted=TRUE; |
| 3507 |
|
| 3508 |
/* We need to ensure the entire sybmol table is "unreferenced" to ensure we get the references |
| 3509 |
for all method invocations for this trace. |
| 3510 |
*/ |
| 3511 |
jvmpiAgent_clearAllPrintFlags(); |
| 3512 |
|
| 3513 |
/* Reset the trigger flag if we are not running in application mode. */ |
| 3514 |
if(!_jvmpiAgent_Options.application) { |
| 3515 |
_triggerSqueezed=FALSE; |
| 3516 |
} |
| 3517 |
else { |
| 3518 |
_jvmpiAgent_Options.startMode=TraceStartModeTriggerMultiThreaded; |
| 3519 |
} |
| 3520 |
|
| 3521 |
resumeTracing(); |
| 3522 |
} |
| 3523 |
|
| 3524 |
static void resumeTracing() { |
| 3525 |
|
| 3526 |
/* Turn on IO */ |
| 3527 |
_jvmpiAgent_suspendIO = 0; |
| 3528 |
|
| 3529 |
/* If we are burst tracing set the burst information */ |
| 3530 |
if(_jvmpiAgent_Options.burstMode>BurstModeNone) { |
| 3531 |
switch(_jvmpiAgent_Options.burstMode) { |
| 3532 |
case BurstModeInvocations: |
| 3533 |
_invocationCountRemaining=_jvmpiAgent_Options.burstInvocations; |
| 3534 |
break; |
| 3535 |
case BurstModeSeconds: |
| 3536 |
{ |
| 3537 |
timestamp_t ticks; |
| 3538 |
jvmpiAgent_getCurrentTime(&_burstTimeout); |
| 3539 |
ticks = timeToTicks(_jvmpiAgent_Options.burstSeconds, 0); |
| 3540 |
TIMESTAMP_ADD(_burstTimeout,ticks); |
| 3541 |
_jvmpiAgent_burstTimeoutSet=TRUE; |
| 3542 |
break; |
| 3543 |
} |
| 3544 |
case BurstModeSecondsAndInvocations: |
| 3545 |
{ |
| 3546 |
timestamp_t ticks; |
| 3547 |
_invocationCountRemaining=_jvmpiAgent_Options.burstInvocations; |
| 3548 |
ticks = timeToTicks(_jvmpiAgent_Options.burstSeconds, 0); |
| 3549 |
jvmpiAgent_getCurrentTime(&_burstTimeout); |
| 3550 |
TIMESTAMP_ADD(_burstTimeout,ticks); |
| 3551 |
_jvmpiAgent_burstTimeoutSet=TRUE; |
| 3552 |
} |
| 3553 |
} |
| 3554 |
} |
| 3555 |
|
| 3556 |
_jvmpiAgent_isSuspended=FALSE; |
| 3557 |
|
| 3558 |
/* Enable the events */ |
| 3559 |
toggleActiveJvmpiEvents(TraceON); |
| 3560 |
} |
| 3561 |
|
| 3562 |
|
| 3563 |
/** SUSPEND_TRACING *********************************************************** |
| 3564 |
* |
| 3565 |
* toggle - TraceOFF - completely turning off tracing |
| 3566 |
* TracePause - pausing tracing |
| 3567 |
*/ |
| 3568 |
static void suspendTracing(TraceToggle toggle) { |
| 3569 |
|
| 3570 |
/* pre-aggregation: |
| 3571 |
* Roll up stacks in live threads and report their data. This applies both |
| 3572 |
* to Pause (RA_STOP_MONITORING_AGENT) and to Detach (RA_DETACH_FROM_AGENT). |
| 3573 |
* NB: the agPops triggered in this stack rollup break the links between the |
| 3574 |
* stackEntries and corresponding stackFrames. This ensures that the |
| 3575 |
* agPops from the stackCleaner below do nothing and thus avoid a double |
| 3576 |
* rollup that would produce double counts. (See jvmpiAgent_agPop.) |
| 3577 |
*/ |
| 3578 |
if (_jvmpiAgent_Options.compressLevel==CompressAggregate) { /* 134635 */ |
| 3579 |
/* pre-agg mode; roll up stacks and dump data */ |
| 3580 |
timestamp_t now; |
| 3581 |
jvmpiAgent_getCurrentTime(&now); |
| 3582 |
rollUpAndPrintAllThreadAgData(now); |
| 3583 |
} |
| 3584 |
|
| 3585 |
/* Turn off IO */ |
| 3586 |
_jvmpiAgent_suspendIO = 1; |
| 3587 |
|
| 3588 |
/* Disable the events */ |
| 3589 |
toggleActiveJvmpiEvents(toggle); |
| 3590 |
|
| 3591 |
_jvmpiAgent_burstTimeoutSet=FALSE; |
| 3592 |
|
| 3593 |
_jvmpiAgent_isSuspended=TRUE; |
| 3594 |
_triggerSqueezed=FALSE; |
| 3595 |
|
| 3596 |
/* We need to destroy the stacks */ |
| 3597 |
jvmpiAgent_ForAll(Thread_t, stackCleaner, NULL); |
| 3598 |
} |
| 3599 |
|
| 3600 |
/** STOP_TRACING ************************************************************** |
| 3601 |
* This is where a trace is stopped. |
| 3602 |
*/ |
| 3603 |
static void stopTracing() { |
| 3604 |
/* Get the global buffer for IO */ |
| 3605 |
ThreadLocalStorage *tps=jvmpiAgent_getThreadLocalStorage(0); |
| 3606 |
|
| 3607 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 3608 |
printf("stopTracing\n"); fflush(stdout); |
| 3609 |
#endif |
| 3610 |
|
| 3611 |
/* Print the TRACE_END element */ |
| 3612 |
jvmpiAgent_printTraceEndElement(tps); |
| 3613 |
|
| 3614 |
suspendTracing(TraceOFF); |
| 3615 |
|
| 3616 |
/* Clean up all our resources for this trace */ |
| 3617 |
cleanUpAllTraceResources(); |
| 3618 |
|
| 3619 |
_jvmpiAgent_isSuspended=FALSE; |
| 3620 |
|
| 3621 |
} |
| 3622 |
|
| 3623 |
|
| 3624 |
/** determineJavaVersion() ********************************************************** |
| 3625 |
* Determine the java vendor and version so that we can disable certain functionality |
| 3626 |
* based on the runtime version to avoid jvm bugs. |
| 3627 |
* |
| 3628 |
* @param env the JNIEnv * to use for the JNI calls |
| 3629 |
*/ |
| 3630 |
#ifdef __OS400__ |
| 3631 |
#pragma convert(819) |
| 3632 |
#endif |
| 3633 |
static void determineJavaVersion(JNIEnv *env) { |
| 3634 |
|
| 3635 |
/* The basic approach is to call System.getProperty("java.version") and |
| 3636 |
System.getProperty("java.vendor") through JNI. If any sort of failure |
| 3637 |
occurs while doing JNI, the behaviour of this method is to fail immediately |
| 3638 |
and return to the caller. */ |
| 3639 |
|
| 3640 |
jclass javaLangSystem; /* java.lang.System class */ |
| 3641 |
jmethodID getPropertyID; /* System.getProperty() method */ |
| 3642 |
jstring javaVersionProperty, javaVersionValue; |
| 3643 |
jstring javaVendorProperty, javaVendorValue; |
| 3644 |
int tmpStrLen; |
| 3645 |
char *javaVersionChars; |
| 3646 |
char *javaVendorChars; |
| 3647 |
|
| 3648 |
/* initialize javaVendor/Version to defaults */ |
| 3649 |
_javaVendor = VendorOther; |
| 3650 |
_javaVersion = VersionOther; |
| 3651 |
|
| 3652 |
/* first we need a reference to the class java.lang.System */ |
| 3653 |
|
| 3654 |
javaLangSystem = FIND_CLASS(env, "java/lang/System"); |
| 3655 |
|
| 3656 |
if (!javaLangSystem) { |
| 3657 |
return; |
| 3658 |
} |
| 3659 |
|
| 3660 |
/* next we need the jmethodID of the static getProperty() method in the |
| 3661 |
System class */ |
| 3662 |
|
| 3663 |
getPropertyID = GET_SMETHODID(env, javaLangSystem, "getProperty", |
| 3664 |
"(Ljava/lang/String;)Ljava/lang/String;"); |
| 3665 |
|
| 3666 |
if (!getPropertyID) { |
| 3667 |
return; |
| 3668 |
} |
| 3669 |
|
| 3670 |
/* we need to create a jstring version of the native string "java.version" */ |
| 3671 |
javaVersionProperty = CREATE_JSTRING(env, "java.version"); |
| 3672 |
if (!javaVersionProperty) { |
| 3673 |
return; |
| 3674 |
} |
| 3675 |
|
| 3676 |
/* we need to create a jstring version of the native string "java.vendor" */ |
| 3677 |
javaVendorProperty = CREATE_JSTRING(env, "java.vendor"); |
| 3678 |
if (!javaVendorProperty) { |
| 3679 |
return; |
| 3680 |
} |
| 3681 |
|
| 3682 |
/* Here we invoke System.getProperty("java.version") */ |
| 3683 |
javaVersionValue = (jstring) CALL_OBJ_SMETHOD1(env, javaLangSystem, |
| 3684 |
getPropertyID, javaVersionProperty); |
| 3685 |
|
| 3686 |
/* make sure there were no exceptions thrown during the preceding call */ |
| 3687 |
if (CHECK_EXCEPTION(env)) { |
| 3688 |
CLEAR_EXCEPTIONS(env); |
| 3689 |
return; |
| 3690 |
} |
| 3691 |
if (!javaVersionValue) { |
| 3692 |
return; |
| 3693 |
} |
| 3694 |
|
| 3695 |
/* Here we invoke System.getProperty("java.vendor") */ |
| 3696 |
javaVendorValue = (jstring) CALL_OBJ_SMETHOD1(env, javaLangSystem, |
| 3697 |
getPropertyID, javaVendorProperty); |
| 3698 |
if (CHECK_EXCEPTION(env)) { |
| 3699 |
CLEAR_EXCEPTIONS(env); |
| 3700 |
return; |
| 3701 |
} |
| 3702 |
if (!javaVendorValue) { |
| 3703 |
return; |
| 3704 |
} |
| 3705 |
|
| 3706 |
/* convert the jstring's into UTF-8 char arrays */ |
| 3707 |
javaVersionChars = (char *)CONVERT_TO_UTF(env, javaVersionValue); |
| 3708 |
if (!javaVersionChars) { |
| 3709 |
return; |
| 3710 |
} |
| 3711 |
|
| 3712 |
javaVendorChars = (char *)CONVERT_TO_UTF(env, javaVendorValue); |
| 3713 |
if (!javaVendorChars) { |
| 3714 |
RELEASE_UTF_CHARS(env,javaVersionValue,javaVersionChars); |
| 3715 |
return; |
| 3716 |
} |
| 3717 |
|
| 3718 |
|
| 3719 |
|
| 3720 |
tmpStrLen = strlen(javaVersionChars); |
| 3721 |
if (tmpStrLen >= 3 && strncmp(javaVersionChars,"1.3",3) == 0) { |
| 3722 |
_javaVersion = Version13; |
| 3723 |
} |
| 3724 |
else if (tmpStrLen >= 5 && strncmp(javaVersionChars,"1.4.0",5) == 0) { |
| 3725 |
_javaVersion = Version140; |
| 3726 |
} |
| 3727 |
else if (tmpStrLen >= 5 && strncmp(javaVersionChars,"1.4.1",5) == 0) { |
| 3728 |
_javaVersion = Version141; |
| 3729 |
} |
| 3730 |
else if (tmpStrLen >= 5 && strncmp(javaVersionChars,"1.4.2",5) == 0) { |
| 3731 |
_javaVersion = Version142; |
| 3732 |
} |
| 3733 |
else { |
| 3734 |
_javaVersion = VersionOther; |
| 3735 |
} |
| 3736 |
|
| 3737 |
|
| 3738 |
/* determine the vendor */ |
| 3739 |
tmpStrLen = strlen(javaVendorChars); |
| 3740 |
if (tmpStrLen >= IBM_VENDOR_STRING_LENGTH && |
| 3741 |
strncmp(javaVendorChars,IBM_VENDOR_STRING,IBM_VENDOR_STRING_LENGTH) == 0) { |
| 3742 |
_javaVendor = VendorIBM; |
| 3743 |
} |
| 3744 |
else if (tmpStrLen >= SUN_VENDOR_STRING_LENGTH && |
| 3745 |
strncmp(javaVendorChars,SUN_VENDOR_STRING,SUN_VENDOR_STRING_LENGTH) == 0) { |
| 3746 |
_javaVendor = VendorSun; |
| 3747 |
} |
| 3748 |
else if (tmpStrLen >= HP_VENDOR_STRING_LENGTH && |
| 3749 |
strncmp(javaVendorChars,HP_VENDOR_STRING,HP_VENDOR_STRING_LENGTH) == 0) { |
| 3750 |
_javaVendor = VendorHP; |
| 3751 |
} |
| 3752 |
else { |
| 3753 |
_javaVendor = VendorOther; |
| 3754 |
} |
| 3755 |
|
| 3756 |
/* free up all the strings */ |
| 3757 |
RELEASE_UTF_CHARS(env,javaVersionValue,javaVersionChars); |
| 3758 |
RELEASE_UTF_CHARS(env,javaVendorValue,javaVendorChars); |
| 3759 |
|
| 3760 |
} |
| 3761 |
#ifdef __OS400__ |
| 3762 |
#pragma convert(0) |
| 3763 |
#endif |
| 3764 |
|
| 3765 |
|
| 3766 |
|
| 3767 |
/** PROCESS_JVM_INIT_DONE_EVENT ********************************************** |
| 3768 |
* Event called by the JVM when the JVM has completed all of it's |
| 3769 |
* initialization. This is the earliest pont where we can start tracing. |
| 3770 |
*/ |
| 3771 |
static void processJvmInitDoneEvent(JVMPI_Event *event, |
| 3772 |
ThreadLocalStorage *tps, |
| 3773 |
BOOL isRequested, |
| 3774 |
timestamp_t timestamp, |
| 3775 |
timestamp_t cpu_timestamp) { |
| 3776 |
|
| 3777 |
|
| 3778 |
int currentSuspendIO = _jvmpiAgent_suspendIO; |
| 3779 |
int isStarted = 0; |
| 3780 |
|
| 3781 |
/* determine the java runtime vendor/version */ |
| 3782 |
determineJavaVersion(event->env_id); |
| 3783 |
|
| 3784 |
/* If we are actively profiling start the trace. This cannot happen in any of the application mode, the |
| 3785 |
additional test is neccessary as applicationControlled will be monitoing at this time. |
| 3786 |
|
| 3787 |
We start tracing even though _jvmpiAgent_suspendIO may be true in order to be able |
| 3788 |
to later monitor applications that were not monitored from the beginning (see |
| 3789 |
bugzilla 49541 and the next comment.) |
| 3790 |
|
| 3791 |
We cannot do this trick if we are in enabled mode, however, since this causes |
| 3792 |
problems with OS/400. Starting tracing actually tries forcing the RAC to write |
| 3793 |
data, which, if premature, can result in the problems described in bugzilla 59667. |
| 3794 |
There should be no need to do this trick anyhow when in enabled mode. |
| 3795 |
*/ |
| 3796 |
if(!_jvmpiAgent_Options.application |
| 3797 |
&& !(currentSuspendIO && _jvmpiAgent_Options.enabled) ) { |
| 3798 |
startTracing(TRUE); |
| 3799 |
isStarted = 1; |
| 3800 |
} |
| 3801 |
|
| 3802 |
/* This little trick is needed to be able to later on monitor |
| 3803 |
* Java applications that have been resumed but not monitored */ |
| 3804 |
|
| 3805 |
if (currentSuspendIO && isStarted) |
| 3806 |
{ |
| 3807 |
stopTracing(); |
| 3808 |
_jvmpiAgent_suspendIO = 1; |
| 3809 |
} |
| 3810 |
|
| 3811 |
|
| 3812 |
|
| 3813 |
/* MARK the heap now so we have a baseline to start from. This is nice |
| 3814 |
as the UI can just ask for an ANALYSE without a preceading MARK if |
| 3815 |
desired |
| 3816 |
*/ |
| 3817 |
analyseHeap(JVMPI_DUMP_LEVEL_0); |
| 3818 |
|
| 3819 |
/* Set the flag to say we can now trace if we wish */ |
| 3820 |
_jvmpiAgent_isJVMInitDone=TRUE; |
| 3821 |
|
| 3822 |
if ( _jvmpiAgent_Options.mode != TraceModeNone || !_jvmpiAgent_Options.standalone ) { |
| 3823 |
jvmpiAgent_printJvmInitDoneElement(event); |
| 3824 |
} |
| 3825 |
|
| 3826 |
|
| 3827 |
} |
| 3828 |
|
| 3829 |
/** SET_DYNAMIC_EVENT_HANDLERS ******************************************************* |
| 3830 |
* Some events will be requested via the RequestEvent() call and hense we need to |
| 3831 |
* set the function pointers for these so we don't get burned. |
| 3832 |
*/ |
| 3833 |
static void setDynamicEventHandlers() { |
| 3834 |
_processEventFunction[JVMPI_EVENT_CLASS_LOAD] = processClassLoadEvent; |
| 3835 |
_processEventFunction[JVMPI_EVENT_OBJECT_ALLOC] = processObjAllocEvent; |
| 3836 |
#ifdef __OS400__ |
| 3837 |
_processEventFunction[JVMPI_EVENT_OBJECT_DUMP] = processObjectDumpEvent; |
| 3838 |
#endif |
| 3839 |
} |
| 3840 |
|
| 3841 |
/** ENABLE_JVMPI_EVENT ******************************************************* |
| 3842 |
* Enables an event in JVMPI so that we start recieving these types of |
| 3843 |
* events. |
| 3844 |
*/ |
| 3845 |
static int enableJvmpiEvent(jint event_type, |
| 3846 |
ProcessEventFunction eventHandler) { |
| 3847 |
_processEventFunction[event_type] = eventHandler; |
| 3848 |
return _jvmpiAgent_jvmpiInterface->EnableEvent(event_type, 0); |
| 3849 |
} |
| 3850 |
|
| 3851 |
|
| 3852 |
/** DISABLE_JVMPI_EVENT ****************************************************** |
| 3853 |
* Disables an event in JVMPI so that we stop recieving these types of |
| 3854 |
* events. |
| 3855 |
*/ |
| 3856 |
static void disableJvmpiEvent(jint event_type) { |
| 3857 |
_jvmpiAgent_jvmpiInterface->DisableEvent(event_type, NULL); |
| 3858 |
} |
| 3859 |
|
| 3860 |
|
| 3861 |
/** ENABLE_GLOBAL_JVMPI_EVENTS *********************************************** |
| 3862 |
* Enables all the JVMPI events that we need in order to start tracing at any |
| 3863 |
* point in time. These are the obligitory events. |
| 3864 |
*/ |
| 3865 |
static void enableGlobalJvmpiEvents(enum TraceMode mode) { |
| 3866 |
|
| 3867 |
/* If Exception tracing or line coverage is enabled then activate the class load hook event so that |
| 3868 |
we can instrument each class with our trace hooks. |
| 3869 |
*/ |
| 3870 |
if (_jvmpiAgent_Options.enableExceptionTracing || _jvmpiAgent_Options.enableLineCoverage) { |
| 3871 |
enableJvmpiEvent(JVMPI_EVENT_CLASS_LOAD_HOOK, processClassLoadHookEvent); |
| 3872 |
} |
| 3873 |
|
| 3874 |
/* Events we always need */ |
| 3875 |
enableJvmpiEvent(JVMPI_EVENT_JVM_INIT_DONE, processJvmInitDoneEvent); |
| 3876 |
enableJvmpiEvent(JVMPI_EVENT_JVM_SHUT_DOWN, processesJVMShutdownEvent); |
| 3877 |
/* Bug 62852 - We do not need to track these events for TraceOptimizedHeap Mode */ |
| 3878 |
if (_jvmpiAgent_Options.mode != TraceOptimizedHeap) { |
| 3879 |
enableJvmpiEvent(JVMPI_EVENT_THREAD_START, processThreadStartEvent); |
| 3880 |
enableJvmpiEvent(JVMPI_EVENT_THREAD_END, processThreadEndEvent); |
| 3881 |
} |
| 3882 |
_processEventFunction[JVMPI_EVENT_HEAP_DUMP] = processHeapDumpEvent; |
| 3883 |
enableJvmpiEvent(JVMPI_EVENT_MONITOR_DUMP, processMonitorDumpEvent); |
| 3884 |
enableJvmpiEvent(JVMPI_EVENT_DATA_DUMP_REQUEST, processDataDumpRequest); |
| 3885 |
} |
| 3886 |
|
| 3887 |
|
| 3888 |
/** SAMPLE_STACK ************************************************************** |
| 3889 |
* Samples the contents of a stack. In the current impl this cleans up the |
| 3890 |
* stack immediately after sampling its contents. If we ever get the stack |
| 3891 |
* traversal stuff fixed in the JVM we should change loadStack to assign |
| 3892 |
* a weight to each stack frame so we can finish the job of providing |
| 3893 |
* a stack sampling profiler. |
| 3894 |
*/ |
| 3895 |
int sampleStack(HashEntry * hashEntry, void *parm) { |
| 3896 |
JNIEnv *env=(JNIEnv*)parm; |
| 3897 |
ThreadPrivateStorage *tps=THREAD_ENTRY(hashEntry); |
| 3898 |
/* Ignore the global thread as it isn't part of the JVM threads. |
| 3899 |
Also don't sample ourselves as this will deadlock. Thi condition occurs |
| 3900 |
because the thread is attached to the JVM |
| 3901 |
*/ |
| 3902 |
if(tps->env && tps->env!=env) { |
| 3903 |
|
| 3904 |
/* suspend the thread */ |
| 3905 |
_jvmpiAgent_jvmpiInterface->SuspendThread(tps->env); |
| 3906 |
|
| 3907 |
/* Load the stack and then clean it up */ |
| 3908 |
loadStack(tps); |
| 3909 |
stackCleaner(hashEntry, NULL); |
| 3910 |
|
| 3911 |
/* Resume the thread */ |
| 3912 |
_jvmpiAgent_jvmpiInterface->ResumeThread(tps->env); |
| 3913 |
} |
| 3914 |
return 0; |
| 3915 |
} |
| 3916 |
|
| 3917 |
/** STACK_SAMPLER ************************************************************* |
| 3918 |
* This is the impl for the background thread that will sample each of the |
| 3919 |
* threads in the JVM when we are running in mode=sampling. |
| 3920 |
*/ |
| 3921 |
void *stackSampler(void *args) { |
| 3922 |
JNIEnv *env; |
| 3923 |
if(!ATTACH_THREAD(env)) { |
| 3924 |
do { |
| 3925 |
/* Disable GC */ |
| 3926 |
_jvmpiAgent_jvmpiInterface->DisableGC(); |
| 3927 |
|
| 3928 |
/* Sample each of the threads in turn */ |
| 3929 |
jvmpiAgent_ForAll(Thread_t, sampleStack, (void *)env); |
| 3930 |
|
| 3931 |
/* Re-enable GC */ |
| 3932 |
_jvmpiAgent_jvmpiInterface->EnableGC(); |
| 3933 |
SLEEP(10); /* Hardcoded period of 10 milliseconds */ |
| 3934 |
} |
| 3935 |
while(_stackSamplerActive); |
| 3936 |
DETACH_THREAD(); |
| 3937 |
} |
| 3938 |
return 0; |
| 3939 |
} |
| 3940 |
|
| 3941 |
|
| 3942 |
/** |
| 3943 |
* Proxy to the stack sampler thread for porting ease |
| 3944 |
*/ |
| 3945 |
#ifdef _WIN32 |
| 3946 |
DWORD WINAPI win32stackSamplerProxy(LPVOID args) { |
| 3947 |
DWORD returnVal=0; |
| 3948 |
stackSampler(args); |
| 3949 |
return returnVal; |
| 3950 |
} |
| 3951 |
#endif |
| 3952 |
|
| 3953 |
/** TOGGLE_ACTIVE_JVMPI_EVENTS ************************************************ |
| 3954 |
* Toggles the optional JVMPI events on and off so that we can minimize our |
| 3955 |
* impact on an executing application when we are not profiling. The events |
| 3956 |
* turned on are determined by the trace mode we are running. |
| 3957 |
*/ |
| 3958 |
static void toggleActiveJvmpiEvents(TraceToggle toggle) { |
| 3959 |
#if defined MVS || defined __OS400__ |
| 3960 |
static TID stackSamplerTid; |
| 3961 |
#else |
| 3962 |
static TID stackSamplerTid=0; |
| 3963 |
#endif |
| 3964 |
|
| 3965 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 3966 |
printf("toggleActiveJvmpiEvents\n"); fflush(stdout); |
| 3967 |
#endif |
| 3968 |
|
| 3969 |
/* Navid Mehregani - bugzilla 162754: Note that 'processClassLoadHookEvent' is an empty method |
| 3970 |
It's the class load event handler in the agent extension that does the real work. */ |
| 3971 |
if (toggle == TraceON) |
| 3972 |
enableJvmpiEvent(JVMPI_EVENT_CLASS_LOAD_HOOK, processClassLoadHookEvent); |
| 3973 |
else |
| 3974 |
disableJvmpiEvent(JVMPI_EVENT_CLASS_LOAD_HOOK); |
| 3975 |
/* End of bugzilla 162754 */ |
| 3976 |
|
| 3977 |
/** the METHOD_COUNTS_ONLY option overrides all other options **/ |
| 3978 |
if (_jvmpiAgent_Options.methodCountsOnly) { |
| 3979 |
if (toggle == TraceON) { |
| 3980 |
enableJvmpiEvent(JVMPI_EVENT_METHOD_ENTRY, processCountingMethodEntryEvent); |
| 3981 |
} |
| 3982 |
else { |
| 3983 |
disableJvmpiEvent(JVMPI_EVENT_METHOD_ENTRY); |
| 3984 |
} |
| 3985 |
/* return immediately as methodCountsOnly overrides all other options */ |
| 3986 |
return; |
| 3987 |
} |
| 3988 |
|
| 3989 |
|
| 3990 |
|
| 3991 |
/* Register for the correct method events based upon trace mode */ |
| 3992 |
/* RKD: We should only turn on stack events if our StackInfo > StackInfoNone */ |
| 3993 |
if(_jvmpiAgent_Options.stackInfo > StackInfoNone) { |
| 3994 |
if(_jvmpiAgent_Options.mode == TraceModeFull) { |
| 3995 |
if(toggle == TraceON) { |
| 3996 |
enableJvmpiEvent(JVMPI_EVENT_METHOD_ENTRY2, processMethodEntryEvent); |
| 3997 |
enableJvmpiEvent(JVMPI_EVENT_METHOD_EXIT, processMethodExitEvent); |
| 3998 |
} |
| 3999 |
else { |
| 4000 |
disableJvmpiEvent(JVMPI_EVENT_METHOD_ENTRY2); |
| 4001 |
disableJvmpiEvent(JVMPI_EVENT_METHOD_EXIT); |
| 4002 |
} |
| 4003 |
} |
| 4004 |
else if(_jvmpiAgent_Options.mode == TraceModeNoObjectCorrelation) { |
| 4005 |
if(toggle == TraceON) { |
| 4006 |
enableJvmpiEvent(JVMPI_EVENT_METHOD_ENTRY, processMethodEntryEvent); |
| 4007 |
enableJvmpiEvent(JVMPI_EVENT_METHOD_EXIT, processMethodExitEvent); |
| 4008 |
} |
| 4009 |
else { |
| 4010 |
disableJvmpiEvent(JVMPI_EVENT_METHOD_ENTRY); |
| 4011 |
disableJvmpiEvent(JVMPI_EVENT_METHOD_EXIT); |
| 4012 |
} |
| 4013 |
} |
| 4014 |
/* RKD: This is placed as a placeholder for a stack sampling profiler. |
| 4015 |
This has not shipped due to problems with the IBM JDK with enumerating |
| 4016 |
stack's. |
| 4017 |
*/ |
| 4018 |
else if(_jvmpiAgent_Options.mode == TraceModeStackSampling) { |
| 4019 |
if(toggle == TraceON) { |
| 4020 |
_stackSamplerActive=TRUE; |
| 4021 |
#ifdef _WIN32 |
| 4022 |
CreateThread(NULL, /* default security attributes */ |
| 4023 |
0, /* same stack size as current thread */ |
| 4024 |
win32stackSamplerProxy, /* Thread entry point */ |
| 4025 |
NULL, /* params */ |
| 4026 |
0, /* start executing immediately */ |
| 4027 |
&stackSamplerTid); /* the thread ID */ |
| 4028 |
#else |
| 4029 |
pthread_create(&stackSamplerTid, |
| 4030 |
NULL, |
| 4031 |
stackSampler, /* explicit cast to avoid HP compilation failure */ |
| 4032 |
NULL); |
| 4033 |
#endif |
| 4034 |
|
| 4035 |
} |
| 4036 |
else { |
| 4037 |
_stackSamplerActive=FALSE; |
| 4038 |
} |
| 4039 |
} |
| 4040 |
else /* TraceHeap, TraceOptimizedHeap, or TraceModeNone */ { |
| 4041 |
disableJvmpiEvent(JVMPI_EVENT_METHOD_ENTRY); |
| 4042 |
disableJvmpiEvent(JVMPI_EVENT_METHOD_ENTRY2); |
| 4043 |
disableJvmpiEvent(JVMPI_EVENT_METHOD_EXIT); |
| 4044 |
} |
| 4045 |
} |
| 4046 |
|
| 4047 |
/* Do we want object heap information */ |
| 4048 |
if (jvmpiAgent_isTracingHeap()) { |
| 4049 |
switch(toggle) { |
| 4050 |
case TraceON: |
| 4051 |
/* RJD We *always* must instrument object free's/move's/and class unloads |
| 4052 |
in this case, because otherwise our hash table |
| 4053 |
may become inconsistent */ |
| 4054 |
|
| 4055 |
/* PA - We need to disable move,free,class Unload events when we are running in |
| 4056 |
TraceOptimized Mode - as in TraceOptimized mode we do not care |
| 4057 |
about the hashtables. If the mode is not TraceOptimizedHeap then |
| 4058 |
enable the moves and frees. |
| 4059 |
*/ |
| 4060 |
if ( _jvmpiAgent_Options.mode == TraceOptimizedHeap ) { |
| 4061 |
disableJvmpiEvent(JVMPI_EVENT_OBJECT_FREE); |
| 4062 |
disableJvmpiEvent(JVMPI_EVENT_OBJECT_MOVE); |
| 4063 |
disableJvmpiEvent(JVMPI_EVENT_CLASS_UNLOAD); |
| 4064 |
} |
| 4065 |
else /* Mode is not Optmized Heap */{ |
| 4066 |
enableJvmpiEvent(JVMPI_EVENT_OBJECT_FREE, processObjFreeEvent); |
| 4067 |
enableJvmpiEvent(JVMPI_EVENT_OBJECT_MOVE, processObjMoveEvent); |
| 4068 |
/*62852 The following events are not required to be tracked |
| 4069 |
during optimized mode */ |
| 4070 |
enableJvmpiEvent(JVMPI_EVENT_OBJECT_ALLOC, processObjAllocEvent); |
| 4071 |
enableJvmpiEvent(JVMPI_EVENT_GC_START, processGcStartEvent); |
| 4072 |
enableJvmpiEvent(JVMPI_EVENT_GC_FINISH, processGcFinishEvent); |
| 4073 |
enableJvmpiEvent(JVMPI_EVENT_CLASS_UNLOAD, processClassUnloadEvent); |
| 4074 |
} |
| 4075 |
|
| 4076 |
break; |
| 4077 |
case TraceOFF: |
| 4078 |
/* PA - We need to disable free events when we are running in |
| 4079 |
TraceOptimized Mode - as in TraceOptimized mode we do not care |
| 4080 |
about the hashtables. If the mode is not TraceOptimizedHeap then |
| 4081 |
enable the moves and frees. If we are in TraceOptimizedHeap then |
| 4082 |
enable them depending on the gc options. |
| 4083 |
*/ |
| 4084 |
if ( _jvmpiAgent_Options.mode == TraceOptimizedHeap ) { |
| 4085 |
/*62852 The following events are not required to be tracked |
| 4086 |
during optimized mode */ |
| 4087 |
disableJvmpiEvent(JVMPI_EVENT_OBJECT_ALLOC); |
| 4088 |
} |
| 4089 |
disableJvmpiEvent(JVMPI_EVENT_OBJECT_MOVE); |
| 4090 |
disableJvmpiEvent(JVMPI_EVENT_OBJECT_FREE); |
| 4091 |
disableJvmpiEvent(JVMPI_EVENT_CLASS_UNLOAD); |
| 4092 |
disableJvmpiEvent(JVMPI_EVENT_GC_START); |
| 4093 |
disableJvmpiEvent(JVMPI_EVENT_GC_FINISH); |
| 4094 |
|
| 4095 |
/* fall through to the TracePause case */ |
| 4096 |
case TracePause: |
| 4097 |
/* RJD We cannot disable object free's/move's/class unloads because |
| 4098 |
we do not clean out the hash table; we can however disable the following |
| 4099 |
events */ |
| 4100 |
disableJvmpiEvent(JVMPI_EVENT_OBJECT_ALLOC); |
| 4101 |
break; |
| 4102 |
default: |
| 4103 |
break; |
| 4104 |
} |
| 4105 |
} |
| 4106 |
|
| 4107 |
/* Do we want monitor information */ |
| 4108 |
/* Events not dealt with currently: |
| 4109 |
JVMPI_EVENT_RAW_MONITOR_CONTENDED_ENTER, |
| 4110 |
JVMPI_EVENT_RAW_MONITOR_CONTENDED_ENTERED, |
| 4111 |
JVMPI_EVENT_RAW_MONITOR_CONTENDED_EXIT |
| 4112 |
(raw monitors aren't created anywhere in the profiler, so they aren't |
| 4113 |
presently needed) |
| 4114 |
|
| 4115 |
JVMPI_EVENT_MONITOR_CONTENDED_EXIT (not currently required according to |
| 4116 |
Bluerat Specs) |
| 4117 |
*/ |
| 4118 |
|
| 4119 |
if (_jvmpiAgent_Options.monitorMode > MonitorNone) { |
| 4120 |
if (toggle == TraceON) { |
| 4121 |
|
| 4122 |
enableJvmpiEvent(JVMPI_EVENT_MONITOR_CONTENDED_ENTER, processMonitorContendedEnter); |
| 4123 |
enableJvmpiEvent(JVMPI_EVENT_MONITOR_CONTENDED_ENTERED, processMonitorContendedEntered); |
| 4124 |
/* enableJvmpiEvent(JVMPI_EVENT_MONITOR_CONTENDED_EXIT, processMonitorContendedExit); */ |
| 4125 |
enableJvmpiEvent(JVMPI_EVENT_MONITOR_WAIT, processMonitorWait); |
| 4126 |
enableJvmpiEvent(JVMPI_EVENT_MONITOR_WAITED, processMonitorWaited); |
| 4127 |
} |
| 4128 |
else { |
| 4129 |
disableJvmpiEvent(JVMPI_EVENT_MONITOR_CONTENDED_ENTER); |
| 4130 |
disableJvmpiEvent(JVMPI_EVENT_MONITOR_CONTENDED_ENTERED); |
| 4131 |
/* disableJvmpiEvent(JVMPI_EVENT_MONITOR_CONTENDED_EXIT); */ |
| 4132 |
disableJvmpiEvent(JVMPI_EVENT_MONITOR_WAIT); |
| 4133 |
disableJvmpiEvent(JVMPI_EVENT_MONITOR_WAITED); |
| 4134 |
} |
| 4135 |
} |
| 4136 |
|
| 4137 |
|
| 4138 |
|
| 4139 |
} |
| 4140 |
|
| 4141 |
/** startListenerShouldBlock -- ENCAPSULATES LOGIC FOR BLOCKING STARTLISTENER ************* |
| 4142 |
* |
| 4143 |
* This function holds the logic telling whether the call to ra_startListener |
| 4144 |
* should block until a RAC connects to this agent. |
| 4145 |
* |
| 4146 |
* This logic is used in two places, which is why I pulled it into this |
| 4147 |
* function rather than open-coding it. If anybody changes this logic, |
| 4148 |
* it'll change in all the places where it's used. |
| 4149 |
* |
| 4150 |
* This answer this function gives does not make sense in standalone mode, |
| 4151 |
* because in that mode we never call ra_startListener. |
| 4152 |
*/ |
| 4153 |
static char startListenerShouldBlock() |
| 4154 |
{ |
| 4155 |
return !_jvmpiAgent_Options.enabled; |
| 4156 |
} |
| 4157 |
|
| 4158 |
/** load_agent_extension_library -- AGENT EXTENSION LOADER ************* |
| 4159 |
* This function loads whatever library is named by the |
| 4160 |
* _jvmpiAgent.extensionLibrary option variable, unless it's the empty string. |
| 4161 |
*/ |
| 4162 |
|
| 4163 |
static void load_agent_extension_library() |
| 4164 |
{ |
| 4165 |
char* extLib = _jvmpiAgent_Options.extensionLibrary; |
| 4166 |
if (extLib[0] != '\0') { |
| 4167 |
DLL_REFERENCE module; |
| 4168 |
module = LOAD_LIBRARY(extLib); |
| 4169 |
#ifdef MVS |
| 4170 |
if (module == NULL) { |
| 4171 |
/* try converting ASCII to EBCDIC */ |
| 4172 |
extLib = strdup(extLib); |
| 4173 |
__atoe(extLib); |
| 4174 |
module = LOAD_LIBRARY(extLib); |
| 4175 |
free(extLib); |
| 4176 |
} |
| 4177 |
#endif |
| 4178 |
|
| 4179 |
if (module != NULL) { |
| 4180 |
AgentExtensionInitFunction agent_extension_init; |
| 4181 |
#ifdef MVS |
| 4182 |
#pragma convlit(suspend) |
| 4183 |
#endif |
| 4184 |
agent_extension_init = (AgentExtensionInitFunction)RESOLVE_ENTRY_POINT(module, "agent_extension_init"); |
| 4185 |
#ifdef MVS |
| 4186 |
#pragma convlit(resume) |
| 4187 |
#endif |
| 4188 |
if (agent_extension_init != NULL) { |
| 4189 |
AgentExtensionInitArgs agent_extension_init_args; |
| 4190 |
agent_extension_init_args.api_version = 1; |
| 4191 |
agent_extension_init_args.options = _jvmpiAgent_Options.invocationOptions; |
| 4192 |
agent_extension_init_args.jvm = _jvmpiAgent_jvm; |
| 4193 |
agent_extension_init_args.jvmpi_interface = _jvmpiAgent_jvmpiInterface; |
| 4194 |
agent_extension_init_args.set_command_handler = agentExtensionSetCommandHandler; |
| 4195 |
agent_extension_init_args.set_event_handler = agentExtensionSetEventHandler; |
| 4196 |
agent_extension_init_args.agent_handle = _jvmpiAgent_bindingStorage; |
| 4197 |
|
| 4198 |
/* |
| 4199 |
* Compute the "safety flag." |
| 4200 |
* This flag is true if it's safe for the agent extension |
| 4201 |
* to call "agentExtensionSetEventHandler" from inside |
| 4202 |
* "agent_extension_init" or false if it's not safe. |
| 4203 |
* |
| 4204 |
* It's safe if ra_startListener blocks until a RAC connects, |
| 4205 |
* and it's safe in standalone mode, but otherwise it's not safe. |
| 4206 |
* |
| 4207 |
* If the "blocking" flag passed to ra_startListener changes, |
| 4208 |
* this code should change too. |
| 4209 |
*/ |
| 4210 |
agent_extension_init_args.event_enable_safety_flag = |
| 4211 |
(_jvmpiAgent_Options.standalone || startListenerShouldBlock()); |
| 4212 |
|
| 4213 |
|
| 4214 |
/* Call the agent extension init function. */ |
| 4215 |
/* See comments at agentExtensionSetEventHandler about this. */ |
| 4216 |
agent_extension_init(&agent_extension_init_args); |
| 4217 |
} |
| 4218 |
else { |
| 4219 |
sendErrorMessage(RA_SEVERE, "IWAT5001E", "Profiler failed to find agent_extension_init entry point in library; continuing.\n"); |
| 4220 |
} |
| 4221 |
} |
| 4222 |
else { |
| 4223 |
sendErrorMessage(RA_SEVERE, "IWAT5000E", "Profiler failed to load agent extension library; continuing.\n"); |
| 4224 |
} |
| 4225 |
} |
| 4226 |
} |
| 4227 |
|
| 4228 |
|
| 4229 |
|
| 4230 |
/** _JVMPIAGENT_NOTIFY_MESSAGE -- AGENT CONTROLLER MESSAGE PUMP ************* |
| 4231 |
* Callback function used to process messages from the Agent Controller. This |
| 4232 |
* is the entry point for all control messages comming from the agent controler. |
| 4233 |
* It is the responsibility of the agent to react to these messages. |
| 4234 |
* |
| 4235 |
* This handler reacts to RA_AGENT_CONTROLER_AVAILABLE |
| 4236 |
* by checking the configuration for an extension library name, |
| 4237 |
* and loading and initializing that library if it's found. |
| 4238 |
*/ |
| 4239 |
|
| 4240 |
#ifdef MVS /* 174190 */ |
| 4241 |
#pragma convlit(suspend) |
| 4242 |
#endif |
| 4243 |
|
| 4244 |
static void _jvmpiAgent_notify_message(ra_command_t *command) { |
| 4245 |
/*------------------------------------------------------------* |
| 4246 |
* Route this message to an agent extension if one is configured and listening |
| 4247 |
*/ |
| 4248 |
if (agent_extension_command_handler != NULL) { |
| 4249 |
agent_extension_command_handler(command); |
| 4250 |
} |
| 4251 |
/*------------------------------------------------------------*/ |
| 4252 |
|
| 4253 |
/* Handle the command */ |
| 4254 |
switch(command->tag) { |
| 4255 |
|
| 4256 |
case RA_AGENT_CONTROLER_AVAILABLE: |
| 4257 |
{ |
| 4258 |
ra_agentConfigList_t* clist = ra_getDefaultConfiguration(_jvmpiAgent_bindingStorage); |
| 4259 |
ra_agentConfigListEntry_t* listEntry; |
| 4260 |
for (listEntry = clist->head; listEntry != NULL; listEntry = listEntry->next) { |
| 4261 |
ra_agentConfigEntry_t* e = &listEntry->entry; |
| 4262 |
const char* name, *type, *value; |
| 4263 |
if (e->name.length == 0) name = ""; |
| 4264 |
else name = e->name.data; |
| 4265 |
if (e->type.length == 0) type = ""; |
| 4266 |
else type= e->type.data; |
| 4267 |
if (e->value.length == 0) value = ""; |
| 4268 |
else value = e->value.data; |
| 4269 |
if ((strcmp(name, "piAgentExtension") == 0) && |
| 4270 |
(strcmp(type, "libraryName") == 0)) |
| 4271 |
{ |
| 4272 |
/* |
| 4273 |
* An empty value string means "don't load anything" |
| 4274 |
*/ |
| 4275 |
if (value[0] != '\0') { |
| 4276 |
/* only load agent extensions if we could successfully copy |
| 4277 |
the value string */ |
| 4278 |
if (strcpyrealloc(&_jvmpiAgent_Options.extensionLibrary, value) == 0) { |
| 4279 |
load_agent_extension_library(); |
| 4280 |
/* bugzilla 66599 -- only load agent extension once */ |
| 4281 |
break; |
| 4282 |
} |
| 4283 |
} |
| 4284 |
} |
| 4285 |
} |
| 4286 |
break; |
| 4287 |
} |
| 4288 |
/* Called by the local monitor to start IO at this point */ |
| 4289 |
case RA_START_MONITORING_AGENT_REMOTE: |
| 4290 |
case RA_START_MONITORING_AGENT_LOCAL: |
| 4291 |
{ |
| 4292 |
int result, type=0; |
| 4293 |
ThreadLocalStorage *tps = jvmpiAgent_getThreadLocalStorage(0); /* Grab the I/O buffer from the static private storage */ |
| 4294 |
|
| 4295 |
if(!_jvmpiAgent_isMonitored && !_jvmpiAgent_isSuspended) { |
| 4296 |
/* Set target handle type - 171664 added this line*/ |
| 4297 |
|
| 4298 |
result=-1; |
| 4299 |
if(command->tag==RA_START_MONITORING_AGENT_LOCAL) { |
| 4300 |
|
| 4301 |
_jvmpiAgent_Options.targetHdl.dtarget = RA_SHAREDMEMORY; |
| 4302 |
type=0; |
| 4303 |
|
| 4304 |
/* transfer data via shared memory */ |
| 4305 |
result = ra_attachToShm(command->info.start_monitor_local.file.data, |
| 4306 |
&_jvmpiAgent_Options.targetHdl.dtargetHdl.shmHdl); |
| 4307 |
} |
| 4308 |
else if(command->tag==RA_START_MONITORING_AGENT_REMOTE) { |
| 4309 |
/* Set target handle type */ |
| 4310 |
_jvmpiAgent_Options.targetHdl.dtarget = RA_SOCKET; |
| 4311 |
type=1; |
| 4312 |
|
| 4313 |
/* Connect to the remote monitor's listening port as indicated in the message */ |
| 4314 |
result=ra_connectToTCPServer(command->info.start_monitor_remote.ip, |
| 4315 |
(unsigned short)command->info.start_monitor_remote.port, |
| 4316 |
&_jvmpiAgent_Options.targetHdl.dtargetHdl.socketFD); |
| 4317 |
} |
| 4318 |
|
| 4319 |
if(result != 0) { |
| 4320 |
#ifdef MVS |
| 4321 |
#pragma convlit(resume) |
| 4322 |
#endif |
| 4323 |
char *connectType[2]={"SharedMemory","Socket"}; /* add type/returncode to error msg if connect failed * 139537 */ |
| 4324 |
char errMsg[2000]; |
| 4325 |
sprintf(errMsg,"Profiler unable to establish connection with Agent Controller via %s. Returncode from attempt is %d.", |
| 4326 |
connectType[type], result); |
| 4327 |
sendErrorMessage(RA_SEVERE,"0",errMsg); |
| 4328 |
#ifdef MVS |
| 4329 |
#pragma convlit(suspend) |
| 4330 |
#endif |
| 4331 |
break; |
| 4332 |
} |
| 4333 |
_jvmpiAgent_isMonitored=TRUE; |
| 4334 |
} |
| 4335 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 4336 |
dumpMethodEventCounts(); printf("Start Monitoring ... begin\n"); fflush(stdout); |
| 4337 |
#endif |
| 4338 |
|
| 4339 |
/* In application mode we never turn on IO here */ |
| 4340 |
if (_jvmpiAgent_suspendIO && !_jvmpiAgent_Options.application) { |
| 4341 |
|
| 4342 |
if(_jvmpiAgent_isJVMInitDone) { |
| 4343 |
JNIEnv *env; |
| 4344 |
/* Attach the current thread to the JVM */ |
| 4345 |
if(ATTACH_THREAD(env)) { |
| 4346 |
break; |
| 4347 |
} |
| 4348 |
|
| 4349 |
/* Start tracing the application now */ |
| 4350 |
if(_jvmpiAgent_isSuspended) { |
| 4351 |
resumeTracing(); |
| 4352 |
} |
| 4353 |
else { |
| 4354 |
startTracing(FALSE); |
| 4355 |
} |
| 4356 |
|
| 4357 |
DETACH_THREAD(); |
| 4358 |
} |
| 4359 |
else { |
| 4360 |
/* Re-enable IO */ |
| 4361 |
_jvmpiAgent_suspendIO = 0; |
| 4362 |
} |
| 4363 |
} |
| 4364 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 4365 |
printf("Start Monitoring ... done\n"); fflush(stdout); |
| 4366 |
#endif |
| 4367 |
break; |
| 4368 |
} |
| 4369 |
/* Called by the remote monitor to turn off IO */ |
| 4370 |
case RA_STOP_MONITORING_AGENT: |
| 4371 |
{ |
| 4372 |
/* Don't do anything if IO is suspended */ |
| 4373 |
if(!_jvmpiAgent_suspendIO) { |
| 4374 |
JNIEnv *env; |
| 4375 |
ThreadLocalStorage *tps=jvmpiAgent_getThreadLocalStorage(0); |
| 4376 |
|
| 4377 |
if(_jvmpiAgent_isJVMInitDone) { |
| 4378 |
if(ATTACH_THREAD(env)) { |
| 4379 |
break; |
| 4380 |
} |
| 4381 |
|
| 4382 |
suspendTracing(TracePause); |
| 4383 |
|
| 4384 |
DETACH_THREAD(); |
| 4385 |
} |
| 4386 |
else { |
| 4387 |
/* In the case where we stop traing before we get the initDone event. We need to just set the |
| 4388 |
IO to off so we don't start tracing when we get the initDone event |
| 4389 |
*/ |
| 4390 |
_jvmpiAgent_suspendIO = 1; |
| 4391 |
} |
| 4392 |
} |
| 4393 |
break; |
| 4394 |
} |
| 4395 |
case RA_DETACH_FROM_AGENT: |
| 4396 |
{ |
| 4397 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 4398 |
dumpMethodEventCounts(); |
| 4399 |
printf("Detach_Agent ... begin: suspendIO=%d, isJVMInitDone=%d\n", |
| 4400 |
_jvmpiAgent_suspendIO, _jvmpiAgent_isJVMInitDone); fflush(stdout); |
| 4401 |
#endif |
| 4402 |
/* Don't do anything if IO is suspended */ |
| 4403 |
if(!_jvmpiAgent_suspendIO) { |
| 4404 |
JNIEnv *env; |
| 4405 |
ThreadLocalStorage *tps=jvmpiAgent_getThreadLocalStorage(0); |
| 4406 |
|
| 4407 |
if(_jvmpiAgent_isJVMInitDone) { |
| 4408 |
if(ATTACH_THREAD(env)) { |
| 4409 |
break; |
| 4410 |
} |
| 4411 |
|
| 4412 |
stopTracing(); |
| 4413 |
|
| 4414 |
DETACH_THREAD(); |
| 4415 |
} |
| 4416 |
else { |
| 4417 |
/* In the case where we stop tracing before we get the initDone event. We need to just set the |
| 4418 |
IO to off so we don't start tracing when we get the initDone event |
| 4419 |
*/ |
| 4420 |
_jvmpiAgent_suspendIO = 1; |
| 4421 |
} |
| 4422 |
} |
| 4423 |
else { |
| 4424 |
JNIEnv *env; |
| 4425 |
ThreadLocalStorage *tps=jvmpiAgent_getThreadLocalStorage(0); |
| 4426 |
if(_jvmpiAgent_isJVMInitDone) { |
| 4427 |
if(ATTACH_THREAD(env)) { |
| 4428 |
break; |
| 4429 |
} |
| 4430 |
toggleActiveJvmpiEvents(TraceOFF); |
| 4431 |
DETACH_THREAD(); |
| 4432 |
} |
| 4433 |
/* Clean up all our resources for this trace */ |
| 4434 |
cleanUpAllTraceResources(); |
| 4435 |
} |
| 4436 |
|
| 4437 |
/* If we have been monitoring THEN */ |
| 4438 |
if (_jvmpiAgent_isMonitored) { |
| 4439 |
|
| 4440 |
if(_jvmpiAgent_Options.targetHdl.dtarget == RA_SHAREDMEMORY) { |
| 4441 |
/* Stop flushing shm buffer */ |
| 4442 |
ra_stopFlushingShm(&_jvmpiAgent_Options.targetHdl.dtargetHdl.shmHdl); /* 175248 */ |
| 4443 |
} |
| 4444 |
else if(_jvmpiAgent_Options.targetHdl.dtarget == RA_SOCKET) { |
| 4445 |
ra_closeSocket(_jvmpiAgent_Options.targetHdl.dtargetHdl.socketFD); |
| 4446 |
} |
| 4447 |
_jvmpiAgent_isMonitored=FALSE; |
| 4448 |
_jvmpiAgent_isSuspended=FALSE; |
| 4449 |
} |
| 4450 |
#if defined (_DEBUG) && !defined (MVS) && !defined (__OS400__) |
| 4451 |
printf("Detach_Agent ... done\n"); fflush(stdout); |
| 4452 |
#endif |
| 4453 |
break; |
| 4454 |
} |
| 4455 |
case RA_CUSTOM_COMMAND: |
| 4456 |
{ |
| 4457 |
jint failed; |
| 4458 |
JNIEnv *env; |
| 4459 |
if(strcmp(command->info.custom_command.message.data, "RESUME")==0) { |
| 4460 |
/* Grab the I/O buffer from the static private storage */ |
| 4461 |
ThreadLocalStorage *tps = jvmpiAgent_getThreadLocalStorage(0); |
| 4462 |
/* RKD: resume should be ignored from an IO standpoint. |
| 4463 |
jvmpiAgent_printVMResume(tps); |
| 4464 |
*/ |
| 4465 |
ra_releaseVMLock(); |
| 4466 |
} |
| 4467 |
else if(strcmp(command->info.custom_command.message.data, "MARKHEAP")==0) { |
| 4468 |
if(_jvmpiAgent_isJVMInitDone && !_jvmShutDown) { |
| 4469 |
failed=ATTACH_THREAD(env); |
| 4470 |
if(!failed) { |
| 4471 |
failed=analyseHeap(JVMPI_DUMP_LEVEL_0); |
| 4472 |
DETACH_THREAD(); |
| 4473 |
} |
| 4474 |
} |
| 4475 |
} |
| 4476 |
else if(strcmp(command->info.custom_command.message.data, "ANALYSEHEAP")==0) { |
| 4477 |
if(_jvmpiAgent_isJVMInitDone && !_jvmShutDown) { |
| 4478 |
failed=ATTACH_THREAD(env); |
| 4479 |
if(!failed) { |
| 4480 |
runGC(); |
| 4481 |
failed=analyseHeap(JVMPI_DUMP_LEVEL_1); |
| 4482 |
DETACH_THREAD(); |
| 4483 |
} |
| 4484 |
} |
| 4485 |
} |
| 4486 |
else if(strcmp(command->info.custom_command.message.data, "TERMINATE")==0) { |
| 4487 |
_jvmpiAgent_jvmpiInterface->ProfilerExit(0); |
| 4488 |
} |
| 4489 |
else if(strcmp(command->info.custom_command.message.data, "APPLYFILTERS")==0) { |
| 4490 |
jvmpiAgent_applyFilters(); |
| 4491 |
|
| 4492 |
/* Check the current filter criteria against existing information */ |
| 4493 |
jvmpiAgent_resetTraceFlags(); |
| 4494 |
} |
| 4495 |
else if(strcmp(command->info.custom_command.message.data, "RUNGC")==0) { |
| 4496 |
if(_jvmpiAgent_isJVMInitDone && !_jvmShutDown) { |
| 4497 |
failed=ATTACH_THREAD(env); |
| 4498 |
if(!failed) { |
| 4499 |
runGC(); |
| 4500 |
DETACH_THREAD(); |
| 4501 |
} |
| 4502 |
} |
| 4503 |
} |
| 4504 |
/* Piyush Agarwal */ |
| 4505 |
/* Change made to enable RAC connected file transfer */ |
| 4506 |
else if(strcmp(command->info.custom_command.message.data, "OPTHEAP")==0) { |
| 4507 |
if(_jvmpiAgent_isJVMInitDone && !_jvmShutDown) { |
| 4508 |
ThreadLocalStorage *tps=jvmpiAgent_getThreadLocalStorage(0); |
| 4509 |
failed=ATTACH_THREAD(env); |
| 4510 |
if(!failed) { |
| 4511 |
runGC(); |
| 4512 |
processRACDataDumpRequest(FALSE,command->info.custom_command.context) ; |
| 4513 |
DETACH_THREAD(); |
| 4514 |
} |
| 4515 |
} |
| 4516 |
} |
| 4517 |
else if(strcmp(command->info.custom_command.message.data, "FINAL_OPTHEAP")==0) { |
| 4518 |
if(_jvmpiAgent_isJVMInitDone && !_jvmShutDown) { |
| 4519 |
ThreadLocalStorage *tps=jvmpiAgent_getThreadLocalStorage(0); |
| 4520 |
failed=ATTACH_THREAD(env); |
| 4521 |
if(!failed) { |
| 4522 |
runGC(); |
| 4523 |
processRACDataDumpRequest(TRUE,command->info.custom_command.context) ; |
| 4524 |
DETACH_THREAD(); |
| 4525 |
} |
| 4526 |
} |
| 4527 |
} |
| 4528 |
/* Indicates a headless client. We will only need to take an action if we are in |
| 4529 |
application mode. */ |
| 4530 |
else if(strcmp(command->info.custom_command.message.data, "HEADLESS")==0) { |
| 4531 |
/* Start profiling the agent (simulating the effect of a JNI call). */ |
| 4532 |
if (_jvmpiAgent_Options.application) { |
| 4533 |
/* Bug 71507 : Do not start profiling if it is applicationControlled */ |
| 4534 |
if(_jvmpiAgent_Options.enabled) { |
| 4535 |
Java_org_eclipse_hyades_collection_profiler_Profiler_startProfiling0((JNIEnv *)NULL, (JOBJECT)NULL, (jboolean)FALSE, 0); |
| 4536 |
} |
| 4537 |
} |
| 4538 |
} |
| 4539 |
/* Bug 64712 */ |
| 4540 |
else if(strcmp(command->info.custom_command.message.data, "KILLED")==0) { |
| 4541 |
stopTracing(); |
| 4542 |
} |
| 4543 |
/* Bug 64712 */ |
| 4544 |
else if(strcmp(command->info.custom_command.message.data, "COLLECTDATA")==0) { |
| 4545 |
/* Pre-aggregation */ |
| 4546 |
/* Dump all the threads' statistics */ |
| 4547 |
if (_jvmpiAgent_Options.compressLevel==CompressAggregate) { /* 134635 */ |
| 4548 |
if (!_jvmpiAgent_suspendIO) { |
| 4549 |
printAllThreadAgData(); /* 140009 */ |
| 4550 |
} |
| 4551 |
} |
| 4552 |
} |
| 4553 |
|
| 4554 |
break; |
| 4555 |
} |
| 4556 |
case RA_SET_NAME_VALUE_PAIR: |
| 4557 |
{ |
| 4558 |
if(strcmp(command->info.set_nv_pair.type.data, "SETOPTION")==0) { |
| 4559 |
jvmpiAgent_SetProfileOption(command->info.set_nv_pair.name.data, |
| 4560 |
command->info.set_nv_pair.value.data); |
| 4561 |
} |
| 4562 |
/* RKD: The SETFILTER name value pair is ffor complicance with the V4 UI and V5 filters not containing method detail */ |
| 4563 |
else if(strcmp(command->info.set_nv_pair.type.data, "SETFILTER")==0) { |
| 4564 |
jvmpiAgent_addFilter(command->info.set_nv_pair.name.data, NULL, !strcmp(command->info.set_nv_pair.value.data,"INCLUDE") ? INCLUDE : EXCLUDE); |
| 4565 |
} |
| 4566 |
else if(strcmp(command->info.set_nv_pair.type.data, "SETMETHODFILTER")==0) { |
| 4567 |
char *separator=strchr(command->info.set_nv_pair.name.data, ' '); |
| 4568 |
if(separator) { |
| 4569 |
*separator='\0'; |
| 4570 |
jvmpiAgent_addFilter(command->info.set_nv_pair.name.data, separator+1, !strcmp(command->info.set_nv_pair.value.data,"INCLUDE") ? INCLUDE : EXCLUDE); |
| 4571 |
} |
| 4572 |
} |
| 4573 |
break; |
| 4574 |
} |
| 4575 |
default: break; |
| 4576 |
} |
| 4577 |
} |
| 4578 |
|
| 4579 |
#ifdef MVS /* 174190 */ |
| 4580 |
#pragma convlit(resume) |
| 4581 |
#endif |
| 4582 |
|
| 4583 |
|
| 4584 |
/** JVM_ON_LOAD *************************************************************** |
| 4585 |
* The entry point for the profiler. This function is called by the JVM if |
| 4586 |
* the .dll is provided on the -Xrun parameter when the JVM is launched. This |
| 4587 |
* function is called at the very bootstrap level of the JVM before much |
| 4588 |
* has happened. |
| 4589 |
*/ |
| 4590 |
|
| 4591 |
|
| 4592 |
|
| 4593 |
#if defined __cplusplus |
| 4594 |
extern "C" { |
| 4595 |
#endif |
| 4596 |
JNIEXPORT jint JNICALL JVM_OnLoad(JavaVM *vm, |
| 4597 |
char *options, |
| 4598 |
void *reserved) { |
| 4599 |
int res; |
| 4600 |
char * buffer; |
| 4601 |
int bogus; |
| 4602 |
|
| 4603 |
initializeJvmpiAgentOptionsDefaults(); |
| 4604 |
|
| 4605 |
determineTicksPerMicrosecond(&bogus); |
| 4606 |
|
| 4607 |
/* Turn IO off until we need to start tracing */ |
| 4608 |
_jvmpiAgent_suspendIO = 1; |
| 4609 |
|
| 4610 |
|
| 4611 |
/* Establish panic exit handler */ |
| 4612 |
signal(SIGABRT, cleanupAndExit); |
| 4613 |
signal(SIGINT, cleanupAndExit); |
| 4614 |
signal(SIGTERM, cleanupAndExit); |
| 4615 |
|
| 4616 |
/* Initialize the global collation value */ |
| 4617 |
jvmpiAgent_initializeSegmentedValue(&_jvmpiAgent_collation, 0); |
| 4618 |
|
| 4619 |
/* Determine start time from here */ |
| 4620 |
jvmpiAgent_collectStartTimeInformation(); |
| 4621 |
|
| 4622 |
/* Create the filter tables. We will assume that this JVM uses the '/' package |
| 4623 |
separator. This can be overriddden during tracing by the setpathDelimiter |
| 4624 |
function. |
| 4625 |
*/ |
| 4626 |
#ifdef __OS400__ |
| 4627 |
#pragma convert(819) |
| 4628 |
#endif |
| 4629 |
|
| 4630 |
jvmpiAgent_initializeFilters('/'); |
| 4631 |
|
| 4632 |
/* Create the trigger tables. We will assume that this JVM uses the '/' package |
| 4633 |
separator. This can be overriddden during tracing by the setpathDelimiter |
| 4634 |
function. |
| 4635 |
*/ |
| 4636 |
jvmpiAgent_initializeTriggers('/'); |
| 4637 |
#ifdef __OS400__ |
| 4638 |
#pragma convert(0) |
| 4639 |
#endif |
| 4640 |
|
| 4641 |
|
| 4642 |
/* Tuck away the JVM pointer for future use */ |
| 4643 |
_jvmpiAgent_jvm = vm; |
| 4644 |
|
| 4645 |
/* Resolve to the JVMPI environment */ |
| 4646 |
#if defined __cplusplus && defined _HPUX |
| 4647 |
res = ENV(_jvmpiAgent_jvm)->GetEnv((void **)&_jvmpiAgent_jvmpiInterface, JVMPI_VERSION_1); |
| 4648 |
#else |
| 4649 |
res = (*_jvmpiAgent_jvm)->GetEnv(_jvmpiAgent_jvm, (void **)&_jvmpiAgent_jvmpiInterface, JVMPI_VERSION_1); |
| 4650 |
#endif |
| 4651 |
if (res < 0 || !_jvmpiAgent_jvmpiInterface) { |
| 4652 |
#ifdef MVS /* 174190 */ |
| 4653 |
#pragma convlit(suspend) |
| 4654 |
#endif |
| 4655 |
fprintf(stderr, " Could not resolve to JVMPI interface\n"); |
| 4656 |
fflush(stderr); |
| 4657 |
#ifdef MVS /* 174190 */ |
| 4658 |
#pragma convlit(resume) |
| 4659 |
#endif |
| 4660 |
return JNI_ERR; |
| 4661 |
} |
| 4662 |
|
| 4663 |
/* Make a global copy of the options for the agent to print later */ |
| 4664 |
if (options) { |
| 4665 |
_jvmpiAgent_Options.invocationOptions = (char*)jvmpiAgent_Calloc(strlen(options)+1); |
| 4666 |
strcpy(_jvmpiAgent_Options.invocationOptions, options); |
| 4667 |
} else { |
| 4668 |
_jvmpiAgent_Options.invocationOptions = ""; /* 101734 */ |
| 4669 |
} |
| 4670 |
|
| 4671 |
/* Process the command line options, continue initialization only if this is successful */ |
| 4672 |
if (jvmpiAgent_ProcessInvocationOptions(options) == 0) { |
| 4673 |
#ifdef MVS /* 174190 */ |
| 4674 |
char *tmpname, *tmpType; |
| 4675 |
#endif |
| 4676 |
|
| 4677 |
if (_jvmpiAgent_Options.standalone) { |
| 4678 |
jvmpiAgent_processProfile(_jvmpiAgent_Options.profileFile); |
| 4679 |
/* Satish: perhaps we should move following code from the bottom of this function |
| 4680 |
* to here. |
| 4681 |
*/ |
| 4682 |
/* jvmpiAgent_processFilters(_jvmpiAgent_Options.filterFileName); */ |
| 4683 |
/* jvmpiAgent_processTriggers(_jvmpiAgent_Options.triggerFileName); */ |
| 4684 |
} |
| 4685 |
|
| 4686 |
/* Now command-line options, as well as profile has been processed, check consistency */ |
| 4687 |
if (jvmpiAgent_CheckOptionsConsistency() != 0) { |
| 4688 |
#ifdef MVS |
| 4689 |
#pragma convlit(suspend) |
| 4690 |
#endif |
| 4691 |
fprintf(stderr, "Specified options are not consistent\n"); |
| 4692 |
#ifdef MVS |
| 4693 |
#pragma convlit(resume) |
| 4694 |
#endif |
| 4695 |
fflush(stderr); |
| 4696 |
printUsage(); |
| 4697 |
return JNI_ERR; |
| 4698 |
} |
| 4699 |
|
| 4700 |
/* Set up the symbol table */ |
| 4701 |
jvmpiAgent_InitializeSymbolTable(); |
| 4702 |
|
| 4703 |
/* Initialize the synchronization lock */ |
| 4704 |
ra_initializeLock(&_jvmpiAgent_synchLock); |
| 4705 |
|
| 4706 |
/* Grab the I/O buffer from the static private storage */ |
| 4707 |
buffer = jvmpiAgent_getThreadLocalStorage(0)->buffer; |
| 4708 |
|
| 4709 |
/* Set the JVMPI pointer to the Agents notify_event handler function */ |
| 4710 |
_jvmpiAgent_jvmpiInterface->NotifyEvent = notify_event; |
| 4711 |
|
| 4712 |
/* Enable all of the appropriate events depending upon our mode */ |
| 4713 |
enableGlobalJvmpiEvents(_jvmpiAgent_Options.mode); |
| 4714 |
|
| 4715 |
/* Set the dynamic event pointers */ |
| 4716 |
setDynamicEventHandlers(); |
| 4717 |
|
| 4718 |
/* Initialize the communication layer bindings */ |
| 4719 |
#ifdef MVS /* 174190 */ |
| 4720 |
tmpname = (char *)malloc(strlen(_jvmpiAgent_Options.processName) + 1); |
| 4721 |
strcpy(tmpname, _jvmpiAgent_Options.processName); |
| 4722 |
__atoe(tmpname); |
| 4723 |
tmpType = (char *)malloc(strlen(_jvmpiAgent_Options.processType) + 1); |
| 4724 |
strcpy(tmpType, _jvmpiAgent_Options.processType); |
| 4725 |
__atoe(tmpType); |
| 4726 |
_jvmpiAgent_bindingStorage = ra_initializeBindings(tmpname, |
| 4727 |
tmpType, |
| 4728 |
_jvmpiAgent_notify_message, |
| 4729 |
_jvmpiAgent_Options.standalone); |
| 4730 |
free(tmpname); |
| 4731 |
free(tmpType); |
| 4732 |
#else |
| 4733 |
#ifdef _HPUX |
| 4734 |
_jvmpiAgent_bindingStorage=ra_initializeBindings(_jvmpiAgent_Options.processName, |
| 4735 |
_jvmpiAgent_Options.processType, |
| 4736 |
_jvmpiAgent_notify_message, |
| 4737 |
(enum _BOOL)_jvmpiAgent_Options.standalone); |
| 4738 |
#else |
| 4739 |
_jvmpiAgent_bindingStorage=ra_initializeBindings(_jvmpiAgent_Options.processName, |
| 4740 |
_jvmpiAgent_Options.processType, |
| 4741 |
_jvmpiAgent_notify_message, |
| 4742 |
_jvmpiAgent_Options.standalone); |
| 4743 |
#endif |
| 4744 |
#endif |
| 4745 |
|
| 4746 |
/* Do setup for Agent when being controlled by the "Agent Controller" */ |
| 4747 |
if (!_jvmpiAgent_Options.standalone) { |
| 4748 |
/*## probably need this global so that I can kill the thread on shutdown */ |
| 4749 |
TID *tid; |
| 4750 |
|
| 4751 |
/* If the trace is "enabled" we don't want to block on invocation. Otherwise |
| 4752 |
we are in "controlled" mode, wait until the controller sends a |
| 4753 |
RA_CUSTOM_COMMAND with "RESUME" message. |
| 4754 |
*/ |
| 4755 |
tid=ra_startListener(_jvmpiAgent_bindingStorage, startListenerShouldBlock()); |
| 4756 |
_jvmpiAgent_isListenerUnblocked = TRUE; |
| 4757 |
|
| 4758 |
/*------------------------------------------------------------* |
| 4759 |
* startListener returned. That means we have processed the |
| 4760 |
* initial message from the RAC, RA_AGENT_CONTROLER_AVAILABLE. |
| 4761 |
* And *that* means we have loaded and initialized the agent |
| 4762 |
* extension, if one was configured. |
| 4763 |
* |
| 4764 |
* See comments at agentExtensionSetEventHandler for more |
| 4765 |
* about initializing agent extensions and having them |
| 4766 |
* enable JVMPI events. |
| 4767 |
*/ |
| 4768 |
{ |
| 4769 |
/* Process the initial agent extension event enable requests */ |
| 4770 |
int i; |
| 4771 |
for (i = 0; i < JVMPI_MAX_EVENT_TYPE_VAL; i++) { |
| 4772 |
if (agent_extension_handlers[i] != NULL) { |
| 4773 |
_jvmpiAgent_jvmpiInterface->EnableEvent(i, 0); |
| 4774 |
} |
| 4775 |
} |
| 4776 |
} |
| 4777 |
} |
| 4778 |
else { |
| 4779 |
/* Standalone mode */ |
| 4780 |
ThreadLocalStorage *tps=jvmpiAgent_getThreadLocalStorage(0); |
| 4781 |
|
| 4782 |
/*------------------------------------------------------------* |
| 4783 |
* If the extensionLibrary option is set, load and |
| 4784 |
* initialize an agent extension. |
| 4785 |
* |
| 4786 |
* In non-stand-alone mode, this will be done based on |
| 4787 |
* the settings available when the RA_AGENT_CONTROLER_AVAILABLE |
| 4788 |
* message arrives. |
| 4789 |
* |
| 4790 |
* In stand-alone mode, we don't need to worry about enabling |
| 4791 |
* events after the agent extension initializes; see notes at |
| 4792 |
* agentExtensionSetEventHandler for an explanation. |
| 4793 |
*/ |
| 4794 |
if (_jvmpiAgent_Options.extensionLibrary[0] != '\0') { |
| 4795 |
load_agent_extension_library(); |
| 4796 |
} |
| 4797 |
|
| 4798 |
ra_initializeVMLock(); |
| 4799 |
#ifdef MVS /* 174190 */ |
| 4800 |
#pragma convlit(suspend) |
| 4801 |
__atoe(_jvmpiAgent_Options.outputFileName); |
| 4802 |
#endif |
| 4803 |
/* Open the output file if we are doing file I/O */ |
| 4804 |
jvmpiAgent_initializeStandaloneIO(); |
| 4805 |
#ifdef MVS /* 174190 */ |
| 4806 |
#pragma convlit(resume) |
| 4807 |
#endif |
| 4808 |
_jvmpiAgent_suspendIO = 0; |
| 4809 |
|
| 4810 |
/* Satish: As a principle, any configuartion file must be processed before, applying |
| 4811 |
* any business logic. Perhaps, we should move these just processing command-line |
| 4812 |
* options. I am moving the call jvmpiAgent_processProfile(_jvmpiAgent_Options.profileFile) |
| 4813 |
* there, because profile specifications might create inconsistencies that must |
| 4814 |
* be checked before doing anything. |
| 4815 |
*/ |
| 4816 |
/* jvmpiAgent_processProfile(_jvmpiAgent_Options.profileFile); */ |
| 4817 |
jvmpiAgent_processFilters(_jvmpiAgent_Options.filterFileName); |
| 4818 |
jvmpiAgent_processTriggers(_jvmpiAgent_Options.triggerFileName); |
| 4819 |
|
| 4820 |
} |
| 4821 |
|
| 4822 |
return JNI_OK; |
| 4823 |
} |
| 4824 |
else { |
| 4825 |
printUsage(); |
| 4826 |
return JNI_ERR; |
| 4827 |
} |
| 4828 |
} |
| 4829 |
|
| 4830 |
/** Giri: <Defect 64462> This method is performs all the optHeap related setup necessary within |
| 4831 |
the agent. Previously, we were doing this set-up only within JVM_OnLoad(), so if we tried |
| 4832 |
to attach a running process, and then tried to do optHeap related operations, the setup |
| 4833 |
would not have happened, and the JVM would crash **/ |
| 4834 |
|
| 4835 |
static void jvmpiAgent_DoOptHeapSetup() |
| 4836 |
{ |
| 4837 |
if (_optHeapSetupDone) { |
| 4838 |
return; |
| 4839 |
} |
| 4840 |
|
| 4841 |
_optHeapSetupDone = TRUE; /* We need to do this set-up only once */ |
| 4842 |
_jvmpiAgent_optHeapCallBack.ohdcb = sendHeapDumpInformation ; |
| 4843 |
|
| 4844 |
StatelessHeapSnapshotManager_setup_FromC(_jvmpiAgent_jvmpiInterface, TRUE); |
| 4845 |
|
| 4846 |
/* Get the LOCAL_AGENT_TEMP_DIR */ |
| 4847 |
/* Bug 59544 querying tempDir from RAC */ |
| 4848 |
if (!_jvmpiAgent_Options.standalone) { |
| 4849 |
char tempDir[1024] ; |
| 4850 |
int result ; |
| 4851 |
result = ra_getEnvironmentVariable(_tempDirOptionName,tempDir,1024) ; |
| 4852 |
/* If "LOCAL_AGENT_TEMP_DIR" is not defined then get try to look |
| 4853 |
for "TMP" */ |
| 4854 |
if ( !result ) |
| 4855 |
result = ra_getEnvironmentVariable("TMP",tempDir,1024) ; |
| 4856 |
/* If tempDir is defined then set it as the workDir . |
| 4857 |
else leave it as default */ |
| 4858 |
if ( result ) { |
| 4859 |
strcpyrealloc(&_jvmpiAgent_Options.workDir,tempDir) ; |
| 4860 |
/* 64476 Convert it to ascii for consistency */ |
| 4861 |
#ifdef MVS |
| 4862 |
__etoa(_jvmpiAgent_Options.workDir) ; |
| 4863 |
#endif |
| 4864 |
} |
| 4865 |
} |
| 4866 |
} |
| 4867 |
|
| 4868 |
static void jvmpiAgent_PrintStartingXMLFragments() |
| 4869 |
{ |
| 4870 |
|
| 4871 |
ThreadLocalStorage *tps; |
| 4872 |
|
| 4873 |
/* Get the global buffer for IO */ |
| 4874 |
tps=jvmpiAgent_getThreadLocalStorage(0); |
| 4875 |
|
| 4876 |
/* If we are in standalone print the required additional elements */ |
| 4877 |
if((_jvmpiAgent_Options.standalone||_jvmpiAgent_Options.application)) /*94955*/ |
| 4878 |
{ |
| 4879 |
jvmpiAgent_printXMLStartElement(tps); |
| 4880 |
jvmpiAgent_printStandaloneTraceTagOpen(tps); |
| 4881 |
} |
| 4882 |
|
| 4883 |
/* Print the trace header */ |
| 4884 |
jvmpiAgent_printNodeElement(tps); |
| 4885 |
jvmpiAgent_printProcessCreateElement(tps); |
| 4886 |
jvmpiAgent_printAgentCreateElement(tps, _jvmpiAgent_Options.invocationOptions); |
| 4887 |
jvmpiAgent_printTraceStartElement(tps, _jvmpiAgent_Options.invocationOptions); |
| 4888 |
|
| 4889 |
/* Print the filters and options only if the proper option is set */ |
| 4890 |
if (_jvmpiAgent_Options.filters) |
| 4891 |
{ |
| 4892 |
jvmpiAgent_printFilters(); |
| 4893 |
} |
| 4894 |
if (_jvmpiAgent_Options.options) |
| 4895 |
{ |
| 4896 |
jvmpiAgent_printOptions(); |
| 4897 |
} |
| 4898 |
} |
| 4899 |
|
| 4900 |
|
| 4901 |
#if defined __cplusplus |
| 4902 |
} |
| 4903 |
#endif |