115 TranslateEvent(curr));
116 result = NSK_FALSE;
117 }
118 } else {
119
120 if (currentCounts[i] > 0) {
121 NSK_COMPLAIN2("Unexpected event %s was sent %d times\n",
122 TranslateEvent(curr),
123 currentCounts[i]);
124 result = NSK_FALSE;
125 }
126 }
127 }
128
129 return result;
130 }
131
132 static void
133 changeCount(jvmtiEvent event, int *currentCounts) {
134
135 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock)))
136 nsk_jvmti_setFailStatus();
137
138 currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
139
140 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock)))
141 nsk_jvmti_setFailStatus();
142
143 }
144
145 /* ============================================================================= */
146
147 /* callbacks */
148 JNIEXPORT void JNICALL
149 cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) {
150 changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]);
151 }
152
153 JNIEXPORT void JNICALL
154 cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) {
155 changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]);
156 showEventStatistics(STEP_NUMBER);
157 if (!checkEvents(STEP_NUMBER))
158 nsk_jvmti_setFailStatus();
159
160 if (!NSK_JVMTI_VERIFY(
161 NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock)))
162 nsk_jvmti_setFailStatus();
163
164 }
165
166 void JNICALL
167 cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
168 jmethodID method, jlocation location, jobject exception,
169 jmethodID catch_method, jlocation catch_location) {
170
171 jvmtiThreadInfo info_ptr;
172
173 if (!NSK_JVMTI_VERIFY(
174 NSK_CPP_STUB3(
175 GetThreadInfo, jvmti_env, thread, &info_ptr))) {
176 nsk_jvmti_setFailStatus();
177 return;
178 }
179
180 if (!strncmp(info_ptr.name,"em02t008", 8)) {
181 NSK_DISPLAY1("\tThread: %s\n", info_ptr.name);
182
183 changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]);
184 }
185
186 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
187 jvmti_env, (unsigned char*)info_ptr.name))) {
188 nsk_jvmti_setFailStatus();
189 }
190 }
191
192 void JNICALL
193 cbNewException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
194 jmethodID method, jlocation location, jobject exception,
195 jmethodID catch_method, jlocation catch_location) {
196
197 jvmtiThreadInfo info_ptr;
198
199 if (!NSK_JVMTI_VERIFY(
200 NSK_CPP_STUB3(
201 GetThreadInfo, jvmti_env, thread, &info_ptr))) {
202 nsk_jvmti_setFailStatus();
203 return;
204 }
205
206 if (!strncmp(info_ptr.name,"em02t008", 8)) {
207 NSK_DISPLAY1("\tThread: %s\n", info_ptr.name);
208
209 changeCount(JVMTI_EVENT_EXCEPTION, &newEventCount[0]);
210 }
211
212 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
213 jvmti_env, (unsigned char*)info_ptr.name))) {
214 nsk_jvmti_setFailStatus();
215 }
216 }
217
218 void JNICALL
219 cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
220 jmethodID method, jlocation location, jobject exception) {
221
222 jvmtiThreadInfo info_ptr;
223
224 if (!NSK_JVMTI_VERIFY(
225 NSK_CPP_STUB3(
226 GetThreadInfo, jvmti_env, thread, &info_ptr))) {
227 nsk_jvmti_setFailStatus();
228 return;
229 }
230
231 if (!strncmp(info_ptr.name,"em02t008", 8)) {
232 NSK_DISPLAY1("\tThread: %s\n", info_ptr.name);
233
234 changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]);
235 }
236
237 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
238 jvmti_env, (unsigned char*)info_ptr.name))) {
239 nsk_jvmti_setFailStatus();
240 }
241 }
242
243 void JNICALL
244 cbNewExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
245 jmethodID method, jlocation location, jobject exception) {
246
247 jvmtiThreadInfo info_ptr;
248
249 if (!NSK_JVMTI_VERIFY(
250 NSK_CPP_STUB3(
251 GetThreadInfo, jvmti_env, thread, &info_ptr))) {
252 nsk_jvmti_setFailStatus();
253 return;
254 }
255
256 if (!strncmp(info_ptr.name,"em02t008", 8)) {
257 NSK_DISPLAY1("\tThread: %s\n", info_ptr.name);
258
259 changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &newEventCount[0]);
260 }
261
262 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
263 jvmti_env, (unsigned char*)info_ptr.name))) {
264 nsk_jvmti_setFailStatus();
265 }
266 }
267
268 void JNICALL
269 cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
270 jmethodID method, jlocation location) {
271
272 changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]);
273 }
274
275 void JNICALL
276 cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
277 jmethodID method, jboolean was_popped_by_exception) {
278 changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]);
279 }
280
281 void JNICALL
282 cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
283 jmethodID method, jlocation location) {
373 cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) {
374
375 changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]);
376 }
377
378 void JNICALL
379 cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
380 jobject object, jclass object_klass, jlong size) {
381
382 changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]);
383 }
384
385 /* ============================================================================= */
386
387 static int enableEvent(jvmtiEvent event) {
388
389 if (nsk_jvmti_isOptionalEvent(event)
390 && (event != JVMTI_EVENT_EXCEPTION)
391 && (event != JVMTI_EVENT_EXCEPTION_CATCH)) {
392 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
393 NSK_CPP_STUB4(SetEventNotificationMode, jvmti,
394 JVMTI_ENABLE, event, NULL))) {
395 NSK_COMPLAIN1("Unexpected error enabling %s\n",
396 TranslateEvent(event));
397 return NSK_FALSE;
398 }
399 } else {
400 if (!NSK_JVMTI_VERIFY(
401 NSK_CPP_STUB4(SetEventNotificationMode, jvmti,
402 JVMTI_ENABLE, event, NULL))) {
403 NSK_COMPLAIN1("Unexpected error enabling %s\n",
404 TranslateEvent(event));
405 return NSK_FALSE;
406 }
407 }
408
409 return NSK_TRUE;
410 }
411
412 /**
413 * Enable or disable tested events.
414 */
415 static int enableEventList() {
416
417 int i, result;
418
419 result = enableEvent(JVMTI_EVENT_VM_INIT);
420
421 result = result && enableEvent(JVMTI_EVENT_VM_DEATH);
422
476 break;
477
478 case 2:
479 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
480 newEventCount[i] = 0;
481 }
482
483 eventCallbacks.Exception = cbNewException;
484 eventCallbacks.ExceptionCatch = cbNewExceptionCatch;
485 break;
486
487 case 3:
488 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
489 newEventCount[i] = 0;
490 }
491
492 eventCallbacks.VMDeath = cbVMDeath;
493 break;
494
495 }
496 if (!NSK_JVMTI_VERIFY(
497 NSK_CPP_STUB3(SetEventCallbacks, jvmti,
498 &eventCallbacks,
499 sizeof(eventCallbacks))))
500 return NSK_FALSE;
501
502 return NSK_TRUE;
503 }
504
505 /* ============================================================================= */
506
507 /** Agent algorithm. */
508 static void JNICALL
509 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
510
511 int i;
512
513 for (i = 1; i <= STEP_NUMBER; i++) {
514
515 if (!nsk_jvmti_waitForSync(timeout))
516 return;
517
518 if (i < STEP_NUMBER) {
519 showEventStatistics(i);
538 JNIEXPORT jint JNICALL Agent_OnLoad_em02t008(JavaVM *jvm, char *options, void *reserved) {
539 return Agent_Initialize(jvm, options, reserved);
540 }
541 JNIEXPORT jint JNICALL Agent_OnAttach_em02t008(JavaVM *jvm, char *options, void *reserved) {
542 return Agent_Initialize(jvm, options, reserved);
543 }
544 JNIEXPORT jint JNI_OnLoad_em02t008(JavaVM *jvm, char *options, void *reserved) {
545 return JNI_VERSION_1_8;
546 }
547 #endif
548 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
549
550 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
551 return JNI_ERR;
552
553 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
554
555 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
556 return JNI_ERR;
557
558 if (!NSK_JVMTI_VERIFY(
559 NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) {
560 nsk_jvmti_setFailStatus();
561 return JNI_ERR;
562 }
563
564 {
565 jvmtiCapabilities caps;
566 memset(&caps, 0, sizeof(caps));
567
568 caps.can_generate_exception_events = 1;
569 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)))
570 return JNI_ERR;
571 }
572
573 if (!setCallBacks(1)) {
574 return JNI_ERR;
575 }
576
577 if (!enableEventList()) {
578 return JNI_ERR;
579 }
580
581 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
582 return JNI_ERR;
583
584 return JNI_OK;
585 }
586
587 /* ============================================================================= */
588
589
|
115 TranslateEvent(curr));
116 result = NSK_FALSE;
117 }
118 } else {
119
120 if (currentCounts[i] > 0) {
121 NSK_COMPLAIN2("Unexpected event %s was sent %d times\n",
122 TranslateEvent(curr),
123 currentCounts[i]);
124 result = NSK_FALSE;
125 }
126 }
127 }
128
129 return result;
130 }
131
132 static void
133 changeCount(jvmtiEvent event, int *currentCounts) {
134
135 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(syncLock)))
136 nsk_jvmti_setFailStatus();
137
138 currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
139
140 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(syncLock)))
141 nsk_jvmti_setFailStatus();
142
143 }
144
145 /* ============================================================================= */
146
147 /* callbacks */
148 JNIEXPORT void JNICALL
149 cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) {
150 changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]);
151 }
152
153 JNIEXPORT void JNICALL
154 cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) {
155 changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]);
156 showEventStatistics(STEP_NUMBER);
157 if (!checkEvents(STEP_NUMBER))
158 nsk_jvmti_setFailStatus();
159
160 if (!NSK_JVMTI_VERIFY(jvmti->DestroyRawMonitor(syncLock)))
161 nsk_jvmti_setFailStatus();
162
163 }
164
165 void JNICALL
166 cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
167 jmethodID method, jlocation location, jobject exception,
168 jmethodID catch_method, jlocation catch_location) {
169
170 jvmtiThreadInfo info_ptr;
171
172 if (!NSK_JVMTI_VERIFY(jvmti_env->GetThreadInfo(thread, &info_ptr))) {
173 nsk_jvmti_setFailStatus();
174 return;
175 }
176
177 if (!strncmp(info_ptr.name,"em02t008", 8)) {
178 NSK_DISPLAY1("\tThread: %s\n", info_ptr.name);
179
180 changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]);
181 }
182
183 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)info_ptr.name))) {
184 nsk_jvmti_setFailStatus();
185 }
186 }
187
188 void JNICALL
189 cbNewException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
190 jmethodID method, jlocation location, jobject exception,
191 jmethodID catch_method, jlocation catch_location) {
192
193 jvmtiThreadInfo info_ptr;
194
195 if (!NSK_JVMTI_VERIFY(jvmti_env->GetThreadInfo(thread, &info_ptr))) {
196 nsk_jvmti_setFailStatus();
197 return;
198 }
199
200 if (!strncmp(info_ptr.name,"em02t008", 8)) {
201 NSK_DISPLAY1("\tThread: %s\n", info_ptr.name);
202
203 changeCount(JVMTI_EVENT_EXCEPTION, &newEventCount[0]);
204 }
205
206 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)info_ptr.name))) {
207 nsk_jvmti_setFailStatus();
208 }
209 }
210
211 void JNICALL
212 cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
213 jmethodID method, jlocation location, jobject exception) {
214
215 jvmtiThreadInfo info_ptr;
216
217 if (!NSK_JVMTI_VERIFY(jvmti_env->GetThreadInfo(thread, &info_ptr))) {
218 nsk_jvmti_setFailStatus();
219 return;
220 }
221
222 if (!strncmp(info_ptr.name,"em02t008", 8)) {
223 NSK_DISPLAY1("\tThread: %s\n", info_ptr.name);
224
225 changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]);
226 }
227
228 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)info_ptr.name))) {
229 nsk_jvmti_setFailStatus();
230 }
231 }
232
233 void JNICALL
234 cbNewExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
235 jmethodID method, jlocation location, jobject exception) {
236
237 jvmtiThreadInfo info_ptr;
238
239 if (!NSK_JVMTI_VERIFY(jvmti_env->GetThreadInfo(thread, &info_ptr))) {
240 nsk_jvmti_setFailStatus();
241 return;
242 }
243
244 if (!strncmp(info_ptr.name,"em02t008", 8)) {
245 NSK_DISPLAY1("\tThread: %s\n", info_ptr.name);
246
247 changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &newEventCount[0]);
248 }
249
250 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)info_ptr.name))) {
251 nsk_jvmti_setFailStatus();
252 }
253 }
254
255 void JNICALL
256 cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
257 jmethodID method, jlocation location) {
258
259 changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]);
260 }
261
262 void JNICALL
263 cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
264 jmethodID method, jboolean was_popped_by_exception) {
265 changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]);
266 }
267
268 void JNICALL
269 cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
270 jmethodID method, jlocation location) {
360 cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) {
361
362 changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]);
363 }
364
365 void JNICALL
366 cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
367 jobject object, jclass object_klass, jlong size) {
368
369 changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]);
370 }
371
372 /* ============================================================================= */
373
374 static int enableEvent(jvmtiEvent event) {
375
376 if (nsk_jvmti_isOptionalEvent(event)
377 && (event != JVMTI_EVENT_EXCEPTION)
378 && (event != JVMTI_EVENT_EXCEPTION_CATCH)) {
379 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
380 jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, NULL))) {
381 NSK_COMPLAIN1("Unexpected error enabling %s\n",
382 TranslateEvent(event));
383 return NSK_FALSE;
384 }
385 } else {
386 if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, NULL))) {
387 NSK_COMPLAIN1("Unexpected error enabling %s\n",
388 TranslateEvent(event));
389 return NSK_FALSE;
390 }
391 }
392
393 return NSK_TRUE;
394 }
395
396 /**
397 * Enable or disable tested events.
398 */
399 static int enableEventList() {
400
401 int i, result;
402
403 result = enableEvent(JVMTI_EVENT_VM_INIT);
404
405 result = result && enableEvent(JVMTI_EVENT_VM_DEATH);
406
460 break;
461
462 case 2:
463 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
464 newEventCount[i] = 0;
465 }
466
467 eventCallbacks.Exception = cbNewException;
468 eventCallbacks.ExceptionCatch = cbNewExceptionCatch;
469 break;
470
471 case 3:
472 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
473 newEventCount[i] = 0;
474 }
475
476 eventCallbacks.VMDeath = cbVMDeath;
477 break;
478
479 }
480 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks))))
481 return NSK_FALSE;
482
483 return NSK_TRUE;
484 }
485
486 /* ============================================================================= */
487
488 /** Agent algorithm. */
489 static void JNICALL
490 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
491
492 int i;
493
494 for (i = 1; i <= STEP_NUMBER; i++) {
495
496 if (!nsk_jvmti_waitForSync(timeout))
497 return;
498
499 if (i < STEP_NUMBER) {
500 showEventStatistics(i);
519 JNIEXPORT jint JNICALL Agent_OnLoad_em02t008(JavaVM *jvm, char *options, void *reserved) {
520 return Agent_Initialize(jvm, options, reserved);
521 }
522 JNIEXPORT jint JNICALL Agent_OnAttach_em02t008(JavaVM *jvm, char *options, void *reserved) {
523 return Agent_Initialize(jvm, options, reserved);
524 }
525 JNIEXPORT jint JNI_OnLoad_em02t008(JavaVM *jvm, char *options, void *reserved) {
526 return JNI_VERSION_1_8;
527 }
528 #endif
529 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
530
531 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
532 return JNI_ERR;
533
534 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
535
536 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
537 return JNI_ERR;
538
539 if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("_syncLock", &syncLock))) {
540 nsk_jvmti_setFailStatus();
541 return JNI_ERR;
542 }
543
544 {
545 jvmtiCapabilities caps;
546 memset(&caps, 0, sizeof(caps));
547
548 caps.can_generate_exception_events = 1;
549 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))
550 return JNI_ERR;
551 }
552
553 if (!setCallBacks(1)) {
554 return JNI_ERR;
555 }
556
557 if (!enableEventList()) {
558 return JNI_ERR;
559 }
560
561 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
562 return JNI_ERR;
563
564 return JNI_OK;
565 }
566
567 /* ============================================================================= */
568
569
|