test/runtime/InternalApi/ThreadCpuTimesDeadlock.java

Wed, 21 May 2014 10:56:41 -0700

author
katleman
date
Wed, 21 May 2014 10:56:41 -0700
changeset 6672
fb9d124d9192
parent 5476
fa57c8104b76
child 6876
710a3c8b516e
permissions
-rw-r--r--

Added tag jdk8u20-b15 for changeset 8c785f9bde6f

kevinw@4090 1 /*
ctornqvi@5476 2 * Copyright (c) 2012, 2013, 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
ctornqvi@5476 28 * @bug 8014294
kevinw@4090 29 * @summary Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.
ctornqvi@5476 30 * @run main/othervm -XX:+UsePerfData -Xmx32m ThreadCpuTimesDeadlock
kevinw@4090 31 */
kevinw@4090 32
kevinw@4090 33 import java.lang.management.ManagementFactory;
kevinw@4090 34 import javax.management.JMException;
kevinw@4090 35 import javax.management.MBeanServer;
kevinw@4090 36 import javax.management.MalformedObjectNameException;
kevinw@4090 37 import javax.management.ObjectName;
kevinw@4090 38
ctornqvi@5476 39 public class ThreadCpuTimesDeadlock {
kevinw@4090 40
ctornqvi@5476 41 public static byte[] dummy;
ctornqvi@5476 42 public static long duration = 10 * 1000;
kevinw@4090 43 private static final String HOTSPOT_INTERNAL = "sun.management:type=HotspotInternal";
kevinw@4090 44
kevinw@4090 45 public static void main(String[] args) {
kevinw@4090 46
kevinw@4090 47 MBeanServer server = ManagementFactory.getPlatformMBeanServer();
kevinw@4090 48 ObjectName objName= null;
kevinw@4090 49 try {
kevinw@4090 50 ObjectName hotspotInternal = new ObjectName(HOTSPOT_INTERNAL);
kevinw@4090 51 try {
kevinw@4090 52 server.registerMBean(new sun.management.HotspotInternal(), hotspotInternal);
kevinw@4090 53 } catch (JMException e) {
kevinw@4090 54 throw new RuntimeException("HotSpotWatcher: Failed to register the HotspotInternal MBean" + e);
kevinw@4090 55 }
kevinw@4090 56 objName= new ObjectName("sun.management:type=HotspotThreading");
kevinw@4090 57
kevinw@4090 58 } catch (MalformedObjectNameException e1) {
kevinw@4090 59 throw new RuntimeException("Bad object name" + e1);
kevinw@4090 60 }
kevinw@4090 61
ctornqvi@5476 62 // Thread that allocs memory to generate GC's
ctornqvi@5476 63 Thread allocThread = new Thread() {
ctornqvi@5476 64 public void run() {
ctornqvi@5476 65 while (true) {
ctornqvi@5476 66 dummy = new byte[4096];
ctornqvi@5476 67 }
ctornqvi@5476 68 }
ctornqvi@5476 69 };
ctornqvi@5476 70
ctornqvi@5476 71 allocThread.setDaemon(true);
ctornqvi@5476 72 allocThread.start();
ctornqvi@5476 73
kevinw@4090 74 long endTime = System.currentTimeMillis() + duration;
kevinw@4090 75 long i = 0;
kevinw@4090 76 while (true) {
kevinw@4090 77 try {
kevinw@4090 78 server.getAttribute(objName, "InternalThreadCpuTimes");
kevinw@4090 79 } catch (Exception ex) {
kevinw@4090 80 System.err.println("Exception while getting attribute: " + ex);
kevinw@4090 81 }
kevinw@4090 82 i++;
kevinw@4090 83 if (i % 10000 == 0) {
kevinw@4090 84 System.out.println("Successful iterations: " + i);
kevinw@4090 85 }
kevinw@4090 86 if (System.currentTimeMillis() > endTime) {
kevinw@4090 87 break;
kevinw@4090 88 }
kevinw@4090 89 }
kevinw@4090 90 System.out.println("PASSED.");
kevinw@4090 91 }
kevinw@4090 92 }

mercurial