38 static jlong timeout = 0;
39
40 /* event counts */
41 static int MonitorContendedEnterEventsCount = 0;
42 static int MonitorContendedEnteredEventsCount = 0;
43 static int MonitorWaitEventsCount = 0;
44 static int MonitorWaitedEventsCount = 0;
45
46 /* ========================================================================== */
47
48 /** callback functions **/
49
50 static void JNICALL
51 MonitorContendedEnter(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
52 jthread thread, jobject object) {
53 jvmtiThreadInfo info;
54
55 MonitorContendedEnterEventsCount++;
56
57 /* get thread information */
58 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti_env,
59 thread, &info))) {
60 nsk_jvmti_setFailStatus();
61 return;
62 }
63 NSK_DISPLAY2("MonitorContendedEnter event: thread=\"%s\", object=0x%p\n",
64 info.name, object);
65 }
66
67 static void JNICALL
68 MonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
69 jthread thread, jobject object) {
70 jvmtiThreadInfo info;
71
72 MonitorContendedEnteredEventsCount++;
73
74 /* get thread information */
75 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti_env,
76 thread, &info))) {
77 nsk_jvmti_setFailStatus();
78 return;
79 }
80 NSK_DISPLAY2("MonitorContendedEntered event: thread=\"%s\", object=0x%p\n",
81 info.name, object);
82 }
83
84 static void JNICALL
85 MonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
86 jthread thread, jobject object, jlong timeout) {
87 jvmtiThreadInfo info;
88
89 MonitorWaitEventsCount++;
90
91 /* get thread information */
92 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti_env,
93 thread, &info))) {
94 nsk_jvmti_setFailStatus();
95 return;
96 }
97 NSK_DISPLAY2("MonitorWait event: thread=\"%s\", object=0x%p\n",
98 info.name, object);
99 }
100
101 static void JNICALL
102 MonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
103 jthread thread, jobject object, jboolean timed_out) {
104 jvmtiThreadInfo info;
105
106 MonitorWaitedEventsCount++;
107
108 /* get thread information */
109 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti_env,
110 thread, &info))) {
111 nsk_jvmti_setFailStatus();
112 return;
113 }
114 NSK_DISPLAY2("MonitorWaited event: thread=\"%s\", object=0x%p\n",
115 info.name, object);
116 }
117
118 /* ========================================================================== */
119
120 /** Agent algorithm. */
121 static void JNICALL
122 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
123
124 if (!nsk_jvmti_waitForSync(timeout))
125 return;
126
127 /* resume debugee and wait for sync */
128 if (!nsk_jvmti_resumeSync())
129 return;
130 if (!nsk_jvmti_waitForSync(timeout))
172 jvmtiEnv* jvmti = NULL;
173 jvmtiCapabilities caps;
174 jvmtiEventCallbacks callbacks;
175
176 NSK_DISPLAY0("Agent_OnLoad\n");
177
178 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
179 return JNI_ERR;
180
181 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
182
183 if (!NSK_VERIFY((jvmti =
184 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
185 return JNI_ERR;
186
187 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
188 return JNI_ERR;
189
190 memset(&caps, 0, sizeof(caps));
191 caps.can_generate_monitor_events = 1;
192 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) {
193 return JNI_ERR;
194 }
195
196 memset(&callbacks, 0, sizeof(callbacks));
197 callbacks.MonitorContendedEnter = &MonitorContendedEnter;
198 callbacks.MonitorContendedEntered = &MonitorContendedEntered;
199 callbacks.MonitorWait = &MonitorWait;
200 callbacks.MonitorWaited = &MonitorWaited;
201 if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks)))
202 return JNI_ERR;
203
204 return JNI_OK;
205 }
206
207 /* ========================================================================== */
208
209 }
|
38 static jlong timeout = 0;
39
40 /* event counts */
41 static int MonitorContendedEnterEventsCount = 0;
42 static int MonitorContendedEnteredEventsCount = 0;
43 static int MonitorWaitEventsCount = 0;
44 static int MonitorWaitedEventsCount = 0;
45
46 /* ========================================================================== */
47
48 /** callback functions **/
49
50 static void JNICALL
51 MonitorContendedEnter(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
52 jthread thread, jobject object) {
53 jvmtiThreadInfo info;
54
55 MonitorContendedEnterEventsCount++;
56
57 /* get thread information */
58 if (!NSK_JVMTI_VERIFY(jvmti_env->GetThreadInfo(thread, &info))) {
59 nsk_jvmti_setFailStatus();
60 return;
61 }
62 NSK_DISPLAY2("MonitorContendedEnter event: thread=\"%s\", object=0x%p\n",
63 info.name, object);
64 }
65
66 static void JNICALL
67 MonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
68 jthread thread, jobject object) {
69 jvmtiThreadInfo info;
70
71 MonitorContendedEnteredEventsCount++;
72
73 /* get thread information */
74 if (!NSK_JVMTI_VERIFY(jvmti_env->GetThreadInfo(thread, &info))) {
75 nsk_jvmti_setFailStatus();
76 return;
77 }
78 NSK_DISPLAY2("MonitorContendedEntered event: thread=\"%s\", object=0x%p\n",
79 info.name, object);
80 }
81
82 static void JNICALL
83 MonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
84 jthread thread, jobject object, jlong timeout) {
85 jvmtiThreadInfo info;
86
87 MonitorWaitEventsCount++;
88
89 /* get thread information */
90 if (!NSK_JVMTI_VERIFY(jvmti_env->GetThreadInfo(thread, &info))) {
91 nsk_jvmti_setFailStatus();
92 return;
93 }
94 NSK_DISPLAY2("MonitorWait event: thread=\"%s\", object=0x%p\n",
95 info.name, object);
96 }
97
98 static void JNICALL
99 MonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
100 jthread thread, jobject object, jboolean timed_out) {
101 jvmtiThreadInfo info;
102
103 MonitorWaitedEventsCount++;
104
105 /* get thread information */
106 if (!NSK_JVMTI_VERIFY(jvmti_env->GetThreadInfo(thread, &info))) {
107 nsk_jvmti_setFailStatus();
108 return;
109 }
110 NSK_DISPLAY2("MonitorWaited event: thread=\"%s\", object=0x%p\n",
111 info.name, object);
112 }
113
114 /* ========================================================================== */
115
116 /** Agent algorithm. */
117 static void JNICALL
118 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
119
120 if (!nsk_jvmti_waitForSync(timeout))
121 return;
122
123 /* resume debugee and wait for sync */
124 if (!nsk_jvmti_resumeSync())
125 return;
126 if (!nsk_jvmti_waitForSync(timeout))
168 jvmtiEnv* jvmti = NULL;
169 jvmtiCapabilities caps;
170 jvmtiEventCallbacks callbacks;
171
172 NSK_DISPLAY0("Agent_OnLoad\n");
173
174 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
175 return JNI_ERR;
176
177 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
178
179 if (!NSK_VERIFY((jvmti =
180 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
181 return JNI_ERR;
182
183 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
184 return JNI_ERR;
185
186 memset(&caps, 0, sizeof(caps));
187 caps.can_generate_monitor_events = 1;
188 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps))) {
189 return JNI_ERR;
190 }
191
192 memset(&callbacks, 0, sizeof(callbacks));
193 callbacks.MonitorContendedEnter = &MonitorContendedEnter;
194 callbacks.MonitorContendedEntered = &MonitorContendedEntered;
195 callbacks.MonitorWait = &MonitorWait;
196 callbacks.MonitorWaited = &MonitorWaited;
197 if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks)))
198 return JNI_ERR;
199
200 return JNI_OK;
201 }
202
203 /* ========================================================================== */
204
205 }
|