Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ArrayReference/getValues/getvalues002.java
41161 views
/*1* Copyright (c) 2001, 2018, 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 getvalues002 {35final static String FIELD_NAME[] = {"z1", "b1", "c1", "d1", "f1", "i1",36"l1", "r1", "lF1", "lP1", "lU1", "lR1",37"lT1", "lV1"};38private static Log log;39private final static String prefix = "nsk.jdi.ArrayReference.getValues.";40private final static String className = "getvalues002";41private final static String debugerName = prefix + className;42private final static String debugeeName = debugerName + "a";43private final static String classToCheckName = prefix + "getvalues002aClassToCheck";4445public static void main(String argv[]) {46System.exit(95 + run(argv, System.out));47}4849public static int run(String argv[], PrintStream out) {50ArgumentHandler argHandler = new ArgumentHandler(argv);51log = new Log(out, argHandler);52Binder binder = new Binder(argHandler, log);53Debugee debugee = binder.bindToDebugee(debugeeName54+ (argHandler.verbose() ? " -verbose" : ""));55IOPipe pipe = debugee.createIOPipe();56boolean testFailed = false;5758// Connect with debugee and resume it59debugee.redirectStderr(out);60debugee.resume();61String line = pipe.readln();62if (line == null) {63log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null");64return 2;65}66if (!line.equals("ready")) {67log.complain("debuger FAILURE> UNEXPECTED debugee's signal - "68+ line);69return 2;70}71else {72log.display("debuger> debugee's \"ready\" signal recieved.");73}7475ReferenceType refType = debugee.classByName(classToCheckName);76if (refType == null) {77log.complain("debuger FAILURE> Class " + classToCheckName78+ " not found.");79return 2;80}81log.display("debuger> Total fields in debugee read: "82+ refType.allFields().size() + " total fields in debuger: "83+ FIELD_NAME.length + "\n");8485// Check all array fields from debugee86for (int i = 0; i < FIELD_NAME.length; i++) {87Field field;88String name = FIELD_NAME[i];89Value value;90ArrayReference arrayRef;91List listOfValues;9293// Get field from debuggee by name94try {95field = refType.fieldByName(name);96} catch (ClassNotPreparedException e) {97log.complain("debuger FAILURE 1> Can't get field by name "98+ name);99log.complain("debuger FAILURE 1> Exception: " + e);100testFailed = true;101continue;102} catch (ObjectCollectedException e) {103log.complain("debuger FAILURE 1> Can't get field by name "104+ name);105log.complain("debuger FAILURE 1> Exception: " + e);106testFailed = true;107continue;108}109log.display("debuger> " + i + " field " + field + " read.");110111// Get field's value112try {113value = refType.getValue(field);114} catch (IllegalArgumentException e) {115log.complain("debuger FAILURE 2> Cannot get value for field "116+ name);117log.complain("debuger FAILURE 2> Exception: " + e);118testFailed = true;119continue;120} catch (ObjectCollectedException e) {121log.complain("debuger FAILURE 2> Cannot get value for field "122+ name);123log.complain("debuger FAILURE 2> Exception: " + e);124testFailed = true;125continue;126}127log.display("debuger> " + i + " field value is " + value);128129// Cast to ArrayReference. All fields in debugee are130// arrays, so ClassCastException should not be thrown131try {132arrayRef = (ArrayReference)value;133} catch (ClassCastException e) {134log.complain("debuger FAILURE 3> Cannot cast value for field "135+ name + " to ArrayReference.");136log.complain("debuger FAILURE 3> Exception: " + e);137testFailed = true;138continue;139}140141// Get all components from array142try {143listOfValues = arrayRef.getValues();144} catch (ObjectCollectedException e) {145log.complain("debuger FAILURE 4> Cannot get values from field "146+ name);147log.complain("debuger FAILURE 4> Exception: " + e);148testFailed = true;149} catch (IndexOutOfBoundsException e) {150log.complain("debuger FAILURE 4> Cannot get values from field "151+ name);152log.complain("debuger FAILURE 4> Exception: " + e);153testFailed = true;154}155log.display("debuger> " + i + " field checked.\n");156}157158pipe.println("quit");159debugee.waitFor();160int status = debugee.getStatus();161if (testFailed) {162log.complain("debuger FAILURE> TEST FAILED");163return 2;164} else {165if (status == 95) {166log.display("debuger> expected Debugee's exit "167+ "status - " + status);168return 0;169} else {170log.complain("debuger FAILURE> UNEXPECTED Debugee's exit "171+ "status (not 95) - " + status);172return 2;173}174}175}176}177178179