hotspot/test/runtime/InternalApi/ThreadCpuTimesDeadlock.java
author ctornqvi
Fri, 02 Aug 2013 18:12:10 +0200
changeset 19146 feb543709508
parent 18500 hotspot/test/runtime/7196045/Test7196045.java@99e313fcf726
child 29678 dd2f3932c21e
permissions -rw-r--r--
8009585: test/runtime/7196045 times out Summary: test/runtime/7196045 times out Reviewed-by: dholmes, mseledtsov
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
/*
19146
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
     2
 * Copyright (c) 2012, 2013, 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.
19146
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    30
 * @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
    31
 */
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
import java.lang.management.ManagementFactory;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    34
import javax.management.JMException;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    35
import javax.management.MBeanServer;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    36
import javax.management.MalformedObjectNameException;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    37
import javax.management.ObjectName;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    38
19146
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    39
public class ThreadCpuTimesDeadlock {
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    40
19146
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    41
    public static byte[] dummy;
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    42
    public static long duration = 10 * 1000;
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    43
    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
    44
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    45
    public static void main(String[] args) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    46
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    47
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    48
        ObjectName objName= null;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    49
        try {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    50
            ObjectName hotspotInternal = new ObjectName(HOTSPOT_INTERNAL);
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    51
            try {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    52
                server.registerMBean(new sun.management.HotspotInternal(), hotspotInternal);
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    53
            } catch (JMException e) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    54
                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
    55
            }
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    56
            objName= new ObjectName("sun.management:type=HotspotThreading");
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    57
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    58
        } catch (MalformedObjectNameException e1) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    59
            throw new RuntimeException("Bad object name" + e1);
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    60
        }
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    61
19146
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    62
        // Thread that allocs memory to generate GC's
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    63
        Thread allocThread = new Thread() {
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    64
          public void run() {
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    65
            while (true) {
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    66
              dummy = new byte[4096];
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    67
            }
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
        allocThread.setDaemon(true);
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    72
        allocThread.start();
feb543709508 8009585: test/runtime/7196045 times out
ctornqvi
parents: 18500
diff changeset
    73
13870
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    74
        long endTime = System.currentTimeMillis() + duration;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    75
        long i = 0;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    76
        while (true) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    77
            try {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    78
                server.getAttribute(objName, "InternalThreadCpuTimes");
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    79
            } catch (Exception ex) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    80
                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
    81
            }
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    82
            i++;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    83
            if (i % 10000 == 0) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    84
                System.out.println("Successful iterations: " + i);
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    85
            }
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    86
            if (System.currentTimeMillis() > endTime) {
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    87
                break;
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    88
            }
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
        System.out.println("PASSED.");
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    91
    }
dd2c6a5a4722 7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
kevinw
parents:
diff changeset
    92
}