< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001/gcstart001.cpp

Print this page
rev 51942 : [mq]: refactor


 103 JNIEXPORT jint JNICALL Agent_OnAttach_gcstart001(JavaVM *jvm, char *options, void *reserved) {
 104     return Agent_Initialize(jvm, options, reserved);
 105 }
 106 JNIEXPORT jint JNI_OnLoad_gcstart001(JavaVM *jvm, char *options, void *reserved) {
 107     return JNI_VERSION_1_8;
 108 }
 109 #endif
 110 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 111     /* init framework and parse options */
 112     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 113         return JNI_ERR;
 114 
 115     /* create JVMTI environment */
 116     if (!NSK_VERIFY((jvmti =
 117             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 118         return JNI_ERR;
 119 
 120     /* add capability to generate compiled method events */
 121     memset(&caps, 0, sizeof(jvmtiCapabilities));
 122     caps.can_generate_garbage_collection_events = 1;
 123     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities,
 124             jvmti, &caps)))
 125         return JNI_ERR;
 126 
 127     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities,
 128             jvmti, &caps)))
 129         return JNI_ERR;
 130 
 131     if (!caps.can_generate_garbage_collection_events)
 132         NSK_DISPLAY0("Warning: generation of garbage collection events is not implemented\n");
 133 
 134     /* set event callback */
 135     NSK_DISPLAY0("setting event callbacks ...\n");
 136     (void) memset(&callbacks, 0, sizeof(callbacks));
 137     callbacks.VMDeath = &VMDeath;
 138     callbacks.GarbageCollectionStart = &GarbageCollectionStart;
 139     callbacks.GarbageCollectionFinish = &GarbageCollectionFinish;
 140     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks,
 141             jvmti, &callbacks, sizeof(callbacks))))
 142         return JNI_ERR;
 143 
 144     NSK_DISPLAY0("setting event callbacks done\nenabling JVMTI events ...\n");
 145     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
 146             jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL)))
 147         return JNI_ERR;
 148     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
 149             jvmti, JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_START, NULL)))
 150         return JNI_ERR;
 151     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
 152             jvmti, JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, NULL)))
 153         return JNI_ERR;
 154     NSK_DISPLAY0("enabling the events done\n\n");
 155 
 156     return JNI_OK;
 157 }
 158 
 159 }


 103 JNIEXPORT jint JNICALL Agent_OnAttach_gcstart001(JavaVM *jvm, char *options, void *reserved) {
 104     return Agent_Initialize(jvm, options, reserved);
 105 }
 106 JNIEXPORT jint JNI_OnLoad_gcstart001(JavaVM *jvm, char *options, void *reserved) {
 107     return JNI_VERSION_1_8;
 108 }
 109 #endif
 110 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 111     /* init framework and parse options */
 112     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 113         return JNI_ERR;
 114 
 115     /* create JVMTI environment */
 116     if (!NSK_VERIFY((jvmti =
 117             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 118         return JNI_ERR;
 119 
 120     /* add capability to generate compiled method events */
 121     memset(&caps, 0, sizeof(jvmtiCapabilities));
 122     caps.can_generate_garbage_collection_events = 1;
 123     if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))

 124         return JNI_ERR;
 125 
 126     if (!NSK_JVMTI_VERIFY(jvmti->GetCapabilities(&caps)))

 127         return JNI_ERR;
 128 
 129     if (!caps.can_generate_garbage_collection_events)
 130         NSK_DISPLAY0("Warning: generation of garbage collection events is not implemented\n");
 131 
 132     /* set event callback */
 133     NSK_DISPLAY0("setting event callbacks ...\n");
 134     (void) memset(&callbacks, 0, sizeof(callbacks));
 135     callbacks.VMDeath = &VMDeath;
 136     callbacks.GarbageCollectionStart = &GarbageCollectionStart;
 137     callbacks.GarbageCollectionFinish = &GarbageCollectionFinish;
 138     if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks))))

 139         return JNI_ERR;
 140 
 141     NSK_DISPLAY0("setting event callbacks done\nenabling JVMTI events ...\n");
 142     if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL)))

 143         return JNI_ERR;
 144     if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_START, NULL)))

 145         return JNI_ERR;
 146     if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, NULL)))

 147         return JNI_ERR;
 148     NSK_DISPLAY0("enabling the events done\n\n");
 149 
 150     return JNI_OK;
 151 }
 152 
 153 }
< prev index next >