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.ThreadStartRequest.addThreadFilter; 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 addthreadfilter004 JDI test. 32 */ 33 34 public class addthreadfilter004a { 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 private 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 Threadaddthreadfilter004a thread1 = null; 58 static Threadaddthreadfilter004a thread2 = null; 59 60 static addthreadfilter004aTestClass objTC = new addthreadfilter004aTestClass(); 61 62 //------------------------------------------------------ common section 63 64 static int exitCode = PASSED; 65 66 static int instruction = 1; 67 static int end = 0; 68 // static int quit = 0; 69 // static int continue = 2; 70 static int maxInstr = 1; // 2; 71 72 static int lineForComm = 2; 73 methodForCommunication()74 private static void methodForCommunication() { 75 int i1 = instruction; 76 int i2 = i1; 77 int i3 = i2; 78 } 79 //---------------------------------------------------- main method 80 main(String argv[])81 public static void main (String argv[]) { 82 83 argHandler = new ArgumentHandler(argv); 84 log = argHandler.createDebugeeLog(); 85 86 log1("debuggee started!"); 87 88 label0: 89 for (int i = 0; ; i++) { 90 91 if (instruction > maxInstr) { 92 logErr("ERROR: unexpected instruction: " + instruction); 93 exitCode = FAILED; 94 break ; 95 } 96 97 switch (i) { 98 99 //------------------------------------------------------ section tested 100 101 case 0: 102 thread1 = new Threadaddthreadfilter004a("thread1"); 103 thread2 = new Threadaddthreadfilter004a("thread2"); 104 break; 105 106 case 1: 107 threadStart(thread1); 108 threadStart(thread2); 109 synchronized(lockingObj[0]) { 110 log1("synchronized(lockingObj[0])"); 111 } 112 synchronized(lockingObj[1]) { 113 log1("synchronized(lockingObj[1])"); 114 } 115 116 //------------------------------------------------- standard end section 117 118 default: 119 instruction = end; 120 break; 121 } 122 log1("methodForCommunication();"); 123 methodForCommunication(); 124 if (instruction == end) 125 break; 126 } 127 128 log1("debuggee exits"); 129 System.exit(exitCode + PASS_BASE); 130 } 131 132 133 static Object waitnotifyObj = new Object(); 134 threadStart(Thread t)135 static int threadStart(Thread t) { 136 synchronized (waitnotifyObj) { 137 t.start(); 138 try { 139 waitnotifyObj.wait(); 140 } catch ( Exception e) { 141 exitCode = FAILED; 142 logErr(" Exception : " + e ); 143 return FAILED; 144 } 145 } 146 return PASSED; 147 } 148 149 150 static Object lockingObj[] = new Object[2]; 151 static volatile int number = 0; 152 153 static class Threadaddthreadfilter004a extends Thread { 154 155 String tName = null; 156 int tNumber; 157 Threadaddthreadfilter004a(String threadName)158 public Threadaddthreadfilter004a(String threadName) { 159 super(threadName); 160 tName = threadName; 161 tNumber = number; 162 number++; 163 lockingObj[tNumber] = threadName; 164 } 165 run()166 public void run() { 167 log1(" 'run': enter :: threadName == " + tName); 168 if (lockingObj[tNumber] == null) 169 log1("lockingObj[tNumber] == null"); 170 synchronized(lockingObj[tNumber]) { 171 synchronized (waitnotifyObj) { 172 waitnotifyObj.notify(); 173 } 174 objTC.method(); 175 } 176 log1(" 'run': exit :: threadName == " + tName); 177 return; 178 } 179 } 180 181 } 182 183 class addthreadfilter004aTestClass { 184 185 static int breakpointLine = 3; 186 static String awFieldName = "var1"; 187 static String mwFieldName = "var2"; 188 189 static int var1 = 0; 190 static int var2 = 0; 191 static int var3 = 0; 192 method()193 static void method () { 194 var1 = 1; 195 var3 = var1; 196 var2 = var3; 197 } 198 } 199