< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach020/attach020Agent00.cpp

Print this page
rev 52285 : 8212884: Remove the assignments in ifs for vmTestbase/[a-s]
Summary: Extract assignments from if statements in vmTestbase
Reviewed-by: cjplummer, sspitsyn


  98 
  99         if (!gcFinishEventReceived) {
 100             if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorWait(gcFinishMonitor, 0))) {
 101                 success = 0;
 102             }
 103         }
 104 
 105         if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(gcFinishMonitor))) {
 106             success = 0;
 107         }
 108     } else {
 109         success = 0;
 110     }
 111 
 112     nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, success, jvmti, jni);
 113 }
 114 
 115 int startAuxiliaryThread(jvmtiEnv* jvmti, JNIEnv* jni) {
 116     jthread thread;
 117 
 118     if (!NSK_VERIFY((thread = nsk_jvmti_aod_createThread(jni)) != NULL))

 119         return NSK_FALSE;
 120 
 121     if (!NSK_JVMTI_VERIFY(jvmti->RunAgentThread(thread, auxiliaryThreadFunction, NULL, JVMTI_THREAD_NORM_PRIORITY))) {
 122         return NSK_FALSE;
 123     }
 124 
 125     NSK_DISPLAY1("%s: auxiliary thread was started\n", agentName);
 126 
 127     return NSK_TRUE;
 128 }
 129 
 130 #ifdef STATIC_BUILD
 131 JNIEXPORT jint JNI_OnLoad_attach020Agent00(JavaVM *jvm, char *options, void *reserved) {
 132     return JNI_VERSION_1_8;
 133 }
 134 #endif
 135 
 136 JNIEXPORT jint JNICALL
 137 #ifdef STATIC_BUILD
 138 Agent_OnAttach_attach020Agent00(JavaVM *vm, char *optionsString, void *reserved)
 139 #else
 140 Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved)
 141 #endif
 142 {
 143     jvmtiEnv* jvmti;
 144     jvmtiEventCallbacks eventCallbacks;
 145     jvmtiCapabilities caps;
 146     JNIEnv* jni;
 147 
 148     if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL))

 149         return JNI_ERR;
 150 
 151     agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION);
 152 
 153     if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL)

 154         return JNI_ERR;
 155 
 156     if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL))

 157         return JNI_ERR;
 158 
 159     if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("GCFinishMonitor", &gcFinishMonitor))) {
 160         return JNI_ERR;
 161     }
 162 
 163     if (!NSK_VERIFY(startAuxiliaryThread(jvmti, jni)))
 164         return JNI_ERR;
 165 
 166     memset(&caps, 0, sizeof(caps));
 167     caps.can_generate_garbage_collection_events = 1;
 168     if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps))) {
 169         return JNI_ERR;
 170     }
 171 
 172     memset(&eventCallbacks,0, sizeof(eventCallbacks));
 173     eventCallbacks.GarbageCollectionStart  = garbageCollectionStartHandler;
 174     eventCallbacks.GarbageCollectionFinish = garbageCollectionFinishHandler;
 175     if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)))) {
 176         return JNI_ERR;


  98 
  99         if (!gcFinishEventReceived) {
 100             if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorWait(gcFinishMonitor, 0))) {
 101                 success = 0;
 102             }
 103         }
 104 
 105         if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(gcFinishMonitor))) {
 106             success = 0;
 107         }
 108     } else {
 109         success = 0;
 110     }
 111 
 112     nsk_jvmti_aod_disableEventsAndFinish(agentName, testEvents, testEventsNumber, success, jvmti, jni);
 113 }
 114 
 115 int startAuxiliaryThread(jvmtiEnv* jvmti, JNIEnv* jni) {
 116     jthread thread;
 117 
 118     thread = nsk_jvmti_aod_createThread(jni);
 119     if (!NSK_VERIFY(thread != NULL))
 120         return NSK_FALSE;
 121 
 122     if (!NSK_JVMTI_VERIFY(jvmti->RunAgentThread(thread, auxiliaryThreadFunction, NULL, JVMTI_THREAD_NORM_PRIORITY))) {
 123         return NSK_FALSE;
 124     }
 125 
 126     NSK_DISPLAY1("%s: auxiliary thread was started\n", agentName);
 127 
 128     return NSK_TRUE;
 129 }
 130 
 131 #ifdef STATIC_BUILD
 132 JNIEXPORT jint JNI_OnLoad_attach020Agent00(JavaVM *jvm, char *options, void *reserved) {
 133     return JNI_VERSION_1_8;
 134 }
 135 #endif
 136 
 137 JNIEXPORT jint JNICALL
 138 #ifdef STATIC_BUILD
 139 Agent_OnAttach_attach020Agent00(JavaVM *vm, char *optionsString, void *reserved)
 140 #else
 141 Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved)
 142 #endif
 143 {
 144     jvmtiEnv* jvmti;
 145     jvmtiEventCallbacks eventCallbacks;
 146     jvmtiCapabilities caps;
 147     JNIEnv* jni;
 148 
 149     options = (Options*) nsk_aod_createOptions(optionsString);
 150     if (!NSK_VERIFY(options != NULL))
 151         return JNI_ERR;
 152 
 153     agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION);
 154 
 155     jni = (JNIEnv*) nsk_aod_createJNIEnv(vm);
 156     if (jni == NULL)
 157         return JNI_ERR;
 158 
 159     jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved);
 160     if (!NSK_VERIFY(jvmti != NULL))
 161         return JNI_ERR;
 162 
 163     if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("GCFinishMonitor", &gcFinishMonitor))) {
 164         return JNI_ERR;
 165     }
 166 
 167     if (!NSK_VERIFY(startAuxiliaryThread(jvmti, jni)))
 168         return JNI_ERR;
 169 
 170     memset(&caps, 0, sizeof(caps));
 171     caps.can_generate_garbage_collection_events = 1;
 172     if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps))) {
 173         return JNI_ERR;
 174     }
 175 
 176     memset(&eventCallbacks,0, sizeof(eventCallbacks));
 177     eventCallbacks.GarbageCollectionStart  = garbageCollectionStartHandler;
 178     eventCallbacks.GarbageCollectionFinish = garbageCollectionFinishHandler;
 179     if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)))) {
 180         return JNI_ERR;
< prev index next >