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.EventRequest.disable; 25 26 import nsk.share.*; 27 import nsk.share.jpda.*; 28 import nsk.share.jdi.*; 29 30 /** 31 * This class is used as debuggee application for the disable002 JDI test. 32 */ 33 34 public class disable002a { 35 36 //----------------------------------------------------- templete section 37 38 static final int PASSED = 0; 39 static final int FAILED = 2; 40 static final int PASS_BASE = 95; 41 42 static ArgumentHandler argHandler; 43 static Log log; 44 45 //-------------------------------------------------- log procedures 46 log1(String message)47 public static void log1(String message) { 48 log.display("**> debuggee: " + message); 49 } 50 logErr(String message)51 private static void logErr(String message) { 52 log.complain("**> debuggee: " + message); 53 } 54 55 //====================================================== test program 56 57 static disable002aThread1 thread1 = null; 58 59 static disable002aTestClass11 obj = new disable002aTestClass11(); 60 61 static NullPointerException excObj = new NullPointerException(); 62 63 //------------------------------------------------------ common section 64 65 static int exitCode = PASSED; 66 67 static int instruction = 1; 68 static int end = 0; 69 // static int quit = 0; 70 // static int continue = 2; 71 static int maxInstr = 1; // 2; 72 73 static int lineForComm = 2; 74 methodForCommunication()75 private static void methodForCommunication() { 76 int i1 = instruction; 77 int i2 = i1; 78 int i3 = i2; 79 } 80 //---------------------------------------------------- main method 81 main(String argv[])82 public static void main (String argv[]) { 83 84 argHandler = new ArgumentHandler(argv); 85 log = argHandler.createDebugeeLog(); 86 87 log1("debuggee started!"); 88 89 label0: 90 for (int i = 0; ; i++) { 91 92 if (instruction > maxInstr) { 93 logErr("ERROR: unexpected instruction: " + instruction); 94 exitCode = FAILED; 95 break ; 96 } 97 98 switch (i) { 99 100 //------------------------------------------------------ section tested 101 102 case 0: 103 thread1 = new disable002aThread1("thread1"); 104 105 synchronized (lockObj) { 106 threadStart(thread1); 107 log1("methodForCommunication();----1"); 108 methodForCommunication(); 109 } 110 i++; 111 112 case 1: 113 break; 114 case 2: 115 break; 116 case 3: 117 break; 118 case 4: 119 break; 120 case 5: 121 break; 122 case 6: 123 break; 124 case 7: 125 break; 126 case 8: 127 break; 128 case 9: 129 break; 130 case 10: 131 break; 132 case 11: 133 break; 134 135 //------------------------------------------------- standard end section 136 137 default: 138 instruction = end; 139 break; 140 } 141 142 143 log1("methodForCommunication();"); 144 methodForCommunication(); 145 if (instruction == end) 146 break; 147 148 149 } 150 151 log1("debuggee exits"); 152 System.exit(exitCode + PASS_BASE); 153 } 154 155 static Object lockObj = new Object(); 156 static Object waitnotifyObj = new Object(); 157 threadStart(Thread t)158 static int threadStart(Thread t) { 159 synchronized (waitnotifyObj) { 160 t.start(); 161 try { 162 waitnotifyObj.wait(); 163 } catch ( Exception e) { 164 exitCode = FAILED; 165 logErr(" Exception : " + e ); 166 return FAILED; 167 } 168 } 169 return PASSED; 170 } 171 } 172 173 class disable002aTestClass10{ 174 175 static int var101 = 0; 176 static int var102 = 0; 177 static int var103 = 0; 178 method10()179 static void method10 () { 180 disable002a.log1("entered: method10"); 181 var101 = 1; 182 var103 = var101; 183 var102 = var103; 184 185 } 186 } 187 class disable002aTestClass11 extends disable002aTestClass10{ 188 189 static int var111 = 0; 190 static int var112 = 0; 191 static int var113 = 0; 192 method11()193 static void method11 () { 194 disable002a.log1("entered: method11"); 195 var101 = 1; 196 var103 = var101; 197 var102 = var103; 198 199 var111 = 1; 200 var113 = var111; 201 var112 = var113; 202 } 203 } 204 205 class disable002aThread1 extends Thread { 206 207 String tName = null; 208 disable002aThread1(String threadName)209 public disable002aThread1(String threadName) { 210 super(threadName); 211 tName = threadName; 212 } 213 run()214 public void run() { 215 disable002a.log1(" 'run': enter :: threadName == " + tName); 216 synchronized(disable002a.waitnotifyObj) { 217 disable002a.waitnotifyObj.notify(); 218 } 219 synchronized(disable002a.lockObj) { 220 disable002aTestClass11.method11(); 221 } 222 disable002a.log1(" 'run': exit :: threadName == " + tName); 223 return; 224 } 225 } 226