GetLocalVariables.java revision 0
0N/A/** hard coded linenumbers in this test - DO NOT CHANGE
1753N/A * @test/nodynamiccopyright/
0N/A * @bug 4359312 4450091
0N/A * @summary Test PTR 1421 JVM exceptions making a call to LocalVariable.type().name()
0N/A *
0N/A * @author Tim Bell (based on the PTR 1421 report submitted by IBM).
0N/A *
0N/A * @run build TestScaffold VMConnection TargetListener TargetAdapter
0N/A * @run compile -g GetLocalVariables.java
0N/A * @run main GetLocalVariables
0N/A */
0N/Aimport com.sun.jdi.*;
0N/Aimport com.sun.jdi.event.*;
0N/Aimport com.sun.jdi.request.*;
0N/A
0N/Aimport java.util.*;
0N/A
0N/A /********** target program **********/
1472N/A
1472N/Aclass GetLocalVariablesTarg {
1472N/A private static char s_char1 = 'a';
0N/A private static char s_char2 = (char) 0;
0N/A private static char s_char3 = (char) 1;
0N/A private static char s_char4 = (char) 32;
1879N/A private static char s_char5 = '\u7ffe';
1879N/A private static char s_char6 = '\u7fff';
1879N/A private static char s_char7 = '\u8000';
1879N/A private static char s_char8 = '\u8001';
1879N/A private static char s_char9 = '\ufffe';
1879N/A private static char s_char10 = '\uffff';
1879N/A
1879N/A private static byte s_byte1 = (byte) 146;
1879N/A private static byte s_byte2 = (byte) 0;
1879N/A private static byte s_byte3 = (byte) 1;
1879N/A private static byte s_byte4 = (byte) 15;
1879N/A private static byte s_byte5 = (byte) 127;
1879N/A private static byte s_byte6 = (byte) 128;
1879N/A private static byte s_byte7 = (byte) - 1;
1879N/A private static byte s_byte8 = (byte) - 15;
1879N/A private static byte s_byte9 = (byte) - 127;
1879N/A private static byte s_byte10 = (byte) - 128;
0N/A
0N/A private static short s_short1 = (short) 28123;
0N/A private static short s_short2 = (short) 0;
0N/A private static short s_short3 = (short) 1;
0N/A private static short s_short4 = (short) 15;
0N/A private static short s_short5 = (short) 0x7ffe;
481N/A private static short s_short6 = (short) 0x7fff;
481N/A private static short s_short7 = (short) -1;
0N/A private static short s_short8 = (short) -15;
0N/A private static short s_short9 = (short) -0x7ffe;
1753N/A private static short s_short10 = (short) -0x7fff;
1753N/A
1753N/A private static int s_int1 = 3101246;
481N/A private static int s_int2 = 0;
481N/A private static int s_int3 = 1;
481N/A private static int s_int4 = 15;
481N/A private static int s_int5 = 0x7ffffffe;
481N/A private static int s_int6 = 0x7fffffff;
481N/A private static int s_int7 = -1;
481N/A private static int s_int8 = -15;
481N/A private static int s_int9 = -0x7ffffffe;
481N/A private static int s_int10 = -0x7fffffff;
481N/A
0N/A private static long s_long1 = 0x0123456789ABCDEFL;
0N/A private static long s_long2 = 0;
0N/A private static long s_long3 = 1;
0N/A private static long s_long4 = 15;
0N/A private static long s_long5 = 0x000000007fffffffL;
0N/A private static long s_long6 = 0x0000000080000000L;
0N/A private static long s_long7 = 0x0000000100000000L;
0N/A private static long s_long8 = 0x7fffffffffffffffL;
0N/A private static long s_long9 = 0x8000000000000000L;
0N/A private static long s_long10 = -15;
0N/A
0N/A private static float s_float1 = 2.3145f;
0N/A private static float s_float2 = 0f;
0N/A
1166N/A private static double s_double1 = 1.469d;
0N/A private static double s_double2 = 0;
0N/A
1166N/A private static int s_iarray1[] = {1, 2, 3};
1166N/A private static int s_iarray2[] = null;
1166N/A
1468N/A private static int s_marray1[][] = {{1, 2, 3}, {3, 4, 5}, null, {6, 7}};
1194N/A private static int s_marray2[][] = null;
1194N/A
1166N/A private static String s_sarray1[] = {"abc", null, "def", "ghi"};
1166N/A private static String s_sarray2[] = null;
1166N/A private static Object s_sarray3[] = s_sarray1;
1166N/A
0N/A private static String s_string1 = "abcdef";
0N/A private static String s_string2 = null;
0N/A private static String s_string3 = "a\u1234b\u7777";
0N/A
0N/A private char i_char;
0N/A private byte i_byte;
0N/A private short i_short;
0N/A private int i_int;
0N/A private long i_long;
0N/A private float i_float;
0N/A private double i_double;
2098N/A private int i_iarray[];
0N/A private int i_marray[][];
0N/A private String i_string;
0N/A
0N/A public GetLocalVariablesTarg()
0N/A {
0N/A int index;
0N/A
0N/A i_char = 'B';
0N/A i_byte = 120;
0N/A i_short = 12048;
0N/A i_int = 0x192842;
0N/A i_long = 123591230941L;
0N/A i_float = 235.15e5f;
0N/A i_double = 176e-1d;
0N/A i_iarray = new int[5];
0N/A i_marray = new int[7][];
0N/A i_string = "empty";
0N/A
0N/A for (index = 0; index < i_iarray.length; ++index)
0N/A i_iarray[index] = index + 1;
0N/A
0N/A i_marray[0] = new int[2];
0N/A i_marray[1] = new int[4];
0N/A i_marray[2] = null;
0N/A i_marray[3] = new int[1];
0N/A i_marray[4] = new int[3];
0N/A i_marray[5] = null;
0N/A i_marray[6] = new int[7];
0N/A
0N/A for (index = 0; index < i_marray.length; ++index)
0N/A if (i_marray[index] != null)
0N/A for (int index2 = 0; index2 < i_marray[index].length; ++index2)
0N/A i_marray[index][index2] = index + index2;
0N/A }
0N/A
0N/A public GetLocalVariablesTarg(char p_char, byte p_byte, short p_short,
0N/A int p_int, long p_long, float p_float,
0N/A double p_double, int p_iarray[], int p_marray[][],
0N/A String p_string)
0N/A {
0N/A i_char = p_char;
0N/A i_byte = p_byte;
0N/A i_short = p_short;
0N/A i_int = p_int;
0N/A i_long = p_long;
0N/A i_float = p_float;
0N/A i_double = p_double;
0N/A i_iarray = p_iarray;
0N/A i_marray = p_marray;
0N/A i_string = p_string;
0N/A }
0N/A
0N/A public static void test_expressions()
0N/A {
0N/A GetLocalVariablesTarg e1 = new GetLocalVariablesTarg();
0N/A GetLocalVariablesTarg e2 = null;
0N/A GetLocalVariablesTarg e3 = e1;
0N/A GetLocalVariablesTarg e4 = new GetLocalVariablesTarg(s_char1, s_byte1, s_short1, s_int1,
0N/A s_long1, s_float1, s_double1,
0N/A s_iarray1, s_marray1, "e4");
0N/A GetLocalVariablesTarg e5 = new GetLocalVariablesTarg(s_char2, s_byte2, s_short2, s_int2,
0N/A s_long2, s_float2, s_double2,
0N/A s_iarray2, s_marray2, "e5");
1027N/A
1027N/A char l_char = (char) (
1027N/A s_char1 + s_char2 + s_char3 + s_char4 + s_char5 +
1166N/A s_char6 + s_char7 + s_char8 + s_char9 + s_char10);
1027N/A byte l_byte = (byte) (
1027N/A s_byte1 + s_byte2 + s_byte3 + s_byte4 + s_byte5 +
1027N/A s_byte6 + s_byte7 + s_byte8 + s_byte9 + s_byte10);
1027N/A short l_short = (short) (
1027N/A s_short1 + s_short2 + s_short3 + s_short4 + s_short5 +
1166N/A s_short6 + s_short7 + s_short8 + s_short9 + s_short10);
1027N/A int l_int = s_int1 + s_int2 + s_int3 + s_int4 + s_int5 +
1027N/A s_int6 + s_int7 + s_int8 + s_int9 + s_int10;
1027N/A long l_long = s_long1 + s_long2 + s_long3 + s_long4 + s_long5 +
1027N/A s_long6 + s_long7 + s_long8 + s_long9 + s_long10;
1027N/A float l_float = s_float1 + s_float2;
1027N/A double l_double = s_double1 + s_double2;
1027N/A int[] l_iarray = null;
1027N/A int[][] l_marray = null;
1027N/A String l_string = s_string1 + s_string3 + s_sarray1[0];
1027N/A
1027N/A if (s_sarray2 == null)
1027N/A l_string += "?";
1027N/A
1027N/A if (s_sarray3 instanceof String[])
1027N/A l_string += "<io>";
1027N/A
1027N/A Object e6 = new GetLocalVariablesTarg(l_char, l_byte, l_short, l_int,
1027N/A l_long, l_float, l_double, l_iarray,
1027N/A l_marray, l_string);
1027N/A
1027N/A e1.test_1(); // <-- this is line 197
1027N/A e3.test_1();
1027N/A e4.test_1();
1027N/A e5.test_1();
1027N/A ((GetLocalVariablesTarg) e6).test_1();
1027N/A
1027N/A e3 = null;
1027N/A if (e3 == e1)
1166N/A e3.test_1();
1027N/A e3 = e4;
1027N/A if (e3 == e2)
1027N/A e3 = e5;
1027N/A e3.test_1();
1027N/A
1027N/A }
1027N/A
1027N/A public void test_1()
1027N/A {
1027N/A double l_add = i_double + i_short;
1027N/A long l_subtract = i_long - i_int;
1027N/A long l_multiply = i_byte * i_int;
1027N/A
1027N/A i_double = l_add + i_float;
1027N/A i_short = (short) l_subtract;
1027N/A i_long = l_multiply + i_byte + i_short;
1027N/A }
1027N/A
1027N/A public static void main(String[] args) {
1027N/A System.out.println("Howdy!");
1027N/A test_expressions();
1027N/A System.out.println("Goodbye from GetLocalVariablesTarg!");
1166N/A }
1166N/A}
1027N/A
1166N/A /********** test program **********/
1166N/A
1166N/Apublic class GetLocalVariables extends TestScaffold {
1166N/A ReferenceType targetClass;
1027N/A ThreadReference mainThread;
1027N/A
1027N/A GetLocalVariables (String args[]) {
1027N/A super(args);
1027N/A }
1027N/A
1027N/A public static void main(String[] args)
1166N/A throws Exception
1166N/A {
1166N/A new GetLocalVariables (args).startTests();
1166N/A }
1166N/A
1166N/A /********** test core **********/
1166N/A
1166N/A protected void runTests()
1166N/A throws Exception
1166N/A {
1166N/A /*
1027N/A * Get to the top of main() to determine targetClass and mainThread
1027N/A */
1027N/A BreakpointEvent bpe = startToMain("GetLocalVariablesTarg");
1027N/A targetClass = bpe.location().declaringType();
481N/A mainThread = bpe.thread();
1491N/A EventRequestManager erm = vm().eventRequestManager();
481N/A
481N/A bpe = resumeTo("GetLocalVariablesTarg", 197);
481N/A /*
1491N/A * We've arrived. Look around at some variables.
481N/A */
481N/A StackFrame frame = bpe.thread().frame(0);
481N/A List localVars = frame.visibleVariables();
481N/A System.out.println(" Visible variables at this point are: ");
481N/A for (Iterator it = localVars.iterator(); it.hasNext();) {
481N/A LocalVariable lv = (LocalVariable) it.next();
481N/A System.out.print(lv.name());
481N/A System.out.print(" typeName: ");
481N/A System.out.print(lv.typeName());
481N/A System.out.print(" signature: ");
481N/A System.out.print(lv.type().signature());
481N/A System.out.print(" primitive type: ");
481N/A System.out.println(lv.type().name());
481N/A }
481N/A
1165N/A /*
481N/A * resume the target listening for events
1165N/A */
481N/A listenUntilVMDisconnect();
481N/A
481N/A /*
481N/A * deal with results of test if anything has called failure("foo")
481N/A * testFailed will be true
481N/A */
481N/A if (!testFailed) {
1165N/A println("GetLocalVariables: passed");
481N/A } else {
481N/A throw new Exception("GetLocalVariables: failed");
481N/A }
481N/A }
481N/A}
481N/A