test/hotspot/jtreg/serviceability/jvmti/GetOwnedMonitorInfo/libGetOwnedMonitorInfoTest.c
equal
deleted
inserted
replaced
47 |
47 |
48 #define TEST_CLASS "GetOwnedMonitorInfoTest" |
48 #define TEST_CLASS "GetOwnedMonitorInfoTest" |
49 |
49 |
50 static volatile jboolean event_has_posted = JNI_FALSE; |
50 static volatile jboolean event_has_posted = JNI_FALSE; |
51 static volatile jint status = PASSED; |
51 static volatile jint status = PASSED; |
|
52 static volatile jclass testClass = NULL; |
52 |
53 |
53 static jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved); |
54 static jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved); |
54 |
55 |
55 static void ShowErrorMessage(jvmtiEnv *jvmti, jvmtiError errCode, const char *message) { |
56 static void ShowErrorMessage(jvmtiEnv *jvmti, jvmtiError errCode, const char *message) { |
56 char *errMsg; |
57 char *errMsg; |
64 fprintf(stderr, "%s (%d)\n", message, errCode); |
65 fprintf(stderr, "%s (%d)\n", message, errCode); |
65 } |
66 } |
66 } |
67 } |
67 |
68 |
68 static jboolean CheckLockObject(JNIEnv *env, jobject monitor) { |
69 static jboolean CheckLockObject(JNIEnv *env, jobject monitor) { |
69 jclass testClass; |
|
70 |
|
71 testClass = (*env)->FindClass(env, TEST_CLASS); |
|
72 if (testClass == NULL) { |
70 if (testClass == NULL) { |
73 fprintf(stderr, "MonitorContendedEnter: " TEST_CLASS " not found\n"); |
71 // JNI_OnLoad has not been called yet, so can't possibly be an instance of TEST_CLASS. |
74 status = FAILED; |
|
75 event_has_posted = JNI_TRUE; |
|
76 return JNI_FALSE; |
72 return JNI_FALSE; |
77 } |
73 } |
78 |
|
79 return (*env)->IsInstanceOf(env, monitor, testClass); |
74 return (*env)->IsInstanceOf(env, monitor, testClass); |
80 } |
75 } |
81 |
76 |
82 JNIEXPORT void JNICALL |
77 JNIEXPORT void JNICALL |
83 MonitorContendedEnter(jvmtiEnv *jvmti, JNIEnv *env, jthread thread, jobject monitor) { |
78 MonitorContendedEnter(jvmtiEnv *jvmti, JNIEnv *env, jthread thread, jobject monitor) { |
169 return Agent_Initialize(jvm, options, reserved); |
164 return Agent_Initialize(jvm, options, reserved); |
170 } |
165 } |
171 |
166 |
172 JNIEXPORT jint JNICALL |
167 JNIEXPORT jint JNICALL |
173 JNI_OnLoad(JavaVM *jvm, void *reserved) { |
168 JNI_OnLoad(JavaVM *jvm, void *reserved) { |
174 return JNI_VERSION_1_8; |
169 jint res; |
|
170 JNIEnv *env; |
|
171 |
|
172 res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &env), |
|
173 JNI_VERSION_9); |
|
174 if (res != JNI_OK || env == NULL) { |
|
175 fprintf(stderr, "Error: GetEnv call failed(%d)!\n", res); |
|
176 return JNI_ERR; |
|
177 } |
|
178 |
|
179 testClass = (*env)->FindClass(env, TEST_CLASS); |
|
180 if (testClass != NULL) { |
|
181 testClass = (*env)->NewGlobalRef(env, testClass); |
|
182 } |
|
183 if (testClass == NULL) { |
|
184 fprintf(stderr, "Error: Could not load class %s!\n", TEST_CLASS); |
|
185 return JNI_ERR; |
|
186 } |
|
187 |
|
188 return JNI_VERSION_9; |
175 } |
189 } |
176 |
190 |
177 static |
191 static |
178 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { |
192 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { |
179 jint res; |
193 jint res; |
183 jvmtiEventCallbacks callbacks; |
197 jvmtiEventCallbacks callbacks; |
184 |
198 |
185 printf("Agent_OnLoad started\n"); |
199 printf("Agent_OnLoad started\n"); |
186 |
200 |
187 res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), |
201 res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), |
188 JVMTI_VERSION_1); |
202 JVMTI_VERSION_9); |
189 if (res != JNI_OK || jvmti == NULL) { |
203 if (res != JNI_OK || jvmti == NULL) { |
190 fprintf(stderr, "Error: wrong result of a valid call to GetEnv!\n"); |
204 fprintf(stderr, "Error: wrong result of a valid call to GetEnv!\n"); |
191 return JNI_ERR; |
205 return JNI_ERR; |
192 } |
206 } |
193 |
207 |
219 if (!caps.can_get_owned_monitor_info) { |
233 if (!caps.can_get_owned_monitor_info) { |
220 fprintf(stderr, "Warning: GetOwnedMonitorInfo is not implemented\n"); |
234 fprintf(stderr, "Warning: GetOwnedMonitorInfo is not implemented\n"); |
221 return JNI_ERR; |
235 return JNI_ERR; |
222 } |
236 } |
223 |
237 |
|
238 memset(&callbacks, 0, sizeof(callbacks)); |
224 callbacks.MonitorContendedEnter = &MonitorContendedEnter; |
239 callbacks.MonitorContendedEnter = &MonitorContendedEnter; |
225 callbacks.MonitorContendedEntered = &MonitorContendedEntered; |
240 callbacks.MonitorContendedEntered = &MonitorContendedEntered; |
226 |
241 |
227 err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(jvmtiEventCallbacks)); |
242 err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(jvmtiEventCallbacks)); |
228 if (err != JVMTI_ERROR_NONE) { |
243 if (err != JVMTI_ERROR_NONE) { |