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.WatchpointRequest.addClassExclusionFilter; 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 filter002 JDI test. 32 */ 33 34 public class filter002a { 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 Thread1filter002a thread1 = null; 58 static Thread2filter002a thread2 = null; 59 60 static filter002aTestClass10 obj10 = new filter002aTestClass10(); 61 static filter002aTestClass11 obj11 = new filter002aTestClass11(); 62 static filter002aTestClass20 obj20 = new filter002aTestClass20(); 63 static filter002aTestClass21 obj21 = new filter002aTestClass21(); 64 65 //------------------------------------------------------ common section 66 67 static int exitCode = PASSED; 68 69 static int instruction = 1; 70 static int end = 0; 71 // static int quit = 0; 72 // static int continue = 2; 73 static int maxInstr = 1; // 2; 74 75 static int lineForComm = 2; 76 methodForCommunication()77 private static void methodForCommunication() { 78 int i1 = instruction; 79 int i2 = i1; 80 int i3 = i2; 81 } 82 //---------------------------------------------------- main method 83 main(String argv[])84 public static void main (String argv[]) { 85 86 argHandler = new ArgumentHandler(argv); 87 log = argHandler.createDebugeeLog(); 88 89 log1("debuggee started!"); 90 91 92 for (int i = 0; ; i++) { 93 94 log1("methodForCommunication();"); 95 methodForCommunication(); 96 if (instruction == end) 97 break; 98 99 if (instruction > maxInstr) { 100 logErr("ERROR: unexpected instruction: " + instruction); 101 exitCode = FAILED; 102 break ; 103 } 104 105 switch (i) { 106 107 //------------------------------------------------------ section tested 108 109 case 0: 110 thread1 = new Thread1filter002a("thread1"); 111 log1("run1(thread1);"); 112 run1(thread1); 113 114 break; 115 116 case 1: 117 thread2 = new Thread2filter002a("thread2"); 118 log1("run1(thread2);"); 119 run1(thread2); 120 121 //------------------------------------------------- standard end section 122 123 default: 124 instruction = end; 125 break; 126 } 127 128 } 129 130 log1("debuggee exits"); 131 System.exit(exitCode + PASS_BASE); 132 } 133 134 static Object waitnotifyObj = new Object(); 135 threadStart(Thread t)136 static int threadStart(Thread t) { 137 synchronized (waitnotifyObj) { 138 t.start(); 139 try { 140 waitnotifyObj.wait(); 141 } catch ( Exception e) { 142 exitCode = FAILED; 143 logErr(" Exception : " + e ); 144 return FAILED; 145 } 146 } 147 return PASSED; 148 } 149 run1(Thread t)150 static void run1(Thread t) { 151 threadStart(t); 152 try { 153 t.join(); 154 } catch ( InterruptedException e ) { 155 } 156 } 157 158 159 static class Thread1filter002a extends Thread { 160 161 String tName = null; 162 Thread1filter002a(String threadName)163 public Thread1filter002a(String threadName) { 164 super(threadName); 165 tName = threadName; 166 } 167 run()168 public void run() { 169 log1(" 'run': enter :: threadName == " + tName); 170 synchronized (waitnotifyObj) { 171 waitnotifyObj.notify(); 172 } 173 obj10.method(); 174 obj11.method(); 175 log1(" 'run': exit :: threadName == " + tName); 176 return; 177 } 178 } 179 180 static class Thread2filter002a extends Thread { 181 182 String tName = null; 183 Thread2filter002a(String threadName)184 public Thread2filter002a(String threadName) { 185 super(threadName); 186 tName = threadName; 187 } 188 run()189 public void run() { 190 log1(" 'run': enter :: threadName == " + tName); 191 synchronized (waitnotifyObj) { 192 waitnotifyObj.notify(); 193 } 194 obj20.method(); 195 obj21.method(); 196 log1(" 'run': exit :: threadName == " + tName); 197 return; 198 } 199 } 200 } 201 202 class filter002aTestClass10 { 203 static int var101 = 0; 204 static int var102 = 0; 205 static int var103 = 0; 206 method()207 static void method () { 208 var101 = 1; 209 var103 = var101; 210 var102 = var103; 211 } 212 } 213 class filter002aTestClass11 extends filter002aTestClass10 { 214 215 static int var111 = 0; 216 static int var112 = 0; 217 static int var113 = 0; 218 method()219 static void method () { 220 var101 = 1; 221 var103 = var101; 222 var102 = var103; 223 224 var111 = 1; 225 var113 = var111; 226 var112 = var113; 227 // TestClass10.method(); 228 } 229 } 230 231 class filter002aTestClass20 { 232 233 static int var201 = 0; 234 static int var202 = 0; 235 static int var203 = 0; 236 method()237 static void method () { 238 var201 = 1; 239 var203 = var201; 240 var202 = var203; 241 } 242 } 243 class filter002aTestClass21 extends filter002aTestClass20 { 244 245 static int var211 = 0; 246 static int var212 = 0; 247 static int var213 = 0; 248 method()249 static void method () { 250 var201 = 1; 251 var203 = var201; 252 var202 = var203; 253 254 var211 = 1; 255 var213 = var211; 256 var212 = var213; 257 // filter002aTestClass20.method(); 258 } 259 } 260