1 /*
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 
17 package art;
18 
19 import java.lang.ref.WeakReference;
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.concurrent.CountDownLatch;
23 import java.util.concurrent.Semaphore;
24 
25 public class Test1951 {
26 
27   // Wait up to 1 minute for the other thread to make progress.
28   public static final long WAIT_TIME_MILLIS = 1000 * 60;
run()29   public static void run() throws Exception {
30     Thread t = new Thread(Test1951::otherThreadStart);
31     t.setDaemon(true);
32     t.start();
33     waitForStart();
34     Suspension.suspend(t);
35     otherThreadResume();
36     long endTime = System.currentTimeMillis() + WAIT_TIME_MILLIS;
37     boolean otherProgressed = false;
38     while (true) {
39       if (otherThreadProgressed()) {
40         otherProgressed = true;
41         break;
42       } else if (System.currentTimeMillis() > endTime) {
43         break;
44       } else {
45         Thread.yield();
46       }
47     }
48     Suspension.resume(t);
49     if (otherProgressed) {
50       t.join(1000);
51     }
52     if (otherProgressed) {
53       System.out.println("Success");
54     } else {
55       System.out.println(
56           "Failure: other thread did not make progress in " + WAIT_TIME_MILLIS + " ms");
57     }
58     return;
59   }
60 
otherThreadStart()61   public static native void otherThreadStart();
waitForStart()62   public static native void waitForStart();
otherThreadResume()63   public static native void otherThreadResume();
otherThreadProgressed()64   public static native boolean otherThreadProgressed();
65 }
66