test/runtime/7196045/Test7196045.java

Wed, 19 Sep 2012 15:24:32 +0100

author
kevinw
date
Wed, 19 Sep 2012 15:24:32 +0100
changeset 4090
6af8f3562069
child 4143
fab6fbf427d2
permissions
-rw-r--r--

7196045: Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
Reviewed-by: sspitsyn, dholmes

     1 /*
     2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 /*
    26  * @test
    27  * @bug 7196045
    28  * @summary Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
    29  * @run main/othervm
    30  */
    32 import java.lang.management.ManagementFactory;
    33 import javax.management.JMException;
    34 import javax.management.MBeanServer;
    35 import javax.management.MalformedObjectNameException;
    36 import javax.management.ObjectName;
    38 public class Test7196045 {
    40     public static long duration = 1000 * 60 * 2;
    41     private static final String HOTSPOT_INTERNAL = "sun.management:type=HotspotInternal";
    43     public static void main(String[] args) {
    45         MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    46         ObjectName objName= null;
    47         try {
    48             ObjectName hotspotInternal = new ObjectName(HOTSPOT_INTERNAL);
    49             try {
    50                 server.registerMBean(new sun.management.HotspotInternal(), hotspotInternal);
    51             } catch (JMException e) {
    52                 throw new RuntimeException("HotSpotWatcher: Failed to register the HotspotInternal MBean" + e);
    53             }
    54             objName= new ObjectName("sun.management:type=HotspotThreading");
    56         } catch (MalformedObjectNameException e1) {
    57             throw new RuntimeException("Bad object name" + e1);
    58         }
    60         long endTime = System.currentTimeMillis() + duration;
    61         long i = 0;
    62         while (true) {
    63             try {
    64                 server.getAttribute(objName, "InternalThreadCpuTimes");
    65             } catch (Exception ex) {
    66                 System.err.println("Exception while getting attribute: " + ex);
    67             }
    68             i++;
    69             if (i % 10000 == 0) {
    70                 System.out.println("Successful iterations: " + i);
    71             }
    72             if (System.currentTimeMillis() > endTime) {
    73                 break;
    74             }
    75         }
    76         System.out.println("PASSED.");
    77     }
    78 }

mercurial