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 4448658
27  * @summary javac produces the inconsistent variable debug in while loops.
28  * @comment converted from test/jdk/com/sun/jdi/GetLocalVariables3Test.sh
29  *
30  * @library /test/lib
31  * @compile -g GetLocalVariables3Test.java
32  * @run main/othervm GetLocalVariables3Test
33  */
34 
35 import jdk.test.lib.process.OutputAnalyzer;
36 import lib.jdb.JdbCommand;
37 import lib.jdb.JdbTest;
38 
39 
40 class GetLocalVariables3Targ {
main(String[] args)41     public static void main(String[] args) {
42         System.out.println("Howdy!");
43         int i = 1, j, k;
44         while ((j = i) > 0) {
45             k = j; i = k - 1;    // @1 breakpoint
46         }
47         System.out.println("Goodbye from GetLocalVariables3Targ!");
48     }
49 }
50 
51 
52 public class GetLocalVariables3Test extends JdbTest {
main(String argv[])53     public static void main(String argv[]) {
54         new GetLocalVariables3Test().run();
55     }
56 
GetLocalVariables3Test()57     private GetLocalVariables3Test() {
58         super(DEBUGGEE_CLASS);
59     }
60 
61     private static final String DEBUGGEE_CLASS = GetLocalVariables3Targ.class.getName();
62 
63     @Override
runCases()64     protected void runCases() {
65         setBreakpointsFromTestSource("GetLocalVariables3Test.java", 1);
66         // Run to breakpoint #1
67         jdb.command(JdbCommand.run());
68 
69         jdb.command(JdbCommand.locals());
70 
71         jdb.contToExit(1);
72 
73         new OutputAnalyzer(getJdbOutput())
74                 .shouldContain("j = 1");
75         new OutputAnalyzer(getDebuggeeOutput())
76                 .shouldContain("Howdy")
77                 .shouldContain("Goodbye from GetLocalVariables3Targ");
78     }
79 
80 }
81