Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ArrayReference/getValue/getvalue002.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 getvalue002 {34final static int MIN_INDEX = -50;35final static int MAX_INDEX = 51;36final static String FIELD_NAME[][] = {37{"z1", "5"},38{"b1", "5"},39{"c1", "6"},40{"d1", "1"},41{"f1", "1"},42{"i1", "10"},43{"l1", "2"},44{"r1", "5"},4546{"lF1", "0"},47{"lP1", "2"},48{"lU1", "3"},49{"lR1", "4"},50{"lT1", "5"},51{"lV1", "6"}52};5354private static Log log;55private final static String prefix = "nsk.jdi.ArrayReference.getValue.";56private final static String className = "getvalue002";57private final static String debugerName = prefix + className;58private final static String debugeeName = debugerName + "a";59private final static String classToCheckName = prefix + "getvalue002aClassToCheck";6061public static void main(String argv[]) {62System.exit(95 + run(argv, System.out));63}6465public static int run(String argv[], PrintStream out) {66ArgumentHandler argHandler = new ArgumentHandler(argv);67log = new Log(out, argHandler);68Binder binder = new Binder(argHandler, log);69Debugee debugee = binder.bindToDebugee(debugeeName70+ (argHandler.verbose() ? " -verbose" : ""));71IOPipe pipe = debugee.createIOPipe();72boolean testFailed = false;7374// Connect with debugee and resume it75debugee.redirectStderr(out);76debugee.resume();77String line = pipe.readln();78if (line == null) {79log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null");80return 2;81}82if (!line.equals("ready")) {83log.complain("debuger FAILURE> UNEXPECTED debugee's signal - "84+ line);85return 2;86}87else {88log.display("debuger> debugee's \"ready\" signal recieved.");89}9091ReferenceType refType = debugee.classByName(classToCheckName);92if (refType == null) {93log.complain("debuger FAILURE> Class " + classToCheckName94+ " not found.");95return 2;96}9798log.display("debuger> Total fields in debugee read: "99+ refType.allFields().size() + " total fields in debuger: "100+ FIELD_NAME.length + "\n");101102// Check all array fields from debugee103for (int i = 0; i < FIELD_NAME.length; i++) {104Field field;105String name = FIELD_NAME[i][0];106Integer totalElements = Integer.valueOf(FIELD_NAME[i][1]);107int lastElementIndex = totalElements.intValue() - 1;108Value value;109ArrayReference arrayRef;110111// Get field from debuggee by name112try {113field = refType.fieldByName(name);114} catch (ClassNotPreparedException e) {115log.complain("debuger FAILURE 1> Can't get field by name "116+ name);117log.complain("debuger FAILURE 1> Exception: " + e);118testFailed = true;119continue;120} catch (ObjectCollectedException e) {121log.complain("debuger FAILURE 1> Can't get field by name "122+ name);123log.complain("debuger FAILURE 1> Exception: " + e);124testFailed = true;125continue;126}127log.display("debuger> " + i + " field " + field + " read.");128129// Get field's value130try {131value = refType.getValue(field);132} catch (IllegalArgumentException e) {133log.complain("debuger FAILURE 2> Cannot get value for field "134+ name);135log.complain("debuger FAILURE 2> Exception: " + e);136testFailed = true;137continue;138} catch (ObjectCollectedException e) {139log.complain("debuger FAILURE 2> Cannot get value for field "140+ name);141log.complain("debuger FAILURE 2> Exception: " + e);142testFailed = true;143continue;144}145log.display("debuger> " + i + " field value is " + value);146147// Cast to ArrayReference. All fields in debugee are148// arrays, so ClassCastException should not be thrown149try {150arrayRef = (ArrayReference)value;151} catch (ClassCastException e) {152log.complain("debuger FAILURE 3> Cannot cast value for field "153+ name + " to ArrayReference.");154log.complain("debuger FAILURE 3> Exception: " + e);155testFailed = true;156continue;157}158159// Try to get value by index from MIN_INDEX to -1 and from160// arrayRef.length() to MAX_INDEX161for (int j = MIN_INDEX; j < MAX_INDEX; j++) {162if ( (j < 0) || (j > lastElementIndex) ) {163Value arrayValue;164165try {166arrayValue = arrayRef.getValue(j);167log.complain("debuger FAILURE 4> Value for " + j168+ " element of field " + name + " is " + arrayValue169+ ", but IndexOutOfBoundsException expected.");170testFailed = true;171} catch (ObjectCollectedException e) {172log.display("debuger> Cannot get " + j + " value from "173+ "field " + name);174log.display("debuger> Exception: " + e);175testFailed = true;176} catch (IndexOutOfBoundsException e) {177// Index is always out of bounds, so178// IndexOutOfBoundsException is expected179log.display("debuger> " + i + " field: cannot get "180+ "element with index " + j + ". Expected "181+ "exception: " + e);182}183}184}185log.display("debuger> " + i + " field checked.\n");186}187188pipe.println("quit");189debugee.waitFor();190int status = debugee.getStatus();191if (testFailed) {192log.complain("debuger FAILURE> TEST FAILED");193return 2;194} else {195if (status == 95) {196log.display("debuger> expected Debugee's exit "197+ "status - " + status);198return 0;199} else {200log.complain("debuger FAILURE> UNEXPECTED Debugee's exit "201+ "status (not 95) - " + status);202return 2;203}204}205}206}207208209