Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ArrayReference/getValues/getvalues001.java
41162 views
/*1* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324package nsk.jdi.ArrayReference.getValues;2526import nsk.share.*;27import nsk.share.jpda.*;28import nsk.share.jdi.*;2930import com.sun.jdi.*;31import java.io.*;32import java.util.*;3334public class getvalues001 {35final static boolean BOOL[] = {true, false};36final static byte BYTE[] = {Byte.MIN_VALUE, -1, 0, 1, Byte.MAX_VALUE};37final static char CHAR[] = {Character.MIN_VALUE, '\u00ff', '\uff00',38Character.MAX_VALUE};39final static double DOUB[] = {Double.NEGATIVE_INFINITY, Double.MIN_VALUE,40-1, -0, 0, 1, Double.MAX_VALUE,41Double.POSITIVE_INFINITY,42Double.NaN};43final static float FLOAT[] = {Float.NEGATIVE_INFINITY, Float.MIN_VALUE,44-1, -0, 0, 1, Float.MAX_VALUE,45Float.POSITIVE_INFINITY, Float.NaN};46final static int INT[] = {Integer.MIN_VALUE, -1, 0, 1,47Integer.MAX_VALUE};48final static long LONG[] = {Long.MIN_VALUE, -1, 0, 1, Long.MAX_VALUE};49final static short SHORT[] = {Short.MIN_VALUE, -1, 0, 1, Short.MAX_VALUE};5051final static String FIELD_NAME[][] = {52{"z1", "boolean"},53{"b1", "byte"},54{"c1", "char"},55{"d1", "double"},56{"f1", "float"},57{"i1", "int"},58{"l1", "long"},59{"r1", "short"},6061{"lF1", "long"},62{"lP1", "long"},63{"lU1", "long"},64{"lR1", "long"},65{"lT1", "long"},66{"lV1", "long"}67};6869private static Log log;70private final static String prefix = "nsk.jdi.ArrayReference.getValues.";71private final static String className = "getvalues001";72private final static String debugerName = prefix + className;73private final static String debugeeName = debugerName + "a";74private final static String classToCheckName = prefix + "getvalues001aClassToCheck";7576public static void main(String argv[]) {77System.exit(95 + run(argv, System.out));78}7980public static int run(String argv[], PrintStream out) {81ArgumentHandler argHandler = new ArgumentHandler(argv);82log = new Log(out, argHandler);83Binder binder = new Binder(argHandler, log);84Debugee debugee = binder.bindToDebugee(debugeeName85+ (argHandler.verbose() ? " -verbose" : ""));86IOPipe pipe = debugee.createIOPipe();87boolean testFailed = false;8889// Connect with debugee and resume it90debugee.redirectStderr(out);91debugee.resume();92String line = pipe.readln();93if (line == null) {94log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null");95return 2;96}97if (!line.equals("ready")) {98log.complain("debuger FAILURE> UNEXPECTED debugee's signal - "99+ line);100return 2;101}102else {103log.display("debuger> debugee's \"ready\" signal recieved.");104}105106ReferenceType refType = debugee.classByName(classToCheckName);107if (refType == null) {108log.complain("debuger FAILURE> Class " + classToCheckName109+ " not found.");110return 2;111}112log.display("debuger> Total fields in debugee read: "113+ refType.allFields().size() + " total fields in debuger: "114+ FIELD_NAME.length + "\n");115116// Check all array fields from debugee117for (int i = 0; i < FIELD_NAME.length; i++) {118Field field;119String name = FIELD_NAME[i][0];120String realType = FIELD_NAME[i][1];121Value value;122Value arrayValue;123ArrayReference arrayRef;124List listOfValues;125126// Get field from debuggee by name127try {128field = refType.fieldByName(name);129} catch (ClassNotPreparedException e) {130log.complain("debuger FAILURE 1> Can't get field by name "131+ name);132log.complain("debuger FAILURE 1> Exception: " + e);133testFailed = true;134continue;135} catch (ObjectCollectedException e) {136log.complain("debuger FAILURE 1> Can't get field by name "137+ name);138log.complain("debuger FAILURE 1> Exception: " + e);139testFailed = true;140continue;141}142log.display("debuger> " + i + " field " + field + " read.");143144// Get field's value145try {146value = refType.getValue(field);147} catch (IllegalArgumentException e) {148log.complain("debuger FAILURE 2> Cannot get value for field "149+ name);150log.complain("debuger FAILURE 2> Exception: " + e);151testFailed = true;152continue;153} catch (ObjectCollectedException e) {154log.complain("debuger FAILURE 2> Cannot get value for field "155+ name);156log.complain("debuger FAILURE 2> Exception: " + e);157testFailed = true;158continue;159}160log.display("debuger> " + i + " field value is " + value);161162// Cast to ArrayReference. All fields in debugee are163// arrays, so ClassCastException should not be thrown164try {165arrayRef = (ArrayReference)value;166} catch (ClassCastException e) {167log.complain("debuger FAILURE 3> Cannot cast value for field "168+ name + " to ArrayReference.");169log.complain("debuger FAILURE 3> Exception: " + e);170testFailed = true;171continue;172}173174// Get all components from array175try {176listOfValues = arrayRef.getValues();177} catch (ObjectCollectedException e) {178log.complain("debuger FAILURE 4> Cannot get values from field "179+ name);180log.complain("debuger FAILURE 4> Exception: " + e);181testFailed = true;182continue;183}184185// Check each element of the list186for (int j = 0; j < listOfValues.size(); j++) {187try {188arrayValue = (Value)listOfValues.get(j);189} catch (ClassCastException e) {190log.complain("debuger FAILURE 5> Cannot cast to Value "191+ j + " element of field " + name);192log.complain("debuger FAILURE 5> Exception: " + e);193testFailed = true;194continue;195}196log.display("debuger> " + i + " field has " + j + " value "197+ arrayValue);198199if (realType.equals("boolean")) {200201///////////////////// Check boolean[] /////////////////////202BooleanValue boolValue;203boolean element;204205try {206boolValue = (BooleanValue)arrayValue;207} catch (ClassCastException e) {208log.complain("debuger FAILURE Z1> Cannot cast to "209+ "boolean " + j + " value of field "210+ name);211log.complain("debuger FAILURE Z1> Exception: " + e);212testFailed = true;213continue;214}215element = boolValue.value();216log.display("debuger> " + i + " field has " + j217+ " element " + element);218219// Check element's value220if (element != BOOL[j]) {221log.complain("debuger FAILURE Z2> " + j + " element "222+ "of array " + name + " was expected "223+ BOOL[j] + ", but returned " + element);224testFailed = true;225continue;226}227} else if (realType.equals("byte")) {228229///////////////////// Check byte[] /////////////////////230ByteValue byteValue;231byte element;232233try {234byteValue = (ByteValue)arrayValue;235} catch (ClassCastException e) {236log.complain("debuger FAILURE B1> Cannot cast to "237+ "byte " + j + " value of field "238+ name);239log.complain("debuger FAILURE B1> Exception: " + e);240testFailed = true;241continue;242}243element = byteValue.value();244log.display("debuger> " + i + " field has " + j245+ " element " + element);246247// Check element's value248if (element != BYTE[j]) {249log.complain("debuger FAILURE B2> " + j + " element "250+ "of array " + name + " was expected "251+ BYTE[j] + ", but returned " + element);252testFailed = true;253continue;254}255} else if (realType.equals("char")) {256257///////////////////// Check char[] /////////////////////258CharValue charValue;259char element;260261try {262charValue = (CharValue)arrayValue;263} catch (ClassCastException e) {264log.complain("debuger FAILURE C1> Cannot cast to "265+ "char " + j + " value of field "266+ name);267log.complain("debuger FAILURE C1> Exception: " + e);268testFailed = true;269continue;270}271element = charValue.value();272log.display("debuger> " + i + " field has " + j273+ " element " + element);274275// Check element's value276if (element != CHAR[j]) {277log.complain("debuger FAILURE C2> " + j + " element "278+ "of array " + name + " was expected "279+ CHAR[j] + ", but returned " + element);280testFailed = true;281continue;282}283} else if (realType.equals("double")) {284285///////////////////// Check double[] /////////////////////286DoubleValue doubleValue;287Double element;288289try {290doubleValue = (DoubleValue)arrayValue;291} catch (ClassCastException e) {292log.complain("debuger FAILURE D1> Cannot cast to "293+ "double " + j + " value of field "294+ name);295log.complain("debuger FAILURE D1> Exception: " + e);296testFailed = true;297continue;298}299element = Double.valueOf(doubleValue.value());300log.display("debuger> " + i + " field has " + j301+ " element " + element);302303// Check element's value304if (!element.equals(Double.valueOf(DOUB[j]))) {305log.complain("debuger FAILURE D2> " + j + " element "306+ "of array " + name + " was expected "307+ DOUB[j] + ", but returned " + element);308testFailed = true;309continue;310}311} else if (realType.equals("float")) {312313///////////////////// Check float[] /////////////////////314FloatValue floatValue;315Float element;316317try {318floatValue = (FloatValue)arrayValue;319} catch (ClassCastException e) {320log.complain("debuger FAILURE F1> Cannot cast to "321+ "float " + j + " value of field "322+ name);323log.complain("debuger FAILURE F1> Exception: " + e);324testFailed = true;325continue;326}327element = Float.valueOf(floatValue.value());328log.display("debuger> " + i + " field has " + j329+ " element " + element);330331// Check element's value332if (!element.equals(Float.valueOf(FLOAT[j]))) {333log.complain("debuger FAILURE F2> " + j + " element "334+ "of array " + name + " was expected "335+ FLOAT[j] + ", but returned " + element);336testFailed = true;337continue;338}339} else if (realType.equals("int")) {340341///////////////////// Check int[] /////////////////////342IntegerValue intValue;343int element;344345try {346intValue = (IntegerValue)arrayValue;347} catch (ClassCastException e) {348log.complain("debuger FAILURE I1> Cannot cast to "349+ "int " + j + " value of field "350+ name);351log.complain("debuger FAILURE I1> Exception: " + e);352testFailed = true;353continue;354}355element = intValue.value();356log.display("debuger> " + i + " field has " + j357+ " element " + element);358359// Check element's value360if (element != INT[j]) {361log.complain("debuger FAILURE I2> " + j + " element "362+ "of array " + name + " was expected "363+ INT[j] + ", but returned " + element);364testFailed = true;365continue;366}367} else if (realType.equals("long")) {368369///////////////////// Check long[] /////////////////////370LongValue longValue;371long element;372373try {374longValue = (LongValue)arrayValue;375} catch (ClassCastException e) {376log.complain("debuger FAILURE L1> Cannot cast to "377+ "long " + j + " value of field "378+ name);379log.complain("debuger FAILURE L1> Exception: " + e);380testFailed = true;381continue;382}383element = longValue.value();384log.display("debuger> " + i + " field has " + j385+ " element " + element);386387// Check element's value388if (element != LONG[j]) {389log.complain("debuger FAILURE L2> " + j + " element "390+ "of array " + name + " was expected "391+ LONG[j] + ", but returned " + element);392testFailed = true;393continue;394}395} else if (realType.equals("short")) {396397///////////////////// Check short[] /////////////////////398ShortValue shortValue;399short element;400401try {402shortValue = (ShortValue)arrayValue;403} catch (ClassCastException e) {404log.complain("debuger FAILURE R1> Cannot cast to "405+ "short " + j + " value of field "406+ name);407log.complain("debuger FAILURE R1> Exception: " + e);408testFailed = true;409continue;410}411element = shortValue.value();412log.display("debuger> " + i + " field has " + j413+ " element " + element);414415// Check element's value416if (element != SHORT[j]) {417log.complain("debuger FAILURE R2> " + j + " element "418+ "of array " + name + " was expected "419+ SHORT[j] + ", but returned " + element);420testFailed = true;421continue;422}423424} else {425log.complain("debuger FAILURE 6> Unexpected type: "426+ realType);427testFailed = true;428break;429}430}431log.display("debuger> " + i + " field checked.\n");432}433434pipe.println("quit");435debugee.waitFor();436int status = debugee.getStatus();437if (testFailed) {438log.complain("debuger FAILURE> TEST FAILED");439return 2;440} else {441if (status == 95) {442log.display("debuger> expected Debugee's exit "443+ "status - " + status);444return 0;445} else {446log.complain("debuger FAILURE> UNEXPECTED Debugee's exit "447+ "status (not 95) - " + status);448return 2;449}450}451}452}453454455