author | jlahoda |
Wed, 12 Dec 2012 20:26:56 +0100 | |
changeset 14803 | 88347e495d34 |
parent 14342 | 8435a30053c1 |
child 14683 | 38921a46c62d |
permissions | -rw-r--r-- |
9699
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
12047
diff
changeset
|
2 |
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
9699
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
4 |
* |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
8 |
* |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
13 |
* accompanied this code). |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
14 |
* |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
18 |
* |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
21 |
* questions. |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
22 |
*/ |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
23 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
24 |
/* |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
25 |
* @test |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
26 |
* @bug 6977677 |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
27 |
* @summary Deadlock between LogManager.<clinit> and Logger.getLogger() |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
28 |
* @author Daniel D. Daugherty |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
29 |
* @build LoggingDeadlock4 |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9699
diff
changeset
|
30 |
* @run main/othervm/timeout=15 -Djava.awt.headless=true LoggingDeadlock4 |
9699
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
31 |
*/ |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
32 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
33 |
import java.awt.Container; |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
34 |
import java.util.concurrent.CountDownLatch; |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
35 |
import java.util.logging.LogManager; |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
36 |
import java.util.logging.Logger; |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
37 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
38 |
public class LoggingDeadlock4 { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
39 |
private static CountDownLatch barrier = new CountDownLatch(1); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
40 |
private static CountDownLatch lmIsRunning = new CountDownLatch(1); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
41 |
private static CountDownLatch logIsRunning = new CountDownLatch(1); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
42 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
43 |
public static void main(String[] args) { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
44 |
System.out.println("main: LoggingDeadlock4 is starting."); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
45 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
46 |
// Loading the java.awt.Container class will create a |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
47 |
// sun.util.logging.PlatformLogger$JavaLogger object |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
48 |
// that has to be redirected when the LogManager class |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
49 |
// is initialized. This can cause a deadlock between |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
50 |
// LogManager.<clinit> and Logger.getLogger(). |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
51 |
try { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
52 |
Class.forName("java.awt.Container"); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
53 |
} catch (ClassNotFoundException cnfe) { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
54 |
throw new RuntimeException("Test failed: could not load" |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
55 |
+ " java.awt.Container." + cnfe); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
56 |
} |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
57 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
58 |
Thread lmThread = new Thread("LogManagerThread") { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
59 |
public void run() { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
60 |
// let main know LogManagerThread is running |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
61 |
lmIsRunning.countDown(); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
62 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
63 |
System.out.println(Thread.currentThread().getName() |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
64 |
+ ": is running."); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
65 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
66 |
try { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
67 |
barrier.await(); // wait for race to start |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
68 |
} catch (InterruptedException e) { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
69 |
} |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
70 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
71 |
LogManager manager = LogManager.getLogManager(); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
72 |
} |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
73 |
}; |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
74 |
lmThread.start(); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
75 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
76 |
Thread logThread = new Thread("LoggerThread") { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
77 |
public void run() { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
78 |
// let main know LoggerThread is running |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
79 |
logIsRunning.countDown(); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
80 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
81 |
System.out.println(Thread.currentThread().getName() |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
82 |
+ ": is running."); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
83 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
84 |
try { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
85 |
barrier.await(); // wait for race to start |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
86 |
} catch (InterruptedException e) { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
87 |
} |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
88 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
89 |
Logger foo = Logger.getLogger("foo logger"); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
90 |
} |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
91 |
}; |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
92 |
logThread.start(); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
93 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
94 |
try { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
95 |
// wait for LogManagerThread and LoggerThread to get going |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
96 |
lmIsRunning.await(); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
97 |
logIsRunning.await(); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
98 |
} catch (InterruptedException e) { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
99 |
} |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
100 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
101 |
barrier.countDown(); // start the race |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
102 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
103 |
try { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
104 |
lmThread.join(); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
105 |
logThread.join(); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
106 |
} catch (InterruptedException ie) { |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
107 |
} |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
108 |
|
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
109 |
System.out.println("main: LoggingDeadlock4 is done."); |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
110 |
} |
5dfc211872f4
6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff
changeset
|
111 |
} |