1 /* 2 * Copyright (c) 2007, 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 /* 25 * @test 26 * 27 * @summary converted from VM Testbase nsk/jdi/ThreadReference/forceEarlyReturn/forceEarlyReturn003. 28 * VM Testbase keywords: [quick, jpda, jdi, feature_jdk6_jpda, vm6] 29 * VM Testbase readme: 30 * DESCRIPTION 31 * The test checks that a result of the method com.sun.jdi.forceEarlyReturn(Value value) 32 * complies with its specification. The test checks: 33 * - attempt to call forceEarlyReturn on not suspended thread throws IncompatibleThreadStateException 34 * Test scenario: 35 * Special thread class is used in debugee VM for testing thread in different states - nsk.share.jpda.StateTestThread. 36 * StateTestThread sequentially changes its state in following order: 37 * - thread not started 38 * - thread is running 39 * - thread is sleeping 40 * - thread in Object.wait() 41 * - thread wait on java monitor 42 * - thread is finished 43 * Debugger VM calls ThreadReference.forceEarlyReturn() for all this states and expects IncompatibleThreadStateException. 44 * 45 * @library /vmTestbase 46 * /test/lib 47 * @run driver jdk.test.lib.FileInstaller . . 48 * @build nsk.jdi.ThreadReference.forceEarlyReturn.forceEarlyReturn003.forceEarlyReturn003 49 * @run main/othervm PropertyResolvingWrapper 50 * nsk.jdi.ThreadReference.forceEarlyReturn.forceEarlyReturn003.forceEarlyReturn003 51 * -verbose 52 * -arch=${os.family}-${os.simpleArch} 53 * -waittime=5 54 * -debugee.vmkind=java 55 * -transport.address=dynamic 56 * "-debugee.vmkeys=${test.vm.opts} ${test.java.opts}" 57 */ 58 59 package nsk.jdi.ThreadReference.forceEarlyReturn.forceEarlyReturn003; 60 61 import java.io.PrintStream; 62 import com.sun.jdi.IncompatibleThreadStateException; 63 import com.sun.jdi.ThreadReference; 64 import nsk.share.Consts; 65 import nsk.share.jdi.*; 66 import nsk.share.jpda.*; 67 68 public class forceEarlyReturn003 extends ForceEarlyReturnDebugger { main(String argv[])69 public static void main(String argv[]) { 70 System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE); 71 } 72 debuggeeClassName()73 public String debuggeeClassName() { 74 return AbstractJDIDebuggee.class.getName(); 75 } 76 run(String argv[], PrintStream out)77 public static int run(String argv[], PrintStream out) { 78 return new forceEarlyReturn003().runIt(argv, out); 79 } 80 test(ThreadReference threadReference)81 public void test(ThreadReference threadReference) { 82 log.display("Thread state: " + threadReference.status()); 83 try { 84 // call ThreadReference.forceEarlyReturn() on non-suspended VM 85 // IncompatibleThreadStateException should be thrown 86 threadReference.forceEarlyReturn(vm.mirrorOf(0)); 87 88 setSuccess(false); 89 log.complain("Expected IncompatibleThreadStateException was not thrown"); 90 } catch (IncompatibleThreadStateException e) { 91 // expected exception 92 } catch (Exception e) { 93 setSuccess(false); 94 log.complain("Unexpected exception: " + e); 95 e.printStackTrace(System.out); 96 } 97 } 98 doTest()99 public void doTest() { 100 pipe.println(AbstractDebuggeeTest.COMMAND_CREATE_STATETESTTHREAD); 101 102 if (!isDebuggeeReady()) 103 return; 104 105 ThreadReference threadReference = (ThreadReference) debuggee.classByName(AbstractDebuggeeTest.stateTestThreadClassName).instances(0).get(0); 106 107 test(threadReference); 108 109 int state = 1; 110 111 while (state++ < StateTestThread.stateTestThreadStates.length) { 112 pipe.println(AbstractDebuggeeTest.COMMAND_NEXTSTATE_STATETESTTHREAD); 113 114 if (!isDebuggeeReady()) 115 return; 116 117 test(threadReference); 118 } 119 } 120 } 121