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.StepRequest.addClassFilter_rt; 25 26 import nsk.share.*; 27 import nsk.share.jpda.*; 28 import nsk.share.jdi.*; 29 import nsk.share.jdi.ThreadState; 30 31 /** 32 * This class is used as debuggee application for the filter_rt003 JDI test. 33 */ 34 35 public class filter_rt003a { 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 static final long THREAD_STATE_TIMEOUT_MS = 30000; 44 static final String STATE_INIT = "init"; 45 static final String STATE_THREAD_STARTED = "threadStarted"; 46 static final String STATE_JDI_INITED = "jdiInited"; 47 48 static ArgumentHandler argHandler; 49 static Log log; 50 51 //-------------------------------------------------- log procedures 52 log1(String message)53 public static void log1(String message) { 54 log.display("**> debuggee: " + message); 55 } 56 logErr(String message)57 private static void logErr(String message) { 58 log.complain("**> debuggee: " + message); 59 } 60 61 //====================================================== test program 62 63 static Thread1filter_rt003a thread1 = new Thread1filter_rt003a( 64 "thread1", new ThreadState(STATE_INIT, THREAD_STATE_TIMEOUT_MS)); 65 static Thread2filter_rt003a thread2 = new Thread2filter_rt003a( 66 "thread2", new ThreadState(STATE_INIT, THREAD_STATE_TIMEOUT_MS)); 67 68 static filter_rt003aTestClass11 obj1 = new filter_rt003aTestClass11(); 69 static filter_rt003aTestClass21 obj2 = new filter_rt003aTestClass21(); 70 71 //------------------------------------------------------ common section 72 73 static int exitCode = PASSED; 74 75 static int instruction = 1; 76 static int end = 0; 77 // static int quit = 0; 78 // static int continue = 2; 79 static int maxInstr = 1; // 2; 80 81 static int lineForComm = 2; 82 methodForCommunication()83 private static void methodForCommunication() { 84 int i1 = instruction; 85 int i2 = i1; 86 int i3 = i2; 87 } 88 //---------------------------------------------------- main method 89 main(String argv[])90 public static void main (String argv[]) { 91 92 argHandler = new ArgumentHandler(argv); 93 log = argHandler.createDebugeeLog(); 94 95 thread1.start(); 96 thread2.start(); 97 thread1.getThreadState().waitForState(STATE_THREAD_STARTED); 98 thread2.getThreadState().waitForState(STATE_THREAD_STARTED); 99 100 log1("debuggee started!"); 101 102 for (int i = 0; ; i++) { 103 104 log1("methodForCommunication();"); 105 methodForCommunication(); 106 if (instruction == end) 107 break; 108 109 if (instruction > maxInstr) { 110 logErr("ERROR: unexpected instruction: " + instruction); 111 exitCode = FAILED; 112 break ; 113 } 114 115 switch (i) { 116 117 //------------------------------------------------------ section tested 118 119 case 0: 120 thread1.getThreadState().setState(STATE_JDI_INITED); 121 thread2.getThreadState().setState(STATE_JDI_INITED); 122 waitForThreadJoin ( thread1, "thread1" ); 123 waitForThreadJoin ( thread2, "thread2" ); 124 125 //------------------------------------------------- standard end section 126 127 default: 128 instruction = end; 129 break; 130 } 131 } 132 133 log1("debuggee exits"); 134 System.exit(exitCode + PASS_BASE); 135 } 136 waitForThreadJoin(Thread thread, String threadName)137 static void waitForThreadJoin (Thread thread, String threadName) { 138 log1("waiting for " + threadName + " join"); 139 140 // get internal timeout in minutes for waiting of thread completion. 141 int waitTime = argHandler.getWaitTime(); 142 if (thread.isAlive()) { 143 try { 144 thread.join(waitTime * 60 * 1000); 145 } catch (InterruptedException e) { 146 throw new Failure("catched unexpected InterruptedException while waiting of " + threadName + " join:" + e); 147 }; 148 } 149 if (thread.isAlive()) { 150 throw new Failure(threadName + " is still alive"); 151 } else { 152 log1(threadName + " joined"); 153 } 154 } 155 156 } 157 158 class filter_rt003aTestClass10{ m10()159 static void m10() { 160 filter_rt003a.log1("entered: m10"); 161 } 162 } 163 class filter_rt003aTestClass11 extends filter_rt003aTestClass10{ m11()164 static void m11() { 165 filter_rt003a.log1("entered: m11"); 166 filter_rt003aTestClass10.m10(); 167 } 168 } 169 170 class Thread1filter_rt003a extends Thread { 171 172 private String tName = null; 173 private ThreadState threadState = null; 174 Thread1filter_rt003a(String threadName, ThreadState threadState)175 public Thread1filter_rt003a(String threadName, ThreadState threadState) { 176 super(threadName); 177 tName = threadName; 178 this.threadState = threadState; 179 } 180 getThreadState()181 public ThreadState getThreadState() { 182 return threadState; 183 } 184 run()185 public void run() { 186 filter_rt003a.log1(" 'run': enter :: threadName == " + tName); 187 threadState.setAndWait(filter_rt001a.STATE_THREAD_STARTED, filter_rt001a.STATE_JDI_INITED); 188 filter_rt003aTestClass11.m11(); 189 filter_rt003a.log1(" 'run': exit :: threadName == " + tName); 190 return; 191 } 192 } 193 194 class filter_rt003aTestClass20{ m20()195 static void m20() { 196 filter_rt003a.log1("entered: m20"); 197 } 198 } 199 class filter_rt003aTestClass21 extends filter_rt003aTestClass20{ m21()200 static void m21() { 201 filter_rt003a.log1("entered: m21"); 202 filter_rt003aTestClass20.m20(); 203 } 204 } 205 206 class Thread2filter_rt003a extends Thread { 207 208 private String tName = null; 209 private ThreadState threadState = null; 210 Thread2filter_rt003a(String threadName, ThreadState threadState)211 public Thread2filter_rt003a(String threadName, ThreadState threadState) { 212 super(threadName); 213 tName = threadName; 214 this.threadState = threadState; 215 } 216 getThreadState()217 public ThreadState getThreadState() { 218 return threadState; 219 } 220 run()221 public void run() { 222 filter_rt003a.log1(" 'run': enter :: threadName == " + tName); 223 threadState.setAndWait(filter_rt001a.STATE_THREAD_STARTED, filter_rt001a.STATE_JDI_INITED); 224 filter_rt003aTestClass21.m21(); 225 filter_rt003a.log1(" 'run': exit :: threadName == " + tName); 226 return; 227 } 228 } 229