Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/management/ThreadMXBean/MaxDepthForThreadInfoTest.java
38855 views
/*1* Copyright (c) 2017, 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 818500326* @library /java/lang/management/ThreadMXBean27* @build ThreadDump28* @run main MaxDepthForThreadInfoTest29* @summary verifies the functionality of ThreadMXBean.dumpAllThreads30* and ThreadMXBean.getThreadInfo with maxDepth argument31*/3233import java.lang.management.ManagementFactory;34import java.lang.management.ThreadInfo;35import java.lang.management.ThreadMXBean;36373839public class MaxDepthForThreadInfoTest {404142public static void main(String[] Args) {4344com.sun.management.ThreadMXBean tmxb =45(com.sun.management.ThreadMXBean)ManagementFactory.getThreadMXBean();4647long[] threadIds = tmxb.getAllThreadIds();4849ThreadInfo[] tinfos = tmxb.getThreadInfo(threadIds, true, true, 0);50for (ThreadInfo ti : tinfos) {51if (ti.getStackTrace().length > 0) {52ThreadDump.printThreadInfo(ti);53throw new RuntimeException("more than requested " +54"number of frames dumped");55}56}5758tinfos = tmxb.getThreadInfo(threadIds, true, true, 3);59for (ThreadInfo ti : tinfos) {60if (ti.getStackTrace().length > 3) {61ThreadDump.printThreadInfo(ti);62throw new RuntimeException("more than requested " +63"number of frames dumped");64}65}6667try {68tmxb.getThreadInfo(threadIds, true, true, -1);69throw new RuntimeException("Didn't throw IllegalArgumentException " +70"for negative maxdepth value");71} catch (IllegalArgumentException e) {72System.out.println("Throwed IllegalArgumentException as expected");73}7475tinfos = tmxb.dumpAllThreads(true, true, 0);76for (ThreadInfo ti : tinfos) {77if (ti.getStackTrace().length > 0) {78ThreadDump.printThreadInfo(ti);79throw new RuntimeException("more than requested " +80"number of frames dumped");81}82}83tinfos = tmxb.dumpAllThreads(true, true, 2);84for (ThreadInfo ti : tinfos) {85if (ti.getStackTrace().length > 2) {86ThreadDump.printThreadInfo(ti);87throw new RuntimeException("more than requested " +88"number of frames dumped");89}90}9192try {93tmxb.dumpAllThreads(true, true, -1);94throw new RuntimeException("Didn't throw IllegalArgumentException " +95"for negative maxdepth value");96} catch (IllegalArgumentException e) {97System.out.println("Throwed IllegalArgumentException as expected");98}99100System.out.println("Test passed");101}102}103104105