1 /* 2 * Copyright (c) 2001, 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 package nsk.jdi.ThreadReference.frames_ii; 25 26 import nsk.share.*; 27 import nsk.share.jpda.*; 28 import nsk.share.jdi.*; 29 30 31 /** 32 * This class is used as debuggee application for the frames_ii001 JDI test. 33 */ 34 35 public class frames_ii001a { 36 37 //----------------------------------------------------- templete section 38 39 static final int PASSED = 0; 40 static final int FAILED = 2; 41 static final int PASS_BASE = 95; 42 43 //-------------------------------------------------- log procedures 44 45 static boolean verbMode = false; 46 log1(String message)47 public static void log1(String message) { 48 if (verbMode) 49 System.err.println("**> mainThread: " + message); 50 } log2(String message)51 public static void log2(String message) { 52 if (verbMode) 53 System.err.println("**> " + message); 54 } 55 logErr(String message)56 private static void logErr(String message) { 57 if (verbMode) 58 System.err.println("!!**> mainThread: " + message); 59 } 60 61 //====================================================== test program 62 //---------------------------------------------------- main method 63 main(String argv[])64 public static void main (String argv[]) { 65 66 for (int i=0; i<argv.length; i++) { 67 if ( argv[i].equals("-vbs") || argv[i].equals("-verbose") ) { 68 verbMode = true; 69 break; 70 } 71 } 72 log1("debuggee started!"); 73 74 // informing a debugger of readyness 75 ArgumentHandler argHandler = new ArgumentHandler(argv); 76 IOPipe pipe = argHandler.createDebugeeIOPipe(); 77 pipe.println("ready"); 78 79 80 int exitCode = PASSED; 81 for (int i = 0; ; i++) { 82 83 String instruction; 84 85 log1("waiting for an instruction from the debugger ..."); 86 instruction = pipe.readln(); 87 if (instruction.equals("quit")) { 88 log1("'quit' recieved"); 89 break ; 90 91 } else if (instruction.equals("newcheck")) { 92 switch (i) { 93 94 //------------------------------------------------------ section tested 95 96 case 0: 97 Threadframes_ii001a test_thread = 98 new Threadframes_ii001a("testedThread"); 99 log1(" thread2 is created"); 100 101 label: 102 synchronized (Threadframes_ii001a.lockingObject) { 103 synchronized (Threadframes_ii001a.waitnotifyObj) { 104 log1(" synchronized (waitnotifyObj) { enter"); 105 log1(" before: test_thread.start()"); 106 test_thread.start(); 107 108 try { 109 log1(" before: waitnotifyObj.wait();"); 110 Threadframes_ii001a.waitnotifyObj.wait(); 111 log1(" after: waitnotifyObj.wait();"); 112 pipe.println("checkready"); 113 instruction = pipe.readln(); 114 if (!instruction.equals("continue")) { 115 logErr("ERROR: unexpected instruction: " + instruction); 116 exitCode = FAILED; 117 break label; 118 } 119 pipe.println("docontinue"); 120 } catch ( Exception e2) { 121 log1(" Exception e2 exception: " + e2 ); 122 pipe.println("waitnotifyerr"); 123 } 124 } 125 } 126 log1("mainThread is out of: synchronized (lockingObject) {"); 127 128 break ; 129 130 //------------------------------------------------- standard end section 131 132 default: 133 pipe.println("checkend"); 134 break ; 135 } 136 137 } else { 138 logErr("ERRROR: unexpected instruction: " + instruction); 139 exitCode = FAILED; 140 break ; 141 } 142 } 143 144 System.exit(exitCode + PASS_BASE); 145 } 146 } 147 148 149 class Threadframes_ii001a extends Thread { 150 Threadframes_ii001a(String threadName)151 public Threadframes_ii001a(String threadName) { 152 super(threadName); 153 } 154 155 public static Object waitnotifyObj = new Object(); 156 public static Object lockingObject = new Object(); 157 158 private int i1 = 0, i2 = 10; 159 run()160 public void run() { 161 log("method 'run' enter"); 162 synchronized (waitnotifyObj) { 163 log("entered into block: synchronized (waitnotifyObj)"); 164 waitnotifyObj.notify(); } 165 log("exited from block: synchronized (waitnotifyObj)"); 166 synchronized (lockingObject) { 167 log("entered into block: synchronized (lockingObject)"); } 168 log("exited from block: synchronized (lockingObject)"); 169 i1++; 170 i1++; 171 i1++; 172 i1++; 173 i1++; 174 i2--; 175 log("call to the method 'runt1'"); 176 runt1(); 177 log("returned from the method 'runt1'"); 178 log("method 'run' exit"); 179 return; 180 } 181 runt1()182 public void runt1() { 183 log("method 'runt1' enter"); 184 i1++; 185 i2--; 186 log("call to the method 'runt2'"); 187 runt2(); 188 log("returned from the method 'runt2'"); 189 i1++; 190 i2--; 191 log("method 'runt1' exit"); 192 return; 193 } 194 runt2()195 public void runt2() { 196 log("method 'runt2' enter"); 197 i1++; 198 i2--; 199 log("method 'run2t' exit"); 200 return; 201 } 202 203 public static final int breakpointLineNumber0 = 9; 204 public static final int breakpointLineNumber1 = 3; 205 public static final int breakpointLineNumber3 = 7; 206 207 public static final int breakpointLineNumber2 = 2; 208 log(String str)209 void log(String str) { 210 frames_ii001a.log2("thread2: " + str); 211 } 212 213 } 214