test/jdk/com/sun/jdi/MixedSuspendTest.java
author amenkov
Wed, 05 Sep 2018 10:39:16 -0700
changeset 51648 b7b69bc93a2d
permissions -rw-r--r--
8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3 Reviewed-by: jcbeyler, cjplummer, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51648
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
     1
/*
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
     2
 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
     4
 *
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
     8
 *
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    13
 * accompanied this code).
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    14
 *
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    18
 *
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    21
 * questions.
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    22
 */
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    23
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    24
/*
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    25
 * @test
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    26
 * @bug 6224859
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    27
 * @summary JDWP: Mixing application suspends and debugger suspends can cause hangs
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    28
 * @comment converted from test/jdk/com/sun/jdi/MixedSuspendTest.sh
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    29
 *
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    30
 * @library /test/lib
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    31
 * @run main/othervm MixedSuspendTest
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    32
 */
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    33
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    34
import lib.jdb.JdbCommand;
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    35
import lib.jdb.JdbTest;
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    36
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    37
class MixedSuspendTarg extends Thread {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    38
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    39
    static volatile boolean started = true;
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    40
    static String lock = "startLock";
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    41
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    42
    public static void main(String[] args){
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    43
        System.out.println("Howdy from MixedSuspendTarg");
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    44
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    45
        MixedSuspendTarg mytarg = new MixedSuspendTarg();
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    46
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    47
        synchronized(lock) {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    48
            mytarg.start();
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    49
            try {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    50
                lock.wait();
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    51
            } catch(InterruptedException ee) {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    52
            }
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    53
        }
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    54
        mytarg.suspend();
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    55
        bkpt();
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    56
        System.out.println("Debuggee: resuming thread");
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    57
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    58
        // If the bug occurs, this resume hangs in the back-end
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    59
        mytarg.resume();
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    60
        System.out.println("Debuggee: resumed thread");
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    61
        synchronized(lock) {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    62
            started = false;
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    63
        }
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    64
        System.out.println("Debuggee: exitting, started = " + started);
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    65
    }
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    66
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    67
    public void run() {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    68
        synchronized(lock) {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    69
            lock.notifyAll();
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    70
        }
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    71
        while (true) {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    72
            synchronized(lock) {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    73
                if (!started) {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    74
                    break;
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    75
                }
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    76
                int i = 0;
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    77
            }
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    78
        }
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    79
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    80
        System.out.println("Debuggee: end of thread");
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    81
    }
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    82
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    83
    static void bkpt() {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    84
        //System.out.println("bkpt reached, thread = " + this.getName());
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    85
        int i = 0;   // @1 breakpoint
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    86
    }
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    87
}
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    88
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    89
public class MixedSuspendTest extends JdbTest {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    90
    public static void main(String argv[]) {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    91
        new MixedSuspendTest().run();
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    92
    }
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    93
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    94
    private MixedSuspendTest() {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    95
        super(DEBUGGEE_CLASS);
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    96
    }
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    97
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    98
    private static final String DEBUGGEE_CLASS = MixedSuspendTarg.class.getName();
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
    99
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
   100
    @Override
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
   101
    protected void runCases() {
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
   102
        setBreakpointsFromTestSource("MixedSuspendTest.java", 1);
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
   103
        jdb.command(JdbCommand.run());
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
   104
        jdb.command(JdbCommand.cont().allowExit());
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
   105
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
   106
        // This test fails by timing out.
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
   107
    }
b7b69bc93a2d 8210243: [TEST] rewrite com/sun/jdi shell tests to java version - step3
amenkov
parents:
diff changeset
   108
}