Object_wait02.java revision 13431:fa2686ded3a7
1157184Sache/*
2157184Sache * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
3157184Sache * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4157184Sache *
5157184Sache * This code is free software; you can redistribute it and/or modify it
6157184Sache * under the terms of the GNU General Public License version 2 only, as
7157184Sache * published by the Free Software Foundation.
8157184Sache *
9157184Sache * This code is distributed in the hope that it will be useful, but WITHOUT
10157184Sache * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11157184Sache * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12157184Sache * version 2 for more details (a copy is included in the LICENSE file that
13157184Sache * accompanied this code).
14157184Sache *
15157184Sache * You should have received a copy of the GNU General Public License version
16157184Sache * 2 along with this work; if not, write to the Free Software Foundation,
17157184Sache * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18157184Sache *
19157184Sache * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20157184Sache * or visit www.oracle.com if you need additional information or have any
21157184Sache * questions.
22157184Sache */
23157184Sache/*
24157184Sache */
25157184Sachepackage org.graalvm.compiler.jtt.threads;
26157184Sache
27157184Sacheimport org.graalvm.compiler.jtt.JTTTest;
28157184Sacheimport org.graalvm.compiler.jtt.hotspot.NotOnDebug;
29157184Sacheimport org.junit.Rule;
30157184Sacheimport org.junit.Test;
31157184Sacheimport org.junit.rules.TestRule;
32157184Sacheimport org.junit.rules.Timeout;
33157184Sache
34157184Sachepublic class Object_wait02 extends JTTTest {
35157184Sache
36157184Sache    @Rule public TestRule timeout = NotOnDebug.create(Timeout.seconds(20));
37157184Sache
38157184Sache    private static class TestClass implements Runnable {
39157184Sache        @Override
40157184Sache        public void run() {
41157184Sache            try {
42157184Sache                Thread.sleep(sleep);
43157184Sache            } catch (InterruptedException ex) {
44157184Sache
45157184Sache            }
46157184Sache            synchronized (object) {
47157184Sache                done = true;
48157184Sache                object.notifyAll();
49157184Sache            }
50157184Sache        }
51157184Sache    }
52157184Sache
53157184Sache    static volatile boolean done;
54157184Sache    static final Object object = new Object();
55157184Sache    static int sleep;
56157184Sache
57157184Sache    public static boolean test(int i) throws InterruptedException {
58157184Sache        done = false;
59157184Sache        sleep = i * 200;
60157184Sache        new Thread(new TestClass()).start();
61157184Sache        synchronized (object) {
62157184Sache            while (!done) {
63157184Sache                object.wait(200);
64157184Sache            }
65157184Sache        }
66157184Sache        return done;
67157184Sache    }
68157184Sache
69157184Sache    @Test
70157184Sache    public void run0() throws Throwable {
71157184Sache        initializeForTimeout();
72157184Sache        runTest("test", 0);
73157184Sache    }
74157184Sache
75157184Sache    @Test
76157184Sache    public void run1() throws Throwable {
77157184Sache        initializeForTimeout();
78157184Sache        runTest("test", 1);
79157184Sache    }
80157184Sache
81157184Sache    @Test
82157184Sache    public void run2() throws Throwable {
83157184Sache        initializeForTimeout();
84157184Sache        runTest("test", 2);
85157184Sache    }
86157184Sache
87157184Sache}
88157184Sache