35 /* ========================================================================== */
36
37 /* scaffold objects */
38 static jlong timeout = 0;
39
40 /* event counts */
41 static int MethodExitEventsCount = 0;
42
43 /* ========================================================================== */
44
45 /** callback functions **/
46
47 static void JNICALL
48 MethodExit(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
49 jthread thread, jmethodID method,
50 jboolean was_poped_by_exception, jvalue return_value) {
51 char *name = NULL;
52 char *signature = NULL;
53
54 MethodExitEventsCount++;
55 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB5(GetMethodName,
56 jvmti_env, method, &name, &signature, NULL))) {
57 nsk_jvmti_setFailStatus();
58 return;
59 }
60 NSK_DISPLAY2("MethodExit event: %s%s\n", name, signature);
61 if (name != NULL)
62 NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)name);
63 if (signature != NULL)
64 NSK_CPP_STUB2(Deallocate, jvmti_env, (unsigned char*)signature);
65 }
66
67 /* ========================================================================== */
68
69 /** Agent algorithm. */
70 static void JNICALL
71 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
72
73 if (!nsk_jvmti_waitForSync(timeout))
74 return;
75
76 /* resume debugee and wait for sync */
77 if (!nsk_jvmti_resumeSync())
78 return;
79 if (!nsk_jvmti_waitForSync(timeout))
80 return;
81
82 NSK_DISPLAY1("MethodExit events received: %d\n",
83 MethodExitEventsCount);
84 if (!NSK_VERIFY(MethodExitEventsCount == 0))
106 jvmtiEnv* jvmti = NULL;
107 jvmtiCapabilities caps;
108 jvmtiEventCallbacks callbacks;
109
110 NSK_DISPLAY0("Agent_OnLoad\n");
111
112 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
113 return JNI_ERR;
114
115 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
116
117 if (!NSK_VERIFY((jvmti =
118 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
119 return JNI_ERR;
120
121 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
122 return JNI_ERR;
123
124 memset(&caps, 0, sizeof(caps));
125 caps.can_generate_method_exit_events = 1;
126 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) {
127 return JNI_ERR;
128 }
129
130 memset(&callbacks, 0, sizeof(callbacks));
131 callbacks.MethodExit = &MethodExit;
132 if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks)))
133 return JNI_ERR;
134
135 return JNI_OK;
136 }
137
138 /* ========================================================================== */
139
140 }
|
35 /* ========================================================================== */
36
37 /* scaffold objects */
38 static jlong timeout = 0;
39
40 /* event counts */
41 static int MethodExitEventsCount = 0;
42
43 /* ========================================================================== */
44
45 /** callback functions **/
46
47 static void JNICALL
48 MethodExit(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
49 jthread thread, jmethodID method,
50 jboolean was_poped_by_exception, jvalue return_value) {
51 char *name = NULL;
52 char *signature = NULL;
53
54 MethodExitEventsCount++;
55 if (!NSK_JVMTI_VERIFY(jvmti_env->GetMethodName(method, &name, &signature, NULL))) {
56 nsk_jvmti_setFailStatus();
57 return;
58 }
59 NSK_DISPLAY2("MethodExit event: %s%s\n", name, signature);
60 if (name != NULL)
61 jvmti_env->Deallocate((unsigned char*)name);
62 if (signature != NULL)
63 jvmti_env->Deallocate((unsigned char*)signature);
64 }
65
66 /* ========================================================================== */
67
68 /** Agent algorithm. */
69 static void JNICALL
70 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
71
72 if (!nsk_jvmti_waitForSync(timeout))
73 return;
74
75 /* resume debugee and wait for sync */
76 if (!nsk_jvmti_resumeSync())
77 return;
78 if (!nsk_jvmti_waitForSync(timeout))
79 return;
80
81 NSK_DISPLAY1("MethodExit events received: %d\n",
82 MethodExitEventsCount);
83 if (!NSK_VERIFY(MethodExitEventsCount == 0))
105 jvmtiEnv* jvmti = NULL;
106 jvmtiCapabilities caps;
107 jvmtiEventCallbacks callbacks;
108
109 NSK_DISPLAY0("Agent_OnLoad\n");
110
111 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
112 return JNI_ERR;
113
114 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
115
116 if (!NSK_VERIFY((jvmti =
117 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
118 return JNI_ERR;
119
120 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
121 return JNI_ERR;
122
123 memset(&caps, 0, sizeof(caps));
124 caps.can_generate_method_exit_events = 1;
125 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps))) {
126 return JNI_ERR;
127 }
128
129 memset(&callbacks, 0, sizeof(callbacks));
130 callbacks.MethodExit = &MethodExit;
131 if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks)))
132 return JNI_ERR;
133
134 return JNI_OK;
135 }
136
137 /* ========================================================================== */
138
139 }
|