duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006 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 6467152 |
| 27 | * |
| 28 | * @summary deadlock occurs in LogManager initialization and JVM termination |
| 29 | * @author Serguei Spitsyn / Hittachi |
| 30 | * |
| 31 | * @build LoggingDeadlock2 |
| 32 | * @run main/timeout=15 LoggingDeadlock2 |
| 33 | * |
| 34 | * There is a clear deadlock between LogManager.<clinit> and |
| 35 | * Cleaner.run() methods. |
| 36 | * T1 thread: |
| 37 | * The LogManager.<clinit> creates LogManager.manager object, |
| 38 | * sets shutdown hook with the Cleaner class and then waits |
| 39 | * to lock the LogManager.manager monitor. |
| 40 | * T2 thread: |
| 41 | * It is started by the System.exit() as shutdown hook thread. |
| 42 | * It locks the LogManager.manager monitor and then calls the |
| 43 | * static methods of the LogManager class (in this particular |
| 44 | * case it is a trick of the inner classes implementation). |
| 45 | * It is waits when the LogManager.<clinit> is completed. |
| 46 | * |
| 47 | * This is a regression test for this bug. |
| 48 | */ |
| 49 | |
| 50 | import java.util.logging.LogManager; |
| 51 | |
| 52 | public class LoggingDeadlock2 implements Runnable { |
| 53 | static final java.io.PrintStream out = System.out; |
| 54 | static Object lock = new Object(); |
| 55 | static int c = 0; |
| 56 | public static void main(String arg[]) { |
| 57 | out.println("\nThis test checks that there is no deadlock."); |
| 58 | out.println("If not crashed or timed-out then it is passed."); |
| 59 | try { |
| 60 | new Thread(new LoggingDeadlock2()).start(); |
| 61 | synchronized(lock) { |
| 62 | c++; |
| 63 | if (c == 2) lock.notify(); |
| 64 | else lock.wait(); |
| 65 | } |
| 66 | LogManager log = LogManager.getLogManager(); |
| 67 | out.println("Test passed"); |
| 68 | } |
| 69 | catch(Exception e) { |
| 70 | e.printStackTrace(); |
| 71 | out.println("Test FAILED"); // Not expected |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | public void run() { |
| 76 | try { |
| 77 | synchronized(lock) { |
| 78 | c++; |
| 79 | if (c == 2) lock.notify(); |
| 80 | else lock.wait(); |
| 81 | } |
| 82 | System.exit(1); |
| 83 | } |
| 84 | catch(Exception e) { |
| 85 | e.printStackTrace(); |
| 86 | out.println("Test FAILED"); // Not expected |
| 87 | } |
| 88 | } |
| 89 | } |