jdk/test/java/util/logging/TestLoggerBundleSync.java
author shurailine
Mon, 08 Feb 2016 18:14:48 -0800
changeset 35768 7066da300a08
parent 32649 2ee9017c7597
permissions -rw-r--r--
8149391: Fix module dependences in java/util tests Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
     1
/*
35768
7066da300a08 8149391: Fix module dependences in java/util tests
shurailine
parents: 32649
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
     4
 *
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
     8
 *
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    14
 *
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    18
 *
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    21
 * questions.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    22
 */
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    23
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    24
import java.lang.management.ManagementFactory;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    25
import java.lang.management.ThreadInfo;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    26
import java.security.Permission;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    27
import java.security.Policy;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    28
import java.security.ProtectionDomain;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    29
import java.util.ArrayList;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    30
import java.util.List;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    31
import java.util.ListResourceBundle;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    32
import java.util.Objects;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    33
import java.util.ResourceBundle;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    34
import java.util.concurrent.Callable;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    35
import java.util.concurrent.ExecutorService;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    36
import java.util.concurrent.Executors;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    37
import java.util.concurrent.FutureTask;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    38
import java.util.concurrent.atomic.AtomicLong;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    39
import java.util.logging.Handler;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    40
import java.util.logging.Level;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    41
import java.util.logging.LogRecord;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    42
import java.util.logging.Logger;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    43
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    44
/**
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    45
 * @test
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    46
 * @bug 8029281 8028763
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    47
 * @summary Attempts to detect synchronization issues with getResourceBundle()
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    48
 *          and getResourceBundleName(). It might also detect issues in the way
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    49
 *          that the logger tree is cleaned up after a logger has been garbage
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    50
 *          collected. This test helped find the root cause of 8029092, so if
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    51
 *          this test fails one might also expect failures in
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    52
 *          java/util/logging/Logger/logrb/TestLogrbResourceBundle.java and
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    53
 *          java/util/logging/Logger/setResourceBundle/TestSetResourceBundle.java.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    54
 *          Note that this is a best effort test. Running it in a loop to
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    55
 *          reproduce intermittent issues can be a good idea.
35768
7066da300a08 8149391: Fix module dependences in java/util tests
shurailine
parents: 32649
diff changeset
    56
 * @modules java.logging
7066da300a08 8149391: Fix module dependences in java/util tests
shurailine
parents: 32649
diff changeset
    57
 *          java.management
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    58
 * @run main/othervm TestLoggerBundleSync
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    59
 * @author danielfuchs
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    60
 */
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    61
public class TestLoggerBundleSync {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    62
25985
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
    63
    static final boolean VERBOSE = false;
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    64
    static volatile Exception thrown = null;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    65
    static volatile boolean goOn = true;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    66
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    67
    static final int READERS = 3;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    68
    static final long TIME = 4 * 1000; // 4 sec.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    69
    static final long STEP = 1 * 1000;  // message every 1 sec.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    70
    static final int  LCOUNT = 50; // change bundle 50 times...
25985
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
    71
    static final AtomicLong ignoreLogCount = new AtomicLong(0);
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    72
    static final AtomicLong setRBcount = new AtomicLong(0);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    73
    static final AtomicLong setRBNameCount = new AtomicLong(0);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    74
    static final AtomicLong getRBcount = new AtomicLong(0);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    75
    static final AtomicLong checkCount = new AtomicLong(0);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    76
    static final AtomicLong nextLong = new AtomicLong(0);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    77
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    78
    public static class MyBundle extends ListResourceBundle {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    79
        @Override
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    80
        protected Object[][] getContents() {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    81
            return new Object[][] {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    82
               {"dummy", "foo"}
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    83
            };
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    84
        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    85
    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    86
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    87
    public static final class MyBundle1 extends MyBundle { };
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    88
    public static final class MyBundle2 extends MyBundle { };
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    89
    public static final class MyBundle3 extends MyBundle { };
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    90
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    91
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    92
    public static final class LoggerRB {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    93
        public final String resourceBundleName;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    94
        public final ResourceBundle userBundle;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    95
        public LoggerRB(String name, ResourceBundle bundle) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    96
            resourceBundleName = name;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    97
            userBundle = bundle;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    98
        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
    99
    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   100
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   101
    static final List<Class<? extends ResourceBundle>> classes = new ArrayList<>();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   102
    static {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   103
        classes.add(MyBundle1.class);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   104
        classes.add(MyBundle2.class);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   105
        classes.add(MyBundle3.class);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   106
    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   107
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   108
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   109
    /**
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   110
     * This test will run both with and without a security manager.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   111
     *
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   112
     * The test starts a number of threads that will attempt to concurrently
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   113
     * set resource bundles on Logger, and verifies the consistency of the
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   114
     * obtained results.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   115
     *
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   116
     * This is a best effort test.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   117
     *
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   118
     * @param args the command line arguments
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   119
     */
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   120
    public static void main(String[] args) throws Exception {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   121
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   122
        try {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   123
            // test without security
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   124
            System.out.println("No security");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   125
            test();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   126
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   127
            // test with security
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   128
            System.out.println("\nWith security");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   129
            Policy.setPolicy(new Policy() {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   130
                @Override
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   131
                public boolean implies(ProtectionDomain domain, Permission permission) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   132
                    if (super.implies(domain, permission)) return true;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   133
                    // System.out.println("Granting " + permission);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   134
                    return true; // all permissions
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   135
                }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   136
            });
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   137
            System.setSecurityManager(new SecurityManager());
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   138
            test();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   139
        } finally {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   140
            SetRB.executor.shutdownNow();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   141
            SetRBName.executor.shutdownNow();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   142
        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   143
    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   144
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   145
    /**
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   146
     * Starts all threads, wait 15secs, then stops all threads.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   147
     * @throws Exception if a deadlock was detected or an error occurred.
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   148
     */
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   149
    public static void test() throws Exception {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   150
          goOn = true;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   151
          thrown = null;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   152
          long sGetRBCount = getRBcount.get();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   153
          long sSetRBCount  = setRBcount.get();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   154
          long sSetRBNameCount  = setRBNameCount.get();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   155
          long sCheckCount = checkCount.get();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   156
          long sNextLong = nextLong.get();
25985
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   157
          long sIgnoreLogCount = ignoreLogCount.get();
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   158
          List<Thread> threads = new ArrayList<>();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   159
          for (Class<? extends ResourceBundle> type : classes) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   160
              threads.add(new SetRB(type));
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   161
              threads.add(new SetRBName(type));
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   162
          }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   163
          for (int i =0 ; i < READERS ; i++) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   164
              threads.add(new GetRB());
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   165
          }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   166
          threads.add(new DeadlockDetector());
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   167
          threads.add(0, new Stopper(TIME));
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   168
          for (Thread t : threads) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   169
              t.start();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   170
          }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   171
          for (Thread t : threads) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   172
              try {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   173
                  t.join();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   174
              } catch (Exception x) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   175
                  fail(x);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   176
              }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   177
          }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   178
          if (thrown != null) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   179
              throw thrown;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   180
          }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   181
          System.out.println("Passed: " + (nextLong.longValue() - sNextLong)
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   182
                  + " unique loggers created");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   183
          System.out.println("\t " +(getRBcount.get() - sGetRBCount)
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   184
                  + " loggers tested by " + READERS + " Thread(s),");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   185
          System.out.println("\t " + (setRBcount.get() - sSetRBCount)
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   186
                  + " resource bundles set by " + classes.size() + " Thread(s),");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   187
          System.out.println("\t " + (setRBNameCount.get() - sSetRBNameCount)
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   188
                  + " resource bundle names set by " + classes.size() + " Thread(s),");
25985
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   189
          System.out.println("\t " + (ignoreLogCount.get() - sIgnoreLogCount)
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   190
                  + " log messages emitted by other GetRB threads were ignored"
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   191
                  + " to ensure MT test consistency,");
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   192
          System.out.println("\t ThreadMXBean.findDeadlockedThreads called "
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   193
                  + (checkCount.get() -sCheckCount) + " times by 1 Thread.");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   194
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   195
    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   196
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25985
diff changeset
   197
    static final class GetRB extends Thread {
25985
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   198
        final class MyHandler extends Handler {
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   199
            volatile ResourceBundle rb;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   200
            volatile String rbName;
22073
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   201
            volatile int count = 0;
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   202
            @Override
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   203
            public synchronized void publish(LogRecord record) {
25985
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   204
                Object[] params = record.getParameters();
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   205
                // Each GetRB thread has its own handler, but since they
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   206
                // log into the same logger, each handler may receive
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   207
                // messages emitted by other threads.
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   208
                // This means that GetRB#2.handler may receive a message
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   209
                // emitted by GetRB#1 at a time where the resource bundle
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   210
                // was still null.
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   211
                // To avoid falling into this trap, the GetRB thread passes
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   212
                // 'this' as argument to the messages it logs - which does
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   213
                // allow us here to ignore messages that where not emitted
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   214
                // by our own GetRB.this thread...
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   215
                if (params.length == 1) {
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   216
                    if (params[0] == GetRB.this) {
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   217
                        // The message was emitted by our thread.
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   218
                        count++;
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   219
                        rb = record.getResourceBundle();
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   220
                        rbName = record.getResourceBundleName();
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   221
                    } else {
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   222
                        // The message was emitted by another thread: just
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   223
                        // ignore it, as it may have been emitted at a time
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   224
                        // where the resource bundle was still null, and
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   225
                        // processing it may overwrite the 'rb' and 'rbName'
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   226
                        // recorded from the message emitted by our own thread.
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   227
                        if (VERBOSE) {
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   228
                            System.out.println("Ignoring message logged by " + params[0]);
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   229
                        }
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   230
                        ignoreLogCount.incrementAndGet();
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   231
                    }
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   232
                } else {
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   233
                    ignoreLogCount.incrementAndGet();
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   234
                    System.err.println("Unexpected message received");
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   235
                }
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   236
            }
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   237
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   238
            void reset() {
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   239
                rbName = null;
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   240
                rb = null;
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   241
            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   242
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   243
            @Override
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   244
            public void flush() {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   245
            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   246
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   247
            @Override
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   248
            public void close() throws SecurityException {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   249
            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   250
        };
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   251
        final MyHandler handler = new MyHandler();
25985
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   252
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   253
        @Override
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   254
        public void run() {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   255
            try {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   256
                handler.setLevel(Level.FINEST);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   257
                while (goOn) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   258
                    Logger l;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   259
                    Logger foo = Logger.getLogger("foo");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   260
                    Logger bar = Logger.getLogger("foo.bar");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   261
                    for (long i=0; i < nextLong.longValue() + 100 ; i++) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   262
                        if (!goOn) break;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   263
                        l = Logger.getLogger("foo.bar.l"+i);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   264
                        final ResourceBundle b = l.getResourceBundle();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   265
                        final String name = l.getResourceBundleName();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   266
                        if (b != null) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   267
                            if (!name.equals(b.getBaseBundleName())) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   268
                                throw new RuntimeException("Unexpected bundle name: "
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   269
                                        +b.getBaseBundleName());
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   270
                            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   271
                        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   272
                        Logger ll = Logger.getLogger(l.getName()+".bie.bye");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   273
                        ResourceBundle hrb;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   274
                        String hrbName;
22073
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   275
                        if (handler.getLevel() != Level.FINEST) {
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   276
                            throw new RuntimeException("Handler level is not finest: "
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   277
                                    + handler.getLevel());
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   278
                        }
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   279
                        final int countBefore = handler.count;
25985
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   280
                        handler.reset();
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   281
                        ll.setLevel(Level.FINEST);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   282
                        ll.addHandler(handler);
25985
aa1e188ea8bf 8054480: Test java/util/logging/TestLoggerBundleSync.java fails: Unexpected bundle name: null
dfuchs
parents: 22073
diff changeset
   283
                        ll.log(Level.FINE, "dummy {0}", this);
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   284
                        ll.removeHandler(handler);
22073
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   285
                        final int countAfter = handler.count;
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   286
                        if (countBefore == countAfter) {
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   287
                            throw new RuntimeException("Handler not called for "
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   288
                                    + ll.getName() + "("+ countAfter +")");
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   289
                        }
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   290
                        hrb = handler.rb;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   291
                        hrbName = handler.rbName;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   292
                        if (name != null) {
22073
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   293
                            // if name is not null, then it implies that it
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   294
                            // won't change, since setResourceBundle() cannot
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   295
                            // replace a non null name.
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   296
                            // Since we never set the resource bundle on 'll',
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   297
                            // then ll must inherit its resource bundle [name]
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   298
                            // from l - and therefor we should find it in
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   299
                            // handler.rb/handler.rbName
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   300
                            if (!name.equals(hrbName)) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   301
                                throw new RuntimeException("Unexpected bundle name: "
22073
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   302
                                        +hrbName);
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   303
                            }
22073
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   304
                            // here we know that hrbName is not null so hrb
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   305
                            // should not be null either.
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   306
                            if (!name.equals(hrb.getBaseBundleName())) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   307
                                throw new RuntimeException("Unexpected bundle name: "
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   308
                                        +hrb.getBaseBundleName());
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   309
                            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   310
                        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   311
22073
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   312
                        // Make sure to refer to 'l' explicitly in order to
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   313
                        // prevent eager garbage collecting before the end of
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   314
                        // the test (JDK-8030192)
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   315
                        if (!ll.getName().startsWith(l.getName())) {
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   316
                            throw new RuntimeException("Logger " + ll.getName()
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   317
                                    + "does not start with expected prefix "
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   318
                                    + l.getName());
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   319
                        }
3cac022a1634 8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents: 21960
diff changeset
   320
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   321
                        getRBcount.incrementAndGet();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   322
                        if (!goOn) break;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   323
                        Thread.sleep(1);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   324
                    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   325
                }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   326
           } catch (Exception x) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   327
               fail(x);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   328
           }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   329
        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   330
    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   331
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25985
diff changeset
   332
    static final class SetRB extends Thread {
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   333
        final Class<? extends ResourceBundle> type;
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25985
diff changeset
   334
        static final ExecutorService executor = Executors.newSingleThreadExecutor();
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25985
diff changeset
   335
        static final class CheckRBTask implements Callable<Exception> {
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   336
            final Logger logger;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   337
            volatile String rbName;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   338
            volatile ResourceBundle rb;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   339
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   340
            public CheckRBTask(Logger logger) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   341
                this.logger = logger;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   342
            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   343
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   344
            @Override
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   345
            public Exception call() throws Exception {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   346
                try {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   347
                    final String name = logger.getResourceBundleName();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   348
                    if (!Objects.equals(name, rbName)) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   349
                        throw new RuntimeException("Unexpected rbname for "
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   350
                            + logger.getName() + ": " + name);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   351
                    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   352
                    final ResourceBundle b = logger.getResourceBundle();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   353
                    if (b != rb) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   354
                        throw new RuntimeException("Unexpected rb for "
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   355
                            + logger.getName() + ": " + b);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   356
                    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   357
                } catch(Exception x) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   358
                    return x;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   359
                }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   360
                return null;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   361
            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   362
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   363
            public void check() throws Exception {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   364
                final FutureTask<Exception> futureTask = new FutureTask<>(this);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   365
                executor.submit(futureTask);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   366
                Exception x = futureTask.get();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   367
                if ( x != null) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   368
                    throw new RuntimeException("Check failed: "+x,x);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   369
                }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   370
            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   371
        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   372
        SetRB(Class<? extends ResourceBundle> type) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   373
            super("SetRB["+type.getSimpleName()+"]");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   374
            this.type = type;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   375
        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   376
        @Override
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   377
        public void run() {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   378
            try {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   379
                while (goOn) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   380
                    Logger l;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   381
                    Logger foo = Logger.getLogger("foo");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   382
                    Logger bar = Logger.getLogger("foo.bar");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   383
                    l = Logger.getLogger("foo.bar.l"+nextLong.incrementAndGet());
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   384
                    final CheckRBTask checkTask = new CheckRBTask(l);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   385
                    checkTask.check();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   386
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   387
                    for (int i=0; i < LCOUNT ; i++) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   388
                        if (!goOn) break;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   389
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   390
                        ResourceBundle b = ResourceBundle.getBundle(type.getName());
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   391
                        try {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   392
                            l.setResourceBundle(b);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   393
                            checkTask.rb = b;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   394
                            checkTask.rbName = type.getName();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   395
                            checkTask.check();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   396
                            if (!goOn) break;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   397
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   398
                            String name = l.getResourceBundleName();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   399
                            ResourceBundle bb = l.getResourceBundle();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   400
                            if (!type.getName().equals(name)) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   401
                                throw new RuntimeException(this.getName()
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   402
                                        + ": Unexpected name: "+name);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   403
                            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   404
                            if (!b.getBaseBundleName().equals(name)) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   405
                                throw new RuntimeException(this.getName()
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   406
                                        + ": Unexpected base name: " +
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   407
                                        b.getBaseBundleName());
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   408
                            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   409
                            if (b != bb) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   410
                                throw new RuntimeException(this.getName()
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   411
                                        + ": Unexpected bundle: "+bb);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   412
                            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   413
                            setRBcount.incrementAndGet();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   414
                        } catch (IllegalArgumentException x) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   415
                            final String name = l.getResourceBundleName();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   416
                            if (!name.startsWith(MyBundle.class.getName())) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   417
                                throw new RuntimeException(this.getName()
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   418
                                        + ": Unexpected name: "+name, x);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   419
                            } else if (type.getName().equals(name)) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   420
                                throw new RuntimeException(this.getName()
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   421
                                        + ": Unexpected exception for "+name, x);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   422
                            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   423
                            throw x;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   424
                        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   425
                        l.fine("I'm fine");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   426
                        if (!goOn) break;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   427
                        Thread.sleep(1);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   428
                    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   429
                }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   430
            } catch (Exception x) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   431
                fail(x);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   432
            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   433
        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   434
    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   435
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25985
diff changeset
   436
    static final class SetRBName extends Thread {
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   437
        int nexti = 0;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   438
        final Class<? extends ResourceBundle> type;
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25985
diff changeset
   439
        static final ExecutorService executor = Executors.newSingleThreadExecutor();
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25985
diff changeset
   440
        static final class CheckRBNameTask implements Callable<Exception> {
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   441
            final Logger logger;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   442
            volatile String rbName;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   443
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   444
            public CheckRBNameTask(Logger logger) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   445
                this.logger = logger;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   446
            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   447
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   448
            @Override
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   449
            public Exception call() throws Exception {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   450
                try {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   451
                    final String name = logger.getResourceBundleName();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   452
                    if (!Objects.equals(name, rbName)) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   453
                        throw new RuntimeException("Unexpected rbname for "
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   454
                            + logger.getName() + ": " + name);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   455
                    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   456
                    final ResourceBundle b = logger.getResourceBundle();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   457
                    if (!Objects.equals(b == null ? null : b.getBaseBundleName(), rbName)) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   458
                        throw new RuntimeException("Unexpected base name for "
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   459
                            + logger.getName() + ": " + b.getBaseBundleName());
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   460
                    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   461
                } catch(Exception x) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   462
                    return x;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   463
                }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   464
                return null;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   465
            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   466
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   467
            public void check() throws Exception {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   468
                final FutureTask<Exception> futureTask = new FutureTask<>(this);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   469
                executor.submit(futureTask);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   470
                Exception x = futureTask.get();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   471
                if ( x != null) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   472
                    throw new RuntimeException("Check failed: "+x,x);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   473
                }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   474
            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   475
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   476
        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   477
        SetRBName(Class<? extends ResourceBundle> type) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   478
            super("SetRB["+type.getSimpleName()+"]");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   479
            this.type = type;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   480
        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   481
        @Override
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   482
        public void run() {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   483
            try {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   484
                while (goOn) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   485
                    Logger foo = Logger.getLogger("foo");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   486
                    Logger bar = Logger.getLogger("foo.bar");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   487
                    Logger l = Logger.getLogger("foo.bar.l"+nextLong.incrementAndGet());
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   488
                    final CheckRBNameTask checkTask = new CheckRBNameTask(l);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   489
                    checkTask.check();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   490
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   491
                    for (int i=0; i < LCOUNT ; i++) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   492
                        if (!goOn) break;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   493
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   494
                        try {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   495
                            Logger l2 = Logger.getLogger(l.getName(), type.getName());
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   496
                            if (l2 != l) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   497
                                System.err.println("**** ERROR WITH "+l.getName());
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   498
                                throw new RuntimeException("l2 != l ["
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   499
                                        + l2 + "(" + l2.getName() + ") != "
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   500
                                        + l  + "(" + l.getName()  + ")]");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   501
                            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   502
                            checkTask.rbName = type.getName();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   503
                            checkTask.check();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   504
                            if (!goOn) break;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   505
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   506
                            String name = l.getResourceBundleName();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   507
                            ResourceBundle bb = l.getResourceBundle();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   508
                            if (!type.getName().equals(name)) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   509
                                throw new RuntimeException(this.getName()
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   510
                                        + ": Unexpected name: "+name);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   511
                            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   512
                            if (!bb.getBaseBundleName().equals(name)) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   513
                                throw new RuntimeException(this.getName()
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   514
                                        + ": Unexpected base name: "
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   515
                                        + bb.getBaseBundleName());
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   516
                            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   517
                            setRBNameCount.incrementAndGet();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   518
                        } catch (IllegalArgumentException x) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   519
                            final String name = l.getResourceBundleName();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   520
                            if (!name.startsWith(MyBundle.class.getName())) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   521
                                throw new RuntimeException(this.getName()
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   522
                                        + ": Unexpected name: "+name, x);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   523
                            } else if (type.getName().equals(name)) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   524
                                throw new RuntimeException(this.getName()
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   525
                                        + ": Unexpected exception for "+name, x);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   526
                            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   527
                            throw x;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   528
                        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   529
                        l.fine("I'm fine");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   530
                        if (!goOn) break;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   531
                        Thread.sleep(1);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   532
                    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   533
                }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   534
            } catch (Exception x) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   535
                fail(x);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   536
            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   537
        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   538
    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   539
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25985
diff changeset
   540
    static final class DeadlockDetector extends Thread {
21960
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   541
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   542
        @Override
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   543
        public void run() {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   544
            while(goOn) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   545
                try {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   546
                    long[] ids = ManagementFactory.getThreadMXBean().findDeadlockedThreads();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   547
                    checkCount.incrementAndGet();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   548
                    ids = ids == null ? new long[0] : ids;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   549
                    if (ids.length == 1) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   550
                        throw new RuntimeException("Found 1 deadlocked thread: "+ids[0]);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   551
                    } else if (ids.length > 0) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   552
                        ThreadInfo[] infos = ManagementFactory.getThreadMXBean().getThreadInfo(ids);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   553
                        System.err.println("Found "+ids.length+" deadlocked threads: ");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   554
                        for (ThreadInfo inf : infos) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   555
                            System.err.println(inf.toString());
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   556
                        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   557
                        throw new RuntimeException("Found "+ids.length+" deadlocked threads");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   558
                    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   559
                    Thread.sleep(100);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   560
                } catch(InterruptedException | RuntimeException x) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   561
                    fail(x);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   562
                }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   563
            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   564
        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   565
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   566
    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   567
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   568
    static final class Stopper extends Thread {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   569
        long start;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   570
        long time;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   571
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   572
        Stopper(long time) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   573
            start = System.currentTimeMillis();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   574
            this.time = time;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   575
        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   576
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   577
        @Override
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   578
        public void run() {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   579
            try {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   580
                long rest, previous;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   581
                previous = time;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   582
                while (goOn && (rest = start - System.currentTimeMillis() + time) > 0) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   583
                    if (previous == time || previous - rest >= STEP) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   584
                        Logger.getLogger("remaining").info(String.valueOf(rest)+"ms remaining...");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   585
                        previous = rest == time ? rest -1 : rest;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   586
                        System.gc();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   587
                    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   588
                    if (goOn == false) break;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   589
                    Thread.sleep(Math.min(rest, 100));
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   590
                }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   591
                System.out.println(System.currentTimeMillis() - start
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   592
                        + " ms elapsed ("+time+ " requested)");
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   593
                goOn = false;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   594
            } catch(InterruptedException | RuntimeException x) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   595
                fail(x);
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   596
            }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   597
        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   598
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   599
    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   600
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   601
    static void fail(Exception x) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   602
        x.printStackTrace();
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   603
        if (thrown == null) {
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   604
            thrown = x;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   605
        }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   606
        goOn = false;
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   607
    }
277d5c6b2172 8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff changeset
   608
}