16 if (JVMTI_REQUESTED_EVENT (X)) \
21 printf ("RequestedEvents: ");
26 DO (ClassFileLoadHook);
36 DO (FieldModification);
39 DO (NativeMethodBind);
40 DO (CompiledMethodLoad);
41 DO (CompiledMethodUnload);
42 DO (DynamicCodeGenerated);
46 DO (MonitorContendedEnter);
47 DO (MonitorContendedEntered);
48 DO (GarbageCollectionStart);
49 DO (GarbageCollectionFinish);
57 VMInitCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread)
59 printf ("VMInitCB jni_env=%#llx thread=%#llx\n",
60 (unsigned long long) jni_env, (unsigned long long) thread);
64 VMDeathCB (jvmtiEnv *env, JNIEnv *jni_env)
66 printf ("VMDeathCB jni_env=%#llx\n", (unsigned long long) jni_env);
70 ThreadStartCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread)
72 printf ("ThreadStartCB jni_env=%#llx thread=%#llx\n",
73 (unsigned long long) jni_env, (unsigned long long) thread);
77 ThreadEndCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread)
79 printf ("ThreadEndCB jni_env=%#llx thread=%#llx\n",
80 (unsigned long long) jni_env, (unsigned long long) thread);
84 ClassFileLoadHookCB (jvmtiEnv *env, JNIEnv *jni_env,
85 jclass class_being_redefined, jobject loader,
86 const char *name, jobject protection_domain,
87 jint class_data_len, const unsigned char *class_data,
88 jint *new_class_data_len, unsigned char **new_class_data)
90 printf ("ClassFileLoadHookCB jni_env=%#llx class_being_redefined=%#llx"
91 " loader=%#llx", (unsigned long long) jni_env, (unsigned long long)
92 class_being_redefined, (unsigned long long) loader);
93 printf (" name=%s protection_domain=%#llx class_data_len=%d class_data=%#llx",
94 name, (unsigned long long) protection_domain, (int) class_data_len,
95 (unsigned long long) class_data);
96 printf (" new_class_data_len=%#llx new_class_data=%#llx\n",
97 (unsigned long long) new_class_data_len, (unsigned long long)
102 ClassLoadCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread, jclass klass)
104 printf ("ClassLoadCB jni_env=%#llx thread=%#llx klass=%#llx\n",
105 (unsigned long long) jni_env, (unsigned long long) thread,
106 (unsigned long long) klass);
110 ClassPrepareCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread, jclass klass)
112 printf ("ClassPrepareCB jni_env=%#llx thread=%#llx klass=%#llx\n",
113 (unsigned long long)jni_env, (unsigned long long) thread,
114 (unsigned long long) klass);
118 VMStartCB (jvmtiEnv *env, JNIEnv *jni_env)
120 printf ("VMStartCB jni_env=%#llx\n", (unsigned long long) jni_env);
124 ExceptionCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread, jmethodID method,
125 jlocation location, jobject exception, jmethodID catch_method,
126 jlocation catch_location)
128 printf ("ExceptionCB jni_env=%#llx thread=%#llx method=%#llx location=%#llx",
129 (unsigned long long) jni_env, (unsigned long long) thread,
130 (unsigned long long) method, (unsigned long long) location);
131 printf (" exception=%#llx catch_method=%#llx catch_location=%#llx\n",
132 (unsigned long long) exception, (unsigned long long) catch_method,
133 (unsigned long long) catch_location);
137 ExceptionCatchCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread,
138 jmethodID method, jlocation location, jobject exception)
140 printf ("ExceptionCatchCB jni_env=%#llx thread=%#llx method=%#llx"
142 (unsigned long long) jni_env, (unsigned long long) thread,
143 (unsigned long long) method, (unsigned long long) location);
144 printf (" exception=%#llx\n", (unsigned long long) exception);
148 SingleStepCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread, jmethodID method,
151 printf ("SingleStepCB jni_env=%#llx thread=%#llx method=%#llx"
153 (unsigned long long) jni_env, (unsigned long long) thread,
154 (unsigned long long) method, (unsigned long long) location);
158 FramePopCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread, jmethodID method,
159 jboolean was_popped_by_exception)
161 printf ("FramePopCB jni_env=%#llx thread=%#llx method=%#llx",
162 (unsigned long long) jni_env, (unsigned long long) thread,
163 (unsigned long long) method);
164 printf (" was_pooped_by_exception=%d\n", (was_popped_by_exception ?
169 BreakpointCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread, jmethodID method,
172 printf ("BreakpointCB jni_env=%#llx thread=%#llx method=%#llx"
173 " location=%#llx\n", (unsigned long long) jni_env,
174 (unsigned long long) thread, (unsigned long long) method,
175 (unsigned long long) location);
179 FieldAccessCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread,
180 jmethodID method, jlocation location, jclass field_klass,
181 jobject object, jfieldID field)
183 printf ("FieldAccessCB jni_env=%#llx thread=%#llx method=%#llx"
184 " location=%#llx", (unsigned long long) jni_env, (unsigned long long)
185 thread, (unsigned long long) method, (unsigned long long) location);
186 printf (" field_klass=%#llx object=%#llx field=%#llx\n", (unsigned long long)
187 field_klass, (unsigned long long) object, (unsigned long long) field);
191 FieldModificationCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread,
192 jmethodID method, jlocation location, jclass field_klass,
193 jobject object, jfieldID field, char signature_type,
197 printf ("FieldModificationCB jni_env=%#llx thread=%#llx method=%#llx"
198 " location=%#llx", (unsigned long long) jni_env, (unsigned long long)
199 thread, (unsigned long long) method, (unsigned long long) location);
200 printf (" field_klass=%#llx object=%#llx field=%#llx signature_type=%c",
201 (unsigned long long) field_klass, (unsigned long long) object,
202 (unsigned long long) field, signature_type);
203 printf (" new_value=%d\n", (int) new_value.i);
207 MethodEntryCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread,
210 printf ("MethodEntryCB jni_env=%#llx thread=%#llx method=%#llx\n",
211 (unsigned long long) jni_env, (unsigned long long) thread,
212 (unsigned long long) method);
216 MethodExitCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread,
217 jmethodID method, jboolean was_popped_by_exception,
220 printf ("MethodExitCB jni_env=%#llx thread=%#llx method=%#llx",
221 (unsigned long long) jni_env, (unsigned long long) thread,
222 (unsigned long long) method);
223 printf (" was_popped_by_exception=%d return_value=%d\n",
224 (was_popped_by_exception) ? 1 : 0, (int) return_value.i);
228 NativeMethodBindCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread,
229 jmethodID method, void *address, void **new_address_ptr)
231 printf ("NativeMethodBindCB jni_env=%#llx thread=%#llx method=%#llx",
232 (unsigned long long) jni_env, (unsigned long long) thread,
233 (unsigned long long) method);
234 printf (" address=%#llx new_address_ptr=%#llx\n", (unsigned long long)
235 address, (unsigned long long) new_address_ptr);
239 CompiledMethodLoadCB (jvmtiEnv *env, jmethodID method, jint code_size,
240 const void *code_addr, jint map_length,
241 const jvmtiAddrLocationMap *map,
242 const void *compile_info)
244 printf ("CompiledMethodLoadCB method=%#llx code_size=%#llx code_addr=%#llx",
245 (unsigned long long) method, (unsigned long long) code_size,
246 (unsigned long long) code_addr);
247 printf (" map_length=%d map=%#llx compile_info=%#llx\n", (int) map_length,
248 (unsigned long long) map, (unsigned long long) compile_info);
252 CompiledMethodUnloadCB (jvmtiEnv *env, jmethodID method, const void *code_addr)
254 printf ("CompiledMethodUnloadCB method=%#llx code_addr=%#llx\n",
255 (unsigned long long) method, (unsigned long long) code_addr);
259 DynamicCodeGeneratedCB (jvmtiEnv *env, const char *name, const void *address,
262 printf ("DynamicCodeGeneratedCB name=%s address=%#llx length=%d\n", name,
263 (unsigned long long) address, (int) length);
267 DataDumpRequestCB (jvmtiEnv *env)
269 printf ("DataDumpRequestCB\n");
273 MonitorWaitCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread, jobject object,
276 printf ("MonitorWaitCB jni_env=%#llx thread=%#llx object=%#llx timeout=%ld\n",
277 (unsigned long long) jni_env, (unsigned long long) thread,
278 (unsigned long long) object, (long) timeout);
282 MonitorWaitedCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread,
283 jobject object, jboolean timed_out)
285 printf ("MonitorWaitedCB jni_env=%#llx thread=%#llx object=%#llx"
286 " timed_out=%d\n", (unsigned long long) jni_env, (unsigned long long)
287 thread, (unsigned long long) object, (timed_out) ? 1 : 0);
291 MonitorContendedEnterCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread,
294 printf ("MonitorContendedEnterCB jni_env=%#llx thread=%#llx object=%#llx\n",
295 (unsigned long long) jni_env, (unsigned long long) thread,
296 (unsigned long long) object);
300 MonitorContendedEnteredCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread,
303 printf ("MonitorContendedEnteredCB jni_env=%#llx thread=%#llx object=%#llx\n",
304 (unsigned long long) jni_env, (unsigned long long) thread,
305 (unsigned long long) object);
309 GarbageCollectionStartCB (jvmtiEnv *env)
311 printf ("GarbageCollectionStartCB\n");
315 GarbageCollectionFinishCB (jvmtiEnv *env)
317 printf ("GarbageCollectionFinishCB\n");
321 ObjectFreeCB (jvmtiEnv *env, jlong tag)
323 printf ("ObjectFreeCB tag=%ld\n", (long) tag);
327 VMObjectAllocCB (jvmtiEnv *env, JNIEnv *jni_env, jthread thread,
328 jobject object, jclass object_klass, jlong size)
330 printf ("VMObjectAllocCB jni_env=%#llx thread=%#llx object=%#llx",
331 (unsigned long long) jni_env, (unsigned long long) thread,
332 (unsigned long long) object);
333 printf (" object_klass=%#llx size=%ld\n", (unsigned long long) object_klass,
340 printf ("- enable tests -\n");
341 JavaVM *vm = _Jv_GetJavaVM ();
344 for (i = 0; i < 3; ++i)
346 vm->GetEnv (reinterpret_cast<void **> (&env[i]), JVMTI_VERSION_1_0);
347 printf ("created JVMTI environment #%d\n", i);
350 jvmtiEventCallbacks callbacks;
351 memset (&callbacks, 0, sizeof (jvmtiEventCallbacks));
353 printf ("setting callbacks for envs\n");
354 callbacks.VMInit = VMInitCB;
355 env[0]->SetEventCallbacks (&callbacks, sizeof (callbacks));
356 callbacks.VMDeath = VMDeathCB;
357 env[1]->SetEventCallbacks (&callbacks, sizeof (callbacks));
358 callbacks.ThreadEnd = ThreadEndCB;
359 env[2]->SetEventCallbacks (&callbacks, sizeof (callbacks));
362 printf ("enable VM_INIT for env0, env1, env2\n");
363 env[0]->SetEventNotificationMode (JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL);
364 env[1]->SetEventNotificationMode (JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL);
365 env[2]->SetEventNotificationMode (JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL);
368 printf ("enable VM_DEATH for env1,env2\n");
369 env[1]->SetEventNotificationMode (JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL);
370 env[2]->SetEventNotificationMode (JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL);
373 /* Used to use a non-NULL event thread, but that causes problems
374 when SetEventNotificationMode tries to validate the thread. */
375 printf ("enable THREAD_END for env2\n");
376 env[2]->SetEventNotificationMode (JVMTI_ENABLE, JVMTI_EVENT_THREAD_END,
380 printf ("disposing of env1\n");
381 env[1]->DisposeEnvironment ();
384 printf ("disposing of env0\n");
385 env[0]->DisposeEnvironment ();
388 printf ("disable VMInit in env2\n");
389 env[2]->SetEventNotificationMode (JVMTI_DISABLE, JVMTI_EVENT_VM_INIT, NULL);
392 printf ("clear VMDeath callback in env2\n");
393 callbacks.VMDeath = NULL;
394 env[2]->SetEventCallbacks (&callbacks, sizeof (callbacks));
397 printf ("sending VMInit\n");
398 _Jv_JVMTI_PostEvent (JVMTI_EVENT_VM_INIT, (jthread) 0x1234,
401 printf ("sending ThreadEnd\n");
402 _Jv_JVMTI_PostEvent (JVMTI_EVENT_THREAD_END, (jthread) 0x1234,
405 /* See comment above re: SetEventNotificationMode and validity
407 printf ("sending ThreadEnd (no match)\n");
408 _Jv_JVMTI_PostEvent (JVMTI_EVENT_THREAD_END, (jthread) 0x4321,
412 printf ("sending VMDeath\n");
413 _Jv_JVMTI_PostEvent (JVMTI_EVENT_VM_DEATH, (jthread) NULL,
416 printf ("disposing of env2\n");
417 env[2]->DisposeEnvironment ();
422 do_callback_arg_tests ()
424 printf ("- callback arg tests -\n");
425 JavaVM *vm = _Jv_GetJavaVM ();
427 vm->GetEnv (reinterpret_cast<void **> (&env), JVMTI_VERSION_1_0);
429 // Define all the callbacks
430 #define DEFINE(Event) callbacks.Event = Event ## CB;
431 jvmtiEventCallbacks callbacks;
436 DEFINE(ClassFileLoadHook);
438 DEFINE(ClassPrepare);
441 DEFINE(ExceptionCatch);
446 DEFINE(FieldModification);
449 DEFINE(NativeMethodBind);
450 DEFINE(CompiledMethodLoad);
451 DEFINE(CompiledMethodUnload);
452 DEFINE(DynamicCodeGenerated);
453 DEFINE(DataDumpRequest);
455 DEFINE(MonitorWaited);
456 DEFINE(MonitorContendedEnter);
457 DEFINE(MonitorContendedEntered);
458 DEFINE(GarbageCollectionStart);
459 DEFINE(GarbageCollectionFinish);
461 DEFINE(VMObjectAlloc);
463 env->SetEventCallbacks (&callbacks, sizeof (callbacks));
465 // Enable all the callbacks
466 #define ENABLE(Event) \
467 env->SetEventNotificationMode (JVMTI_ENABLE, JVMTI_EVENT_ ## Event, NULL)
470 ENABLE (THREAD_START);
472 ENABLE (CLASS_FILE_LOAD_HOOK);
474 ENABLE (CLASS_PREPARE);
477 ENABLE (EXCEPTION_CATCH);
478 ENABLE (SINGLE_STEP);
481 ENABLE (FIELD_ACCESS);
482 ENABLE (FIELD_MODIFICATION);
483 ENABLE (METHOD_ENTRY);
484 ENABLE (METHOD_EXIT);
485 ENABLE (NATIVE_METHOD_BIND);
486 ENABLE (COMPILED_METHOD_LOAD);
487 ENABLE (COMPILED_METHOD_UNLOAD);
488 ENABLE (DYNAMIC_CODE_GENERATED);
489 ENABLE (DATA_DUMP_REQUEST);
490 ENABLE (MONITOR_WAIT);
491 ENABLE (MONITOR_WAITED);
492 ENABLE (MONITOR_CONTENDED_ENTER);
493 ENABLE (MONITOR_CONTENDED_ENTERED);
494 ENABLE (GARBAGE_COLLECTION_START);
495 ENABLE (GARBAGE_COLLECTION_FINISH);
496 ENABLE (OBJECT_FREE);
497 ENABLE (VM_OBJECT_ALLOC);
499 // All events should now be enabled.
502 _Jv_JVMTI_PostEvent (JVMTI_EVENT_VM_INIT, (jthread) 0x2, (JNIEnv *) 0x1);
503 _Jv_JVMTI_PostEvent (JVMTI_EVENT_VM_DEATH, (jthread) 0x2, (JNIEnv *) 0x1);
504 _Jv_JVMTI_PostEvent (JVMTI_EVENT_THREAD_START, (jthread) 0x2,
506 _Jv_JVMTI_PostEvent (JVMTI_EVENT_THREAD_END, (jthread) 0x2,
508 _Jv_JVMTI_PostEvent (JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, (jthread) 0xb00,
509 (JNIEnv *) 0x1, (jclass) 0x2, (jobject) 0x3,
510 "4", (jobject) 0x5, (jint) 6,
511 (const unsigned char *) 0x7, (jint *) 0x8,
512 (unsigned char **) 0x9);
513 _Jv_JVMTI_PostEvent (JVMTI_EVENT_CLASS_LOAD, (jthread) 0x2, (JNIEnv *) 0x1,
515 _Jv_JVMTI_PostEvent (JVMTI_EVENT_CLASS_PREPARE, (jthread) 0x2,
516 (JNIEnv *) 0x1, (jclass) 0x3);
517 _Jv_JVMTI_PostEvent (JVMTI_EVENT_VM_START, (jthread) 0xb00, (JNIEnv *) 0x1);
518 _Jv_JVMTI_PostEvent (JVMTI_EVENT_EXCEPTION, (jthread) 0x2, (JNIEnv *) 0x1,
519 (jmethodID) 0x3, (jlocation) 0x4, (jobject) 0x5,
520 (jmethodID) 0x6, (jlocation) 0x7);
521 _Jv_JVMTI_PostEvent (JVMTI_EVENT_EXCEPTION_CATCH, (jthread) 0x2,
522 (JNIEnv *) 0x1, (jmethodID) 0x3, (jlocation) 0x4,
524 _Jv_JVMTI_PostEvent (JVMTI_EVENT_SINGLE_STEP, (jthread) 0x2, (JNIEnv *) 0x1,
525 (jmethodID) 0x3, (jlocation) 0x4);
526 _Jv_JVMTI_PostEvent (JVMTI_EVENT_FRAME_POP, (jthread) 0x2, (JNIEnv *) 0x1,
528 _Jv_JVMTI_PostEvent (JVMTI_EVENT_BREAKPOINT, (jthread) 0x2, (JNIEnv *) 0x1,
529 (jmethodID) 0x3, (jlocation) 0x4);
530 _Jv_JVMTI_PostEvent (JVMTI_EVENT_FIELD_ACCESS, (jthread) 0x2,
531 (JNIEnv *) 0x1, (jmethodID) 0x3, (jlocation) 0x4,
532 (jclass) 0x5, (jobject) 0x6, (jfieldID) 0x7);
534 value.l = (jobject) 0x9;
535 _Jv_JVMTI_PostEvent (JVMTI_EVENT_FIELD_MODIFICATION, (jthread) 0x2,
536 (JNIEnv *) 0x1, (jmethodID) 0x3, (jlocation) 0x4,
537 (jclass) 0x5, (jobject) 0x6, (jfieldID) 0x7,
539 _Jv_JVMTI_PostEvent (JVMTI_EVENT_METHOD_ENTRY, (jthread) 0x2,
540 (JNIEnv *) 0x1, (jmethodID) 0x3);
543 _Jv_JVMTI_PostEvent (JVMTI_EVENT_METHOD_EXIT, (jthread) 0x2,
544 (JNIEnv *) 0x1, (jmethodID) 0x3, 4, value2);
545 _Jv_JVMTI_PostEvent (JVMTI_EVENT_NATIVE_METHOD_BIND, (jthread) 0x2,
546 (JNIEnv *) 0x1, (jmethodID) 0x3, (void *) 0x4,
548 _Jv_JVMTI_PostEvent (JVMTI_EVENT_COMPILED_METHOD_LOAD, (jthread) 0xb00,
549 (jmethodID) 0x1, (jint) 2, (const void *) 0x3,
550 (jint) 4, (const jvmtiAddrLocationMap *) 0x5,
552 _Jv_JVMTI_PostEvent (JVMTI_EVENT_COMPILED_METHOD_UNLOAD, (jthread) 0xb00,
553 (jmethodID) 0x1, (const void *) 0x2);
554 _Jv_JVMTI_PostEvent (JVMTI_EVENT_DYNAMIC_CODE_GENERATED, (jthread) 0xb00,
555 "1", (const void *) 0x2, (jint) 3);
556 _Jv_JVMTI_PostEvent (JVMTI_EVENT_DATA_DUMP_REQUEST, (jthread) 0xb00);
557 _Jv_JVMTI_PostEvent (JVMTI_EVENT_MONITOR_WAIT, (jthread) 0x2,
558 (JNIEnv *) 0x1, (jobject) 0x3, (jlong) 4);
559 _Jv_JVMTI_PostEvent (JVMTI_EVENT_MONITOR_WAITED, (jthread) 0x2,
560 (JNIEnv *) 0x1, (jobject) 0x3, (int) 4);
561 _Jv_JVMTI_PostEvent (JVMTI_EVENT_MONITOR_CONTENDED_ENTER, (jthread) 0x2,
562 (JNIEnv *) 0x1, (jobject) 0x3);
563 _Jv_JVMTI_PostEvent (JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, (jthread) 0x2,
564 (JNIEnv *) 0x1, (jobject) 0x3);
565 _Jv_JVMTI_PostEvent (JVMTI_EVENT_GARBAGE_COLLECTION_START, (jthread) 0xb00);
566 _Jv_JVMTI_PostEvent (JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, (jthread) 0xb00);
567 _Jv_JVMTI_PostEvent (JVMTI_EVENT_OBJECT_FREE, (jthread) 0xb00, (jlong) 1);
568 _Jv_JVMTI_PostEvent (JVMTI_EVENT_VM_OBJECT_ALLOC, (jthread) 0x2,
569 (JNIEnv *) 0x1, (jobject) 0x3, (jclass) 0x4,
574 events::do_events_tests ()
577 do_callback_arg_tests ();