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