1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.harmony.jpda.tests.jdwp.ThreadReference; 20 21 import org.apache.harmony.jpda.tests.framework.DebuggeeSynchronizer; 22 import org.apache.harmony.jpda.tests.framework.LogWriter; 23 import org.apache.harmony.jpda.tests.framework.jdwp.Value; 24 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 25 import org.apache.harmony.jpda.tests.share.SyncDebuggee; 26 27 /** 28 * The class specifies debuggee for 29 * <code>org.apache.harmony.jpda.tests.jdwp.ThreadReference.ForceEarlyReturnTest</code>. 30 * This debuggee starts the tested thread which name is supplied by test and 31 * synchronized with test via the <code>SGNL_READY</code> and 32 * <code>SGNL_CONTINUE</code> signals. 33 */ 34 public class ForceEarlyReturnDebuggee extends SyncDebuggee { 35 36 public static String threadName; 37 38 static boolean isFuncVoidBreak = true; 39 40 static TestObject testObj = new TestObject(); 41 42 public static final String THREAD_VOID = "THREAD_VOID"; 43 44 public static final String THREAD_OBJECT = "THREAD_OBJECT"; 45 46 public static final String THREAD_INT = "THREAD_INT"; 47 48 public static final String THREAD_SHORT = "THREAD_SHORT"; 49 50 public static final String THREAD_BYTE = "THREAD_BYTE"; 51 52 public static final String THREAD_CHAR = "THREAD_CHAR"; 53 54 public static final String THREAD_BOOLEAN = "THREAD_BOOLEAN"; 55 56 public static final String THREAD_LONG = "THREAD_LONG"; 57 58 public static final String THREAD_FLOAT = "THREAD_FLOAT"; 59 60 public static final String THREAD_DOUBLE = "THREAD_DOUBLE"; 61 62 public static boolean condition = true; 63 64 static Object waitForStart = new Object(); 65 66 static Object waitForFinish = new Object(); 67 run()68 public void run() { 69 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 70 threadName = synchronizer.receiveMessage(); 71 DebuggeeThread thrd = new DebuggeeThread(threadName, logWriter, 72 synchronizer); 73 synchronized (waitForStart) { 74 thrd.start(); 75 try { 76 waitForStart.wait(); 77 } catch (InterruptedException e) { 78 79 } 80 } 81 synchronized (waitForFinish) { 82 logWriter.println("thread is finished"); 83 } 84 85 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 86 } 87 func_Object()88 public Object func_Object() { 89 logWriter.println("In func_Object"); 90 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 91 while (condition) 92 ; 93 return new Object(); 94 } 95 func_Int()96 public int func_Int() { 97 logWriter.println("In func_Int"); 98 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 99 while (condition) 100 ; 101 return -1; 102 } 103 func_Short()104 public short func_Short() { 105 logWriter.println("In func_Short"); 106 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 107 while (condition) 108 ; 109 return -1; 110 } 111 func_Byte()112 public byte func_Byte() { 113 logWriter.println("In func_Byte"); 114 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 115 while (condition) 116 ; 117 return -1; 118 } 119 func_Char()120 public char func_Char() { 121 logWriter.println("In func_Char"); 122 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 123 while (condition) 124 ; 125 return 'Z'; 126 } 127 func_Boolean()128 public boolean func_Boolean() { 129 logWriter.println("In func_Boolean"); 130 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 131 while (condition) 132 ; 133 return false; 134 } 135 func_Long()136 public long func_Long() { 137 logWriter.println("In func_Long"); 138 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 139 while (condition) 140 ; 141 return -1; 142 } 143 func_Float()144 public float func_Float() { 145 logWriter.println("In func_Float"); 146 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 147 while (condition) 148 ; 149 return -1; 150 } 151 func_Double()152 public double func_Double() { 153 logWriter.println("In func_Double"); 154 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 155 while (condition) 156 ; 157 return -1; 158 } 159 func_Void()160 public void func_Void() { 161 logWriter.println("In func_Void"); 162 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 163 while (condition) 164 ; 165 isFuncVoidBreak = false; 166 return; 167 } 168 169 class DebuggeeThread extends Thread { 170 171 LogWriter logWriter; 172 173 DebuggeeSynchronizer synchronizer; 174 DebuggeeThread(String name, LogWriter logWriter, DebuggeeSynchronizer synchronizer)175 public DebuggeeThread(String name, LogWriter logWriter, 176 DebuggeeSynchronizer synchronizer) { 177 super(name); 178 this.logWriter = logWriter; 179 this.synchronizer = synchronizer; 180 } 181 run()182 public void run() { 183 184 synchronized (ForceEarlyReturnDebuggee.waitForFinish) { 185 186 synchronized (ForceEarlyReturnDebuggee.waitForStart) { 187 188 ForceEarlyReturnDebuggee.waitForStart.notifyAll(); 189 190 logWriter.println(getName() + ": started"); 191 192 if (getName().equals(THREAD_OBJECT)) { 193 Object result = func_Object(); 194 logWriter.println(getName() + ": " + "Object"); 195 if (result instanceof TestObject) { 196 synchronizer.sendMessage("TRUE"); 197 } else { 198 synchronizer.sendMessage("FALSE"); 199 } 200 logWriter 201 .println(getName() + ": func_Object returned."); 202 203 } else if (getName().equals(THREAD_INT)) { 204 int result = func_Int(); 205 logWriter.println(getName() + ": " + result); 206 synchronizer 207 .sendMessage(new Integer(result).toString()); 208 logWriter.println(getName() + ": func_Int returned."); 209 } else if (getName().equals(THREAD_SHORT)) { 210 short result = func_Short(); 211 logWriter.println(getName() + ": " + result); 212 synchronizer 213 .sendMessage(new Integer(result).toString()); 214 logWriter.println(getName() + ": func_Short returned."); 215 } else if (getName().equals(THREAD_BYTE)) { 216 byte result = func_Byte(); 217 logWriter.println(getName() + ": " + result); 218 synchronizer 219 .sendMessage(new Integer(result).toString()); 220 logWriter.println(getName() + ": func_Byte returned."); 221 } else if (getName().equals(THREAD_CHAR)) { 222 char result = func_Char(); 223 logWriter.println(getName() + ": " + result); 224 synchronizer.sendMessage(new Character(result) 225 .toString()); 226 logWriter.println(getName() + ": func_Char returned."); 227 } else if (getName().equals(THREAD_BOOLEAN)) { 228 Boolean result = func_Boolean(); 229 logWriter.println(getName() + ": " + result); 230 synchronizer 231 .sendMessage(new Boolean(result).toString()); 232 logWriter.println(getName() 233 + ": func_Boolean returned."); 234 } else if (getName().equals(THREAD_LONG)) { 235 long result = func_Long(); 236 logWriter.println(getName() + ": " + result); 237 synchronizer.sendMessage(new Long(result).toString()); 238 logWriter.println(getName() + ": func_Long returned."); 239 } else if (getName().equals(THREAD_FLOAT)) { 240 float result = func_Float(); 241 logWriter.println(getName() + ": " + result); 242 synchronizer.sendMessage(new Float(result).toString()); 243 logWriter.println(getName() + ": func_Float returned."); 244 } else if (getName().equals(THREAD_DOUBLE)) { 245 double result = func_Double(); 246 logWriter.println(getName() + ": " + result); 247 synchronizer.sendMessage(new Double(result).toString()); 248 logWriter 249 .println(getName() + ": func_Double returned."); 250 } else if (getName().equals(THREAD_VOID)) { 251 func_Void(); 252 logWriter.println(getName() + ": " + "void"); 253 if (isFuncVoidBreak) { 254 synchronizer.sendMessage("TRUE"); 255 } else { 256 synchronizer.sendMessage("FALSE"); 257 } 258 logWriter.println(getName() + ": func_Void returned."); 259 } else { 260 logWriter.println(getName() + ": no func is called."); 261 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 262 synchronizer.receiveMessage("ThreadExit"); 263 } 264 265 logWriter.println(getName() + ": finished"); 266 267 } 268 } 269 } 270 } 271 main(String[] args)272 public static void main(String[] args) { 273 runDebuggee(ForceEarlyReturnDebuggee.class); 274 } 275 276 } 277 278 class TestObject { 279 280 } 281