hotspot/test/runtime/InternalApi/ThreadCpuTimesDeadlock.java
author tschatzl
Wed, 06 Jul 2016 11:22:55 +0200
changeset 39698 4016de4e596b
parent 29678 dd2f3932c21e
child 41705 332239c052cc
permissions -rw-r--r--
8159978: Use an array to store the collection set regions instead of linking through regions Summary: Fix a potential problem with memory visibility in the sampling thread in the collection set by changing the way we store the collection set. Reviewed-by: ehelin, jmasa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 19146
diff changeset
     2
 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
     4
 *
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
     8
 *
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    13
 * accompanied this code).
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    14
 *
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    18
 *
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    21
 * questions.
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    22
 *
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    23
 */
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    24
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    25
/*
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    26
 * @test
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    27
 * @bug 7196045
19146
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    28
 * @bug 8014294
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    29
 * @summary Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 19146
diff changeset
    30
 * @modules java.management/sun.management
19146
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    31
 * @run main/othervm -XX:+UsePerfData -Xmx32m ThreadCpuTimesDeadlock
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    32
 */
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    33
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    34
import java.lang.management.ManagementFactory;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    35
import javax.management.JMException;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    36
import javax.management.MBeanServer;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    37
import javax.management.MalformedObjectNameException;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    38
import javax.management.ObjectName;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    39
19146
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    40
public class ThreadCpuTimesDeadlock {
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    41
19146
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    42
    public static byte[] dummy;
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    43
    public static long duration = 10 * 1000;
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    44
    private static final String HOTSPOT_INTERNAL = "sun.management:type=HotspotInternal";
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    45
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    46
    public static void main(String[] args) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    47
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    48
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    49
        ObjectName objName= null;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    50
        try {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    51
            ObjectName hotspotInternal = new ObjectName(HOTSPOT_INTERNAL);
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    52
            try {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    53
                server.registerMBean(new sun.management.HotspotInternal(), hotspotInternal);
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    54
            } catch (JMException e) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    55
                throw new RuntimeException("HotSpotWatcher: Failed to register the HotspotInternal MBean" + e);
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    56
            }
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    57
            objName= new ObjectName("sun.management:type=HotspotThreading");
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    58
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    59
        } catch (MalformedObjectNameException e1) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    60
            throw new RuntimeException("Bad object name" + e1);
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    61
        }
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    62
19146
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    63
        // Thread that allocs memory to generate GC's
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    64
        Thread allocThread = new Thread() {
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    65
          public void run() {
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    66
            while (true) {
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    67
              dummy = new byte[4096];
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    68
            }
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    69
          }
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    70
        };
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    71
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    72
        allocThread.setDaemon(true);
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    73
        allocThread.start();
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    74
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    75
        long endTime = System.currentTimeMillis() + duration;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    76
        long i = 0;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    77
        while (true) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    78
            try {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    79
                server.getAttribute(objName, "InternalThreadCpuTimes");
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    80
            } catch (Exception ex) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    81
                System.err.println("Exception while getting attribute: " + ex);
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    82
            }
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    83
            i++;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    84
            if (i % 10000 == 0) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    85
                System.out.println("Successful iterations: " + i);
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    86
            }
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    87
            if (System.currentTimeMillis() > endTime) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    88
                break;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    89
            }
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    90
        }
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    91
        System.out.println("PASSED.");
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    92
    }
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    93
}