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
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;
177 }
178
179 if (!(nsk_jvmti_aod_enableEvents(jvmti, testEvents, testEventsNumber))) {
180 return JNI_ERR;
181 }
182
183 NSK_DISPLAY1("%s: initialization was done\n", agentName);
184
185 if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName)))
186 return JNI_ERR;
187
188 return JNI_OK;
189 }
190 }
|
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
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;
177 }
178
179 if (!(nsk_jvmti_aod_enableEvents(jvmti, testEvents, testEventsNumber))) {
180 return JNI_ERR;
181 }
182
183 NSK_DISPLAY1("%s: initialization was done\n", agentName);
184
185 if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName)))
186 return JNI_ERR;
187
188 return JNI_OK;
189 }
190 }
|