blob: 3f5ae59e1886551bd73fe8e87581b920146ed77c [file] [log] [blame]
Andreas Gampe966de9e2017-01-12 20:51:02 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andreas Gampe46651672017-04-07 09:00:04 -070017package art;
18
Andreas Gampe966de9e2017-01-12 20:51:02 -080019public class OtherThread {
20 public static void doTestOtherThreadWait() throws Exception {
21 System.out.println("################################");
22 System.out.println("### Other thread (suspended) ###");
23 System.out.println("################################");
24 final ControlData data = new ControlData();
25 data.waitFor = new Object();
Andreas Gampe8a3d0b82017-02-14 14:28:32 -080026 Thread t = new Thread("OtherThread doTestOtherThreadWait") {
Andreas Gampe966de9e2017-01-12 20:51:02 -080027 public void run() {
28 Recurse.foo(4, 0, 0, data);
29 }
30 };
31 t.start();
32 data.reached.await();
33 Thread.yield();
34 Thread.sleep(500); // A little bit of time...
35
36 System.out.println("From top");
37 PrintThread.print(t, 0, 25);
38 PrintThread.print(t, 1, 25);
Paul Duffin03004e62018-05-23 11:52:10 +010039 PrintThread.print(t, 0, 7);
40 PrintThread.print(t, 2, 7);
Andreas Gampe966de9e2017-01-12 20:51:02 -080041
42 System.out.println("From bottom");
43 PrintThread.print(t, -1, 25);
44 PrintThread.print(t, -5, 5);
45 PrintThread.print(t, -7, 5);
46
47 // Let the thread make progress and die.
48 synchronized(data.waitFor) {
49 data.waitFor.notifyAll();
50 }
51 t.join();
52 }
53
54 public static void doTestOtherThreadBusyLoop() throws Exception {
55 System.out.println("###########################");
56 System.out.println("### Other thread (live) ###");
57 System.out.println("###########################");
58 final ControlData data = new ControlData();
Andreas Gampe8a3d0b82017-02-14 14:28:32 -080059 Thread t = new Thread("OtherThread doTestOtherThreadBusyLoop") {
Andreas Gampe966de9e2017-01-12 20:51:02 -080060 public void run() {
61 Recurse.foo(4, 0, 0, data);
62 }
63 };
64 t.start();
65 data.reached.await();
66 Thread.yield();
67 Thread.sleep(500); // A little bit of time...
68
69 System.out.println("From top");
70 PrintThread.print(t, 0, 25);
71 PrintThread.print(t, 1, 25);
72 PrintThread.print(t, 0, 5);
73 PrintThread.print(t, 2, 5);
74
75 System.out.println("From bottom");
76 PrintThread.print(t, -1, 25);
77 PrintThread.print(t, -5, 5);
78 PrintThread.print(t, -7, 5);
79
80 // Let the thread stop looping and die.
81 data.stop = true;
82 t.join();
83 }
84}