83 static void JNICALL
84 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
85 jni = agentJNI;
86
87 /* wait for initial sync */
88 if (!nsk_jvmti_waitForSync(timeout))
89 return;
90
91 /* testcase(s) */
92 {
93 /* obtain threads list */
94 if (!prepare()) {
95 nsk_jvmti_setFailStatus();
96 return;
97 }
98
99 /* testcase #1: suspend and check threads on THREAD_START event */
100 {
101 eventsStart = 0;
102 if (!NSK_JVMTI_VERIFY(
103 NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE,
104 JVMTI_EVENT_THREAD_START, NULL))) {
105 nsk_jvmti_setFailStatus();
106 return;
107 }
108
109 NSK_DISPLAY0("Let threads to start\n");
110 if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
111 return;
112
113 NSK_DISPLAY0("Wait for THREAD_START events\n");
114 {
115 int i;
116
117 for (i = 0; i * TIMEOUT_DELTA < timeout; i++) {
118 if (eventsStart >= THREADS_COUNT)
119 break;
120 nsk_jvmti_sleep(TIMEOUT_DELTA);
121 }
122 }
123
124 if (!NSK_JVMTI_VERIFY(
125 NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE,
126 JVMTI_EVENT_THREAD_START, NULL))) {
127 nsk_jvmti_setFailStatus();
128 }
129
130 /* check if all threads suspended on THREAD_START events */
131 if (eventsStart != THREADS_COUNT) {
132 NSK_COMPLAIN2("Unexpected number of THREAD_START events:\n"
133 "# received: %d\n"
134 "# expected: %d\n",
135 eventsStart, THREADS_COUNT);
136 }
137
138 NSK_DISPLAY0("Testcase #1: check threads on THREAD_START\n");
139 if (!NSK_VERIFY(checkThreads("starting")))
140 return;
141
142 NSK_DISPLAY0("Resume all threads\n");
143 if (!NSK_VERIFY(resumeThreads("starting")))
144 return;
145
146 NSK_DISPLAY0("Wait for threads to run\n");
147 if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
148 return;
149 }
150
151 /* testcase #2: suspend and check threads on THREAD_END event */
152 {
153 eventsEnd = 0;
154 if (!NSK_JVMTI_VERIFY(
155 NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE,
156 JVMTI_EVENT_THREAD_END, NULL))) {
157 nsk_jvmti_setFailStatus();
158 return;
159 }
160
161 NSK_DISPLAY0("Let threads to finish\n");
162 if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
163 return;
164
165 NSK_DISPLAY0("Wait for THREAD_END events\n");
166 {
167 int i;
168
169 for (i = 0; i * TIMEOUT_DELTA < timeout; i++) {
170 if (eventsEnd >= THREADS_COUNT)
171 break;
172 nsk_jvmti_sleep(TIMEOUT_DELTA);
173 }
174 }
175
176 if (!NSK_JVMTI_VERIFY(
177 NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE,
178 JVMTI_EVENT_THREAD_END, NULL))) {
179 nsk_jvmti_setFailStatus();
180 }
181
182 /* check ia all threads suspended on THREAD_END event */
183 if (eventsEnd != THREADS_COUNT) {
184 NSK_COMPLAIN2("Unexpected number of THREAD_END events:\n"
185 "# received: %d\n"
186 "# expected: %d\n",
187 eventsEnd, THREADS_COUNT);
188 }
189
190 NSK_DISPLAY0("Testcase #2: check threads on THREAD_END\n");
191 if (!NSK_VERIFY(checkThreads("finishing")))
192 return;
193
194 NSK_DISPLAY0("Resume all threads\n");
195 if (!NSK_VERIFY(resumeThreads("finishing")))
196 return;
197
198 NSK_DISPLAY0("Wait for threads to finish\n");
204 if (!clean()) {
205 nsk_jvmti_setFailStatus();
206 return;
207 }
208 }
209
210 /* resume debugee after last sync */
211 if (!nsk_jvmti_resumeSync())
212 return;
213 }
214
215 /* ============================================================================= */
216
217 /**
218 * Resume all threads in given state.
219 */
220 static int resumeThreads(const char* kind) {
221 int i;
222
223 for (i = 0; i < THREADS_COUNT; i++) {
224 if (!NSK_JVMTI_VERIFY(
225 NSK_CPP_STUB2(ResumeThread, jvmti, threadsList[i]))) {
226 nsk_jvmti_setFailStatus();
227 }
228 }
229 return NSK_TRUE;
230 }
231
232 /**
233 * Prepare data:
234 * - get threads array from static field
235 * - get each thread from array
236 * - make global refs
237 */
238 static int prepare() {
239 jclass debugeeClass = NULL;
240 jfieldID threadsFieldID = NULL;
241 jobjectArray threadsArray = NULL;
242 jsize threadsArrayLength = 0;
243 jsize i;
244
245 /* find debugee class */
246 if (!NSK_JNI_VERIFY(jni, (debugeeClass =
247 NSK_CPP_STUB2(FindClass, jni, DEBUGEE_CLASS_NAME)) != NULL))
248 return NSK_FALSE;
249
250 /* find static field with threads array */
251 if (!NSK_JNI_VERIFY(jni, (threadsFieldID =
252 NSK_CPP_STUB4(GetStaticFieldID, jni, debugeeClass,
253 THREADS_FIELD_NAME, THREADS_FIELD_SIG)) != NULL))
254 return NSK_FALSE;
255
256 /* get threads array from static field */
257 if (!NSK_JNI_VERIFY(jni, (threadsArray = (jobjectArray)
258 NSK_CPP_STUB3(GetStaticObjectField, jni, debugeeClass, threadsFieldID)) != NULL))
259 return NSK_FALSE;
260
261 /* check array length */
262 if (!NSK_JNI_VERIFY(jni, (threadsArrayLength =
263 NSK_CPP_STUB2(GetArrayLength, jni, threadsArray)) == THREADS_COUNT))
264 return NSK_FALSE;
265
266 /* get each thread from array */
267 for (i = 0; i < THREADS_COUNT; i++) {
268 if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread)
269 NSK_CPP_STUB3(GetObjectArrayElement, jni, threadsArray, i)) != NULL))
270 return NSK_FALSE;
271 }
272
273 /* make global references to threads */
274 for (i = 0; i < THREADS_COUNT; i++) {
275 if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread)
276 NSK_CPP_STUB2(NewGlobalRef, jni, threadsList[i])) != NULL))
277 return NSK_FALSE;
278 }
279
280 return NSK_TRUE;
281 }
282
283 /**
284 * Check thread's stack on event.
285 *
286 * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break.
287 */
288 static int checkThread(jthread thread, int i, const char* kind) {
289 jint framesCount = 0;
290 jint stackDepth = 0;
291 jvmtiFrameInfo stackFrames[MAX_STACK_DEPTH];
292
293 NSK_DISPLAY3(" thread #%d (%s): %p\n", i, threadsName[i], (void*)thread);
294
295 /* get frames count */
296 if (!NSK_JVMTI_VERIFY(
297 NSK_CPP_STUB3(GetFrameCount, jvmti, thread, &framesCount))) {
298 nsk_jvmti_setFailStatus();
299 return NSK_TRUE;
300 }
301 NSK_DISPLAY1(" frames count: %d\n", (int)framesCount);
302
303 /* get stack frames */
304 if (!NSK_JVMTI_VERIFY(
305 NSK_CPP_STUB6(GetStackTrace, jvmti, thread, 0, MAX_STACK_DEPTH,
306 stackFrames, &stackDepth))) {
307 nsk_jvmti_setFailStatus();
308 return NSK_TRUE;
309 }
310 NSK_DISPLAY1(" stack depth: %d\n", (int)stackDepth);
311
312 /* check against emptyness */
313 if (framesCount != 0) {
314 NSK_COMPLAIN5("Unexpected GetFramesCount() for %s thread #%d (%s):\n"
315 "# got frames: %d\n"
316 "# expected: %d\n",
317 kind, i, threadsName[i],
318 framesCount, 0);
319 nsk_jvmti_setFailStatus();
320 }
321 if (stackDepth != 0) {
322 NSK_COMPLAIN5("Unexpected GetStackTrace() for %s thread #%d (%s):\n"
323 "# got frames: %d\n"
324 "# expected: %d\n",
325 kind, i, threadsName[i],
326 stackDepth, 0);
338 */
339 static int checkThreads(const char* kind) {
340 int i;
341
342 for (i = 0; i < THREADS_COUNT; i++) {
343 if (!checkThread(threadsList[i], i, kind))
344 return NSK_FALSE;
345 }
346 return NSK_TRUE;
347 }
348
349 /**
350 * Clean data:
351 * - dispose global references to tested threads
352 */
353 static int clean() {
354 int i;
355
356 /* dispose global references to threads */
357 for (i = 0; i < THREADS_COUNT; i++) {
358 NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, threadsList[i]));
359 }
360
361 return NSK_TRUE;
362 }
363
364 /* ============================================================================= */
365
366 /**
367 * THREAD_START callback:
368 * - check thread's stack on THREAD_START
369 */
370 JNIEXPORT void JNICALL
371 callbackThreadStart(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) {
372 int i;
373
374 /* check if thread is not NULL */
375 if (!NSK_VERIFY(thread != NULL)) {
376 nsk_jvmti_setFailStatus();
377 return;
378 }
379
380 /* check if event is for tested thread */
381 for (i = 0; i < THREADS_COUNT; i++) {
382 if (NSK_CPP_STUB3(IsSameObject, jni, threadsList[i], thread)) {
383 NSK_DISPLAY0("SUCCESS: expected THREAD_START event\n");
384
385 /* suspend thread */
386 NSK_DISPLAY3(" suspend starting thread #%d (%s): %p\n",
387 i, threadsName[i], (void*)thread);
388
389 if (!NSK_JVMTI_VERIFY(
390 NSK_CPP_STUB2(SuspendThread, jvmti, thread))) {
391 nsk_jvmti_setFailStatus();
392 return;
393 }
394 eventsStart++;
395
396 break;
397 }
398 }
399 }
400
401 /**
402 * THREAD_END callback:
403 * - check thread's stack on THREAD_END
404 */
405 JNIEXPORT void JNICALL
406 callbackThreadEnd(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) {
407 int i;
408
409 /* check if thread is not NULL */
410 if (!NSK_VERIFY(thread != NULL)) {
411 nsk_jvmti_setFailStatus();
412 return;
413 }
414
415 /* check if event is for tested thread */
416 for (i = 0; i < THREADS_COUNT; i++) {
417 if (NSK_CPP_STUB3(IsSameObject, jni, threadsList[i], thread)) {
418 NSK_DISPLAY0("SUCCESS: expected THREAD_END event\n");
419
420 /* suspend thread */
421 NSK_DISPLAY3(" suspend finishing thread #%d (%s): %p\n",
422 i, threadsName[i], (void*)thread);
423
424 if (!NSK_JVMTI_VERIFY(
425 NSK_CPP_STUB2(SuspendThread, jvmti, thread))) {
426 nsk_jvmti_setFailStatus();
427 return;
428 }
429 eventsEnd++;
430
431 break;
432 }
433 }
434 }
435
436 /* ============================================================================= */
437
438 static volatile int testedThreadRunning = NSK_FALSE;
439 static volatile int testedThreadShouldFinish = NSK_FALSE;
440
441 /** Native running method in tested thread. */
442 JNIEXPORT void JNICALL
443 Java_nsk_jvmti_scenarios_sampling_SP05_sp05t003ThreadRunningNative_run(JNIEnv* jni,
444 jobject obj) {
445 volatile int i = 0, n = 1000;
487 return JNI_VERSION_1_8;
488 }
489 #endif
490 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
491 /* init framework and parse options */
492 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
493 return JNI_ERR;
494
495 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
496
497 /* create JVMTI environment */
498 if (!NSK_VERIFY((jvmti =
499 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
500 return JNI_ERR;
501
502 /* add capabilities for suspending thread */
503 {
504 jvmtiCapabilities suspendCaps;
505 memset(&suspendCaps, 0, sizeof(suspendCaps));
506 suspendCaps.can_suspend = 1;
507 if (!NSK_JVMTI_VERIFY(
508 NSK_CPP_STUB2(AddCapabilities, jvmti, &suspendCaps)))
509 return JNI_ERR;
510 }
511
512 /* set events callbacks */
513 {
514 jvmtiEventCallbacks eventCallbacks;
515 memset(&eventCallbacks, 0, sizeof(eventCallbacks));
516 eventCallbacks.ThreadStart = callbackThreadStart;
517 eventCallbacks.ThreadEnd = callbackThreadEnd;
518 if (!NSK_JVMTI_VERIFY(
519 NSK_CPP_STUB3(SetEventCallbacks, jvmti,
520 &eventCallbacks, sizeof(eventCallbacks))))
521 return JNI_ERR;
522 }
523
524 /* register agent proc and arg */
525 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
526 return JNI_ERR;
527
528 return JNI_OK;
529 }
530
531 /* ============================================================================= */
532
533 }
|
83 static void JNICALL
84 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
85 jni = agentJNI;
86
87 /* wait for initial sync */
88 if (!nsk_jvmti_waitForSync(timeout))
89 return;
90
91 /* testcase(s) */
92 {
93 /* obtain threads list */
94 if (!prepare()) {
95 nsk_jvmti_setFailStatus();
96 return;
97 }
98
99 /* testcase #1: suspend and check threads on THREAD_START event */
100 {
101 eventsStart = 0;
102 if (!NSK_JVMTI_VERIFY(
103 jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_THREAD_START, NULL))) {
104 nsk_jvmti_setFailStatus();
105 return;
106 }
107
108 NSK_DISPLAY0("Let threads to start\n");
109 if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
110 return;
111
112 NSK_DISPLAY0("Wait for THREAD_START events\n");
113 {
114 int i;
115
116 for (i = 0; i * TIMEOUT_DELTA < timeout; i++) {
117 if (eventsStart >= THREADS_COUNT)
118 break;
119 nsk_jvmti_sleep(TIMEOUT_DELTA);
120 }
121 }
122
123 if (!NSK_JVMTI_VERIFY(
124 jvmti->SetEventNotificationMode(JVMTI_DISABLE, JVMTI_EVENT_THREAD_START, NULL))) {
125 nsk_jvmti_setFailStatus();
126 }
127
128 /* check if all threads suspended on THREAD_START events */
129 if (eventsStart != THREADS_COUNT) {
130 NSK_COMPLAIN2("Unexpected number of THREAD_START events:\n"
131 "# received: %d\n"
132 "# expected: %d\n",
133 eventsStart, THREADS_COUNT);
134 }
135
136 NSK_DISPLAY0("Testcase #1: check threads on THREAD_START\n");
137 if (!NSK_VERIFY(checkThreads("starting")))
138 return;
139
140 NSK_DISPLAY0("Resume all threads\n");
141 if (!NSK_VERIFY(resumeThreads("starting")))
142 return;
143
144 NSK_DISPLAY0("Wait for threads to run\n");
145 if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
146 return;
147 }
148
149 /* testcase #2: suspend and check threads on THREAD_END event */
150 {
151 eventsEnd = 0;
152 if (!NSK_JVMTI_VERIFY(
153 jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_THREAD_END, NULL))) {
154 nsk_jvmti_setFailStatus();
155 return;
156 }
157
158 NSK_DISPLAY0("Let threads to finish\n");
159 if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
160 return;
161
162 NSK_DISPLAY0("Wait for THREAD_END events\n");
163 {
164 int i;
165
166 for (i = 0; i * TIMEOUT_DELTA < timeout; i++) {
167 if (eventsEnd >= THREADS_COUNT)
168 break;
169 nsk_jvmti_sleep(TIMEOUT_DELTA);
170 }
171 }
172
173 if (!NSK_JVMTI_VERIFY(
174 jvmti->SetEventNotificationMode(JVMTI_DISABLE, JVMTI_EVENT_THREAD_END, NULL))) {
175 nsk_jvmti_setFailStatus();
176 }
177
178 /* check ia all threads suspended on THREAD_END event */
179 if (eventsEnd != THREADS_COUNT) {
180 NSK_COMPLAIN2("Unexpected number of THREAD_END events:\n"
181 "# received: %d\n"
182 "# expected: %d\n",
183 eventsEnd, THREADS_COUNT);
184 }
185
186 NSK_DISPLAY0("Testcase #2: check threads on THREAD_END\n");
187 if (!NSK_VERIFY(checkThreads("finishing")))
188 return;
189
190 NSK_DISPLAY0("Resume all threads\n");
191 if (!NSK_VERIFY(resumeThreads("finishing")))
192 return;
193
194 NSK_DISPLAY0("Wait for threads to finish\n");
200 if (!clean()) {
201 nsk_jvmti_setFailStatus();
202 return;
203 }
204 }
205
206 /* resume debugee after last sync */
207 if (!nsk_jvmti_resumeSync())
208 return;
209 }
210
211 /* ============================================================================= */
212
213 /**
214 * Resume all threads in given state.
215 */
216 static int resumeThreads(const char* kind) {
217 int i;
218
219 for (i = 0; i < THREADS_COUNT; i++) {
220 if (!NSK_JVMTI_VERIFY(jvmti->ResumeThread(threadsList[i]))) {
221 nsk_jvmti_setFailStatus();
222 }
223 }
224 return NSK_TRUE;
225 }
226
227 /**
228 * Prepare data:
229 * - get threads array from static field
230 * - get each thread from array
231 * - make global refs
232 */
233 static int prepare() {
234 jclass debugeeClass = NULL;
235 jfieldID threadsFieldID = NULL;
236 jobjectArray threadsArray = NULL;
237 jsize threadsArrayLength = 0;
238 jsize i;
239
240 /* find debugee class */
241 if (!NSK_JNI_VERIFY(jni, (debugeeClass = jni->FindClass(DEBUGEE_CLASS_NAME)) != NULL))
242 return NSK_FALSE;
243
244 /* find static field with threads array */
245 if (!NSK_JNI_VERIFY(jni, (threadsFieldID =
246 jni->GetStaticFieldID(debugeeClass, THREADS_FIELD_NAME, THREADS_FIELD_SIG)) != NULL))
247 return NSK_FALSE;
248
249 /* get threads array from static field */
250 if (!NSK_JNI_VERIFY(jni, (threadsArray = (jobjectArray)
251 jni->GetStaticObjectField(debugeeClass, threadsFieldID)) != NULL))
252 return NSK_FALSE;
253
254 /* check array length */
255 if (!NSK_JNI_VERIFY(jni, (threadsArrayLength =
256 jni->GetArrayLength(threadsArray)) == THREADS_COUNT))
257 return NSK_FALSE;
258
259 /* get each thread from array */
260 for (i = 0; i < THREADS_COUNT; i++) {
261 if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread)
262 jni->GetObjectArrayElement(threadsArray, i)) != NULL))
263 return NSK_FALSE;
264 }
265
266 /* make global references to threads */
267 for (i = 0; i < THREADS_COUNT; i++) {
268 if (!NSK_JNI_VERIFY(jni, (threadsList[i] = (jthread)
269 jni->NewGlobalRef(threadsList[i])) != NULL))
270 return NSK_FALSE;
271 }
272
273 return NSK_TRUE;
274 }
275
276 /**
277 * Check thread's stack on event.
278 *
279 * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break.
280 */
281 static int checkThread(jthread thread, int i, const char* kind) {
282 jint framesCount = 0;
283 jint stackDepth = 0;
284 jvmtiFrameInfo stackFrames[MAX_STACK_DEPTH];
285
286 NSK_DISPLAY3(" thread #%d (%s): %p\n", i, threadsName[i], (void*)thread);
287
288 /* get frames count */
289 if (!NSK_JVMTI_VERIFY(jvmti->GetFrameCount(thread, &framesCount))) {
290 nsk_jvmti_setFailStatus();
291 return NSK_TRUE;
292 }
293 NSK_DISPLAY1(" frames count: %d\n", (int)framesCount);
294
295 /* get stack frames */
296 if (!NSK_JVMTI_VERIFY(
297 jvmti->GetStackTrace(thread, 0, MAX_STACK_DEPTH, stackFrames, &stackDepth))) {
298 nsk_jvmti_setFailStatus();
299 return NSK_TRUE;
300 }
301 NSK_DISPLAY1(" stack depth: %d\n", (int)stackDepth);
302
303 /* check against emptyness */
304 if (framesCount != 0) {
305 NSK_COMPLAIN5("Unexpected GetFramesCount() for %s thread #%d (%s):\n"
306 "# got frames: %d\n"
307 "# expected: %d\n",
308 kind, i, threadsName[i],
309 framesCount, 0);
310 nsk_jvmti_setFailStatus();
311 }
312 if (stackDepth != 0) {
313 NSK_COMPLAIN5("Unexpected GetStackTrace() for %s thread #%d (%s):\n"
314 "# got frames: %d\n"
315 "# expected: %d\n",
316 kind, i, threadsName[i],
317 stackDepth, 0);
329 */
330 static int checkThreads(const char* kind) {
331 int i;
332
333 for (i = 0; i < THREADS_COUNT; i++) {
334 if (!checkThread(threadsList[i], i, kind))
335 return NSK_FALSE;
336 }
337 return NSK_TRUE;
338 }
339
340 /**
341 * Clean data:
342 * - dispose global references to tested threads
343 */
344 static int clean() {
345 int i;
346
347 /* dispose global references to threads */
348 for (i = 0; i < THREADS_COUNT; i++) {
349 NSK_TRACE(jni->DeleteGlobalRef(threadsList[i]));
350 }
351
352 return NSK_TRUE;
353 }
354
355 /* ============================================================================= */
356
357 /**
358 * THREAD_START callback:
359 * - check thread's stack on THREAD_START
360 */
361 JNIEXPORT void JNICALL
362 callbackThreadStart(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) {
363 int i;
364
365 /* check if thread is not NULL */
366 if (!NSK_VERIFY(thread != NULL)) {
367 nsk_jvmti_setFailStatus();
368 return;
369 }
370
371 /* check if event is for tested thread */
372 for (i = 0; i < THREADS_COUNT; i++) {
373 if (jni->IsSameObject(threadsList[i], thread)) {
374 NSK_DISPLAY0("SUCCESS: expected THREAD_START event\n");
375
376 /* suspend thread */
377 NSK_DISPLAY3(" suspend starting thread #%d (%s): %p\n",
378 i, threadsName[i], (void*)thread);
379
380 if (!NSK_JVMTI_VERIFY(jvmti->SuspendThread(thread))) {
381 nsk_jvmti_setFailStatus();
382 return;
383 }
384 eventsStart++;
385
386 break;
387 }
388 }
389 }
390
391 /**
392 * THREAD_END callback:
393 * - check thread's stack on THREAD_END
394 */
395 JNIEXPORT void JNICALL
396 callbackThreadEnd(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread) {
397 int i;
398
399 /* check if thread is not NULL */
400 if (!NSK_VERIFY(thread != NULL)) {
401 nsk_jvmti_setFailStatus();
402 return;
403 }
404
405 /* check if event is for tested thread */
406 for (i = 0; i < THREADS_COUNT; i++) {
407 if (jni->IsSameObject(threadsList[i], thread)) {
408 NSK_DISPLAY0("SUCCESS: expected THREAD_END event\n");
409
410 /* suspend thread */
411 NSK_DISPLAY3(" suspend finishing thread #%d (%s): %p\n",
412 i, threadsName[i], (void*)thread);
413
414 if (!NSK_JVMTI_VERIFY(jvmti->SuspendThread(thread))) {
415 nsk_jvmti_setFailStatus();
416 return;
417 }
418 eventsEnd++;
419
420 break;
421 }
422 }
423 }
424
425 /* ============================================================================= */
426
427 static volatile int testedThreadRunning = NSK_FALSE;
428 static volatile int testedThreadShouldFinish = NSK_FALSE;
429
430 /** Native running method in tested thread. */
431 JNIEXPORT void JNICALL
432 Java_nsk_jvmti_scenarios_sampling_SP05_sp05t003ThreadRunningNative_run(JNIEnv* jni,
433 jobject obj) {
434 volatile int i = 0, n = 1000;
476 return JNI_VERSION_1_8;
477 }
478 #endif
479 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
480 /* init framework and parse options */
481 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
482 return JNI_ERR;
483
484 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
485
486 /* create JVMTI environment */
487 if (!NSK_VERIFY((jvmti =
488 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
489 return JNI_ERR;
490
491 /* add capabilities for suspending thread */
492 {
493 jvmtiCapabilities suspendCaps;
494 memset(&suspendCaps, 0, sizeof(suspendCaps));
495 suspendCaps.can_suspend = 1;
496 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&suspendCaps)))
497 return JNI_ERR;
498 }
499
500 /* set events callbacks */
501 {
502 jvmtiEventCallbacks eventCallbacks;
503 memset(&eventCallbacks, 0, sizeof(eventCallbacks));
504 eventCallbacks.ThreadStart = callbackThreadStart;
505 eventCallbacks.ThreadEnd = callbackThreadEnd;
506 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks))))
507 return JNI_ERR;
508 }
509
510 /* register agent proc and arg */
511 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
512 return JNI_ERR;
513
514 return JNI_OK;
515 }
516
517 /* ============================================================================= */
518
519 }
|