author | shade |
Thu, 02 Oct 2014 17:13:31 +0400 | |
changeset 27003 | 19617f4c9dd0 |
parent 24000 | 4ed166e87a9d |
permissions | -rw-r--r-- |
24000
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
1 |
/* |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
4 |
* |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
8 |
* |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
13 |
* accompanied this code). |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
14 |
* |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
18 |
* |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
21 |
* questions. |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
22 |
*/ |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
23 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
24 |
/** |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
25 |
* This test is useful for finding out whether a Thread can have a |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
26 |
* private variable indicate whether or not it is finished, and to illustrate |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
27 |
* the ease with which Threads terminate each other. |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
28 |
* |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
29 |
* @test |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
30 |
*/ |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
31 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
32 |
public class CancellableThreadTest { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
33 |
public static final int THREADPAIRS = Integer.parseInt(System.getProperty("test.threadpairs", "128")); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
34 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
35 |
public static void main(String args[]) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
36 |
Thread[] threads = new Thread[THREADPAIRS]; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
37 |
Canceller[] cancellers = new Canceller[THREADPAIRS]; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
38 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
39 |
System.out.println("Running with " + THREADPAIRS + " thread pairs"); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
40 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
41 |
for (int i = 0; i < THREADPAIRS; i++) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
42 |
cancellers[i] = new Canceller(i); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
43 |
threads[i] = new Thread(cancellers[i]); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
44 |
threads[i].start(); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
45 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
46 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
47 |
for (int i = 0; i < THREADPAIRS; i++) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
48 |
try { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
49 |
threads[i].join(); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
50 |
} catch (InterruptedException e) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
51 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
52 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
53 |
if (cancellers[i].failed) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
54 |
throw new RuntimeException(" Test failed in " + i + " th pair. See error messages above."); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
55 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
56 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
57 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
58 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
59 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
60 |
class Canceller implements Runnable { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
61 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
62 |
private final CancellableTimer timer; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
63 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
64 |
public final String name; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
65 |
public volatile boolean failed = false; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
66 |
private volatile boolean hasBeenNotified = false; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
67 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
68 |
public Canceller(int index) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
69 |
this.name = "Canceller #" + index; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
70 |
timer = new CancellableTimer(index, this); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
71 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
72 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
73 |
public void setHasBeenNotified() { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
74 |
hasBeenNotified = true; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
75 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
76 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
77 |
/** |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
78 |
* This method contains the "action" of this Canceller Thread. |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
79 |
* It starts a CancellableTimer, waits, and then interrupts the |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
80 |
* CancellableTimer after the CancellableTimer notifies it. It then |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
81 |
* tries to join the CancellableTimer to itself and reports on whether |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
82 |
* it was successful in doing so. |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
83 |
*/ |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
84 |
public void run() { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
85 |
Thread timerThread = new Thread(timer); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
86 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
87 |
try { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
88 |
synchronized(this) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
89 |
timerThread.start(); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
90 |
wait(); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
91 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
92 |
} catch (InterruptedException e) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
93 |
System.err.println(name + " was interrupted during wait()"); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
94 |
failed = true; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
95 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
96 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
97 |
if (!hasBeenNotified) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
98 |
System.err.println(name + ".hasBeenNotified is not true as expected"); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
99 |
failed = true; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
100 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
101 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
102 |
synchronized (timer) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
103 |
timerThread.interrupt(); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
104 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
105 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
106 |
try { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
107 |
timerThread.join(); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
108 |
} catch (InterruptedException ie) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
109 |
System.err.println(name + " was interrupted while joining " + |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
110 |
timer.name); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
111 |
failed = true; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
112 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
113 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
114 |
if (timerThread.isAlive()) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
115 |
System.err.println(timer.name + " is still alive after " + name + |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
116 |
" attempted to join it."); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
117 |
failed = true; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
118 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
119 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
120 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
121 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
122 |
/** |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
123 |
* This non-public class is the Thread which the Canceller Thread deliberately |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
124 |
* interrupts and then joins to itself after this Thread has slept for a few milliseconds. |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
125 |
*/ |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
126 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
127 |
class CancellableTimer implements Runnable { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
128 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
129 |
public final String name; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
130 |
private final Canceller myCanceller; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
131 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
132 |
public CancellableTimer(int index, Canceller aCanceller) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
133 |
this.name = "CancellableTimer #" + index; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
134 |
this.myCanceller = aCanceller; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
135 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
136 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
137 |
/** |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
138 |
* This is where this CancellableTimer does its work. It notifies its |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
139 |
* Canceller, waits for the Canceller to interrupt it, then catches the |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
140 |
* InterruptedException, and sleeps for a few milliseconds before exiting. |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
141 |
*/ |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
142 |
public void run() { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
143 |
try { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
144 |
synchronized (this) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
145 |
synchronized (myCanceller) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
146 |
myCanceller.setHasBeenNotified(); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
147 |
myCanceller.notify(); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
148 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
149 |
wait(); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
150 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
151 |
} catch (InterruptedException first) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
152 |
// isInterrupted should've been cleared here and we should not register a |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
153 |
// second interrupt |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
154 |
if (Thread.currentThread().isInterrupted()) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
155 |
System.err.println(name + " should not register an interrupt here"); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
156 |
myCanceller.failed = true; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
157 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
158 |
|
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
159 |
try { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
160 |
Thread.sleep(1); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
161 |
} catch (InterruptedException e) { |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
162 |
System.err.println(name + " was interrupted when sleeping"); |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
163 |
myCanceller.failed = true; |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
164 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
165 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
166 |
} |
4ed166e87a9d
8035173: [TESTBUG] runtime/threads/CancellableThreadTest fails with OOM on windows-i586
ctornqvi
parents:
diff
changeset
|
167 |
} |