2
|
1 |
/** hard coded linenumbers in this test - DO NOT CHANGE
|
|
2 |
* @test/nodynamiccopyright/
|
|
3 |
* @bug 4359312 4450091
|
|
4 |
* @summary Test PTR 1421 JVM exceptions making a call to LocalVariable.type().name()
|
|
5 |
*
|
|
6 |
* @author Tim Bell (based on the PTR 1421 report submitted by IBM).
|
|
7 |
*
|
|
8 |
* @run build TestScaffold VMConnection TargetListener TargetAdapter
|
|
9 |
* @run compile -g GetLocalVariables.java
|
|
10 |
* @run main GetLocalVariables
|
|
11 |
*/
|
|
12 |
import com.sun.jdi.*;
|
|
13 |
import com.sun.jdi.event.*;
|
|
14 |
import com.sun.jdi.request.*;
|
|
15 |
|
|
16 |
import java.util.*;
|
|
17 |
|
|
18 |
/********** target program **********/
|
|
19 |
|
|
20 |
class GetLocalVariablesTarg {
|
|
21 |
private static char s_char1 = 'a';
|
|
22 |
private static char s_char2 = (char) 0;
|
|
23 |
private static char s_char3 = (char) 1;
|
|
24 |
private static char s_char4 = (char) 32;
|
|
25 |
private static char s_char5 = '\u7ffe';
|
|
26 |
private static char s_char6 = '\u7fff';
|
|
27 |
private static char s_char7 = '\u8000';
|
|
28 |
private static char s_char8 = '\u8001';
|
|
29 |
private static char s_char9 = '\ufffe';
|
|
30 |
private static char s_char10 = '\uffff';
|
|
31 |
|
|
32 |
private static byte s_byte1 = (byte) 146;
|
|
33 |
private static byte s_byte2 = (byte) 0;
|
|
34 |
private static byte s_byte3 = (byte) 1;
|
|
35 |
private static byte s_byte4 = (byte) 15;
|
|
36 |
private static byte s_byte5 = (byte) 127;
|
|
37 |
private static byte s_byte6 = (byte) 128;
|
|
38 |
private static byte s_byte7 = (byte) - 1;
|
|
39 |
private static byte s_byte8 = (byte) - 15;
|
|
40 |
private static byte s_byte9 = (byte) - 127;
|
|
41 |
private static byte s_byte10 = (byte) - 128;
|
|
42 |
|
|
43 |
private static short s_short1 = (short) 28123;
|
|
44 |
private static short s_short2 = (short) 0;
|
|
45 |
private static short s_short3 = (short) 1;
|
|
46 |
private static short s_short4 = (short) 15;
|
|
47 |
private static short s_short5 = (short) 0x7ffe;
|
|
48 |
private static short s_short6 = (short) 0x7fff;
|
|
49 |
private static short s_short7 = (short) -1;
|
|
50 |
private static short s_short8 = (short) -15;
|
|
51 |
private static short s_short9 = (short) -0x7ffe;
|
|
52 |
private static short s_short10 = (short) -0x7fff;
|
|
53 |
|
|
54 |
private static int s_int1 = 3101246;
|
|
55 |
private static int s_int2 = 0;
|
|
56 |
private static int s_int3 = 1;
|
|
57 |
private static int s_int4 = 15;
|
|
58 |
private static int s_int5 = 0x7ffffffe;
|
|
59 |
private static int s_int6 = 0x7fffffff;
|
|
60 |
private static int s_int7 = -1;
|
|
61 |
private static int s_int8 = -15;
|
|
62 |
private static int s_int9 = -0x7ffffffe;
|
|
63 |
private static int s_int10 = -0x7fffffff;
|
|
64 |
|
|
65 |
private static long s_long1 = 0x0123456789ABCDEFL;
|
|
66 |
private static long s_long2 = 0;
|
|
67 |
private static long s_long3 = 1;
|
|
68 |
private static long s_long4 = 15;
|
|
69 |
private static long s_long5 = 0x000000007fffffffL;
|
|
70 |
private static long s_long6 = 0x0000000080000000L;
|
|
71 |
private static long s_long7 = 0x0000000100000000L;
|
|
72 |
private static long s_long8 = 0x7fffffffffffffffL;
|
|
73 |
private static long s_long9 = 0x8000000000000000L;
|
|
74 |
private static long s_long10 = -15;
|
|
75 |
|
|
76 |
private static float s_float1 = 2.3145f;
|
|
77 |
private static float s_float2 = 0f;
|
|
78 |
|
|
79 |
private static double s_double1 = 1.469d;
|
|
80 |
private static double s_double2 = 0;
|
|
81 |
|
|
82 |
private static int s_iarray1[] = {1, 2, 3};
|
|
83 |
private static int s_iarray2[] = null;
|
|
84 |
|
|
85 |
private static int s_marray1[][] = {{1, 2, 3}, {3, 4, 5}, null, {6, 7}};
|
|
86 |
private static int s_marray2[][] = null;
|
|
87 |
|
|
88 |
private static String s_sarray1[] = {"abc", null, "def", "ghi"};
|
|
89 |
private static String s_sarray2[] = null;
|
|
90 |
private static Object s_sarray3[] = s_sarray1;
|
|
91 |
|
|
92 |
private static String s_string1 = "abcdef";
|
|
93 |
private static String s_string2 = null;
|
|
94 |
private static String s_string3 = "a\u1234b\u7777";
|
|
95 |
|
|
96 |
private char i_char;
|
|
97 |
private byte i_byte;
|
|
98 |
private short i_short;
|
|
99 |
private int i_int;
|
|
100 |
private long i_long;
|
|
101 |
private float i_float;
|
|
102 |
private double i_double;
|
|
103 |
private int i_iarray[];
|
|
104 |
private int i_marray[][];
|
|
105 |
private String i_string;
|
|
106 |
|
|
107 |
public GetLocalVariablesTarg()
|
|
108 |
{
|
|
109 |
int index;
|
|
110 |
|
|
111 |
i_char = 'B';
|
|
112 |
i_byte = 120;
|
|
113 |
i_short = 12048;
|
|
114 |
i_int = 0x192842;
|
|
115 |
i_long = 123591230941L;
|
|
116 |
i_float = 235.15e5f;
|
|
117 |
i_double = 176e-1d;
|
|
118 |
i_iarray = new int[5];
|
|
119 |
i_marray = new int[7][];
|
|
120 |
i_string = "empty";
|
|
121 |
|
|
122 |
for (index = 0; index < i_iarray.length; ++index)
|
|
123 |
i_iarray[index] = index + 1;
|
|
124 |
|
|
125 |
i_marray[0] = new int[2];
|
|
126 |
i_marray[1] = new int[4];
|
|
127 |
i_marray[2] = null;
|
|
128 |
i_marray[3] = new int[1];
|
|
129 |
i_marray[4] = new int[3];
|
|
130 |
i_marray[5] = null;
|
|
131 |
i_marray[6] = new int[7];
|
|
132 |
|
|
133 |
for (index = 0; index < i_marray.length; ++index)
|
|
134 |
if (i_marray[index] != null)
|
|
135 |
for (int index2 = 0; index2 < i_marray[index].length; ++index2)
|
|
136 |
i_marray[index][index2] = index + index2;
|
|
137 |
}
|
|
138 |
|
|
139 |
public GetLocalVariablesTarg(char p_char, byte p_byte, short p_short,
|
|
140 |
int p_int, long p_long, float p_float,
|
|
141 |
double p_double, int p_iarray[], int p_marray[][],
|
|
142 |
String p_string)
|
|
143 |
{
|
|
144 |
i_char = p_char;
|
|
145 |
i_byte = p_byte;
|
|
146 |
i_short = p_short;
|
|
147 |
i_int = p_int;
|
|
148 |
i_long = p_long;
|
|
149 |
i_float = p_float;
|
|
150 |
i_double = p_double;
|
|
151 |
i_iarray = p_iarray;
|
|
152 |
i_marray = p_marray;
|
|
153 |
i_string = p_string;
|
|
154 |
}
|
|
155 |
|
|
156 |
public static void test_expressions()
|
|
157 |
{
|
|
158 |
GetLocalVariablesTarg e1 = new GetLocalVariablesTarg();
|
|
159 |
GetLocalVariablesTarg e2 = null;
|
|
160 |
GetLocalVariablesTarg e3 = e1;
|
|
161 |
GetLocalVariablesTarg e4 = new GetLocalVariablesTarg(s_char1, s_byte1, s_short1, s_int1,
|
|
162 |
s_long1, s_float1, s_double1,
|
|
163 |
s_iarray1, s_marray1, "e4");
|
|
164 |
GetLocalVariablesTarg e5 = new GetLocalVariablesTarg(s_char2, s_byte2, s_short2, s_int2,
|
|
165 |
s_long2, s_float2, s_double2,
|
|
166 |
s_iarray2, s_marray2, "e5");
|
|
167 |
|
|
168 |
char l_char = (char) (
|
|
169 |
s_char1 + s_char2 + s_char3 + s_char4 + s_char5 +
|
|
170 |
s_char6 + s_char7 + s_char8 + s_char9 + s_char10);
|
|
171 |
byte l_byte = (byte) (
|
|
172 |
s_byte1 + s_byte2 + s_byte3 + s_byte4 + s_byte5 +
|
|
173 |
s_byte6 + s_byte7 + s_byte8 + s_byte9 + s_byte10);
|
|
174 |
short l_short = (short) (
|
|
175 |
s_short1 + s_short2 + s_short3 + s_short4 + s_short5 +
|
|
176 |
s_short6 + s_short7 + s_short8 + s_short9 + s_short10);
|
|
177 |
int l_int = s_int1 + s_int2 + s_int3 + s_int4 + s_int5 +
|
|
178 |
s_int6 + s_int7 + s_int8 + s_int9 + s_int10;
|
|
179 |
long l_long = s_long1 + s_long2 + s_long3 + s_long4 + s_long5 +
|
|
180 |
s_long6 + s_long7 + s_long8 + s_long9 + s_long10;
|
|
181 |
float l_float = s_float1 + s_float2;
|
|
182 |
double l_double = s_double1 + s_double2;
|
|
183 |
int[] l_iarray = null;
|
|
184 |
int[][] l_marray = null;
|
|
185 |
String l_string = s_string1 + s_string3 + s_sarray1[0];
|
|
186 |
|
|
187 |
if (s_sarray2 == null)
|
|
188 |
l_string += "?";
|
|
189 |
|
|
190 |
if (s_sarray3 instanceof String[])
|
|
191 |
l_string += "<io>";
|
|
192 |
|
|
193 |
Object e6 = new GetLocalVariablesTarg(l_char, l_byte, l_short, l_int,
|
|
194 |
l_long, l_float, l_double, l_iarray,
|
|
195 |
l_marray, l_string);
|
|
196 |
|
|
197 |
e1.test_1(); // <-- this is line 197
|
|
198 |
e3.test_1();
|
|
199 |
e4.test_1();
|
|
200 |
e5.test_1();
|
|
201 |
((GetLocalVariablesTarg) e6).test_1();
|
|
202 |
|
|
203 |
e3 = null;
|
|
204 |
if (e3 == e1)
|
|
205 |
e3.test_1();
|
|
206 |
e3 = e4;
|
|
207 |
if (e3 == e2)
|
|
208 |
e3 = e5;
|
|
209 |
e3.test_1();
|
|
210 |
|
|
211 |
}
|
|
212 |
|
|
213 |
public void test_1()
|
|
214 |
{
|
|
215 |
double l_add = i_double + i_short;
|
|
216 |
long l_subtract = i_long - i_int;
|
|
217 |
long l_multiply = i_byte * i_int;
|
|
218 |
|
|
219 |
i_double = l_add + i_float;
|
|
220 |
i_short = (short) l_subtract;
|
|
221 |
i_long = l_multiply + i_byte + i_short;
|
|
222 |
}
|
|
223 |
|
|
224 |
public static void main(String[] args) {
|
|
225 |
System.out.println("Howdy!");
|
|
226 |
test_expressions();
|
|
227 |
System.out.println("Goodbye from GetLocalVariablesTarg!");
|
|
228 |
}
|
|
229 |
}
|
|
230 |
|
|
231 |
/********** test program **********/
|
|
232 |
|
|
233 |
public class GetLocalVariables extends TestScaffold {
|
|
234 |
ReferenceType targetClass;
|
|
235 |
ThreadReference mainThread;
|
|
236 |
|
|
237 |
GetLocalVariables (String args[]) {
|
|
238 |
super(args);
|
|
239 |
}
|
|
240 |
|
|
241 |
public static void main(String[] args)
|
|
242 |
throws Exception
|
|
243 |
{
|
|
244 |
new GetLocalVariables (args).startTests();
|
|
245 |
}
|
|
246 |
|
|
247 |
/********** test core **********/
|
|
248 |
|
|
249 |
protected void runTests()
|
|
250 |
throws Exception
|
|
251 |
{
|
|
252 |
/*
|
|
253 |
* Get to the top of main() to determine targetClass and mainThread
|
|
254 |
*/
|
|
255 |
BreakpointEvent bpe = startToMain("GetLocalVariablesTarg");
|
|
256 |
targetClass = bpe.location().declaringType();
|
|
257 |
mainThread = bpe.thread();
|
|
258 |
EventRequestManager erm = vm().eventRequestManager();
|
|
259 |
|
|
260 |
bpe = resumeTo("GetLocalVariablesTarg", 197);
|
|
261 |
/*
|
|
262 |
* We've arrived. Look around at some variables.
|
|
263 |
*/
|
|
264 |
StackFrame frame = bpe.thread().frame(0);
|
|
265 |
List localVars = frame.visibleVariables();
|
|
266 |
System.out.println(" Visible variables at this point are: ");
|
|
267 |
for (Iterator it = localVars.iterator(); it.hasNext();) {
|
|
268 |
LocalVariable lv = (LocalVariable) it.next();
|
|
269 |
System.out.print(lv.name());
|
|
270 |
System.out.print(" typeName: ");
|
|
271 |
System.out.print(lv.typeName());
|
|
272 |
System.out.print(" signature: ");
|
|
273 |
System.out.print(lv.type().signature());
|
|
274 |
System.out.print(" primitive type: ");
|
|
275 |
System.out.println(lv.type().name());
|
|
276 |
}
|
|
277 |
|
|
278 |
/*
|
|
279 |
* resume the target listening for events
|
|
280 |
*/
|
|
281 |
listenUntilVMDisconnect();
|
|
282 |
|
|
283 |
/*
|
|
284 |
* deal with results of test if anything has called failure("foo")
|
|
285 |
* testFailed will be true
|
|
286 |
*/
|
|
287 |
if (!testFailed) {
|
|
288 |
println("GetLocalVariables: passed");
|
|
289 |
} else {
|
|
290 |
throw new Exception("GetLocalVariables: failed");
|
|
291 |
}
|
|
292 |
}
|
|
293 |
}
|