• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.share.JPDADebuggeeSynchronizer;
22 import org.apache.harmony.jpda.tests.share.SyncDebuggee;
23 
24 /**
25  * The class specifies debuggee for
26  * <code>org.apache.harmony.jpda.tests.jdwp.ThreadReference.ForceEarlyReturnTest</code>.
27  * This debuggee starts the tested thread which name is supplied by test and
28  * synchronized with test via the <code>SGNL_READY</code> and
29  * <code>SGNL_CONTINUE</code> signals.
30  */
31 public class ForceEarlyReturnDebuggee extends SyncDebuggee {
32 
33     public static String threadName;
34 
35     static boolean isFuncVoidBreak = true;
36 
37     static TestObject testObj = new TestObject();
38 
39     public static final String THREAD_VOID = "THREAD_VOID";
40 
41     public static final String THREAD_OBJECT = "THREAD_OBJECT";
42 
43     public static final String THREAD_INT = "THREAD_INT";
44 
45     public static final String THREAD_SHORT = "THREAD_SHORT";
46 
47     public static final String THREAD_BYTE = "THREAD_BYTE";
48 
49     public static final String THREAD_CHAR = "THREAD_CHAR";
50 
51     public static final String THREAD_BOOLEAN = "THREAD_BOOLEAN";
52 
53     public static final String THREAD_LONG = "THREAD_LONG";
54 
55     public static final String THREAD_FLOAT = "THREAD_FLOAT";
56 
57     public static final String THREAD_DOUBLE = "THREAD_DOUBLE";
58 
59     public static boolean condition = true;
60 
61     static Object waitForStart = new Object();
62 
63     static Object waitForFinish = new Object();
64 
65     private final class NoCallSynchronizer extends Thread {
66         public volatile boolean signalReady = false;
67 
NoCallSynchronizer(String name)68         public NoCallSynchronizer(String name) {
69           super(name + " - NoCallSynchronizer thread");
70         }
71 
run()72         public void run() {
73             while (!signalReady) {
74                 Thread.yield();
75             }
76             logWriter.println(getName() + ": " + "resuming debugger");
77             synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
78         }
79 
sjoin()80         public void sjoin() {
81           try {
82               join();
83           } catch (InterruptedException ie) {
84               logWriter.println("Interrupted exception: " + ie);
85               throw new Error("join interrupted!", ie);
86           }
87         }
88     }
89 
90     @Override
run()91     public void run() {
92         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
93         threadName = synchronizer.receiveMessage();
94         DebuggeeThread thrd = new DebuggeeThread(threadName);
95         synchronized (waitForStart) {
96             thrd.start();
97             try {
98                 waitForStart.wait();
99             } catch (InterruptedException e) {
100 
101             }
102         }
103         synchronized (waitForFinish) {
104             logWriter.println("thread is finished");
105         }
106 
107         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
108     }
109 
func_Object(NoCallSynchronizer ncs)110     public Object func_Object(NoCallSynchronizer ncs) {
111         logWriter.println("In func_Object");
112         ncs.signalReady = true;
113         while (condition)
114             ;
115         return new Object();
116     }
117 
func_Int(NoCallSynchronizer ncs)118     public int func_Int(NoCallSynchronizer ncs) {
119         logWriter.println("In func_Int");
120         ncs.signalReady = true;
121         while (condition)
122             ;
123         return -1;
124     }
125 
func_Short(NoCallSynchronizer ncs)126     public short func_Short(NoCallSynchronizer ncs) {
127         logWriter.println("In func_Short");
128         ncs.signalReady = true;
129         while (condition)
130             ;
131         return -1;
132     }
133 
func_Byte(NoCallSynchronizer ncs)134     public byte func_Byte(NoCallSynchronizer ncs) {
135         logWriter.println("In func_Byte");
136         ncs.signalReady = true;
137         while (condition)
138             ;
139         return -1;
140     }
141 
func_Char(NoCallSynchronizer ncs)142     public char func_Char(NoCallSynchronizer ncs) {
143         logWriter.println("In func_Char");
144         ncs.signalReady = true;
145         while (condition)
146             ;
147         return 'Z';
148     }
149 
func_Boolean(NoCallSynchronizer ncs)150     public boolean func_Boolean(NoCallSynchronizer ncs) {
151         logWriter.println("In func_Boolean");
152         ncs.signalReady = true;
153         while (condition)
154             ;
155         return false;
156     }
157 
func_Long(NoCallSynchronizer ncs)158     public long func_Long(NoCallSynchronizer ncs) {
159         logWriter.println("In func_Long");
160         ncs.signalReady = true;
161         while (condition)
162             ;
163         return -1;
164     }
165 
func_Float(NoCallSynchronizer ncs)166     public float func_Float(NoCallSynchronizer ncs) {
167         logWriter.println("In func_Float");
168         ncs.signalReady = true;
169         while (condition)
170             ;
171         return -1;
172     }
173 
func_Double(NoCallSynchronizer ncs)174     public double func_Double(NoCallSynchronizer ncs) {
175         logWriter.println("In func_Double");
176         ncs.signalReady = true;
177         while (condition)
178             ;
179         return -1;
180     }
181 
func_Void(NoCallSynchronizer ncs)182     public void func_Void(NoCallSynchronizer ncs) {
183         logWriter.println("In func_Void");
184         ncs.signalReady = true;
185         while (condition)
186             ;
187         isFuncVoidBreak = false;
188         return;
189     }
190 
191     class DebuggeeThread extends Thread {
192 
DebuggeeThread(String name)193         public DebuggeeThread(String name) {
194             super(name);
195         }
196 
197         @Override
run()198         public void run() {
199             NoCallSynchronizer ncs = new NoCallSynchronizer(getName());
200             ncs.start();
201 
202             synchronized (ForceEarlyReturnDebuggee.waitForFinish) {
203 
204                 synchronized (ForceEarlyReturnDebuggee.waitForStart) {
205 
206                     ForceEarlyReturnDebuggee.waitForStart.notifyAll();
207 
208                     logWriter.println(getName() + ": started");
209 
210                     if (getName().equals(THREAD_OBJECT)) {
211                         Object result = func_Object(ncs);
212                         ncs.sjoin();
213                         logWriter.println(getName() + ": " + "Object");
214                         if (result instanceof TestObject) {
215                             synchronizer.sendMessage("TRUE");
216                         } else {
217                             synchronizer.sendMessage("FALSE");
218                         }
219                         logWriter
220                                 .println(getName() + ": func_Object returned.");
221 
222                     } else if (getName().equals(THREAD_INT)) {
223                         int result = func_Int(ncs);
224                         ncs.sjoin();
225                         logWriter.println(getName() + ": " + result);
226                         synchronizer
227                                 .sendMessage(new Integer(result).toString());
228                         logWriter.println(getName() + ": func_Int returned.");
229                     } else if (getName().equals(THREAD_SHORT)) {
230                         short result = func_Short(ncs);
231                         ncs.sjoin();
232                         logWriter.println(getName() + ": " + result);
233                         synchronizer
234                                 .sendMessage(new Integer(result).toString());
235                         logWriter.println(getName() + ": func_Short returned.");
236                     } else if (getName().equals(THREAD_BYTE)) {
237                         byte result = func_Byte(ncs);
238                         ncs.sjoin();
239                         logWriter.println(getName() + ": " + result);
240                         synchronizer
241                                 .sendMessage(new Integer(result).toString());
242                         logWriter.println(getName() + ": func_Byte returned.");
243                     } else if (getName().equals(THREAD_CHAR)) {
244                         char result = func_Char(ncs);
245                         ncs.sjoin();
246                         logWriter.println(getName() + ": " + result);
247                         synchronizer.sendMessage(new Character(result)
248                                 .toString());
249                         logWriter.println(getName() + ": func_Char returned.");
250                     } else if (getName().equals(THREAD_BOOLEAN)) {
251                         Boolean result = func_Boolean(ncs);
252                         ncs.sjoin();
253                         logWriter.println(getName() + ": " + result);
254                         synchronizer
255                                 .sendMessage(new Boolean(result).toString());
256                         logWriter.println(getName()
257                                 + ": func_Boolean returned.");
258                     } else if (getName().equals(THREAD_LONG)) {
259                         long result = func_Long(ncs);
260                         ncs.sjoin();
261                         logWriter.println(getName() + ": " + result);
262                         synchronizer.sendMessage(new Long(result).toString());
263                         logWriter.println(getName() + ": func_Long returned.");
264                     } else if (getName().equals(THREAD_FLOAT)) {
265                         float result = func_Float(ncs);
266                         ncs.sjoin();
267                         logWriter.println(getName() + ": " + result);
268                         synchronizer.sendMessage(new Float(result).toString());
269                         logWriter.println(getName() + ": func_Float returned.");
270                     } else if (getName().equals(THREAD_DOUBLE)) {
271                         double result = func_Double(ncs);
272                         ncs.sjoin();
273                         logWriter.println(getName() + ": " + result);
274                         synchronizer.sendMessage(new Double(result).toString());
275                         logWriter
276                                 .println(getName() + ": func_Double returned.");
277                     } else if (getName().equals(THREAD_VOID)) {
278                         func_Void(ncs);
279                         ncs.sjoin();
280                         logWriter.println(getName() + ": " + "void");
281                         if (isFuncVoidBreak) {
282                             synchronizer.sendMessage("TRUE");
283                         } else {
284                             synchronizer.sendMessage("FALSE");
285                         }
286                         logWriter.println(getName() + ": func_Void returned.");
287                     } else {
288                         logWriter.println(getName() + ": no func is called.");
289                         ncs.signalReady = true;
290                         ncs.sjoin();
291                         synchronizer.receiveMessage("ThreadExit");
292                     }
293 
294                     logWriter.println(getName() + ": finished");
295 
296                 }
297             }
298         }
299     }
300 
main(String[] args)301     public static void main(String[] args) {
302         runDebuggee(ForceEarlyReturnDebuggee.class);
303     }
304 
305 }
306 
307 class TestObject {
308 
309 }
310