Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ArrayReference/length/length001.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.length;2526import nsk.share.*;27import nsk.share.jpda.*;28import nsk.share.jdi.*;2930import com.sun.jdi.*;31import java.io.*;3233public class length001 {34final static String FIELD_NAME[][] = {35{"z1", "0"},36{"z2", "7"},37{"b1", "1"},38{"b2", "6"},39{"c1", "2"},40{"c2", "5"},41{"d1", "3"},42{"d2", "4"},43{"f1", "4"},44{"f2", "3"},45{"i1", "5"},46{"i2", "2"},47{"l1", "6"},48{"l2", "1"},49{"r1", "7"},50{"r2", "0"},5152{"lF1", "3"},53{"lP1", "3"},54{"lU1", "2"},55{"lR1", "2"},56{"lT1", "1"},57{"lV1", "1"},5859{"E1", "0"},60{"E2", "2"},61{"X1", "1"},62{"X2", "1"},63{"O1", "2"},64{"O2", "0"},6566{"LF1", "3"},67{"LP1", "3"},68{"LU1", "2"},69{"LR1", "2"},70{"LT1", "1"},71{"LV1", "1"},7273{"EF1", "0"},74{"EP1", "1"},75{"EU1", "1"},76{"ER1", "1"},77{"ET1", "1"},78{"EV1", "1"},79};8081private static Log log;82private final static String prefix = "nsk.jdi.ArrayReference.length.";83private final static String className = "length001";84private final static String debugerName = prefix + className;85private final static String debugeeName = debugerName + "a";86private final static String classToCheckName = prefix + "ClassToCheck";8788public static void main(String argv[]) {89System.exit(95 + run(argv, System.out));90}9192public static int run(String argv[], PrintStream out) {93ArgumentHandler argHandler = new ArgumentHandler(argv);94log = new Log(out, argHandler);95Binder binder = new Binder(argHandler, log);96Debugee debugee = binder.bindToDebugee(debugeeName97+ (argHandler.verbose() ? " -verbose" : ""));98IOPipe pipe = debugee.createIOPipe();99boolean testFailed = false;100101// Connect with debugee and resume it102debugee.redirectStderr(out);103debugee.resume();104String line = pipe.readln();105if (line == null) {106log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null");107return 2;108}109if (!line.equals("ready")) {110log.complain("debuger FAILURE> UNEXPECTED debugee's signal - "111+ line);112return 2;113}114else {115log.display("debuger> debugee's \"ready\" signal recieved.");116}117118ReferenceType refType = debugee.classByName(classToCheckName);119if (refType == null) {120log.complain("debuger FAILURE> Class " + classToCheckName121+ " not found.");122return 2;123}124log.display("debuger> Total fields in debugee read: "125+ refType.allFields().size() + " total fields in debuger: "126+ FIELD_NAME.length + "\n");127128// Check all array fields from debugee129for (int i = 0; i < FIELD_NAME.length; i++) {130Field field;131String name = FIELD_NAME[i][0];132String realLength = FIELD_NAME[i][1];133Value value;134ArrayReference arrayRef;135int length;136String lengthStr;137138// Get field from debuggee by name139try {140field = refType.fieldByName(name);141} catch (ClassNotPreparedException e) {142log.complain("debuger FAILURE 1> Can't get field by name "143+ name);144log.complain("debuger FAILURE 1> Exception: " + e);145testFailed = true;146continue;147} catch (ObjectCollectedException e) {148log.complain("debuger FAILURE 1> Can't get field by name "149+ name);150log.complain("debuger FAILURE 1> Exception: " + e);151testFailed = true;152continue;153}154log.display("debuger> " + i + " field " + field + " read.");155156// Get field's value157try {158value = refType.getValue(field);159} catch (IllegalArgumentException e) {160log.complain("debuger FAILURE 2> Cannot get value for field "161+ name);162log.complain("debuger FAILURE 2> Exception: " + e);163testFailed = true;164continue;165} catch (ObjectCollectedException e) {166log.complain("debuger FAILURE 2> Cannot get value for field "167+ name);168log.complain("debuger FAILURE 2> Exception: " + e);169testFailed = true;170continue;171}172log.display("debuger> " + i + " field value is " + value);173174// Cast to ArrayReference. All fields in debugee are175// arrays, so ClassCastException should not be thrown176try {177arrayRef = (ArrayReference)value;178} catch (ClassCastException e) {179log.complain("debuger FAILURE 3> Cannot cast value for field "180+ name + " to ArrayReference.");181log.complain("debuger FAILURE 3> Exception: " + e);182testFailed = true;183continue;184}185186// Get length of ArrayReference object187try {188length = arrayRef.length();189} catch (ObjectCollectedException e) {190log.complain("debuger FAILURE 4> Cannot get length for array "191+ name);192log.complain("debuger FAILURE 4> Exception: " + e);193testFailed = true;194continue;195}196log.display("debuger> " + i + " field length is " + length);197lengthStr = realLength.valueOf(length);198199// Check array's length200if (!realLength.equals(lengthStr)) {201log.complain("debuger FAILURE 5> Length of array " + name202+ " is " + length + ", but expected " + realLength);203testFailed = true;204}205log.display("debuger> " + i + " field checked.\n");206}207208pipe.println("quit");209debugee.waitFor();210int status = debugee.getStatus();211if (testFailed) {212log.complain("debuger FAILURE> TEST FAILED");213return 2;214} else {215if (status == 95) {216log.display("debuger> expected Debugee's exit "217+ "status - " + status);218return 0;219} else {220log.complain("debuger FAILURE> UNEXPECTED Debugee's exit "221+ "status (not 95) - " + status);222return 2;223}224}225}226}227228229