test/jdk/java/util/logging/LoggingDeadlock4.java
author mikael
Mon, 29 Jul 2019 09:59:04 -0700
changeset 57584 9d82a35b6ff7
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9699
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
     1
/*
35768
7066da300a08 8149391: Fix module dependences in java/util tests
shurailine
parents: 30820
diff changeset
     2
 * Copyright (c) 2011, 2016, 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
14897
99faf9db81d8 8004928: TEST_BUG: Reduce dependence of CoreLib tests from the AWT subsystem
uta
parents: 14683
diff changeset
    26
 * @bug     6977677 8004928
9699
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
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 14897
diff changeset
    29
 * @modules java.base/sun.util.logging
35768
7066da300a08 8149391: Fix module dependences in java/util tests
shurailine
parents: 30820
diff changeset
    30
 *          java.logging
14897
99faf9db81d8 8004928: TEST_BUG: Reduce dependence of CoreLib tests from the AWT subsystem
uta
parents: 14683
diff changeset
    31
 * @compile -XDignore.symbol.file LoggingDeadlock4.java
99faf9db81d8 8004928: TEST_BUG: Reduce dependence of CoreLib tests from the AWT subsystem
uta
parents: 14683
diff changeset
    32
 * @run main/othervm/timeout=15 LoggingDeadlock4
9699
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    33
 */
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    34
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    35
import java.util.concurrent.CountDownLatch;
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    36
import java.util.logging.LogManager;
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    37
import java.util.logging.Logger;
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    38
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    39
public class LoggingDeadlock4 {
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    40
    private static CountDownLatch barrier      = new CountDownLatch(1);
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    41
    private static CountDownLatch lmIsRunning  = new CountDownLatch(1);
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    42
    private static CountDownLatch logIsRunning = new CountDownLatch(1);
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    43
14897
99faf9db81d8 8004928: TEST_BUG: Reduce dependence of CoreLib tests from the AWT subsystem
uta
parents: 14683
diff changeset
    44
    // Create a sun.util.logging.PlatformLogger$JavaLogger object
99faf9db81d8 8004928: TEST_BUG: Reduce dependence of CoreLib tests from the AWT subsystem
uta
parents: 14683
diff changeset
    45
    // that has to be redirected when the LogManager class
99faf9db81d8 8004928: TEST_BUG: Reduce dependence of CoreLib tests from the AWT subsystem
uta
parents: 14683
diff changeset
    46
    // is initialized. This can cause a deadlock between
99faf9db81d8 8004928: TEST_BUG: Reduce dependence of CoreLib tests from the AWT subsystem
uta
parents: 14683
diff changeset
    47
    // LogManager.<clinit> and Logger.getLogger().
99faf9db81d8 8004928: TEST_BUG: Reduce dependence of CoreLib tests from the AWT subsystem
uta
parents: 14683
diff changeset
    48
    private static final sun.util.logging.PlatformLogger log =
99faf9db81d8 8004928: TEST_BUG: Reduce dependence of CoreLib tests from the AWT subsystem
uta
parents: 14683
diff changeset
    49
        sun.util.logging.PlatformLogger.getLogger("java.util.logging");
99faf9db81d8 8004928: TEST_BUG: Reduce dependence of CoreLib tests from the AWT subsystem
uta
parents: 14683
diff changeset
    50
9699
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    51
    public static void main(String[] args) {
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    52
        System.out.println("main: LoggingDeadlock4 is starting.");
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    53
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    54
        Thread lmThread = new Thread("LogManagerThread") {
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    55
            public void run() {
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    56
                // let main know LogManagerThread is running
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    57
                lmIsRunning.countDown();
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    58
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    59
                System.out.println(Thread.currentThread().getName()
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    60
                    + ": is running.");
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    61
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    62
                try {
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    63
                    barrier.await();  // wait for race to start
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    64
                } catch (InterruptedException e) {
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
14683
38921a46c62d 8003380: Compiler warnings in logging test code
jgish
parents: 14342
diff changeset
    67
                LogManager.getLogManager();
9699
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    68
            }
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
        lmThread.start();
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    71
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    72
        Thread logThread = new Thread("LoggerThread") {
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    73
            public void run() {
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    74
                // let main know LoggerThread is running
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    75
                logIsRunning.countDown();
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    76
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    77
                System.out.println(Thread.currentThread().getName()
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    78
                    + ": is running.");
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    79
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    80
                try {
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    81
                    barrier.await();  // wait for race to start
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    82
                } catch (InterruptedException e) {
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
14683
38921a46c62d 8003380: Compiler warnings in logging test code
jgish
parents: 14342
diff changeset
    85
                Logger.getLogger("foo logger");
9699
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    86
            }
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
        logThread.start();
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    89
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    90
        try {
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    91
            // wait for LogManagerThread and LoggerThread to get going
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    92
            lmIsRunning.await();
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    93
            logIsRunning.await();
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    94
        } catch (InterruptedException e) {
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    95
        }
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    96
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    97
        barrier.countDown();  // start the race
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    98
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
    99
        try {
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
   100
            lmThread.join();
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
   101
            logThread.join();
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
   102
        } catch (InterruptedException ie) {
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
   103
        }
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
   104
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
   105
        System.out.println("main: LoggingDeadlock4 is done.");
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
   106
    }
5dfc211872f4 6977677: 3/2 Deadlock on logging subsystem initialization
dcubed
parents:
diff changeset
   107
}