1 #!/bin/sh 2 3 # 4 # Copyright (c) 2002, 2014, 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 # This is a manual test. The script isn't smart enough 28 # to detect the correct ordering of the output since it 29 # is produced by multiple threads and can be interleaved 30 # in many different ways. 31 # 32 # @bug 4629548 33 # @summary Deferred StepRequests are lost in multithreaded debuggee 34 # @author Jim Holmlund 35 # 36 # @run shell/manual DeferredStepTest.sh 37 38 # Run this script to see the bug. See comments at the end 39 # of the .java file for info on what the bug looks like. 40 41 # These are variables that can be set to control execution 42 43 #pkg=untitled7 44 classname=DeferredStepTest 45 #compileOptions=-g 46 #java=java_g 47 #mode=-Xcomp 48 49 createJavaFile() 50 { 51 cat <<EOF > $classname.java.1 52 public class $classname { 53 static class jj1 implements Runnable { 54 public void run() { 55 int count = 0; 56 57 for ( int ii = 0; ii < 10; ii++) { // line 6 58 int intInPotato04 = 666; // line 7 59 ++count; // line 8; @1 breakpoint 60 System.out.println("Thread: " + Thread.currentThread().getName()); // line 9 61 } 62 } 63 } 64 65 static class jj2 implements Runnable { 66 public void run() { 67 int count2 = 0; 68 69 for (int ii = 0; ii < 10; ii++) { // line 18 70 String StringInPotato05 = "I am"; // line 19 71 ++count2; // line 20; @1 breakpoint 72 System.out.println("Thread: " + Thread.currentThread().getName()); // line 21 73 } 74 } 75 } 76 77 public static void main(String argv[]) { 78 System.out.println("Version = " + System.getProperty("java.version")); 79 80 jj1 aRP = new jj1(); 81 jj2 asRP = new jj2(); 82 new Thread(aRP, "jj1 *").start(); 83 new Thread(asRP, "jj2 **").start(); 84 // new Thread(aRP, "jj3 ***").start(); 85 // new Thread(asRP, "jj4 ****").start(); 86 } 87 } 88 89 /**************************** 90 To see this bug, do this 91 92 jdb DeferredStep 93 stop at DeferredStepTest$jj1:8 94 stop at DeferredStepTest$jj2:20 95 run 96 next 97 next 98 : 99 100 ********/ 101 102 EOF 103 } 104 105 #sleepcmd="sleep 2" 106 107 # This is called to feed cmds to jdb. 108 dojdbCmds() 109 { 110 #set -x 111 # We can't use setBkpts because it can only set bkpts in one class :-( 112 #setBkpts @1 113 cmd stop at $classname'$jj1:8' 114 cmd stop at $classname'$jj2:20' 115 #cmd run; $sleepcmd 116 runToBkpt @1 117 cmd next; $sleepcmd 118 cmd next; $sleepcmd 119 cmd next; $sleepcmd 120 cmd next; $sleepcmd 121 cmd next; $sleepcmd 122 cmd next; $sleepcmd 123 cmd next; $sleepcmd 124 cmd next; $sleepcmd 125 cmd next; $sleepcmd 126 cmd next; $sleepcmd 127 cmd next; $sleepcmd 128 cmd next; $sleepcmd 129 cmd next; $sleepcmd 130 cmd next; $sleepcmd 131 cmd next; $sleepcmd 132 } 133 134 mysetup() 135 { 136 if [ -z "$TESTSRC" ] ; then 137 TESTSRC=. 138 fi 139 140 for ii in . $TESTSRC $TESTSRC/.. ; do 141 if [ -r "$ii/ShellScaffold.sh" ] ; then 142 . $ii/ShellScaffold.sh 143 break 144 fi 145 done 146 } 147 148 149 # You could replace this next line with the contents 150 # of ShellScaffold.sh and this script will run just the same. 151 mysetup 152 153 cat <<EOF 154 **************************************************************** 155 This test should be run and checked manually. 156 157 If this works right, you should see StepEvents/Breakpoint events for lines 158 8, 9, 6, 7, 8, 9, 6, .... for thread jj11 159 and 160 20, 21, 18, 19, 20, 21, 18, ... for thread jj2 161 162 Since both threads are running at the same time, these 163 events can be intermixed. 164 165 The bug is that you will frequently see step events missing. 166 EG, you will see 167 8, 9, 8 168 or 169 20, 21, 20, 21 170 etc 171 172 ============================================================ 173 At some point you might get the msg 'Nothing suspended' 174 This is bug: 175 4619349 Step Over fails in a multi threaded debuggee 176 177 Kill the test and rerun it if this happens. 178 **************************************************************** 179 180 EOF 181 runit 182 #jdbFailIfPresent "Nothing suspended" 183 #pass | 1 /* 2 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4629548 27 * @summary Deferred StepRequests are lost in multithreaded debuggee 28 * @comment converted from test/jdk/com/sun/jdi/DeferredStepTest.sh 29 * 30 * @library /test/lib 31 * @build DeferredStepTest 32 * @run main/othervm DeferredStepTest 33 */ 34 35 import jdk.test.lib.Asserts; 36 import jdk.test.lib.Utils; 37 import lib.jdb.JdbCommand; 38 import lib.jdb.JdbTest; 39 40 import java.util.HashMap; 41 import java.util.List; 42 import java.util.Map; 43 import java.util.regex.Matcher; 44 import java.util.regex.Pattern; 45 import java.util.stream.Collectors; 46 47 class DeferredStepTestTarg { 48 static class jj1 implements Runnable { 49 public void run() { 50 int count = 0; 51 52 for ( int ii = 0; ii < 10; ii++) { 53 int intInPotato04 = 666; 54 ++count; // @1 breakpoint 55 System.out.println("Thread: " + Thread.currentThread().getName()); 56 } 57 } 58 } 59 60 static class jj2 implements Runnable { 61 public void run() { 62 int count2 = 0; 63 64 for (int ii = 0; ii < 10; ii++) { 65 String StringInPotato05 = "I am"; 66 ++count2; // @2 breakpoint 67 System.out.println("Thread: " + Thread.currentThread().getName()); 68 } 69 } 70 } 71 72 public static void main(String argv[]) { 73 System.out.println("Version = " + System.getProperty("java.version")); 74 75 jj1 aRP = new jj1(); 76 jj2 asRP = new jj2(); 77 new Thread(aRP, "jj1").start(); 78 new Thread(asRP, "jj2").start(); 79 // new Thread(aRP, "jj3").start(); 80 // new Thread(asRP, "jj4").start(); 81 } 82 } 83 84 public class DeferredStepTest extends JdbTest { 85 public static void main(String argv[]) { 86 new DeferredStepTest().run(); 87 } 88 89 private DeferredStepTest() { 90 super(DeferredStepTestTarg.class.getName()); 91 } 92 93 private static class ThreadData { 94 // line of the last stop 95 int lastLine = -1; 96 // min line (-1 means "not known yet") 97 int minLine = -1; 98 // max line (-1 means "not known yet") 99 int maxLine = -1; 100 } 101 102 private Map<String, ThreadData> threadData = new HashMap<>(); 103 104 private Pattern threadRegexp = Pattern.compile("^(.+)\\[\\d+\\].*"); 105 private Pattern lineRegexp = Pattern.compile("^(\\d+)\\b.*", Pattern.MULTILINE); 106 107 // returns the 1st group of the pattern. 108 private String parse(Pattern p, String input) { 109 Matcher m = p.matcher(input); 110 if (!m.find()) { 111 throw new RuntimeException("Input '" + input + "' does not matches '" + p.pattern() + "'"); 112 } 113 return m.group(1); 114 } 115 116 private void next() { 117 List<String> reply = jdb.command(JdbCommand.next()); 118 /* each "next" produces something like ("Breakpoint hit" line only if the line has BP) 119 Step completed: 120 Breakpoint hit: "thread=jj2", DeferredStepTestTarg$jj2.run(), line=74 bci=12 121 74 ++count2; // @2 breakpoint 122 <empty line> 123 jj2[1] 124 */ 125 // detect thread from the last line 126 String lastLine = reply.get(reply.size() - 1); 127 String threadName = parse(threadRegexp, lastLine); 128 String wholeReply = reply.stream().collect(Collectors.joining(Utils.NEW_LINE)); 129 int lineNum = Integer.parseInt(parse(lineRegexp, wholeReply)); 130 131 System.out.println("got: thread=" + threadName + ", line=" + lineNum); 132 133 ThreadData data = threadData.get(threadName); 134 if (data == null) { 135 data = new ThreadData(); 136 threadData.put(threadName, data); 137 } 138 do { 139 if (data.lastLine < 0) { 140 // the 1st stop in the thread 141 break; 142 } 143 if (lineNum == data.lastLine + 1) { 144 // expected. 145 break; 146 } 147 if (lineNum < data.lastLine) { 148 // looks like step to the beginning of the cycle 149 if (data.minLine > 0) { 150 // minLine and maxLine are not set - verify 151 Asserts.assertEquals(lineNum, data.minLine, threadName + " - minLine"); 152 Asserts.assertEquals(data.lastLine, data.maxLine, threadName + " - maxLine"); 153 } else { 154 // set minLine/maxLine 155 data.minLine = lineNum; 156 data.maxLine = data.lastLine; 157 } 158 break; 159 } 160 // 161 throw new RuntimeException(threadName + " (line " + lineNum + ") - unexpected." 162 + " lastLine=" + data.lastLine + ", minLine=" + data.minLine + ", maxLine=" + data.maxLine); 163 } while (false); 164 data.lastLine = lineNum; 165 } 166 167 @Override 168 protected void runCases() { 169 setBreakpoints(jdb, DeferredStepTestTarg.jj1.class.getName(), 170 getTestSourcePath("DeferredStepTest.java"), 1); 171 setBreakpoints(jdb, DeferredStepTestTarg.jj2.class.getName(), 172 getTestSourcePath("DeferredStepTest.java"), 2); 173 174 // Run to breakpoint #1 175 jdb.command(JdbCommand.run()); 176 177 // 2 cycles with 4 lines each - maximum 80 stops 178 for (int i=0; i<50; i++) { 179 next(); 180 } 181 } 182 } |