156 /* allocate and clean threads list */ |
156 /* allocate and clean threads list */ |
157 for (i = 0; i < THREADS_KINDS; i++) { |
157 for (i = 0; i < THREADS_KINDS; i++) { |
158 threadsCounts[i] = 0; |
158 threadsCounts[i] = 0; |
159 threadsList[i] = NULL; |
159 threadsList[i] = NULL; |
160 |
160 |
161 if (!NSK_JVMTI_VERIFY( |
161 if (!NSK_JVMTI_VERIFY(jvmti->Allocate(threadsCount * sizeof(jthread), |
162 NSK_CPP_STUB3(Allocate, jvmti, (threadsCount * sizeof(jthread)), |
162 (unsigned char**)&threadsList[i]))) |
163 (unsigned char**)&threadsList[i]))) |
|
164 return NSK_FALSE; |
163 return NSK_FALSE; |
165 |
164 |
166 for (j = 0; j < threadsCount; j++) { |
165 for (j = 0; j < threadsCount; j++) { |
167 threadsList[i][j] = NULL; |
166 threadsList[i][j] = NULL; |
168 } |
167 } |
169 } |
168 } |
170 |
169 |
171 /* get all live threads */ |
170 /* get all live threads */ |
172 if (!NSK_JVMTI_VERIFY( |
171 if (!NSK_JVMTI_VERIFY(jvmti->GetAllThreads(&allThreadsCount, &allThreadsList))) |
173 NSK_CPP_STUB3(GetAllThreads, jvmti, &allThreadsCount, &allThreadsList))) |
|
174 return NSK_FALSE; |
172 return NSK_FALSE; |
175 |
173 |
176 if (!NSK_VERIFY(allThreadsCount > 0 && allThreadsList != NULL)) |
174 if (!NSK_VERIFY(allThreadsCount > 0 && allThreadsList != NULL)) |
177 return NSK_FALSE; |
175 return NSK_FALSE; |
178 |
176 |
182 |
180 |
183 if (!NSK_VERIFY(allThreadsList[i] != NULL)) |
181 if (!NSK_VERIFY(allThreadsList[i] != NULL)) |
184 return NSK_FALSE; |
182 return NSK_FALSE; |
185 |
183 |
186 /* get thread name (info) */ |
184 /* get thread name (info) */ |
187 if (!NSK_JVMTI_VERIFY( |
185 if (!NSK_JVMTI_VERIFY(jvmti->GetThreadInfo(allThreadsList[i], &threadInfo))) |
188 NSK_CPP_STUB3(GetThreadInfo, jvmti, allThreadsList[i], &threadInfo))) |
|
189 return NSK_FALSE; |
186 return NSK_FALSE; |
190 |
187 |
191 /* find by name */ |
188 /* find by name */ |
192 if (threadInfo.name != NULL) { |
189 if (threadInfo.name != NULL) { |
193 for (j = 0; j < THREADS_KINDS; j++) { |
190 for (j = 0; j < THREADS_KINDS; j++) { |
200 } |
197 } |
201 } |
198 } |
202 } |
199 } |
203 |
200 |
204 /* deallocate all threads list */ |
201 /* deallocate all threads list */ |
205 if (!NSK_JVMTI_VERIFY( |
202 if (!NSK_JVMTI_VERIFY(jvmti->Deallocate((unsigned char*)allThreadsList))) |
206 NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)allThreadsList))) |
|
207 return NSK_FALSE; |
203 return NSK_FALSE; |
208 |
204 |
209 /* check if all tested threads found */ |
205 /* check if all tested threads found */ |
210 notfound = 0; |
206 notfound = 0; |
211 for (i = 0; i < THREADS_KINDS; i++) { |
207 for (i = 0; i < THREADS_KINDS; i++) { |
224 |
220 |
225 /* make global refs */ |
221 /* make global refs */ |
226 for (i = 0; i < THREADS_KINDS; i++) { |
222 for (i = 0; i < THREADS_KINDS; i++) { |
227 for (j = 0; j < threadsCount; j++) { |
223 for (j = 0; j < threadsCount; j++) { |
228 if (!NSK_JNI_VERIFY(jni, (threadsList[i][j] = |
224 if (!NSK_JNI_VERIFY(jni, (threadsList[i][j] = |
229 NSK_CPP_STUB2(NewGlobalRef, jni, threadsList[i][j])) != NULL)) |
225 jni->NewGlobalRef(threadsList[i][j])) != NULL)) |
230 return NSK_FALSE; |
226 return NSK_FALSE; |
231 } |
227 } |
232 } |
228 } |
233 |
229 |
234 return NSK_TRUE; |
230 return NSK_TRUE; |
242 jvmtiError* results = NULL; |
238 jvmtiError* results = NULL; |
243 const char* kind = (suspend ? "suspending" : "resuming"); |
239 const char* kind = (suspend ? "suspending" : "resuming"); |
244 int i, j; |
240 int i, j; |
245 |
241 |
246 /* allocate results array */ |
242 /* allocate results array */ |
247 if (!NSK_JVMTI_VERIFY( |
243 if (!NSK_JVMTI_VERIFY(jvmti->Allocate(resultsSize, (unsigned char**)&results))) { |
248 NSK_CPP_STUB3(Allocate, jvmti, resultsSize, (unsigned char**)&results))) { |
|
249 nsk_jvmti_setFailStatus(); |
244 nsk_jvmti_setFailStatus(); |
250 return NSK_FALSE; |
245 return NSK_FALSE; |
251 } |
246 } |
252 |
247 |
253 for (i = 0; i < THREADS_KINDS; i++) { |
248 for (i = 0; i < THREADS_KINDS; i++) { |
254 /* suspend or resume threads list */ |
249 /* suspend or resume threads list */ |
255 if (suspend) { |
250 if (suspend) { |
256 if (!NSK_JVMTI_VERIFY( |
251 if (!NSK_JVMTI_VERIFY(jvmti->SuspendThreadList(threadsCount, threadsList[i], results))) |
257 NSK_CPP_STUB4(SuspendThreadList, jvmti, threadsCount, |
|
258 threadsList[i], results))) |
|
259 nsk_jvmti_setFailStatus(); |
252 nsk_jvmti_setFailStatus(); |
260 } else { |
253 } else { |
261 if (!NSK_JVMTI_VERIFY( |
254 if (!NSK_JVMTI_VERIFY(jvmti->ResumeThreadList(threadsCount, threadsList[i], results))) |
262 NSK_CPP_STUB4(ResumeThreadList, jvmti, threadsCount, |
|
263 threadsList[i], results))) |
|
264 nsk_jvmti_setFailStatus(); |
255 nsk_jvmti_setFailStatus(); |
265 } |
256 } |
266 |
257 |
267 /* check results */ |
258 /* check results */ |
268 for (j = 0; j < threadsCount; j++) { |
259 for (j = 0; j < threadsCount; j++) { |
293 |
283 |
294 for (i = 0; i < THREADS_KINDS; i++) { |
284 for (i = 0; i < THREADS_KINDS; i++) { |
295 for (j = 0; j < threadsCount; j++) { |
285 for (j = 0; j < threadsCount; j++) { |
296 if (suspend) { |
286 if (suspend) { |
297 NSK_DISPLAY2(" suspend thread #%d (%s)\n", j, threadsName[i]); |
287 NSK_DISPLAY2(" suspend thread #%d (%s)\n", j, threadsName[i]); |
298 if (!NSK_JVMTI_VERIFY( |
288 if (!NSK_JVMTI_VERIFY(jvmti->SuspendThread(threadsList[i][j]))) |
299 NSK_CPP_STUB2(SuspendThread, jvmti, threadsList[i][j]))) |
|
300 nsk_jvmti_setFailStatus(); |
289 nsk_jvmti_setFailStatus(); |
301 } else { |
290 } else { |
302 NSK_DISPLAY2(" resume thread #%d (%s)\n", j, threadsName[i]); |
291 NSK_DISPLAY2(" resume thread #%d (%s)\n", j, threadsName[i]); |
303 if (!NSK_JVMTI_VERIFY( |
292 if (!NSK_JVMTI_VERIFY(jvmti->ResumeThread(threadsList[i][j]))) |
304 NSK_CPP_STUB2(ResumeThread, jvmti, threadsList[i][j]))) |
|
305 nsk_jvmti_setFailStatus(); |
293 nsk_jvmti_setFailStatus(); |
306 } |
294 } |
307 } |
295 } |
308 } |
296 } |
309 return NSK_TRUE; |
297 return NSK_TRUE; |
327 jlong t = 0; |
315 jlong t = 0; |
328 |
316 |
329 NSK_DISPLAY2(" thread #%d (%s):\n", j, threadsName[i]); |
317 NSK_DISPLAY2(" thread #%d (%s):\n", j, threadsName[i]); |
330 |
318 |
331 /* get thread state */ |
319 /* get thread state */ |
332 if (!NSK_JVMTI_VERIFY( |
320 if (!NSK_JVMTI_VERIFY(jvmti->GetThreadState(threadsList[i][j], &state))) { |
333 NSK_CPP_STUB3(GetThreadState, jvmti, threadsList[i][j], &state))) { |
|
334 nsk_jvmti_setFailStatus(); |
321 nsk_jvmti_setFailStatus(); |
335 return NSK_FALSE; |
322 return NSK_FALSE; |
336 } |
323 } |
337 |
324 |
338 NSK_DISPLAY2(" state = %s (%d)\n", |
325 NSK_DISPLAY2(" state = %s (%d)\n", |
371 int i, j; |
358 int i, j; |
372 |
359 |
373 /* dispose global references to threads */ |
360 /* dispose global references to threads */ |
374 for (i = 0; i < THREADS_KINDS; i++) { |
361 for (i = 0; i < THREADS_KINDS; i++) { |
375 for (j = 0; j < threadsCount; j++) { |
362 for (j = 0; j < threadsCount; j++) { |
376 NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, threadsList[i][j])); |
363 NSK_TRACE(jni->DeleteGlobalRef(threadsList[i][j])); |
377 } |
364 } |
378 } |
365 } |
379 |
366 |
380 /* deallocate memory */ |
367 /* deallocate memory */ |
381 for (i = 0; i < THREADS_KINDS; i++) { |
368 for (i = 0; i < THREADS_KINDS; i++) { |
382 if (!NSK_JVMTI_VERIFY( |
369 if (!NSK_JVMTI_VERIFY(jvmti->Deallocate((unsigned char*)threadsList[i]))) |
383 NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)threadsList[i]))) |
|
384 return NSK_FALSE; |
370 return NSK_FALSE; |
385 threadsList[i] = NULL; |
371 threadsList[i] = NULL; |
386 } |
372 } |
387 |
373 |
388 return NSK_TRUE; |
374 return NSK_TRUE; |
463 /* add specific capabilities for suspending thread */ |
449 /* add specific capabilities for suspending thread */ |
464 { |
450 { |
465 jvmtiCapabilities suspendCaps; |
451 jvmtiCapabilities suspendCaps; |
466 memset(&suspendCaps, 0, sizeof(suspendCaps)); |
452 memset(&suspendCaps, 0, sizeof(suspendCaps)); |
467 suspendCaps.can_suspend = 1; |
453 suspendCaps.can_suspend = 1; |
468 if (!NSK_JVMTI_VERIFY( |
454 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&suspendCaps))) |
469 NSK_CPP_STUB2(AddCapabilities, jvmti, &suspendCaps))) |
|
470 return JNI_ERR; |
455 return JNI_ERR; |
471 } |
456 } |
472 |
457 |
473 /* register agent proc and arg */ |
458 /* register agent proc and arg */ |
474 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) |
459 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) |