Commit 948b210e authored by Lubomir Bulej's avatar Lubomir Bulej

Make agent initialization a bit less cluttered

parent 1587e80b
......@@ -756,14 +756,13 @@ JNIEXPORT jint JNICALL VISIBLE
Agent_OnLoad (JavaVM * jvm, char * options, void * reserved) {
jvmtiEnv * jvmti = __get_jvmti (jvm);
// add capabilities
// Request JVMTI capabilities:
jvmtiCapabilities caps = {
.can_redefine_classes = 1,
.can_generate_all_class_hook_events = 1,
};
jvmtiError error = (*jvmti)->AddCapabilities (jvmti, &caps);
check_jvmti_error (jvmti, error, "failed to add capabilities");
__jvmti_add_capabilities (jvmti, &caps);
// configure agent and init connections
......@@ -779,7 +778,7 @@ Agent_OnLoad (JavaVM * jvm, char * options, void * reserved) {
session_start(&agent_config);
// register callbacks
// Register JVMTI event callbacks.
jvmtiEventCallbacks callbacks = {
.VMStart = &jvmti_callback_vm_start,
.VMInit = &jvmti_callback_vm_init,
......@@ -787,22 +786,22 @@ Agent_OnLoad (JavaVM * jvm, char * options, void * reserved) {
.ClassFileLoadHook = &jvmti_callback_class_file_load,
};
error = (*jvmti)->SetEventCallbacks (jvmti, &callbacks, (jint) sizeof (callbacks));
check_jvmti_error (jvmti, error, "failed to register event callbacks");
__jvmti_register_callbacks (jvmti, &callbacks, sizeof (callbacks));
// Enable JVMTI events globally for all threads.
jvmtiEvent events [] = {
JVMTI_EVENT_VM_START,
JVMTI_EVENT_VM_INIT,
JVMTI_EVENT_VM_DEATH,
JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,
};
__jvmti_enable_events (jvmti, events, sizeof_array (events));
// enable event notification
error = (*jvmti)->SetEventNotificationMode (jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_START, NULL);
check_jvmti_error (jvmti, error, "failed to enable VM START event");
error = (*jvmti)->SetEventNotificationMode (jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL);
check_jvmti_error (jvmti, error, "failed to enable VM INIT event");
error = (*jvmti)->SetEventNotificationMode (jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL);
check_jvmti_error (jvmti, error, "failed to enable VM DEATH event");
error = (*jvmti)->SetEventNotificationMode (jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL);
check_jvmti_error (jvmti, error, "failed to enable CLASS FILE LOAD event");
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment