Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/DebuggerThreadTest.java
38855 views
/*1* Copyright (c) 2001, 2002, 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 451348826* @summary Test for JDI: Internal JDI helper threads should setDaemon(true)27*28* @author Tim Bell29*30* @run build TestScaffold VMConnection TargetListener TargetAdapter31* @run compile -g DebuggerThreadTest.java32* @run main DebuggerThreadTest33*/34import com.sun.jdi.*;35import com.sun.jdi.event.*;36import com.sun.jdi.request.*;3738import java.util.*;3940/********** target program **********/4142class DebuggerThreadTarg {43public void ready() {44}45public static void main(String[] args){46System.out.println("Howdy!");47DebuggerThreadTarg targ = new DebuggerThreadTarg();48targ.ready();49System.out.println("Goodbye from DebuggerThreadTarg!");50}51}5253/********** test program **********/5455public class DebuggerThreadTest extends TestScaffold {5657DebuggerThreadTest (String args[]) {58super(args);59}6061public static void main(String[] args) throws Exception {62new DebuggerThreadTest(args).startTests();63}6465/*66* Move to top ThreadGroup and dump all threads.67*/68public void dumpThreads() {69ThreadGroup tg = Thread.currentThread().getThreadGroup();70ThreadGroup parent = tg.getParent();71while (parent != null) {72tg = parent;73parent = tg.getParent();74}75int listThreads = tg.activeCount();76Thread list[] = new Thread[listThreads * 2];77int gotThreads = tg.enumerate(list, true);78for (int i = 0; i < Math.min(gotThreads, list.length); i++){79Thread t = list[i];80String groupName = t.getThreadGroup().getName();8182System.out.println("Thread [" + i + "] group = '" +83groupName +84"' name = '" + t.getName() +85"' daemon = " + t.isDaemon());8687if (groupName.startsWith("JDI ") &&88(! t.isDaemon())) {89failure("FAIL: non-daemon thread '" + t.getName() +90"' found in ThreadGroup '" + groupName + "'");91}9293}94}9596protected void runTests() throws Exception {97try {98/*99* Get to the top of ready()100*/101startTo("DebuggerThreadTarg", "ready", "()V");102103dumpThreads();104105listenUntilVMDisconnect();106107} finally {108/*109* deal with results of test110* if anything has called failure("foo") testFailed will be true111*/112if (!testFailed) {113println("DebuggerThreadTest: passed");114} else {115throw new Exception("DebuggerThreadTest: failed");116}117}118return;119}120}121122123