Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/InternalApi/ThreadCpuTimesDeadlock.java
32284 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324/*25* @test26* @bug 719604527* @bug 801429428* @summary Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.29* @run main/othervm -XX:+UsePerfData -Xmx32m ThreadCpuTimesDeadlock30*/3132import java.lang.management.ManagementFactory;33import javax.management.JMException;34import javax.management.MBeanServer;35import javax.management.MalformedObjectNameException;36import javax.management.ObjectName;3738public class ThreadCpuTimesDeadlock {3940public static byte[] dummy;41public static long duration = 10 * 1000;42private static final String HOTSPOT_INTERNAL = "sun.management:type=HotspotInternal";4344public static void main(String[] args) {4546MBeanServer server = ManagementFactory.getPlatformMBeanServer();47ObjectName objName= null;48try {49ObjectName hotspotInternal = new ObjectName(HOTSPOT_INTERNAL);50try {51server.registerMBean(new sun.management.HotspotInternal(), hotspotInternal);52} catch (JMException e) {53throw new RuntimeException("HotSpotWatcher: Failed to register the HotspotInternal MBean" + e);54}55objName= new ObjectName("sun.management:type=HotspotThreading");5657} catch (MalformedObjectNameException e1) {58throw new RuntimeException("Bad object name" + e1);59}6061// Thread that allocs memory to generate GC's62Thread allocThread = new Thread() {63public void run() {64while (true) {65dummy = new byte[4096];66}67}68};6970allocThread.setDaemon(true);71allocThread.start();7273long endTime = System.currentTimeMillis() + duration;74long i = 0;75while (true) {76try {77server.getAttribute(objName, "InternalThreadCpuTimes");78} catch (Exception ex) {79System.err.println("Exception while getting attribute: " + ex);80}81i++;82if (i % 10000 == 0) {83System.out.println("Successful iterations: " + i);84}85if (System.currentTimeMillis() > endTime) {86break;87}88}89System.out.println("PASSED.");90}91}929394