1 /*
2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 #include <stdio.h>
25 #include <string.h>
26 #include "jni_tools.h"
27 #include "agent_common.h"
28 #include "jvmti_tools.h"
29
30 extern "C" {
31
32 #define CAPABILITY can_signal_thread
33 #define CAPABILITY_STR "can_signal_thread"
34
35 /* The test checks capability can_signal_thread
36 * and correspondent functions:
37 * StopThread
38 * InterruptThread
39 *
40 * Testcases:
41 * 1. Check if GetPotentialCapabilities returns the capability
42 * 2. Add the capability during Onload phase
43 * 3. Check if GetCapabilities returns the capability
44 * 4. Relinquish the capability during Onload phase
45 * 5. Check if GetCapabilities does not return the capability
46 * 6. Add back the capability and check with GetCapabilities
47 * 7. Check that only correspondent function work and functions of
48 * other capabilities return JVMTI_ERROR_MUST_POSSESS_CAPABILITY
49 * 8. Check if VM exits well with the capability has not been relinquished
50 */
51
52 /* ========================================================================== */
53
54 /* scaffold objects */
55 static JNIEnv* jni = NULL;
56 static jvmtiEnv *jvmti = NULL;
57 static jlong timeout = 0;
58
59 /* test objects */
60 static jthread thread = NULL;
61 static jclass klass = NULL;
62 static jmethodID method = NULL;
63 static jfieldID field = NULL;
64
65 /* ========================================================================== */
66
prepare()67 static int prepare() {
68 const char* THREAD_NAME = "Debuggee Thread";
69 jvmtiThreadInfo info;
70 jthread *threads = NULL;
71 jint threads_count = 0;
72 int i;
73
74 NSK_DISPLAY0("Prepare: find tested thread\n");
75
76 /* get all live threads */
77 if (!NSK_JVMTI_VERIFY(jvmti->GetAllThreads(&threads_count, &threads)))
78 return NSK_FALSE;
79
80 if (!NSK_VERIFY(threads_count > 0 && threads != NULL))
81 return NSK_FALSE;
82
83 /* find tested thread */
84 for (i = 0; i < threads_count; i++) {
85 if (!NSK_VERIFY(threads[i] != NULL))
86 return NSK_FALSE;
87
88 /* get thread information */
89 if (!NSK_JVMTI_VERIFY(jvmti->GetThreadInfo(threads[i], &info)))
90 return NSK_FALSE;
91
92 NSK_DISPLAY3(" thread #%d (%s): %p\n", i, info.name, threads[i]);
93
94 /* find by name */
95 if (info.name != NULL && (strcmp(info.name, THREAD_NAME) == 0)) {
96 thread = threads[i];
97 }
98 }
99
100 /* deallocate threads list */
101 if (!NSK_JVMTI_VERIFY(jvmti->Deallocate((unsigned char*)threads)))
102 return NSK_FALSE;
103
104 /* get tested thread class */
105 if (!NSK_JNI_VERIFY(jni, (klass = jni->GetObjectClass(thread)) != NULL))
106 return NSK_FALSE;
107
108 /* get tested thread method 'run' */
109 if (!NSK_JNI_VERIFY(jni, (method = jni->GetMethodID(klass, "run", "()V")) != NULL))
110 return NSK_FALSE;
111
112 /* get tested thread field 'waitingMonitor' */
113 if (!NSK_JNI_VERIFY(jni, (field =
114 jni->GetFieldID(klass, "waitingMonitor", "Ljava/lang/Object;")) != NULL))
115 return NSK_FALSE;
116
117 return NSK_TRUE;
118 }
119
120 /* ========================================================================== */
121
122 /* Check "can_suspend" functions
123 */
checkSuspend()124 static int checkSuspend() {
125 jvmtiError err;
126
127 NSK_DISPLAY0("Checking negative: SuspendThread\n");
128 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, jvmti->SuspendThread(thread)))
129 return NSK_FALSE;
130
131 NSK_DISPLAY0("Checking negative: ResumeThread\n");
132 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, jvmti->ResumeThread(thread)))
133 return NSK_FALSE;
134
135 NSK_DISPLAY0("Checking negative: SuspendThreadList\n");
136 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
137 jvmti->SuspendThreadList(1, &thread, &err)))
138 return NSK_FALSE;
139
140 NSK_DISPLAY0("Checking negative: ResumeThreadList\n");
141 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
142 jvmti->ResumeThreadList(1, &thread, &err)))
143 return NSK_FALSE;
144
145 return NSK_TRUE;
146 }
147
148 /* Check "can_signal_thread" functions
149 */
checkSignalThread()150 static int checkSignalThread() {
151 const char* THREAD_DEATH_CLASS_NAME = "java/lang/ThreadDeath";
152 const char* THREAD_DEATH_CTOR_NAME = "<init>";
153 const char* THREAD_DEATH_CTOR_SIGNATURE = "()V";
154 jclass cls = NULL;
155 jmethodID ctor = NULL;
156 jobject exception = NULL;
157
158 if (!NSK_JNI_VERIFY(jni, (cls = jni->FindClass(THREAD_DEATH_CLASS_NAME)) != NULL))
159 return NSK_FALSE;
160
161 if (!NSK_JNI_VERIFY(jni, (ctor =
162 jni->GetMethodID(cls, THREAD_DEATH_CTOR_NAME, THREAD_DEATH_CTOR_SIGNATURE)) != NULL))
163 return NSK_FALSE;
164
165 if (!NSK_JNI_VERIFY(jni, (exception = jni->NewObject(cls, ctor)) != NULL))
166 return NSK_FALSE;
167
168 NSK_DISPLAY0("Checking positive: InterruptThread\n");
169 if (!NSK_JVMTI_VERIFY(jvmti->InterruptThread(thread)))
170 return NSK_FALSE;
171
172 NSK_DISPLAY0("Checking positive: StopThread\n");
173 if (!NSK_JVMTI_VERIFY(jvmti->StopThread(thread, exception)))
174 return NSK_FALSE;
175
176 return NSK_TRUE;
177 }
178
179 /* Check "can_get_owned_monitor_info" function
180 */
checkGetOwnedMonitorInfo()181 static int checkGetOwnedMonitorInfo() {
182 jint count;
183 jobject *monitors = NULL;
184
185 NSK_DISPLAY0("Checking negative: GetOwnedMonitorInfo\n");
186 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
187 jvmti->GetOwnedMonitorInfo(thread, &count, &monitors)))
188 return NSK_FALSE;
189
190 return NSK_TRUE;
191 }
192
193 /* Check "can_get_current_contended_monitor" function
194 */
checkGetCurrentContendedMonitor()195 static int checkGetCurrentContendedMonitor() {
196 jobject monitor = NULL;
197
198 NSK_DISPLAY0("Checking negative: GetCurrentContendedMonitor\n");
199 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
200 jvmti->GetCurrentContendedMonitor(thread, &monitor)))
201 return NSK_FALSE;
202
203 return NSK_TRUE;
204 }
205
206 /* Check "can_pop_frame" function
207 */
checkPopFrame()208 static int checkPopFrame() {
209 NSK_DISPLAY0("Checking negative: PopFrame\n");
210 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, jvmti->PopFrame(thread)))
211 return NSK_FALSE;
212
213 return NSK_TRUE;
214 }
215
216 /* Check "can_tag_objects" functions
217 */
218
219 static jvmtiIterationControl JNICALL
HeapObject(jlong class_tag,jlong size,jlong * tag_ptr,void * user_data)220 HeapObject(jlong class_tag, jlong size, jlong *tag_ptr, void *user_data) {
221 return JVMTI_ITERATION_ABORT;
222 }
223
224 static jvmtiIterationControl JNICALL
HeapRoot(jvmtiHeapRootKind root_kind,jlong class_tag,jlong size,jlong * tag_ptr,void * user_data)225 HeapRoot(jvmtiHeapRootKind root_kind, jlong class_tag, jlong size,
226 jlong *tag_ptr, void *user_data) {
227 return JVMTI_ITERATION_ABORT;
228 }
229
230 static jvmtiIterationControl JNICALL
StackReference(jvmtiHeapRootKind root_kind,jlong class_tag,jlong size,jlong * tag_ptr,jlong thread_tag,jint depth,jmethodID method,jint slot,void * user_data)231 StackReference(jvmtiHeapRootKind root_kind, jlong class_tag, jlong size,
232 jlong *tag_ptr, jlong thread_tag, jint depth, jmethodID method,
233 jint slot, void *user_data) {
234 return JVMTI_ITERATION_ABORT;
235 }
236
237 static jvmtiIterationControl JNICALL
ObjectReference(jvmtiObjectReferenceKind reference_kind,jlong class_tag,jlong size,jlong * tag_ptr,jlong referrer_tag,jint referrer_index,void * user_data)238 ObjectReference(jvmtiObjectReferenceKind reference_kind, jlong class_tag,
239 jlong size, jlong *tag_ptr, jlong referrer_tag,
240 jint referrer_index, void *user_data) {
241 return JVMTI_ITERATION_ABORT;
242 }
243
checkHeapFunctions()244 static int checkHeapFunctions() {
245 const jlong TAG_VALUE = (123456789L);
246 jlong tag;
247 jint count;
248 jobject *res_objects = NULL;
249 jlong *res_tags = NULL;
250 jint dummy_user_data = 0;
251
252 NSK_DISPLAY0("Checking negative: SetTag\n");
253 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
254 jvmti->SetTag(thread, TAG_VALUE)))
255 return NSK_FALSE;
256
257 NSK_DISPLAY0("Checking negative: GetTag\n");
258 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, jvmti->GetTag(thread, &tag)))
259 return NSK_FALSE;
260
261 NSK_DISPLAY0("Checking negative: GetObjectsWithTags\n");
262 tag = TAG_VALUE;
263 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
264 jvmti->GetObjectsWithTags(1, &tag, &count, &res_objects, &res_tags)))
265 return NSK_FALSE;
266
267 NSK_DISPLAY0("Checking negative: IterateOverHeap\n");
268 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
269 jvmti->IterateOverHeap(JVMTI_HEAP_OBJECT_TAGGED, HeapObject, &dummy_user_data)))
270 return NSK_FALSE;
271
272 NSK_DISPLAY0("Checking negative: IterateOverInstancesOfClass\n");
273 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
274 jvmti->IterateOverInstancesOfClass(klass,
275 JVMTI_HEAP_OBJECT_UNTAGGED,
276 HeapObject,
277 &dummy_user_data)))
278 return NSK_FALSE;
279
280 NSK_DISPLAY0("Checking negative: IterateOverObjectsReachableFromObject\n");
281 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
282 jvmti->IterateOverObjectsReachableFromObject(thread,
283 ObjectReference,
284 &dummy_user_data)))
285 return NSK_FALSE;
286
287 NSK_DISPLAY0("Checking negative: IterateOverReachableObjects\n");
288 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
289 jvmti->IterateOverReachableObjects(HeapRoot,
290 StackReference,
291 ObjectReference,
292 &dummy_user_data)))
293 return NSK_FALSE;
294
295 return NSK_TRUE;
296 }
297
298 /* Check "can_access_local_variables" functions
299 */
checkLocalVariableFunctions()300 static int checkLocalVariableFunctions() {
301 jint count;
302 jvmtiLocalVariableEntry *local_variable_table = NULL;
303 jobject object_value;
304 jint int_value;
305 jlong long_value;
306 jfloat float_value;
307 jdouble double_value;
308
309 NSK_DISPLAY0("Checking negative: GetLocalVariableTable\n");
310 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
311 jvmti->GetLocalVariableTable(method, &count, &local_variable_table)))
312 return NSK_FALSE;
313
314 NSK_DISPLAY0("Checking negative: GetLocalObject\n");
315 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
316 jvmti->GetLocalObject(thread, 0, 0, &object_value)))
317 return NSK_FALSE;
318
319 NSK_DISPLAY0("Checking negative: GetLocalInt\n");
320 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
321 jvmti->GetLocalInt(thread, 0, 0, &int_value)))
322 return NSK_FALSE;
323
324 NSK_DISPLAY0("Checking negative: GetLocalLong\n");
325 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
326 jvmti->GetLocalLong(thread, 0, 0, &long_value)))
327 return NSK_FALSE;
328
329 NSK_DISPLAY0("Checking negative: GetLocalFloat\n");
330 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
331 jvmti->GetLocalFloat(thread, 0, 0, &float_value)))
332 return NSK_FALSE;
333
334 NSK_DISPLAY0("Checking negative: GetLocalDouble\n");
335 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
336 jvmti->GetLocalDouble(thread, 0, 0, &double_value)))
337 return NSK_FALSE;
338
339 NSK_DISPLAY0("Checking negative: SetLocalObject\n");
340 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
341 jvmti->SetLocalObject(thread, 0, 0, thread)))
342 return NSK_FALSE;
343
344 NSK_DISPLAY0("Checking negative: SetLocalInt\n");
345 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
346 jvmti->SetLocalInt(thread, 0, 0, (jint)0)))
347 return NSK_FALSE;
348
349 NSK_DISPLAY0("Checking negative: SetLocalLong\n");
350 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
351 jvmti->SetLocalLong(thread, 0, 0, (jlong)0)))
352 return NSK_FALSE;
353
354 NSK_DISPLAY0("Checking negative: SetLocalFloat\n");
355 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
356 jvmti->SetLocalFloat(thread, 0, 0, (jfloat)0.0)))
357 return NSK_FALSE;
358
359 NSK_DISPLAY0("Checking negative: SetLocalDouble\n");
360 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
361 jvmti->SetLocalDouble(thread, 0, 0, (jdouble)0.0)))
362 return NSK_FALSE;
363
364 return NSK_TRUE;
365 }
366
367 /* Check "can_get_source_info" functions
368 */
checkSourceInfoFunctions()369 static int checkSourceInfoFunctions() {
370 char *name;
371 jint count;
372 jvmtiLineNumberEntry *line_number_table = NULL;
373
374 NSK_DISPLAY0("Checking negative: GetSourceFileName\n");
375 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
376 jvmti->GetSourceFileName(klass, &name)))
377 return NSK_FALSE;
378
379 NSK_DISPLAY0("Checking negative: GetSourceDebugExtension\n");
380 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
381 jvmti->GetSourceDebugExtension(klass, &name)))
382 return NSK_FALSE;
383
384 NSK_DISPLAY0("Checking negative: GetLineNumberTable\n");
385 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
386 jvmti->GetLineNumberTable(method, &count, &line_number_table)))
387 return NSK_FALSE;
388
389 return NSK_TRUE;
390 }
391
392 /* Check "can_redefine_classes" functions
393 */
checkRedefineClasses()394 static int checkRedefineClasses() {
395 jvmtiClassDefinition class_def;
396
397 NSK_DISPLAY0("Checking negative: RedefineClasses\n");
398 class_def.klass = klass;
399 class_def.class_byte_count = 0;
400 class_def.class_bytes = NULL;
401 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
402 jvmti->RedefineClasses(1, &class_def)))
403 return NSK_FALSE;
404
405 return NSK_TRUE;
406 }
407
408 /* Check "can_get_monitor_info" function
409 */
checkGetObjectMonitorUsage()410 static int checkGetObjectMonitorUsage() {
411 jvmtiMonitorUsage monitor_info;
412
413 NSK_DISPLAY0("Checking negative: GetObjectMonitorUsage\n");
414 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
415 jvmti->GetObjectMonitorUsage(thread, &monitor_info)))
416 return NSK_FALSE;
417
418 return NSK_TRUE;
419 }
420
421 /* Check "can_get_synthetic_attribute" functions
422 */
checkIsSyntheticFunctions()423 static int checkIsSyntheticFunctions() {
424 jboolean is_synthetic;
425
426 NSK_DISPLAY0("Checking negative: IsFieldSynthetic\n");
427 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
428 jvmti->IsFieldSynthetic(klass, field, &is_synthetic)))
429 return NSK_FALSE;
430
431 NSK_DISPLAY0("Checking negative: IsMethodSynthetic\n");
432 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
433 jvmti->IsMethodSynthetic(method, &is_synthetic)))
434 return NSK_FALSE;
435
436 return NSK_TRUE;
437 }
438
439 /* Check "can_get_bytecodes" function
440 */
checkGetBytecodes()441 static int checkGetBytecodes() {
442 jint count;
443 unsigned char *bytecodes;
444
445 NSK_DISPLAY0("Checking negative: GetBytecodes\n");
446 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
447 jvmti->GetBytecodes(method, &count, &bytecodes)))
448 return NSK_FALSE;
449
450 return NSK_TRUE;
451 }
452
453 /* Check "can_get_current_thread_cpu_time" function
454 */
checkGetCurrentThreadCpuTime()455 static int checkGetCurrentThreadCpuTime() {
456 jvmtiTimerInfo info;
457 jlong nanos;
458
459 NSK_DISPLAY0("Checking negative: GetCurrentThreadCpuTimerInfo\n");
460 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
461 jvmti->GetCurrentThreadCpuTimerInfo(&info)))
462 return NSK_FALSE;
463
464 NSK_DISPLAY0("Checking negative: GetCurrentThreadCpuTime\n");
465 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
466 jvmti->GetCurrentThreadCpuTime(&nanos)))
467 return NSK_FALSE;
468
469 return NSK_TRUE;
470 }
471
472 /* Check "can_get_thread_cpu_time" function
473 */
checkGetThreadCpuTime()474 static int checkGetThreadCpuTime() {
475 jvmtiTimerInfo info;
476 jlong nanos;
477
478 NSK_DISPLAY0("Checking negative: GetThreadCpuTimerInfo\n");
479 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
480 jvmti->GetThreadCpuTimerInfo(&info)))
481 return NSK_FALSE;
482
483 NSK_DISPLAY0("Checking negative: GetThreadCpuTime\n");
484 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
485 jvmti->GetThreadCpuTime(thread, &nanos)))
486 return NSK_FALSE;
487
488 return NSK_TRUE;
489 }
490
491 /* ========================================================================== */
492
493 /* agent algorithm */
494 static void JNICALL
agentProc(jvmtiEnv * jvmti,JNIEnv * agentJNI,void * arg)495 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
496 jni = agentJNI;
497
498 /* wait for initial sync */
499 if (!nsk_jvmti_waitForSync(timeout))
500 return;
501
502 if (!prepare()) {
503 nsk_jvmti_setFailStatus();
504 return;
505 }
506
507 /* testcase #7: check that only correspondent function work */
508 NSK_DISPLAY0("Testcase #7: check that only correspondent function work but not others\n");
509 if (!checkSuspend())
510 nsk_jvmti_setFailStatus();
511 if (!checkGetOwnedMonitorInfo())
512 nsk_jvmti_setFailStatus();
513 if (!checkGetCurrentContendedMonitor())
514 nsk_jvmti_setFailStatus();
515 if (!checkPopFrame())
516 nsk_jvmti_setFailStatus();
517 if (!checkHeapFunctions())
518 nsk_jvmti_setFailStatus();
519 if (!checkLocalVariableFunctions())
520 nsk_jvmti_setFailStatus();
521 if (!checkSourceInfoFunctions())
522 nsk_jvmti_setFailStatus();
523 if (!checkRedefineClasses())
524 nsk_jvmti_setFailStatus();
525 if (!checkGetObjectMonitorUsage())
526 nsk_jvmti_setFailStatus();
527 if (!checkIsSyntheticFunctions())
528 nsk_jvmti_setFailStatus();
529 if (!checkGetBytecodes())
530 nsk_jvmti_setFailStatus();
531 if (!checkGetCurrentThreadCpuTime())
532 nsk_jvmti_setFailStatus();
533 if (!checkGetThreadCpuTime())
534 nsk_jvmti_setFailStatus();
535 if (!checkSignalThread())
536 nsk_jvmti_setFailStatus();
537
538 /* testcase #8: exits with the capability has not been relinquished */
539 NSK_DISPLAY0("Testcase #8: check if VM exits well with the capability has not been relinquished\n");
540
541 /* resume debugee after last sync */
542 if (!nsk_jvmti_resumeSync())
543 return;
544 }
545
546 /* ========================================================================== */
547
548 /* agent library initialization */
549 #ifdef STATIC_BUILD
Agent_OnLoad_cm01t009(JavaVM * jvm,char * options,void * reserved)550 JNIEXPORT jint JNICALL Agent_OnLoad_cm01t009(JavaVM *jvm, char *options, void *reserved) {
551 return Agent_Initialize(jvm, options, reserved);
552 }
Agent_OnAttach_cm01t009(JavaVM * jvm,char * options,void * reserved)553 JNIEXPORT jint JNICALL Agent_OnAttach_cm01t009(JavaVM *jvm, char *options, void *reserved) {
554 return Agent_Initialize(jvm, options, reserved);
555 }
JNI_OnLoad_cm01t009(JavaVM * jvm,char * options,void * reserved)556 JNIEXPORT jint JNI_OnLoad_cm01t009(JavaVM *jvm, char *options, void *reserved) {
557 return JNI_VERSION_1_8;
558 }
559 #endif
Agent_Initialize(JavaVM * jvm,char * options,void * reserved)560 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
561 jvmtiCapabilities caps;
562
563 /* init framework and parse options */
564 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
565 return JNI_ERR;
566
567 timeout = nsk_jvmti_getWaitTime() * 60000;
568 NSK_DISPLAY1("Timeout: %d msc\n", (int)timeout);
569
570 /* create JVMTI environment */
571 if (!NSK_VERIFY((jvmti =
572 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
573 return JNI_ERR;
574
575 /* register agent proc and arg */
576 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
577 return JNI_ERR;
578
579 /* testcase #1: check GetPotentialCapabilities */
580 NSK_DISPLAY0("Testcase #1: check if GetPotentialCapabilities returns the capability\n");
581 if (!NSK_JVMTI_VERIFY(jvmti->GetPotentialCapabilities(&caps)))
582 return JNI_ERR;
583 if (!caps.CAPABILITY) {
584 NSK_COMPLAIN1("GetPotentialCapabilities does not return \"%s\" capability\n",
585 CAPABILITY_STR);
586 return JNI_ERR;
587 }
588
589 /* testcase #2: add the capability during Onload phase */
590 NSK_DISPLAY0("Testcase #2: add the capability during Onload phase\n");
591 memset(&caps, 0, sizeof(caps));
592 caps.CAPABILITY = 1;
593 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))
594 return JNI_ERR;
595
596 /* testcase #3: check if GetCapabilities returns the capability */
597 NSK_DISPLAY0("Testcase #3: check if GetCapabilities returns the capability\n");
598 memset(&caps, 0, sizeof(caps));
599 if (!NSK_JVMTI_VERIFY(jvmti->GetCapabilities(&caps)))
600 return JNI_ERR;
601 if (!caps.CAPABILITY) {
602 NSK_COMPLAIN1("GetCapabilities does not return \"%s\" capability\n",
603 CAPABILITY_STR);
604 return JNI_ERR;
605 }
606
607 /* testcase #4: relinquish the capability during Onload phase */
608 NSK_DISPLAY0("Testcase #4: relinquish the capability during Onload phase\n");
609 memset(&caps, 0, sizeof(caps));
610 caps.CAPABILITY = 1;
611 if (!NSK_JVMTI_VERIFY(jvmti->RelinquishCapabilities(&caps)))
612 return JNI_ERR;
613
614 /* testcase #5: check if GetCapabilities does not return the capability */
615 NSK_DISPLAY0("Testcase #5: check if GetCapabilities does not return the capability\n");
616 memset(&caps, 0, sizeof(caps));
617 if (!NSK_JVMTI_VERIFY(jvmti->GetCapabilities(&caps)))
618 return JNI_ERR;
619 if (caps.CAPABILITY) {
620 NSK_COMPLAIN1("GetCapabilities returns relinquished \"%s\" capability\n",
621 CAPABILITY_STR);
622 return JNI_ERR;
623 }
624
625 /* testcase #6: add back the capability and check with GetCapabilities */
626 NSK_DISPLAY0("Testcase #6: add back the capability and check with GetCapabilities\n");
627 memset(&caps, 0, sizeof(caps));
628 caps.CAPABILITY = 1;
629 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))
630 return JNI_ERR;
631 memset(&caps, 0, sizeof(caps));
632 if (!NSK_JVMTI_VERIFY(jvmti->GetCapabilities(&caps)))
633 return JNI_ERR;
634 if (!caps.CAPABILITY) {
635 NSK_COMPLAIN1("GetCapabilities does not return \"%s\" capability\n",
636 CAPABILITY_STR);
637 return JNI_ERR;
638 }
639
640 return JNI_OK;
641 }
642
643 /* ========================================================================== */
644
645 }
646