Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/ArgumentValuesTest.java
38855 views
/** hard coded linenumbers in other tests - DO NOT CHANGE1* @test/nodynamiccopyright/2* @bug 44908243* @summary JDI: provide arguments when no debug attributes present4*5* @author jjh6*7* @run build TestScaffold VMConnection TargetListener TargetAdapter8* @run compile ArgumentValuesTest.java9* @run main ArgumentValuesTest10*/11import com.sun.jdi.*;12import com.sun.jdi.event.*;13import com.sun.jdi.request.*;1415import java.util.*;1617/********** target program **********/1819class ArgumentValuesTarg {20static char s_char1 = 'a';21static byte s_byte1 = (byte) 146;22static short s_short1 = (short) 28123;23static int s_int1 = 3101246;24static long s_long1 = 0x0123456789ABCDEFL;25static float s_float1 = 2.3145f;26static double s_double1 = 1.469d;27static int s_iarray1[] = {1, 2, 3};28static int s_marray1[][] = {{1, 2, 3}, {3, 4, 5}, null, {6, 7}};29static String s_sarray1[] = {"abc", null, "def", "ghi"};30static String s_string1 = "abcdef";3132static String s_string2 = "xy";33static String s_string3 = "wz";34static List<Integer> intList;3536public static void noArgs() {37int index = 0; // line 3838}3940public static void allArgs(char p_char, byte p_byte, short p_short,41int p_int, long p_long, float p_float,42double p_double, int p_iarray[], int p_marray[][],43String p_sarray1[], String p_string) {44int index = 0; // line 4545}4647public static void varArgs(String ... p1) {48int index = 0; // line 4949}5051public static void genericArgs(List<Integer> p1) {52int index = 0; // line 5353}5455public void instanceMethod(char p_char, byte p_byte) {56int index = 0; // line 5757}5859public static void main(String[] args) {60System.out.println("Howdy!");61allArgs(62s_char1, s_byte1, s_short1, s_int1,63s_long1, s_float1, s_double1, s_iarray1,64s_marray1, s_sarray1, s_string1);6566noArgs();67varArgs(s_string1, s_string2, s_string3);68ArgumentValuesTarg avt = new ArgumentValuesTarg();69intList = new ArrayList<Integer>(10);70intList.add(10);71intList.add(20);72genericArgs(intList);7374avt.instanceMethod(s_char1, s_byte1);7576System.out.println("Goodbye from ArgumentValuesTarg!");77}78}7980/********** test program **********/8182public class ArgumentValuesTest extends TestScaffold {83// Must be in same order as args to allArgs(....)84String fieldNames[] = {"s_char1", "s_byte1", "s_short1", "s_int1",85"s_long1", "s_float1", "s_double1", "s_iarray1",86"s_marray1", "s_sarray1", "s_string1"};8788String fieldNamesVarArgs[] = {"s_string1", "s_string2", "s_string3"};89String fieldNamesInstance[] = {"s_char1", "s_byte1"};9091ReferenceType targetClass;92ThreadReference mainThread;9394ArgumentValuesTest (String args[]) {95super(args);96}9798public static void main(String[] args)99throws Exception100{101new ArgumentValuesTest (args).startTests();102}103104/********** test core **********/105106protected void runTests()107throws Exception108{109/*110* Get to the top of main() to determine targetClass and mainThread111*/112BreakpointEvent bpe = startToMain("ArgumentValuesTarg");113targetClass = bpe.location().declaringType();114mainThread = bpe.thread();115EventRequestManager erm = vm().eventRequestManager();116117118{119System.out.println("----- Testing each type of arg");120bpe = resumeTo("ArgumentValuesTarg", 45);121StackFrame frame = bpe.thread().frame(0);122123Method mmm = frame.location().method();124System.out.println("Arg types are: " + mmm.argumentTypeNames());125126List<Value> argVals = frame.getArgumentValues();127128if (argVals.size() != fieldNames.length) {129failure("failure: Varargs: expected length " + fieldNames.length +130" args, got: " + argVals);131}132for (int ii = 0; ii < argVals.size(); ii++) {133Value gotVal = argVals.get(ii);134135Field theField = targetClass.fieldByName(fieldNames[ii]);136Value expectedVal = targetClass.getValue(theField);137System.out.println(fieldNames[ii] + ": gotVal = " + gotVal +138", expected = " + expectedVal);139//System.out.println(gotVal.getClass() + ", " + expectedVal.getClass());140if (!gotVal.equals(expectedVal)) {141failure(" failure: gotVal != expected");142}143}144}145146// a method with no params147{148System.out.println("----- Testing no args");149bpe = resumeTo("ArgumentValuesTarg", 38);150StackFrame frame = bpe.thread().frame(0);151152Method mmm = frame.location().method();153System.out.println("Arg types are: " + mmm.argumentTypeNames());154155List<Value> argVals = frame.getArgumentValues();156if (argVals.size() == 0) {157System.out.println("Empty arg list ok");158} else {159failure("failure: Expected empty val list, got: " + argVals);160}161}162163// var args. 3 Strings are passed in and they appear164// as a String[3] in the method.165{166System.out.println("----- Testing var args");167bpe = resumeTo("ArgumentValuesTarg", 49);168StackFrame frame = bpe.thread().frame(0);169170Method mmm = frame.location().method();171System.out.println("Arg types are: " + mmm.argumentTypeNames());172173List<Value> argVals = frame.getArgumentValues();174if (argVals.size() != 1) {175failure("failure: Varargs: expected one arg, got: " + argVals);176}177argVals = ((ArrayReference)argVals.get(0)).getValues();178179if (argVals.size() != fieldNamesVarArgs.length) {180failure("failure: Varargs: expected length " + fieldNamesVarArgs.length +181" array elements, got: " + argVals);182}183184for (int ii = 0; ii < argVals.size(); ii++) {185Value gotVal = argVals.get(ii);186187Field theField = targetClass.fieldByName(fieldNamesVarArgs[ii]);188Value expectedVal = targetClass.getValue(theField);189System.out.println(fieldNamesVarArgs[ii] + ": gotVal = " + gotVal +190", expected = " + expectedVal);191//System.out.println(gotVal.getClass() + ", " + expectedVal.getClass());192if (!gotVal.equals(expectedVal)) {193failure(" failure: gotVal != expected");194}195}196}197198// a method with with one generic param199{200System.out.println("----- Testing generic args");201bpe = resumeTo("ArgumentValuesTarg", 53);202StackFrame frame = bpe.thread().frame(0);203204Method mmm = frame.location().method();205System.out.println("Arg types are: " + mmm.argumentTypeNames());206207List<Value> argVals = frame.getArgumentValues();208if (argVals.size() != 1) {209failure("failure: Expected one arg, got: " + argVals);210} else {211Value gotVal = argVals.get(0);212213Field theField = targetClass.fieldByName("intList");214Value expectedVal = targetClass.getValue(theField);215System.out.println("intList " + ": gotVal = " + gotVal +216", expected = " + expectedVal);217if (!gotVal.equals(expectedVal)) {218failure("failure: gotVal != expected");219}220}221}222223// test instance method call224{225System.out.println("----- Testing instance method call");226bpe = resumeTo("ArgumentValuesTarg", 57);227StackFrame frame = bpe.thread().frame(0);228229Method mmm = frame.location().method();230System.out.println("Arg types are: " + mmm.argumentTypeNames());231232List<Value> argVals = frame.getArgumentValues();233234if (argVals.size() != fieldNamesInstance.length) {235failure("failure: Varargs: expected length " + fieldNamesInstance.length +236" args, got: " + argVals);237}238for (int ii = 0; ii < argVals.size(); ii++) {239Value gotVal = argVals.get(ii);240241Field theField = targetClass.fieldByName(fieldNamesInstance[ii]);242Value expectedVal = targetClass.getValue(theField);243System.out.println(fieldNamesInstance[ii] + ": gotVal = " + gotVal +244", expected = " + expectedVal);245//System.out.println(gotVal.getClass() + ", " + expectedVal.getClass());246if (!gotVal.equals(expectedVal)) {247failure(" failure: gotVal != expected");248}249}250}251252253/*254* resume the target listening for events255*/256listenUntilVMDisconnect();257258/*259* deal with results of test if anything has called failure("foo")260* testFailed will be true261*/262if (!testFailed) {263println("ArgumentValuesTest: passed");264} else {265throw new Exception("ArgumentValuesTest: failed");266}267}268}269270271