author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 51837 | 46ca82c15f6c |
permissions | -rw-r--r-- |
51837
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
1 |
/* |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
4 |
* |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
7 |
* published by the Free Software Foundation. |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
8 |
* |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
13 |
* accompanied this code). |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
14 |
* |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
18 |
* |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
21 |
* questions. |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
22 |
*/ |
2 | 23 |
|
51837
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
24 |
/* |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
25 |
* @test |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
26 |
* @bug 4724076 |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
27 |
* @summary Redefine does not work in for/while loop |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
28 |
* @comment converted from test/jdk/com/sun/jdi/RedefineMulti.sh |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
29 |
* |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
30 |
* @library /test/lib |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
31 |
* @compile -g RedefineMulti.java |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
32 |
* @run main/othervm RedefineMulti |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
33 |
*/ |
2 | 34 |
|
51837
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
35 |
/* |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
36 |
* The failure occurs when a method is active and |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
37 |
* a method that it calls multiple times is redefined |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
38 |
* more than once. |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
39 |
*/ |
2 | 40 |
|
51837
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
41 |
import jdk.test.lib.process.OutputAnalyzer; |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
42 |
import lib.jdb.JdbCommand; |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
43 |
import lib.jdb.JdbTest; |
2 | 44 |
|
51837
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
45 |
class RedefineMultiTarg { |
2 | 46 |
|
47 |
String field1; |
|
48 |
String field2; |
|
49 |
||
50 |
// The first time thru the loop in start, |
|
51 |
// "Before update..." should be printed. |
|
52 |
// After the first redefine, "After update..." should be printed |
|
53 |
// After the 2nd redefine, "abcde..." should be printed. |
|
54 |
// The bug is that "After update..." is printed instead because |
|
55 |
// stat() calls version 2 of doSomething() instead of |
|
56 |
// version 3. |
|
57 |
private void doSomething() { |
|
58 |
System.out.println("Before update..."); // @1 commentout |
|
59 |
// @1 uncomment System.out.println("After update..."); // @2 commentout |
|
60 |
// @2 uncomment System.out.println("abcde..."); |
|
61 |
} |
|
62 |
||
63 |
public void start() { |
|
64 |
for (int i=0; i < 3; i++) { |
|
65 |
doSomething(); // @1 breakpoint here line 16 |
|
66 |
System.out.println("field1 = " + field1); |
|
67 |
System.out.println("field2 = " + field2); |
|
68 |
} |
|
69 |
// Redefinex myx = new Redefinex(); |
|
70 |
// for (int i = 0; i < 5; i++) { |
|
71 |
// myx.methodx1(); // line 22 |
|
72 |
// System.out.println("fieldx1 = " + myx.fieldx1); |
|
73 |
// System.out.println("fieldx2 = " + myx.fieldx2); |
|
74 |
// } |
|
75 |
} |
|
76 |
||
77 |
public static void main(String[] args) { |
|
51837
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
78 |
RedefineMultiTarg xxx = new RedefineMultiTarg(); |
2 | 79 |
xxx.field1 = "field1"; |
80 |
xxx.field2 = "field2"; |
|
81 |
xxx.start(); |
|
82 |
} |
|
83 |
} |
|
84 |
||
85 |
class Redefinex { |
|
86 |
public String fieldx1; |
|
87 |
public String fieldx2; |
|
88 |
||
89 |
Redefinex() { |
|
90 |
fieldx1 = "fieldx1"; |
|
91 |
fieldx2 = "fieldx2"; |
|
92 |
} |
|
93 |
||
94 |
public void methodx1() { |
|
95 |
System.out.println("redefinex 1"); |
|
96 |
//System.out.println("redefinex 2"); |
|
97 |
//System.out.println("redefinex 3"); |
|
98 |
} |
|
99 |
} |
|
100 |
||
51837
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
101 |
/********* |
2 | 102 |
Steps to reproduce this problem: |
103 |
a. add line breakpoint in start() |
|
104 |
b. debug |
|
51837
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
105 |
c. when breakpoint is hit, type continue. You should see output "Before update..." |
2 | 106 |
d. change "Before update" to "After update" |
107 |
e. redefine, and set line breakpoint (see step a) |
|
108 |
f. type continue. You should see output "After update" |
|
109 |
g. change "After update" to "abcde" |
|
110 |
h. redefine, and set line breakpoint (see step a) |
|
111 |
i. type continue. The output is shown as "After update" |
|
51837
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
112 |
j. to see "abcde" output, users will have to pop the stack, and re-execute method start(). |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
113 |
************/ |
2 | 114 |
|
51837
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
115 |
public class RedefineMulti extends JdbTest { |
2 | 116 |
|
51837
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
117 |
public static void main(String argv[]) { |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
118 |
new RedefineMulti().run(); |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
119 |
} |
2 | 120 |
|
51837
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
121 |
private RedefineMulti() { |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
122 |
super(RedefineMultiTarg.class.getName(), "RedefineMulti.java"); |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
123 |
} |
2 | 124 |
|
51837
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
125 |
@Override |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
126 |
protected void runCases() { |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
127 |
setBreakpoints(1); |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
128 |
jdb.command(JdbCommand.run()); |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
129 |
jdb.command(JdbCommand.cont()); |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
130 |
redefineClass(1, "-g"); |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
131 |
setBreakpoints(1); |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
132 |
jdb.command(JdbCommand.cont()); |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
133 |
redefineClass(2, "-g"); |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
134 |
jdb.contToExit(1); |
2 | 135 |
|
51837
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
136 |
new OutputAnalyzer(getDebuggeeOutput()) |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
137 |
.shouldNotContain("Internal exception:") |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
138 |
.shouldContain("abcde"); |
46ca82c15f6c
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents:
47216
diff
changeset
|
139 |
} |
2 | 140 |
} |