test/jdk/com/sun/jdi/DebuggerThreadTest.java
author gadams
Thu, 13 Sep 2018 07:54:38 -0400
changeset 51732 dc68380e6497
parent 47216 71c04702a3d5
permissions -rw-r--r--
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE Reviewed-by: cjplummer, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
51732
dc68380e6497 8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents: 47216
diff changeset
     2
 * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    25
 * @test
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    26
 * @bug 4513488
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    27
 * @summary Test for JDI: Internal JDI helper threads should setDaemon(true)
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    28
 * @author Tim Bell
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    30
 * @run build TestScaffold VMConnection TargetListener TargetAdapter
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    31
 * @run compile -g DebuggerThreadTest.java
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    32
 * @run driver DebuggerThreadTest
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    /********** target program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
class DebuggerThreadTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    public void ready() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static void main(String[] args){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        System.out.println("Howdy!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        DebuggerThreadTarg targ = new DebuggerThreadTarg();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        targ.ready();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        System.out.println("Goodbye from DebuggerThreadTarg!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class DebuggerThreadTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    DebuggerThreadTest (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        new DebuggerThreadTest(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Move to top ThreadGroup and dump all threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public void dumpThreads() {
51732
dc68380e6497 8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents: 47216
diff changeset
    69
        int finishedThreads = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        ThreadGroup tg = Thread.currentThread().getThreadGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        ThreadGroup parent = tg.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        while (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            tg = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            parent = tg.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        int listThreads = tg.activeCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        Thread list[] = new Thread[listThreads * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        int gotThreads = tg.enumerate(list, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        for (int i = 0; i < Math.min(gotThreads, list.length); i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            Thread t = list[i];
51732
dc68380e6497 8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents: 47216
diff changeset
    81
            ThreadGroup tga = t.getThreadGroup();
dc68380e6497 8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents: 47216
diff changeset
    82
            String groupName;
dc68380e6497 8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents: 47216
diff changeset
    83
            if (tga == null) {
dc68380e6497 8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents: 47216
diff changeset
    84
                groupName = "<completed>";
dc68380e6497 8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents: 47216
diff changeset
    85
                finishedThreads++ ;
dc68380e6497 8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents: 47216
diff changeset
    86
            } else {
dc68380e6497 8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents: 47216
diff changeset
    87
                groupName = tga.getName();
dc68380e6497 8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents: 47216
diff changeset
    88
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            System.out.println("Thread [" + i + "] group = '" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                               groupName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                               "' name = '" + t.getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                               "' daemon = " + t.isDaemon());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            if (groupName.startsWith("JDI ") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                (! t.isDaemon())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                failure("FAIL: non-daemon thread '" + t.getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                        "' found in ThreadGroup '" + groupName + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
51732
dc68380e6497 8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents: 47216
diff changeset
   100
        }
dc68380e6497 8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents: 47216
diff changeset
   101
        if (finishedThreads > 0 ) {
dc68380e6497 8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents: 47216
diff changeset
   102
            failure("FAIL: " + finishedThreads +
dc68380e6497 8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents: 47216
diff changeset
   103
                    " threads completed while VM suspended.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
             * Get to the top of ready()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            startTo("DebuggerThreadTarg", "ready", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            dumpThreads();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
             * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
             * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                println("DebuggerThreadTest: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                throw new Exception("DebuggerThreadTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
}