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