2
|
1 |
/*
|
|
2 |
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 6379235
|
2401
|
27 |
* @ignore until 6721694 is fixed
|
2
|
28 |
* @run main/othervm -server -Xmx32m -Xms32m -Xss256m StartOOMTest
|
|
29 |
* @summary ThreadGroup accounting mistake possible with failure of Thread.start()
|
|
30 |
*/
|
|
31 |
|
|
32 |
import java.util.*;
|
|
33 |
|
|
34 |
public class StartOOMTest
|
|
35 |
{
|
|
36 |
public static void main(String[] args) throws Throwable {
|
|
37 |
Runnable r = new SleepRunnable();
|
|
38 |
ThreadGroup tg = new ThreadGroup("buggy");
|
|
39 |
List<Thread> threads = new ArrayList<Thread>();
|
|
40 |
Thread failedThread;
|
|
41 |
int i = 0;
|
|
42 |
for (i = 0; ; i++) {
|
|
43 |
Thread t = new Thread(tg, r);
|
|
44 |
try {
|
|
45 |
t.start();
|
|
46 |
threads.add(t);
|
|
47 |
} catch (Throwable x) {
|
|
48 |
failedThread = t;
|
|
49 |
System.out.println(x);
|
|
50 |
System.out.println(i);
|
|
51 |
break;
|
|
52 |
}
|
|
53 |
}
|
|
54 |
|
|
55 |
int j = 0;
|
|
56 |
for (Thread t : threads)
|
|
57 |
t.interrupt();
|
|
58 |
|
|
59 |
while (tg.activeCount() > i/2)
|
|
60 |
Thread.yield();
|
|
61 |
failedThread.start();
|
|
62 |
failedThread.interrupt();
|
|
63 |
|
|
64 |
for (Thread t : threads)
|
|
65 |
t.join();
|
|
66 |
failedThread.join();
|
|
67 |
|
|
68 |
try {
|
|
69 |
Thread.sleep(1000);
|
|
70 |
} catch (Throwable ignore) {
|
|
71 |
}
|
|
72 |
|
|
73 |
int activeCount = tg.activeCount();
|
|
74 |
System.out.println("activeCount = " + activeCount);
|
|
75 |
|
|
76 |
if (activeCount > 0) {
|
|
77 |
throw new RuntimeException("Failed: there should be no active Threads in the group");
|
|
78 |
}
|
|
79 |
}
|
|
80 |
|
|
81 |
static class SleepRunnable implements Runnable
|
|
82 |
{
|
|
83 |
public void run() {
|
|
84 |
try {
|
|
85 |
Thread.sleep(60*1000);
|
|
86 |
} catch (Throwable t) {
|
|
87 |
}
|
|
88 |
}
|
|
89 |
}
|
|
90 |
}
|