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 4705330
27  * @summary Netbeans Fix and Continue crashes JVM
28  * @comment converted from test/jdk/com/sun/jdi/RedefineClearBreakpoint.sh
29  *
30  * @library /test/lib
31  * @compile -g RedefineClearBreakpoint.java
32  * @run main/othervm RedefineClearBreakpoint
33  */
34 
35 /*
36  * The failure occurs after a breakpoint is set and then cleared
37  * after a class redefinition, in a method that was EMCP.
38  * This sequence creates a state in which subsequent operations
39  * such as accessing local vars via JVMDI, can cause a hotspot crash.
40  */
41 
42 import jdk.test.lib.Asserts;
43 import jdk.test.lib.process.OutputAnalyzer;
44 import lib.jdb.JdbCommand;
45 import lib.jdb.JdbTest;
46 
47 import java.util.List;
48 
49 class RedefineClearBreakpointTarg {
50 
RedefineClearBreakpointTarg()51     public RedefineClearBreakpointTarg() {
52         int a=23;
53         a=m(a);
54     }
m(int b)55     public int m(int b){
56         int bb=89;
57         System.out.println("RedefineClearBreakpointTarg -  constructor" + b); //@1 breakpoint
58         return b*b;
59     }
60 
main(java.lang.String[] args)61     public static void main(java.lang.String[] args) {
62         new RedefineClearBreakpointTarg();
63         int jj = 0;   //@1 delete
64     }
65 
66 }
67 
68 
69 public class RedefineClearBreakpoint extends JdbTest {
70 
main(String argv[])71     public static void main(String argv[]) {
72         new RedefineClearBreakpoint().run();
73     }
74 
RedefineClearBreakpoint()75     private RedefineClearBreakpoint() {
76         super(DEBUGGEE_CLASS, SOURCE_FILE);
77     }
78 
79     private static final String DEBUGGEE_CLASS = RedefineClearBreakpointTarg.class.getName();
80     private static final String SOURCE_FILE = "RedefineClearBreakpoint.java";
81 
82     @Override
runCases()83     protected void runCases() {
84         List<Integer> bps = parseBreakpoints(getTestSourcePath(SOURCE_FILE), 1);
85         Asserts.assertEquals(bps.size(), 1, "unexpected breakpoint count");
86         jdb.command(JdbCommand.stopAt(DEBUGGEE_CLASS, bps.get(0)));
87         jdb.command(JdbCommand.run());
88         redefineClass(1, "-g");
89 
90         jdb.command(JdbCommand.stopAt(DEBUGGEE_CLASS, bps.get(0)));
91         jdb.command(JdbCommand.next());     // This is needed to make the crash happen at the 'locals' cmd
92 
93         jdb.command(JdbCommand.clear(DEBUGGEE_CLASS, bps.get(0)));
94         jdb.command(JdbCommand.locals());   // The crash happens here
95 
96         new OutputAnalyzer(getDebuggeeOutput())
97                 .shouldNotContain("Internal exception:");
98     }
99 }
100