1 #include <stdio.h>
2 #include <jvmti.h>
3 #include <tijmp.h>
4 #include <tijmp_TIJMPController.h>
5
6 static JNINativeMethod registry[6] = {
7 {"runGC", "()V", (void*)&TIJMPController_runGC},
8 {"walkHeap", "()V", (void*)&TIJMPController_walkHeap},
9 {"showInstances", "(Ljava/lang/Class;)V",
10 (void*)&TIJMPController_showInstances},
11 {"showOwners", "(Ljava/lang/Class;)V",
12 (void*)&TIJMPController_showOwners},
13 {"childObjectsSummary", "(Ljava/lang/Object;)V",
14 (void*)&TIJMPController_childObjectsSummary},
15 {"getObjectsForTags", "([J)[Ljava/lang/Object;",
16 (void*)&TIJMPController_getObjectsForTags}
17 };
18
VMInit(jvmtiEnv * jvmti,JNIEnv * jni_env,jthread thread)19 void JNICALL VMInit (jvmtiEnv *jvmti, JNIEnv* jni_env, jthread thread) {
20 jmethodID m_init;
21 jclass cls;
22 jint rc;
23
24 tijmp_vm_inited ();
25 cls = (*jni_env)->FindClass (jni_env, "tijmp/TIJMPController");
26 if (!cls) {
27 fprintf (stdout, "Failed to find java classes, will not run\n");
28 return;
29 }
30
31 /* register native methods */
32 rc = (*jni_env)->RegisterNatives (jni_env, cls, registry, 6);
33 if (rc != 0) {
34 fprintf (stdout,
35 "Failed to register native methos, will probably crash: %d\n",
36 rc);
37 }
38
39 fprintf (stdout, "Trying to call java gui init()\n");
40
41 /* Init java gui */
42 m_init = (*jni_env)->GetStaticMethodID (jni_env, cls, "init", "()V");
43 (*jni_env)->CallStaticVoidMethod (jni_env, cls, m_init);
44 }
45