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.ExceptionRequest.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_rt003 JDI test. 32 */ 33 34 public class filter_rt003a { 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 filter_rt003aThread1 thread1 = null; 58 static filter_rt003aThread2 thread2 = null; 59 60 //------------------------------------------------------ common section 61 62 static int exitCode = PASSED; 63 64 static int instruction = 1; 65 static int end = 0; 66 // static int quit = 0; 67 // static int continue = 2; 68 static int maxInstr = 1; // 2; 69 70 static int lineForComm = 2; 71 methodForCommunication()72 private static void methodForCommunication() { 73 int i1 = instruction; 74 int i2 = i1; 75 int i3 = i2; 76 } 77 //---------------------------------------------------- main method 78 main(String argv[])79 public static void main (String argv[]) { 80 81 argHandler = new ArgumentHandler(argv); 82 log = argHandler.createDebugeeLog(); 83 84 filter_rt003aTestClass11 obj1 = new filter_rt003aTestClass11(); 85 filter_rt003aTestClass21 obj2 = new filter_rt003aTestClass21(); 86 87 thread1 = new filter_rt003aThread1("thread1"); 88 thread2 = new filter_rt003aThread2("thread2"); 89 90 log1("debuggee started!"); 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 log1("new filter_rt003a().run1(thread1);"); 111 new filter_rt003a().run1(thread1); 112 113 log1("new filter_rt003a().run1(thread2);"); 114 new filter_rt003a().run1(thread2); 115 116 //------------------------------------------------- standard end section 117 118 default: 119 instruction = end; 120 break; 121 } 122 } 123 124 log1("debuggee exits"); 125 System.exit(exitCode + PASS_BASE); 126 } 127 128 static Object waitnotifyObj = new Object(); 129 threadStart(Thread t)130 static int threadStart(Thread t) { 131 synchronized (waitnotifyObj) { 132 t.start(); 133 try { 134 waitnotifyObj.wait(); 135 } catch ( Exception e) { 136 exitCode = FAILED; 137 logErr(" Exception : " + e ); 138 return FAILED; 139 } 140 } 141 return PASSED; 142 } 143 run1(Thread t)144 public void run1(Thread t) { 145 t.start(); 146 try { 147 t.join(); 148 } catch ( InterruptedException e ) { 149 } 150 } 151 } 152 153 154 class filter_rt003aTestClass10{ m10()155 void m10() { 156 throw new NullPointerException("m10"); 157 } 158 } 159 class filter_rt003aTestClass11 extends filter_rt003aTestClass10{ m11()160 void m11() { 161 162 try { 163 (new filter_rt003aTestClass10()).m10(); 164 } catch ( NullPointerException e ) { 165 } 166 throw new NullPointerException("m11"); 167 } 168 } 169 170 class filter_rt003aThread1 extends Thread { 171 172 String tName = null; 173 filter_rt003aThread1(String threadName)174 public filter_rt003aThread1(String threadName) { 175 super(threadName); 176 tName = threadName; 177 } 178 run()179 public void run() { 180 filter_rt003a.log1(" 'run': enter :: threadName == " + tName); 181 try { 182 (new filter_rt003aTestClass11()).m11(); 183 } catch ( NullPointerException e) { 184 } 185 filter_rt003a.log1(" 'run': exit :: threadName == " + tName); 186 return; 187 } 188 } 189 190 191 class filter_rt003aTestClass20{ m20()192 void m20() { 193 throw new NullPointerException("m20"); 194 } 195 } 196 class filter_rt003aTestClass21 extends filter_rt003aTestClass20{ m21()197 void m21() { 198 199 try { 200 (new filter_rt003aTestClass20()).m20(); 201 } catch ( NullPointerException e ) { 202 } 203 throw new NullPointerException("m11"); 204 } 205 } 206 207 class filter_rt003aThread2 extends Thread { 208 209 String tName = null; 210 filter_rt003aThread2(String threadName)211 public filter_rt003aThread2(String threadName) { 212 super(threadName); 213 tName = threadName; 214 } 215 run()216 public void run() { 217 filter_rt003a.log1(" 'run': enter :: threadName == " + tName); 218 try { 219 (new filter_rt003aTestClass21()).m21(); 220 } catch ( NullPointerException e) { 221 } 222 filter_rt003a.log1(" 'run': exit :: threadName == " + tName); 223 return; 224 } 225 } 226