1 #!/bin/sh 2 3 # 4 # Copyright (c) 2005, 2015 Oracle and/or its affiliates. All rights reserved. 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 # 7 # This code is free software; you can redistribute it and/or modify it 8 # under the terms of the GNU General Public License version 2 only, as 9 # published by the Free Software Foundation. 10 # 11 # This code is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 # version 2 for more details (a copy is included in the LICENSE file that 15 # accompanied this code). 16 # 17 # You should have received a copy of the GNU General Public License version 18 # 2 along with this work; if not, write to the Free Software Foundation, 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 # or visit www.oracle.com if you need additional information or have any 23 # questions. 24 # 25 26 # @test 27 # @bug 6224859 28 # @summary JDWP: Mixing application suspends and debugger suspends can cause hangs 29 # 30 # @author Jim Holmlund 31 # 32 # @key intermittent 33 # @modules jdk.jdi 34 # @run build TestScaffold VMConnection TargetListener TargetAdapter 35 # @run shell MixedSuspendTest.sh 36 37 classname=MixedSuspendTarg 38 39 createJavaFile() 40 { 41 cat <<EOF > $classname.java.1 42 43 import java.util.*; 44 45 public class $classname extends Thread { 46 47 static volatile boolean started = true; 48 static String lock = "startLock"; 49 50 public static void main(String[] args){ 51 System.out.println("Howdy from MixedSuspendTarg"); 52 53 MixedSuspendTarg mytarg = new MixedSuspendTarg(); 54 55 synchronized(lock) { 56 mytarg.start(); 57 try { 58 lock.wait(); 59 } catch(InterruptedException ee) { 60 } 61 } 62 mytarg.suspend(); 63 bkpt(); 64 System.out.println("Debuggee: resuming thread"); 65 66 // If the bug occurs, this resume hangs in the back-end 67 mytarg.resume(); 68 System.out.println("Debuggee: resumed thread"); 69 synchronized(lock) { 70 started = false; 71 } 72 System.out.println("Debuggee: exitting, started = " + started); 73 } 74 75 public void run() { 76 synchronized(lock) { 77 lock.notifyAll(); 78 } 79 while (true) { 80 synchronized(lock) { 81 if (!started) { 82 break; 83 } 84 int i = 0; 85 } 86 } 87 88 System.out.println("Debuggee: end of thread"); 89 } 90 91 static void bkpt() { 92 //System.out.println("bkpt reached, thread = " + this.getName()); 93 int i = 0; // @1 breakpoint 94 } 95 } 96 97 EOF 98 } 99 100 dojdbCmds() 101 { 102 setBkpts @1 103 runToBkpt @1 104 cmd allowExit cont 105 } 106 107 108 mysetup() 109 { 110 if [ -z "$TESTSRC" ] ; then 111 TESTSRC=. 112 fi 113 114 for ii in . $TESTSRC $TESTSRC/.. ; do 115 if [ -r "$ii/ShellScaffold.sh" ] ; then 116 . $ii/ShellScaffold.sh 117 break 118 fi 119 done 120 } 121 122 # You could replace this next line with the contents 123 # of ShellScaffold.sh and this script will run just the same. 124 mysetup 125 126 runit 127 ## This test fails by timing out. 128 pass