Path: blob/master/test/hotspot/jtreg/runtime/InternalApi/ThreadCpuTimesDeadlock.java
40942 views
/*1* Copyright (c) 2012, 2021, 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*/2223/*24* @test25* @bug 719604526* @bug 801429427* @summary Possible JVM deadlock in ThreadTimesClosure when using HotspotInternal non-public API.28* @modules java.management/sun.management29* @run main/othervm -XX:+UsePerfData -Xmx128m ThreadCpuTimesDeadlock30*/3132/*33* @test34* @bug 826464935* @summary OSR compiled method crash when UseTLAB is off36* @requires vm.debug37* @modules java.management/sun.management38* @run main/othervm -XX:-UseTLAB -XX:+UsePerfData -Xmx128m ThreadCpuTimesDeadlock39*/4041import java.lang.management.ManagementFactory;42import javax.management.JMException;43import javax.management.MBeanServer;44import javax.management.MalformedObjectNameException;45import javax.management.ObjectName;4647public class ThreadCpuTimesDeadlock {4849public static byte[] dummy;50public static long duration = 10 * 1000;51private static final String HOTSPOT_INTERNAL = "sun.management:type=HotspotInternal";5253public static void main(String[] args) {5455MBeanServer server = ManagementFactory.getPlatformMBeanServer();56ObjectName objName= null;57try {58ObjectName hotspotInternal = new ObjectName(HOTSPOT_INTERNAL);59try {60server.registerMBean(new sun.management.HotspotInternal(), hotspotInternal);61} catch (JMException e) {62throw new RuntimeException("HotSpotWatcher: Failed to register the HotspotInternal MBean" + e);63}64objName= new ObjectName("sun.management:type=HotspotThreading");6566} catch (MalformedObjectNameException e1) {67throw new RuntimeException("Bad object name" + e1);68}6970// Thread that allocs memory to generate GC's71Thread allocThread = new Thread() {72public void run() {73while (true) {74dummy = new byte[4096];75}76}77};7879allocThread.setDaemon(true);80allocThread.start();8182long endTime = System.currentTimeMillis() + duration;83long i = 0;84while (true) {85try {86server.getAttribute(objName, "InternalThreadCpuTimes");87} catch (Exception ex) {88System.err.println("Exception while getting attribute: " + ex);89}90i++;91if (i % 10000 == 0) {92System.out.println("Successful iterations: " + i);93}94if (System.currentTimeMillis() > endTime) {95break;96}97}98System.out.println("PASSED.");99}100}101102103