Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ArrayReference/getValue/getvalue001.java
41161 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.getValue;2526import nsk.share.*;27import nsk.share.jpda.*;28import nsk.share.jdi.*;2930import com.sun.jdi.*;31import java.io.*;3233public class getvalue001 {34final static boolean BOOL[] = {true, false};35final static byte BYTE[] = {Byte.MIN_VALUE, -1, 0, 1, Byte.MAX_VALUE};36final static char CHAR[] = {Character.MIN_VALUE, '\u00ff', '\uff00',37Character.MAX_VALUE};38final static double DOUB[] = {Double.NEGATIVE_INFINITY, Double.MIN_VALUE,39-1, -0, 1111111111.0, 1, Double.MAX_VALUE,40Double.POSITIVE_INFINITY,41Double.NaN};42final static float FLOAT[] = {Float.NEGATIVE_INFINITY, Float.MIN_VALUE,43-1, -0, 0, 1, Float.MAX_VALUE,44Float.POSITIVE_INFINITY, Float.NaN};45final static int INT[] = {Integer.MIN_VALUE, -1, 0, 1,46Integer.MAX_VALUE};47final static long LONG[] = {Long.MIN_VALUE, -1, 0, 1, Long.MAX_VALUE};48final static short SHORT[] = {Short.MIN_VALUE, -1, 0, 1, Short.MAX_VALUE};4950final static String FIELD_NAME[][] = {51{"z1", "boolean"},52{"b1", "byte"},53{"c1", "char"},54{"d1", "double"},55{"f1", "float"},56{"i1", "int"},57{"l1", "long"},58{"r1", "short"},5960{"lF1", "long"},61{"lP1", "long"},62{"lU1", "long"},63{"lR1", "long"},64{"lT1", "long"},65{"lV1", "long"}66};6768private static Log log;69private final static String prefix = "nsk.jdi.ArrayReference.getValue.";70private final static String className = "getvalue001";71private final static String debugerName = prefix + className;72private final static String debugeeName = debugerName + "a";73private final static String classToCheckName = prefix + "getvalue001aClassToCheck";7475public static void main(String argv[]) {76System.exit(95 + run(argv, System.out));77}7879public static int run(String argv[], PrintStream out) {80ArgumentHandler argHandler = new ArgumentHandler(argv);81log = new Log(out, argHandler);82Binder binder = new Binder(argHandler, log);83Debugee debugee = binder.bindToDebugee(debugeeName84+ (argHandler.verbose() ? " -verbose" : ""));85IOPipe pipe = debugee.createIOPipe();86boolean testFailed = false;8788// Connect with debugee and resume it89debugee.redirectStderr(out);90debugee.resume();91String line = pipe.readln();92if (line == null) {93log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null");94return 2;95}96if (!line.equals("ready")) {97log.complain("debuger FAILURE> UNEXPECTED debugee's signal - "98+ line);99return 2;100}101else {102log.display("debuger> debugee's \"ready\" signal recieved.");103}104105ReferenceType refType = debugee.classByName(classToCheckName);106if (refType == null) {107log.complain("debuger FAILURE> Class " + classToCheckName108+ " not found.");109return 2;110}111log.display("debuger> Total fields in debugee read: "112+ refType.allFields().size() + " total fields in debuger: "113+ FIELD_NAME.length + "\n");114115// Check all array fields from debugee116for (int i = 0; i < FIELD_NAME.length; i++) {117Field field;118String name = FIELD_NAME[i][0];119String realType = FIELD_NAME[i][1];120Value value;121ArrayReference arrayRef;122123// Get field from debuggee by name124try {125field = refType.fieldByName(name);126} catch (ClassNotPreparedException e) {127log.complain("debuger FAILURE 1> Can't get field by name "128+ name);129log.complain("debuger FAILURE 1> Exception: " + e);130testFailed = true;131continue;132} catch (ObjectCollectedException e) {133log.complain("debuger FAILURE 1> Can't get field by name "134+ name);135log.complain("debuger FAILURE 1> Exception: " + e);136testFailed = true;137continue;138}139log.display("debuger> " + i + " field " + field + " read.");140141// Get field's value142try {143value = refType.getValue(field);144} catch (IllegalArgumentException e) {145log.complain("debuger FAILURE 2> Cannot get value for field "146+ name);147log.complain("debuger FAILURE 2> Exception: " + e);148testFailed = true;149continue;150} catch (ObjectCollectedException e) {151log.complain("debuger FAILURE 2> Cannot get value for field "152+ name);153log.complain("debuger FAILURE 2> Exception: " + e);154testFailed = true;155continue;156}157log.display("debuger> " + i + " field value is " + value);158159// Cast to ArrayReference. All fields in debugee are160// arrays, so ClassCastException should not be thrown161try {162arrayRef = (ArrayReference)value;163} catch (ClassCastException e) {164log.complain("debuger FAILURE 3> Cannot cast value for field "165+ name + " to ArrayReference.");166log.complain("debuger FAILURE 3> Exception: " + e);167testFailed = true;168continue;169}170171// All arrays have different length, so cycle "for (int j..)"172// is inside "if realType.equal("173174if (realType.equals("boolean")) {175///////////////////// Check boolean[] /////////////////////176177for (int j = 0; j < BOOL.length; j++){178Value arrayValue;179BooleanValue boolValue;180boolean element;181182// Get each element from array183try {184arrayValue = arrayRef.getValue(j);185} catch (ObjectCollectedException e) {186log.complain("debuger FAILURE Z1> Cannot get " + j187+ " value from field " + name);188log.complain("debuger FAILURE Z1> Exception: " + e);189testFailed = true;190continue;191} catch (IndexOutOfBoundsException e) {192log.complain("debuger FAILURE Z1> Cannot get " + j193+ " value from field " + name);194log.complain("debuger FAILURE Z1> Exception: " + e);195testFailed = true;196continue;197}198try {199boolValue = (BooleanValue)arrayValue;200} catch (ClassCastException e) {201log.complain("debuger FAILURE Z2> Cannot cast to "202+ "boolean " + j + " value of field "203+ name);204log.complain("debuger FAILURE Z2> Exception: " + e);205testFailed = true;206continue;207}208element = boolValue.value();209log.display("debuger> " + i + " field has " + j210+ " element " + element);211212// Check element's value213if (element != BOOL[j]) {214log.complain("debuger FAILURE Z3> " + j + " element of "215+ "array " + name + " was expected "216+ BOOL[j] + ", but returned " + element);217testFailed = true;218continue;219}220}221} else if (realType.equals("byte")) {222///////////////////// Check byte[] /////////////////////223224for (int j = 0; j < BYTE.length; j++){225Value arrayValue;226ByteValue byteValue;227byte element;228229// Get each element from array230try {231arrayValue = arrayRef.getValue(j);232} catch (ObjectCollectedException e) {233log.complain("debuger FAILURE B1> Cannot get " + j234+ " value from field " + name);235log.complain("debuger FAILURE B1> Exception: " + e);236testFailed = true;237continue;238} catch (IndexOutOfBoundsException e) {239log.complain("debuger FAILURE B1> Cannot get " + j240+ " value from field " + name);241log.complain("debuger FAILURE B1> Exception: " + e);242testFailed = true;243continue;244}245try {246byteValue = (ByteValue)arrayValue;247} catch (ClassCastException e) {248log.complain("debuger FAILURE B2> Cannot cast to "249+ "byte " + j + " value of field " + name);250log.complain("debuger FAILURE B2> Exception: " + e);251testFailed = true;252continue;253}254element = byteValue.value();255log.display("debuger> " + i + " field has " + j256+ " element " + element);257258// Check element's value259if (element != BYTE[j]) {260log.complain("debuger FAILURE B3> " + j + " element of "261+ "array " + name + " was expected "262+ CHAR[j] + ", but returned " + element);263testFailed = true;264continue;265}266}267} else if (realType.equals("char")) {268///////////////////// Check char[] /////////////////////269270for (int j = 0; j < CHAR.length; j++){271Value arrayValue;272CharValue charValue;273char element;274275// Get each element from array276try {277arrayValue = arrayRef.getValue(j);278} catch (ObjectCollectedException e) {279log.complain("debuger FAILURE C1> Cannot get " + j280+ " value from field " + name);281log.complain("debuger FAILURE C1> Exception: " + e);282testFailed = true;283continue;284} catch (IndexOutOfBoundsException e) {285log.complain("debuger FAILURE C1> Cannot get " + j286+ " value from field " + name);287log.complain("debuger FAILURE C1> Exception: " + e);288testFailed = true;289continue;290}291try {292charValue = (CharValue)arrayValue;293} catch (ClassCastException e) {294log.complain("debuger FAILURE C2> Cannot cast to "295+ "char " + j + " value of field " + name);296log.complain("debuger FAILURE C2> Exception: " + e);297testFailed = true;298continue;299}300element = charValue.value();301log.display("debuger> " + i + " field has " + j302+ " element " + element);303304if (element != CHAR[j]) {305log.complain("debuger FAILURE C3> " + j + " element of "306+ "array " + name + " was expected "307+ CHAR[j] + ", but returned " + element);308testFailed = true;309continue;310}311}312} else if (realType.equals("double")) {313///////////////////// Check double[] /////////////////////314315for (int j = 0; j < DOUB.length; j++){316Value arrayValue;317DoubleValue doubleValue;318Double element;319320// Get each element from array321try {322arrayValue = arrayRef.getValue(j);323} catch (ObjectCollectedException e) {324log.complain("debuger FAILURE D1> Cannot get " + j325+ " value from field " + name);326log.complain("debuger FAILURE D1> Exception: " + e);327testFailed = true;328continue;329} catch (IndexOutOfBoundsException e) {330log.complain("debuger FAILURE D1> Cannot get " + j331+ " value from field " + name);332log.complain("debuger FAILURE D1> Exception: " + e);333testFailed = true;334continue;335}336try {337doubleValue = (DoubleValue)arrayValue;338} catch (ClassCastException e) {339log.complain("debuger FAILURE D2> Cannot cast to "340+ "double " + j + " value of field " + name);341log.complain("debuger FAILURE D2> Exception: " + e);342testFailed = true;343continue;344}345element = Double.valueOf(doubleValue.value());346log.display("debuger> " + i + " field has " + j347+ " element " + element);348349if (!element.equals(Double.valueOf(DOUB[j]))) {350log.complain("debuger FAILURE D3> " + j + " element of "351+ "array " + name + " was expected "352+ DOUB[j] + ", but returned " + element);353testFailed = true;354continue;355}356}357} else if (realType.equals("float")) {358///////////////////// Check float[] /////////////////////359360for (int j = 0; j < FLOAT.length; j++){361Value arrayValue;362FloatValue floatValue;363Float element;364365// Get each element from array366try {367arrayValue = arrayRef.getValue(j);368} catch (ObjectCollectedException e) {369log.complain("debuger FAILURE F1> Cannot get " + j370+ " value from field " + name);371log.complain("debuger FAILURE F1> Exception: " + e);372testFailed = true;373continue;374} catch (IndexOutOfBoundsException e) {375log.complain("debuger FAILURE F1> Cannot get " + j376+ " value from field " + name);377log.complain("debuger FAILURE F1> Exception: " + e);378testFailed = true;379continue;380}381try {382floatValue = (FloatValue)arrayValue;383} catch (ClassCastException e) {384log.complain("debuger FAILURE F2> Cannot cast to "385+ "float " + j + " value of field " + name);386log.complain("debuger FAILURE F2> Exception: " + e);387testFailed = true;388continue;389}390element = Float.valueOf(floatValue.value());391log.display("debuger> " + i + " field has " + j392+ " element " + element);393394if (!element.equals(Float.valueOf(FLOAT[j]))) {395log.complain("debuger FAILURE F3> " + j + " element of "396+ "array " + name + " was expected "397+ FLOAT[j] + ", but returned " + element);398testFailed = true;399continue;400}401}402} else if (realType.equals("int")) {403///////////////////// Check int[] /////////////////////404405for (int j = 0; j < INT.length; j++){406Value arrayValue;407IntegerValue intValue;408int element;409410// Get each element from array411try {412arrayValue = arrayRef.getValue(j);413} catch (ObjectCollectedException e) {414log.complain("debuger FAILURE I1> Cannot get " + j415+ " value from field " + name);416log.complain("debuger FAILURE I1> Exception: " + e);417testFailed = true;418continue;419} catch (IndexOutOfBoundsException e) {420log.complain("debuger FAILURE I1> Cannot get " + j421+ " value from field " + name);422log.complain("debuger FAILURE I1> Exception: " + e);423testFailed = true;424continue;425}426try {427intValue = (IntegerValue)arrayValue;428} catch (ClassCastException e) {429log.complain("debuger FAILURE I2> Cannot cast to "430+ "int " + j + " value of field " + name);431log.complain("debuger FAILURE I2> Exception: " + e);432testFailed = true;433continue;434}435element = intValue.value();436log.display("debuger> " + i + " field has " + j437+ " element " + element + " ("438+ Integer.toHexString(element) + ") ");439440if (element != INT[j]) {441log.complain("debuger FAILURE I3> " + j + " element of "442+ "array " + name + " was expected " + INT[j]443+ " (" + Integer.toHexString(INT[j]) + "), "444+ " but returned " + element);445testFailed = true;446continue;447}448}449} else if (realType.equals("long")) {450///////////////////// Check long[] /////////////////////451452for (int j = 0; j < LONG.length; j++){453Value arrayValue;454LongValue longValue;455long element;456457// Get each element from array458try {459arrayValue = arrayRef.getValue(j);460} catch (ObjectCollectedException e) {461log.complain("debuger FAILURE L1> Cannot get " + j462+ " value from field " + name);463log.complain("debuger FAILURE L1> Exception: " + e);464testFailed = true;465continue;466} catch (IndexOutOfBoundsException e) {467log.complain("debuger FAILURE L1> Cannot get " + j468+ " value from field " + name);469log.complain("debuger FAILURE L1> Exception: " + e);470testFailed = true;471continue;472}473try {474longValue = (LongValue)arrayValue;475} catch (ClassCastException e) {476log.complain("debuger FAILURE L2> Cannot cast to "477+ "long " + j + " value of field " + name);478log.complain("debuger FAILURE L2> Exception: " + e);479testFailed = true;480continue;481}482element = longValue.value();483log.display("debuger> " + i + " field has " + j484+ " element " + element + " ("485+ Long.toHexString(element) + ") ");486487if (element != LONG[j]) {488log.complain("debuger FAILURE L3> " + j + " element of "489+ "array " + name + " was expected "490+ LONG[j] + " (" + Long.toHexString(LONG[j])491+ "), but returned " + element);492testFailed = true;493continue;494}495}496} else if (realType.equals("short")) {497///////////////////// Check short[] /////////////////////498499for (int j = 0; j < SHORT.length; j++){500Value arrayValue;501ShortValue shortValue;502short element;503504// Get each element from array505try {506arrayValue = arrayRef.getValue(j);507} catch (ObjectCollectedException e) {508log.complain("debuger FAILURE R1> Cannot get " + j509+ " value from field " + name);510log.complain("debuger FAILURE R1> Exception: " + e);511testFailed = true;512continue;513} catch (IndexOutOfBoundsException e) {514log.complain("debuger FAILURE R1> Cannot get " + j515+ " value from field " + name);516log.complain("debuger FAILURE R1> Exception: " + e);517testFailed = true;518continue;519}520try {521shortValue = (ShortValue)arrayValue;522} catch (ClassCastException e) {523log.complain("debuger FAILURE R2> Cannot cast to "524+ "short " + j + " value of field " + name);525log.complain("debuger FAILURE R2> Exception: " + e);526testFailed = true;527continue;528}529element = shortValue.value();530log.display("debuger> " + i + " field has " + j531+ " element " + element);532533if (element != SHORT[j]) {534log.complain("debuger FAILURE R3> " + j + " element of "535+ "array " + name + " was expected "536+ SHORT[j] + ", but returned " + element);537testFailed = true;538continue;539}540}541} else {542log.complain("debuger FAILURE 4> Unexpected type: " + realType);543testFailed = true;544continue;545}546log.display("debuger> " + i + " field checked.\n");547}548549pipe.println("quit");550debugee.waitFor();551int status = debugee.getStatus();552if (testFailed) {553log.complain("debuger FAILURE> TEST FAILED");554return 2;555} else {556if (status == 95) {557log.display("debuger> expected Debugee's exit "558+ "status - " + status);559return 0;560} else {561log.complain("debuger FAILURE> UNEXPECTED Debugee's exit "562+ "status (not 95) - " + status);563return 2;564}565}566}567}568569570