Path: blob/master/test/jdk/com/sun/jdi/DebuggerThreadTest.java
41149 views
/*1* Copyright (c) 2001, 2018, 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* @author Tim Bell28*29* @run build TestScaffold VMConnection TargetListener TargetAdapter30* @run compile -g DebuggerThreadTest.java31* @run driver DebuggerThreadTest32*/33import com.sun.jdi.*;34import com.sun.jdi.event.*;35import com.sun.jdi.request.*;3637import java.util.*;3839/********** target program **********/4041class DebuggerThreadTarg {42public void ready() {43}44public static void main(String[] args){45System.out.println("Howdy!");46DebuggerThreadTarg targ = new DebuggerThreadTarg();47targ.ready();48System.out.println("Goodbye from DebuggerThreadTarg!");49}50}5152/********** test program **********/5354public class DebuggerThreadTest extends TestScaffold {5556DebuggerThreadTest (String args[]) {57super(args);58}5960public static void main(String[] args) throws Exception {61new DebuggerThreadTest(args).startTests();62}6364/*65* Move to top ThreadGroup and dump all threads.66*/67public void dumpThreads() {68int finishedThreads = 0;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];80ThreadGroup tga = t.getThreadGroup();81String groupName;82if (tga == null) {83groupName = "<completed>";84finishedThreads++ ;85} else {86groupName = tga.getName();87}8889System.out.println("Thread [" + i + "] group = '" +90groupName +91"' name = '" + t.getName() +92"' daemon = " + t.isDaemon());9394if (groupName.startsWith("JDI ") &&95(! t.isDaemon())) {96failure("FAIL: non-daemon thread '" + t.getName() +97"' found in ThreadGroup '" + groupName + "'");98}99}100if (finishedThreads > 0 ) {101failure("FAIL: " + finishedThreads +102" threads completed while VM suspended.");103}104}105106protected void runTests() throws Exception {107try {108/*109* Get to the top of ready()110*/111startTo("DebuggerThreadTarg", "ready", "()V");112113dumpThreads();114115listenUntilVMDisconnect();116117} finally {118/*119* deal with results of test120* if anything has called failure("foo") testFailed will be true121*/122if (!testFailed) {123println("DebuggerThreadTest: passed");124} else {125throw new Exception("DebuggerThreadTest: failed");126}127}128return;129}130}131132133