![]() |
|
|
Definition in file inspectorjagent.cpp.
#include "inspectorj/agent/inspectorjagent.h"
Include dependency graph for inspectorjagent.cpp:
Go to the source code of this file.
Classes | |
struct | MethodInfo |
Data structure to hold method information. More... | |
struct | ClassInfo |
Data structure to hold class information. More... | |
struct | AgentGlobalContext |
Data structure to hold global data for the agent such as pointers to the JavaVM and the jvmtiEnv. More... | |
Defines | |
#define | MAX_TOKEN_LENGTH 256 |
Max length of tokens. | |
#define | MAX_THREAD_NAME_LENGTH 512 |
Max length of thread name. | |
#define | MAX_METHOD_NAME_LENGTH 1024 |
Max length or method name. | |
#define | INSPECTORJ_class Mtrace |
Name of class we are using. | |
#define | INSPECTORJ_entry method_entry |
Name of java entry method. | |
#define | INSPECTORJ_exit method_exit |
Name of java exit method. | |
#define | INSPECTORJ_native_entry _method_entry |
Name of java entry native. | |
#define | INSPECTORJ_native_exit _method_exit |
Name of java exit native. | |
#define | INSPECTORJ_engaged engaged |
Name of java static field. | |
#define | _STRING(s) #s |
#define | STRING(s) _STRING(s) |
Functions | |
static void | deallocate (jvmtiEnv *jvmti, void *ptr) |
Deallocate all memory allocated by JVMTI. | |
static void * | allocate (jvmtiEnv *jvmti, jint len) |
Allocate JVMTI managed memory. | |
static void | enter_critical_section (jvmtiEnv *jvmti) |
Enter a critical section by doing a JVMTI Raw Monitor Enter. | |
static void | exit_critical_section (jvmtiEnv *jvmti) |
Exit a critical section by doing a JVMTI Raw Monitor Exit. | |
static void | get_thread_name (jvmtiEnv *jvmti, jthread thread, char *tname, int maxlen) |
Gets a name for a jthread. | |
static int | class_compar (const void *e1, const void *e2) |
Sort class compare routine. | |
static int | method_compar (const void *e1, const void *e2) |
Sort method compare routine. | |
static void | mnum_callbacks (unsigned cnum, const char **names, const char **sigs, int mcount) |
Callback from java_crw_demo() that gives us mnum mappings. | |
static void | INSPECTORJ_native_entry (JNIEnv *env, jclass klass, jobject thread, jint cnum, jint mnum) |
Java Native Method for entry. | |
static void | INSPECTORJ_native_exit (JNIEnv *env, jclass klass, jobject thread, jint cnum, jint mnum) |
Java Native Method for exit. | |
static void JNICALL | cbVMStart (jvmtiEnv *jvmti, JNIEnv *env) |
Callback for JVMTI_EVENT_VM_START. | |
void | startServer () |
Start the agent server after VM_INIT. | |
static void JNICALL | cbVMInit (jvmtiEnv *jvmti, JNIEnv *env, jthread thread) |
Callback for JVMTI_EVENT_VM_INIT. | |
static void JNICALL | cbVMDeath (jvmtiEnv *jvmti, JNIEnv *env) |
Callback for JVMTI_EVENT_VM_DEATH. | |
static void JNICALL | cbThreadStart (jvmtiEnv *jvmti, JNIEnv *env, jthread thread) |
Callback for JVMTI_EVENT_THREAD_START. | |
static void JNICALL | cbThreadEnd (jvmtiEnv *jvmti, JNIEnv *env, jthread thread) |
Callback for JVMTI_EVENT_THREAD_END. | |
static void JNICALL | cbClassFileLoadHook (jvmtiEnv *jvmti, JNIEnv *env, jclass class_being_redefined, jobject loader, const char *name, jobject protection_domain, jint class_data_len, const unsigned char *class_data, jint *new_class_data_len, unsigned char **new_class_data) |
Callback for JVMTI_EVENT_CLASS_FILE_LOAD_HOOK. | |
static void | parseOptions (char *options) |
Parse the options for this agent. | |
JNIEXPORT jint JNICALL | Agent_OnLoad (JavaVM *vm, char *options, void *reserved) |
Agent_OnLoad: This is called immediately after the shared library is loaded. | |
JNIEXPORT void JNICALL | Agent_OnUnload (JavaVM *vm) |
Agent_OnUnload: This is called immediately before the shared library is unloaded. | |
Variables | |
static AgentGlobalContext * | context |
#define INSPECTORJ_class Mtrace |
Name of class we are using.
Definition at line 39 of file inspectorjagent.cpp.
Referenced by cbClassFileLoadHook(), cbVMDeath(), and cbVMStart().
#define INSPECTORJ_engaged engaged |
Name of java static field.
Definition at line 44 of file inspectorjagent.cpp.
Referenced by cbVMDeath(), and cbVMStart().
#define INSPECTORJ_entry method_entry |
Name of java entry method.
Definition at line 40 of file inspectorjagent.cpp.
Referenced by cbClassFileLoadHook().
#define INSPECTORJ_exit method_exit |
Name of java exit method.
Definition at line 41 of file inspectorjagent.cpp.
Referenced by cbClassFileLoadHook().
#define INSPECTORJ_native_entry _method_entry |
Name of java entry native.
Definition at line 42 of file inspectorjagent.cpp.
Referenced by cbVMStart().
#define INSPECTORJ_native_exit _method_exit |
Name of java exit native.
Definition at line 43 of file inspectorjagent.cpp.
Referenced by cbVMStart().
#define MAX_METHOD_NAME_LENGTH 1024 |
#define MAX_THREAD_NAME_LENGTH 512 |
Max length of thread name.
Definition at line 37 of file inspectorjagent.cpp.
Referenced by cbThreadEnd(), cbThreadStart(), and cbVMInit().
#define MAX_TOKEN_LENGTH 256 |
Max length of tokens.
Definition at line 36 of file inspectorjagent.cpp.
Referenced by parseOptions().
JNIEXPORT jint JNICALL Agent_OnLoad | ( | JavaVM * | vm, | |
char * | options, | |||
void * | reserved | |||
) |
Agent_OnLoad: This is called immediately after the shared library is loaded.
This is the first code executed.
Definition at line 731 of file inspectorjagent.cpp.
References cbClassFileLoadHook(), cbThreadEnd(), cbThreadStart(), cbVMDeath(), cbVMInit(), cbVMStart(), check_jvmti_error(), context, AgentGlobalContext::jvmti, AgentGlobalContext::lock, parseOptions(), and AgentGlobalContext::vm.
JNIEXPORT void JNICALL Agent_OnUnload | ( | JavaVM * | vm | ) |
Agent_OnUnload: This is called immediately before the shared library is unloaded.
This is the last code executed.
Definition at line 832 of file inspectorjagent.cpp.
References AgentGlobalContext::ccount, AgentGlobalContext::classes, AgentGlobalContext::cmdHandler, context, inspectorj::agent::AgentServer::isStarted(), ClassInfo::methods, AgentGlobalContext::profile, AgentGlobalContext::regexFilterList, AgentGlobalContext::server, and inspectorj::agent::AgentServer::stop().
static void* allocate | ( | jvmtiEnv * | jvmti, | |
jint | len | |||
) | [static] |
Allocate JVMTI managed memory.
Definition at line 117 of file inspectorjagent.cpp.
References check_jvmti_error().
Referenced by cbClassFileLoadHook().
static void JNICALL cbClassFileLoadHook | ( | jvmtiEnv * | jvmti, | |
JNIEnv * | env, | |||
jclass | class_being_redefined, | |||
jobject | loader, | |||
const char * | name, | |||
jobject | protection_domain, | |||
jint | class_data_len, | |||
const unsigned char * | class_data, | |||
jint * | new_class_data_len, | |||
unsigned char ** | new_class_data | |||
) | [static] |
Callback for JVMTI_EVENT_CLASS_FILE_LOAD_HOOK.
Definition at line 533 of file inspectorjagent.cpp.
References allocate(), ClassInfo::calls, AgentGlobalContext::ccount, AgentGlobalContext::classes, context, enter_critical_section(), exit_critical_section(), INSPECTORJ_class, INSPECTORJ_entry, INSPECTORJ_exit, interested(), ClassInfo::mcount, ClassInfo::methods, mnum_callbacks(), ClassInfo::name, AgentGlobalContext::regexFilterList, STRING, AgentGlobalContext::vm_is_dead, and AgentGlobalContext::vm_is_started.
Referenced by Agent_OnLoad().
static void JNICALL cbThreadEnd | ( | jvmtiEnv * | jvmti, | |
JNIEnv * | env, | |||
jthread | thread | |||
) | [static] |
Callback for JVMTI_EVENT_THREAD_END.
Definition at line 516 of file inspectorjagent.cpp.
References context, enter_critical_section(), exit_critical_section(), get_thread_name(), MAX_THREAD_NAME_LENGTH, and AgentGlobalContext::vm_is_dead.
Referenced by Agent_OnLoad().
static void JNICALL cbThreadStart | ( | jvmtiEnv * | jvmti, | |
JNIEnv * | env, | |||
jthread | thread | |||
) | [static] |
Callback for JVMTI_EVENT_THREAD_START.
Definition at line 499 of file inspectorjagent.cpp.
References context, enter_critical_section(), exit_critical_section(), get_thread_name(), MAX_THREAD_NAME_LENGTH, and AgentGlobalContext::vm_is_dead.
Referenced by Agent_OnLoad().
static void JNICALL cbVMDeath | ( | jvmtiEnv * | jvmti, | |
JNIEnv * | env | |||
) | [static] |
Callback for JVMTI_EVENT_VM_DEATH.
Definition at line 418 of file inspectorjagent.cpp.
References MethodInfo::calls, ClassInfo::calls, AgentGlobalContext::ccount, class_compar(), AgentGlobalContext::classes, context, enter_critical_section(), exit_critical_section(), INSPECTORJ_class, INSPECTORJ_engaged, ClassInfo::mcount, method_compar(), ClassInfo::methods, MethodInfo::name, ClassInfo::name, MethodInfo::returns, MethodInfo::signature, STRING, and AgentGlobalContext::vm_is_dead.
Referenced by Agent_OnLoad().
static void JNICALL cbVMInit | ( | jvmtiEnv * | jvmti, | |
JNIEnv * | env, | |||
jthread | thread | |||
) | [static] |
Callback for JVMTI_EVENT_VM_INIT.
Definition at line 373 of file inspectorjagent.cpp.
References check_jvmti_error(), AgentGlobalContext::cmdHandler, context, enter_critical_section(), AgentGlobalContext::env, exit_critical_section(), get_thread_name(), inspectorj::client::SessionProfile::getConnection(), AgentGlobalContext::jvmti, MAX_THREAD_NAME_LENGTH, AgentGlobalContext::profile, AgentGlobalContext::server, AgentGlobalContext::serverThread, startServer(), and AgentGlobalContext::vm.
Referenced by Agent_OnLoad().
static void JNICALL cbVMStart | ( | jvmtiEnv * | jvmti, | |
JNIEnv * | env | |||
) | [static] |
Callback for JVMTI_EVENT_VM_START.
Definition at line 311 of file inspectorjagent.cpp.
References context, enter_critical_section(), exit_critical_section(), INSPECTORJ_class, INSPECTORJ_engaged, INSPECTORJ_native_entry, INSPECTORJ_native_exit, STRING, and AgentGlobalContext::vm_is_started.
Referenced by Agent_OnLoad().
static int class_compar | ( | const void * | e1, | |
const void * | e2 | |||
) | [static] |
Sort class compare routine.
Definition at line 189 of file inspectorjagent.cpp.
References ClassInfo::calls.
Referenced by cbVMDeath().
static void deallocate | ( | jvmtiEnv * | jvmti, | |
void * | ptr | |||
) | [static] |
Deallocate all memory allocated by JVMTI.
Memory must be freed by the JVMTI Deallocate interface.
Definition at line 105 of file inspectorjagent.cpp.
References check_jvmti_error().
Referenced by get_thread_name().
static void enter_critical_section | ( | jvmtiEnv * | jvmti | ) | [static] |
Enter a critical section by doing a JVMTI Raw Monitor Enter.
Definition at line 131 of file inspectorjagent.cpp.
References check_jvmti_error(), context, and AgentGlobalContext::lock.
Referenced by cbClassFileLoadHook(), cbThreadEnd(), cbThreadStart(), cbVMDeath(), cbVMInit(), cbVMStart(), INSPECTORJ_native_entry(), and INSPECTORJ_native_exit().
static void exit_critical_section | ( | jvmtiEnv * | jvmti | ) | [static] |
Exit a critical section by doing a JVMTI Raw Monitor Exit.
Definition at line 143 of file inspectorjagent.cpp.
References check_jvmti_error(), context, and AgentGlobalContext::lock.
Referenced by cbClassFileLoadHook(), cbThreadEnd(), cbThreadStart(), cbVMDeath(), cbVMInit(), cbVMStart(), INSPECTORJ_native_entry(), and INSPECTORJ_native_exit().
static void get_thread_name | ( | jvmtiEnv * | jvmti, | |
jthread | thread, | |||
char * | tname, | |||
int | maxlen | |||
) | [static] |
Gets a name for a jthread.
Definition at line 155 of file inspectorjagent.cpp.
References check_jvmti_error(), and deallocate().
Referenced by cbThreadEnd(), cbThreadStart(), and cbVMInit().
static void INSPECTORJ_native_entry | ( | JNIEnv * | env, | |
jclass | klass, | |||
jobject | thread, | |||
jint | cnum, | |||
jint | mnum | |||
) | [static] |
Java Native Method for entry.
Definition at line 254 of file inspectorjagent.cpp.
References ClassInfo::calls, MethodInfo::calls, AgentGlobalContext::ccount, AgentGlobalContext::classes, context, enter_critical_section(), exit_critical_section(), interested(), AgentGlobalContext::jvmti, ClassInfo::mcount, ClassInfo::methods, MethodInfo::name, ClassInfo::name, AgentGlobalContext::regexFilterList, and AgentGlobalContext::vm_is_dead.
static void INSPECTORJ_native_exit | ( | JNIEnv * | env, | |
jclass | klass, | |||
jobject | thread, | |||
jint | cnum, | |||
jint | mnum | |||
) | [static] |
Java Native Method for exit.
Definition at line 283 of file inspectorjagent.cpp.
References AgentGlobalContext::ccount, AgentGlobalContext::classes, context, enter_critical_section(), exit_critical_section(), interested(), AgentGlobalContext::jvmti, ClassInfo::mcount, ClassInfo::methods, MethodInfo::name, ClassInfo::name, AgentGlobalContext::regexFilterList, MethodInfo::returns, and AgentGlobalContext::vm_is_dead.
static int method_compar | ( | const void * | e1, | |
const void * | e2 | |||
) | [static] |
Sort method compare routine.
Definition at line 202 of file inspectorjagent.cpp.
References MethodInfo::calls.
Referenced by cbVMDeath().
static void mnum_callbacks | ( | unsigned | cnum, | |
const char ** | names, | |||
const char ** | sigs, | |||
int | mcount | |||
) | [static] |
Callback from java_crw_demo() that gives us mnum mappings.
Definition at line 215 of file inspectorjagent.cpp.
References ClassInfo::calls, AgentGlobalContext::ccount, AgentGlobalContext::classes, context, ClassInfo::mcount, ClassInfo::methods, and MethodInfo::name.
Referenced by cbClassFileLoadHook().
static void parseOptions | ( | char * | options | ) | [static] |
Parse the options for this agent.
Definition at line 648 of file inspectorjagent.cpp.
References context, createAgentClassFilter(), inspectorj::client::SessionProfile::getClassFilters(), getToken(), MAX_TOKEN_LENGTH, AgentGlobalContext::profile, and AgentGlobalContext::regexFilterList.
Referenced by Agent_OnLoad().
void startServer | ( | ) |
Start the agent server after VM_INIT.
Definition at line 359 of file inspectorjagent.cpp.
References context, inspectorj::client::SessionProfile::getConnection(), AgentGlobalContext::profile, AgentGlobalContext::server, and inspectorj::agent::AgentServer::start().
Referenced by cbVMInit().