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.ObjectReference.invokeMethod; 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 invokemethod001 JDI test. 33 */ 34 35 public class invokemethod001a { 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 private static void log1(String message) { 48 if (verbMode) 49 System.err.println("**> debuggee: " + message); 50 } 51 log2(String message)52 public static void log2(String message) { 53 if (verbMode) 54 System.err.println("**> " + message); 55 } 56 logErr(String message)57 private static void logErr(String message) { 58 if (verbMode) 59 System.err.println("!!**> debuggee: " + message); 60 } 61 62 //====================================================== test program 63 //---------------------------------------------------- main method 64 main(String argv[])65 public static void main (String argv[]) { 66 67 for (int i=0; i<argv.length; i++) { 68 if ( argv[i].equals("-vbs") || argv[i].equals("-verbose") ) { 69 verbMode = true; 70 break; 71 } 72 } 73 log1("debuggee started!"); 74 75 // informing a debugger of readyness 76 ArgumentHandler argHandler = new ArgumentHandler(argv); 77 IOPipe pipe = argHandler.createDebugeeIOPipe(); 78 pipe.println("ready"); 79 80 81 int exitCode = PASSED; 82 for (int i = 0; ; i++) { 83 84 String instruction; 85 86 log1("waiting for an instruction from the debugger ..."); 87 instruction = pipe.readln(); 88 if (instruction.equals("quit")) { 89 log1("'quit' recieved"); 90 break ; 91 92 } else if (instruction.equals("newcheck")) { 93 switch (i) { 94 95 //------------------------------------------------------ section tested 96 97 case 0: 98 Threadinvokemethod001a test_thread = 99 new Threadinvokemethod001a("testedThread"); 100 log1(" thread2 is created"); 101 102 label: 103 synchronized (Threadinvokemethod001a.lockingObject) { 104 synchronized (Threadinvokemethod001a.waitnotifyObj) { 105 log1(" synchronized (waitnotifyObj) { enter"); 106 log1(" before: test_thread.start()"); 107 test_thread.start(); 108 109 try { 110 log1(" before: waitnotifyObj.wait();"); 111 Threadinvokemethod001a.waitnotifyObj.wait(); 112 log1(" after: waitnotifyObj.wait();"); 113 pipe.println("checkready"); 114 instruction = pipe.readln(); 115 if (!instruction.equals("continue")) { 116 logErr("ERROR: unexpected instruction: " + instruction); 117 exitCode = FAILED; 118 break label; 119 } 120 pipe.println("docontinue"); 121 } catch ( Exception e2) { 122 log1(" Exception e2 exception: " + e2 ); 123 pipe.println("waitnotifyerr"); 124 } 125 } 126 } 127 log1("mainThread is out of: synchronized (lockingObject) {"); 128 129 break ; 130 131 //------------------------------------------------- standard end section 132 133 default: 134 pipe.println("checkend"); 135 break ; 136 } 137 138 } else { 139 logErr("ERRROR: unexpected instruction: " + instruction); 140 exitCode = FAILED; 141 break ; 142 } 143 } 144 145 System.exit(exitCode + PASS_BASE); 146 } 147 } 148 149 class Threadinvokemethod001a extends Thread { 150 Threadinvokemethod001a(String threadName)151 public Threadinvokemethod001a(String threadName) { 152 super(threadName); 153 } 154 155 public static Object waitnotifyObj = new Object(); 156 public static Object lockingObject = new Object(); 157 run()158 public void run() { 159 log("method 'run' enter"); 160 synchronized (waitnotifyObj) { 161 log("entered into block: synchronized (waitnotifyObj)"); 162 waitnotifyObj.notify(); } 163 log("exited from block: synchronized (waitnotifyObj)"); 164 synchronized (lockingObject) { 165 log("entered into block: synchronized (lockingObject)"); } 166 log("exited from block: synchronized (lockingObject)"); 167 log("call to the method 'runt1'"); 168 runt1(); 169 log("returned from the method 'runt1'"); 170 log("method 'run' exit"); 171 return; 172 } 173 runt1()174 public void runt1() { 175 176 int i0 = 0; 177 log("method 'runt1': enter"); 178 i0 = 1; 179 log("method 'runt1': body: i0 == " + i0); 180 log("method 'runt1': exit"); 181 return; 182 } 183 184 public static final int breakpointLineNumber1 = 3; 185 186 log(String str)187 void log(String str) { 188 invokemethod001a.log2("thread2: " + str); 189 } 190 blValue()191 public static boolean blValue() { 192 return true; 193 } btValue()194 public static byte btValue() { 195 return 1; 196 } chValue()197 public static char chValue() { 198 return 1; 199 } dbValue()200 public static double dbValue() { 201 return 1.0d; 202 } flValue()203 public static float flValue() { 204 return 1.0f; 205 } inValue()206 public static int inValue() { 207 return 1; 208 } lnValue()209 public static long lnValue() { 210 return 1; 211 } shValue()212 public static short shValue() { 213 return 1; 214 } vdValue()215 public static void vdValue() { 216 return ; 217 } 218 219 } 220