116 TranslateEvent(curr));
117 result = NSK_FALSE;
118 }
119 } else {
120
121 if (currentCounts[i] > 0) {
122 NSK_COMPLAIN2("Unexpected event %s was sent %d times\n",
123 TranslateEvent(curr),
124 currentCounts[i]);
125 result = NSK_FALSE;
126 }
127 }
128 }
129
130 return result;
131 }
132
133 static void
134 changeCount(jvmtiEvent event, int *currentCounts) {
135
136 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock)))
137 nsk_jvmti_setFailStatus();
138
139 currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
140
141 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock)))
142 nsk_jvmti_setFailStatus();
143
144 }
145
146 /* ============================================================================= */
147
148 /* callbacks */
149 JNIEXPORT void JNICALL
150 cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) {
151 changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]);
152 }
153
154 JNIEXPORT void JNICALL
155 cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) {
156 changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]);
157 showEventStatistics(STEP_NUMBER);
158 if (!checkEvents(STEP_NUMBER))
159 nsk_jvmti_setFailStatus();
160
161 if (!NSK_JVMTI_VERIFY(
162 NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock)))
163 nsk_jvmti_setFailStatus();
164
165 }
166
167 void JNICALL
168 cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
169 jmethodID method, jlocation location, jobject exception,
170 jmethodID catch_method, jlocation catch_location) {
171 changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]);
172 }
173
174 void JNICALL
175 cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
176 jmethodID method, jlocation location, jobject exception) {
177 changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]);
178 }
179
180 void JNICALL
181 cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
182 jmethodID method, jlocation location) {
183 char *name;
184 char *sign;
185 char *genc;
186
187 if (!NSK_JVMTI_VERIFY(
188 NSK_CPP_STUB5(
189 GetMethodName, jvmti_env, method, &name, &sign, &genc))) {
190 nsk_jvmti_setFailStatus();
191 return;
192 }
193
194 if (!strncmp(name,"javaMethod", 8)) {
195 NSK_DISPLAY2("\tMethod: %s, location: %lld\n",
196 name, location);
197 changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]);
198 }
199
200 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
201 jvmti_env, (unsigned char*)name))) {
202 nsk_jvmti_setFailStatus();
203 }
204 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
205 jvmti_env, (unsigned char*)sign))) {
206 nsk_jvmti_setFailStatus();
207 }
208 if (genc != NULL)
209 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
210 jvmti_env, (unsigned char*)genc))) {
211 nsk_jvmti_setFailStatus();
212 }
213 }
214
215 void JNICALL
216 cbNewSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
217 jmethodID method, jlocation location) {
218 char *name;
219 char *sign;
220 char *genc;
221
222 if (!NSK_JVMTI_VERIFY(
223 NSK_CPP_STUB5(
224 GetMethodName, jvmti_env, method, &name, &sign, &genc))) {
225 nsk_jvmti_setFailStatus();
226 return;
227 }
228
229 if (!strncmp(name,"javaMethod", 8)) {
230 NSK_DISPLAY2("\tMethod: %s, location: %lld\n",
231 name, location);
232 changeCount(JVMTI_EVENT_SINGLE_STEP, &newEventCount[0]);
233 }
234
235 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
236 jvmti_env, (unsigned char*)name))) {
237 nsk_jvmti_setFailStatus();
238 }
239 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
240 jvmti_env, (unsigned char*)sign))) {
241 nsk_jvmti_setFailStatus();
242 }
243 if (genc != NULL)
244 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
245 jvmti_env, (unsigned char*)genc))) {
246 nsk_jvmti_setFailStatus();
247 }
248 }
249
250 void JNICALL
251 cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
252 jmethodID method, jboolean was_popped_by_exception) {
253 changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]);
254 }
255
256 void JNICALL
257 cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
258 jmethodID method, jlocation location) {
259 changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]);
260 }
261
262 void JNICALL
263 cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
264 jmethodID method, jlocation location, jclass field_klass,
265 jobject object, jfieldID field) {
351 if (tag < 1 || tag > OBJECT_NUMBER) {
352 NSK_COMPLAIN1("Unexpected tag value %lld\n", tag);
353 nsk_jvmti_setFailStatus();
354 }
355 }
356
357 void JNICALL
358 cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
359 jobject object, jclass object_klass, jlong size) {
360
361 changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]);
362 }
363
364 /* ============================================================================= */
365
366 static int enableEvent(jvmtiEvent event) {
367
368 if (nsk_jvmti_isOptionalEvent(event)
369 && (event != JVMTI_EVENT_SINGLE_STEP)) {
370 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
371 NSK_CPP_STUB4(SetEventNotificationMode, jvmti,
372 JVMTI_ENABLE, event, NULL))) {
373 NSK_COMPLAIN1("Unexpected error enabling %s\n",
374 TranslateEvent(event));
375 return NSK_FALSE;
376 }
377 } else {
378 if (!NSK_JVMTI_VERIFY(
379 NSK_CPP_STUB4(SetEventNotificationMode, jvmti,
380 JVMTI_ENABLE, event, NULL))) {
381 NSK_COMPLAIN1("Unexpected error enabling %s\n",
382 TranslateEvent(event));
383 return NSK_FALSE;
384 }
385 }
386
387 return NSK_TRUE;
388 }
389
390 /**
391 * Enable or disable tested events.
392 */
393 static int enableEventList() {
394
395 int i, result;
396
397 result = enableEvent(JVMTI_EVENT_VM_INIT);
398
399 result = result && enableEvent(JVMTI_EVENT_VM_DEATH);
400
460
461 eventCallbacks.SingleStep = cbNewSingleStep;
462 break;
463
464 case 3:
465 /* comparing number of JVMTI_EVENT_SINGLE_STEP events for steps*/
466 if (eventCount[singleStepIdx] != newEventCount[singleStepIdx]) {
467 NSK_COMPLAIN2("Number of JVMTI_EVENT_SINGLE_STEP events must be the same\n\t1-st callback=%d; 2-nd callback=%d\n",
468 eventCount[singleStepIdx],
469 newEventCount[singleStepIdx]);
470 }
471
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(
481 NSK_CPP_STUB3(SetEventCallbacks, jvmti,
482 &eventCallbacks,
483 sizeof(eventCallbacks))))
484 return NSK_FALSE;
485
486 return NSK_TRUE;
487 }
488
489 /* ============================================================================= */
490
491 /** Agent algorithm. */
492 static void JNICALL
493 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
494
495 int i;
496
497 for (i = 1; i <= STEP_NUMBER; i++) {
498
499 if (!nsk_jvmti_waitForSync(timeout))
500 return;
501
502 NSK_DISPLAY0("Check received events\n");
503
524 JNIEXPORT jint JNICALL Agent_OnLoad_em02t007(JavaVM *jvm, char *options, void *reserved) {
525 return Agent_Initialize(jvm, options, reserved);
526 }
527 JNIEXPORT jint JNICALL Agent_OnAttach_em02t007(JavaVM *jvm, char *options, void *reserved) {
528 return Agent_Initialize(jvm, options, reserved);
529 }
530 JNIEXPORT jint JNI_OnLoad_em02t007(JavaVM *jvm, char *options, void *reserved) {
531 return JNI_VERSION_1_8;
532 }
533 #endif
534 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
535
536 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
537 return JNI_ERR;
538
539 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
540
541 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
542 return JNI_ERR;
543
544 if (!NSK_JVMTI_VERIFY(
545 NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) {
546 nsk_jvmti_setFailStatus();
547 return JNI_ERR;
548 }
549
550 {
551 jvmtiCapabilities caps;
552 memset(&caps, 0, sizeof(caps));
553
554 caps.can_generate_single_step_events = 1;
555 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)))
556 return JNI_ERR;
557 }
558
559 if (!setCallBacks(1)) {
560 return JNI_ERR;
561 }
562
563 if (!enableEventList()) {
564 return JNI_ERR;
565 }
566
567 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
568 return JNI_ERR;
569
570 return JNI_OK;
571 }
572
573 /* ============================================================================= */
574
575
|
116 TranslateEvent(curr));
117 result = NSK_FALSE;
118 }
119 } else {
120
121 if (currentCounts[i] > 0) {
122 NSK_COMPLAIN2("Unexpected event %s was sent %d times\n",
123 TranslateEvent(curr),
124 currentCounts[i]);
125 result = NSK_FALSE;
126 }
127 }
128 }
129
130 return result;
131 }
132
133 static void
134 changeCount(jvmtiEvent event, int *currentCounts) {
135
136 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(syncLock)))
137 nsk_jvmti_setFailStatus();
138
139 currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
140
141 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(syncLock)))
142 nsk_jvmti_setFailStatus();
143
144 }
145
146 /* ============================================================================= */
147
148 /* callbacks */
149 JNIEXPORT void JNICALL
150 cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) {
151 changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]);
152 }
153
154 JNIEXPORT void JNICALL
155 cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) {
156 changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]);
157 showEventStatistics(STEP_NUMBER);
158 if (!checkEvents(STEP_NUMBER))
159 nsk_jvmti_setFailStatus();
160
161 if (!NSK_JVMTI_VERIFY(jvmti->DestroyRawMonitor(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 changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]);
171 }
172
173 void JNICALL
174 cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
175 jmethodID method, jlocation location, jobject exception) {
176 changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]);
177 }
178
179 void JNICALL
180 cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
181 jmethodID method, jlocation location) {
182 char *name;
183 char *sign;
184 char *genc;
185
186 if (!NSK_JVMTI_VERIFY(jvmti_env->GetMethodName(method, &name, &sign, &genc))) {
187 nsk_jvmti_setFailStatus();
188 return;
189 }
190
191 if (!strncmp(name,"javaMethod", 8)) {
192 NSK_DISPLAY2("\tMethod: %s, location: %lld\n",
193 name, location);
194 changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]);
195 }
196
197 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)name))) {
198 nsk_jvmti_setFailStatus();
199 }
200 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)sign))) {
201 nsk_jvmti_setFailStatus();
202 }
203 if (genc != NULL)
204 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)genc))) {
205 nsk_jvmti_setFailStatus();
206 }
207 }
208
209 void JNICALL
210 cbNewSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
211 jmethodID method, jlocation location) {
212 char *name;
213 char *sign;
214 char *genc;
215
216 if (!NSK_JVMTI_VERIFY(jvmti_env->GetMethodName(method, &name, &sign, &genc))) {
217 nsk_jvmti_setFailStatus();
218 return;
219 }
220
221 if (!strncmp(name,"javaMethod", 8)) {
222 NSK_DISPLAY2("\tMethod: %s, location: %lld\n",
223 name, location);
224 changeCount(JVMTI_EVENT_SINGLE_STEP, &newEventCount[0]);
225 }
226
227 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)name))) {
228 nsk_jvmti_setFailStatus();
229 }
230 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)sign))) {
231 nsk_jvmti_setFailStatus();
232 }
233 if (genc != NULL)
234 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)genc))) {
235 nsk_jvmti_setFailStatus();
236 }
237 }
238
239 void JNICALL
240 cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
241 jmethodID method, jboolean was_popped_by_exception) {
242 changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]);
243 }
244
245 void JNICALL
246 cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
247 jmethodID method, jlocation location) {
248 changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]);
249 }
250
251 void JNICALL
252 cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
253 jmethodID method, jlocation location, jclass field_klass,
254 jobject object, jfieldID field) {
340 if (tag < 1 || tag > OBJECT_NUMBER) {
341 NSK_COMPLAIN1("Unexpected tag value %lld\n", tag);
342 nsk_jvmti_setFailStatus();
343 }
344 }
345
346 void JNICALL
347 cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
348 jobject object, jclass object_klass, jlong size) {
349
350 changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]);
351 }
352
353 /* ============================================================================= */
354
355 static int enableEvent(jvmtiEvent event) {
356
357 if (nsk_jvmti_isOptionalEvent(event)
358 && (event != JVMTI_EVENT_SINGLE_STEP)) {
359 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
360 jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, NULL))) {
361 NSK_COMPLAIN1("Unexpected error enabling %s\n",
362 TranslateEvent(event));
363 return NSK_FALSE;
364 }
365 } else {
366 if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, NULL))) {
367 NSK_COMPLAIN1("Unexpected error enabling %s\n",
368 TranslateEvent(event));
369 return NSK_FALSE;
370 }
371 }
372
373 return NSK_TRUE;
374 }
375
376 /**
377 * Enable or disable tested events.
378 */
379 static int enableEventList() {
380
381 int i, result;
382
383 result = enableEvent(JVMTI_EVENT_VM_INIT);
384
385 result = result && enableEvent(JVMTI_EVENT_VM_DEATH);
386
446
447 eventCallbacks.SingleStep = cbNewSingleStep;
448 break;
449
450 case 3:
451 /* comparing number of JVMTI_EVENT_SINGLE_STEP events for steps*/
452 if (eventCount[singleStepIdx] != newEventCount[singleStepIdx]) {
453 NSK_COMPLAIN2("Number of JVMTI_EVENT_SINGLE_STEP events must be the same\n\t1-st callback=%d; 2-nd callback=%d\n",
454 eventCount[singleStepIdx],
455 newEventCount[singleStepIdx]);
456 }
457
458 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
459 newEventCount[i] = 0;
460 }
461
462 eventCallbacks.VMDeath = cbVMDeath;
463 break;
464
465 }
466 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks))))
467 return NSK_FALSE;
468
469 return NSK_TRUE;
470 }
471
472 /* ============================================================================= */
473
474 /** Agent algorithm. */
475 static void JNICALL
476 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
477
478 int i;
479
480 for (i = 1; i <= STEP_NUMBER; i++) {
481
482 if (!nsk_jvmti_waitForSync(timeout))
483 return;
484
485 NSK_DISPLAY0("Check received events\n");
486
507 JNIEXPORT jint JNICALL Agent_OnLoad_em02t007(JavaVM *jvm, char *options, void *reserved) {
508 return Agent_Initialize(jvm, options, reserved);
509 }
510 JNIEXPORT jint JNICALL Agent_OnAttach_em02t007(JavaVM *jvm, char *options, void *reserved) {
511 return Agent_Initialize(jvm, options, reserved);
512 }
513 JNIEXPORT jint JNI_OnLoad_em02t007(JavaVM *jvm, char *options, void *reserved) {
514 return JNI_VERSION_1_8;
515 }
516 #endif
517 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
518
519 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
520 return JNI_ERR;
521
522 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
523
524 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
525 return JNI_ERR;
526
527 if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("_syncLock", &syncLock))) {
528 nsk_jvmti_setFailStatus();
529 return JNI_ERR;
530 }
531
532 {
533 jvmtiCapabilities caps;
534 memset(&caps, 0, sizeof(caps));
535
536 caps.can_generate_single_step_events = 1;
537 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))
538 return JNI_ERR;
539 }
540
541 if (!setCallBacks(1)) {
542 return JNI_ERR;
543 }
544
545 if (!enableEventList()) {
546 return JNI_ERR;
547 }
548
549 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
550 return JNI_ERR;
551
552 return JNI_OK;
553 }
554
555 /* ============================================================================= */
556
557
|