Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Field/equals/equals001.java
41161 views
/*1* Copyright (c) 2000, 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.Field.equals;2526import nsk.share.*;27import nsk.share.jpda.*;28import nsk.share.jdi.*;2930import com.sun.jdi.*;31import java.util.*;32import java.io.*;3334public class equals001 {35private static Log log;36private final static String prefix = "nsk.jdi.Field.equals.";37private final static String className = "equals001";38private final static String debugerName = prefix + className;39private final static String debugeeName = debugerName + "a";40private final static String classToCheckName = prefix + "ClassToCheck";4142public static void main(String argv[]) {43System.exit(95 + run(argv, System.out));44}4546public static int run(String argv[], PrintStream out) {47ArgumentHandler argHandler = new ArgumentHandler(argv);48log = new Log(out, argHandler);49Binder binder = new Binder(argHandler, log);50Debugee debugee = binder.bindToDebugee(debugeeName51+ (argHandler.verbose() ? " -verbose" : ""));52IOPipe pipe = new IOPipe(debugee);53boolean testFailed = false;54List fieldsDebugee;55List methods;56Iterator methodsIterator;57java.lang.reflect.Field[] fieldsDebuger;58ClassOfFields classOfFields = new ClassOfFields();5960// Connect with debugee and resume it61debugee.redirectStderr(out);62debugee.resume();63String line = pipe.readln();64if (line == null) {65log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null");66return 2;67}68if (!line.equals("ready")) {69log.complain("debuger FAILURE> UNEXPECTED debugee's signal - "70+ line);71return 2;72}73else {74log.display("debuger> debugee's \"ready\" signal recieved.");75}7677// Get all fields from debugee78ReferenceType refType = debugee.classByName(classToCheckName);79if (refType == null) {80log.complain("debuger FAILURE> Class " + classToCheckName81+ " not found.");82return 2;83}84try {85fieldsDebugee = refType.allFields();86} catch (Exception e) {87log.complain("debuger FAILURE> Can't get fields from class");88log.complain("debuger FAILURE> Exception: " + e);89return 2;90}91int totalFields = fieldsDebugee.size();92if (totalFields < 1) {93log.complain("debuger FAILURE> Total number of fields read "94+ totalFields);95return 2;96}97log.display("debuger> Total fields found: " + totalFields);9899// Compare each Field and Method from debugee100try {101methods = refType.allMethods();102} catch (Exception e) {103log.complain("debuger FAILURE 1> Can't get methods from class");104log.complain("debuger FAILURE 1> Exception: " + e);105return 2;106}107log.display("debuger> Total methods found: " + methods.size());108Iterator fieldsIterator = fieldsDebugee.iterator();109for (int i = 0; fieldsIterator.hasNext(); i++) {110Field fieldDebugee = (Field)fieldsIterator.next();111String name = fieldDebugee.name();112methodsIterator = methods.iterator();113114for (int j = 0; methodsIterator.hasNext(); j++) {115Method method = (Method)methodsIterator.next();116String methodName = method.name();117118log.display("debuger> Field " + name + " and method "119+ methodName + " read from debugee.");120if (fieldDebugee.equals(method)) {121// Field is not equal to any Object which type is not Field122log.complain("debuger FAILURE 2> Field " + name123+ " and method " + methodName + " are equal. "124+ "Expected result: not equal.");125testFailed = true;126continue;127}128}129}130131// Compare Field (com.sun.jdi.Field) from debugee and Field132// from debuger (java.lang.reflect.Field)133Class classDebuger = classOfFields.getClass();134try {135fieldsDebuger = classDebuger.getDeclaredFields();136} catch (SecurityException e) {137log.complain("debuger FAILURE 3> Can't get fields from debuger's"138+ " class");139log.complain("debuger FAILURE 3> Exception: " + e);140return 2;141}142int totalDebugerFields = fieldsDebuger.length;143log.display("debuger> Total fields in debuger found: "144+ totalDebugerFields);145fieldsIterator = fieldsDebugee.iterator();146for (int i = 0; fieldsIterator.hasNext(); i++) {147Field fieldDebugee = (Field)fieldsIterator.next();148String name = fieldDebugee.name();149150for (int j = 1; j < totalDebugerFields; j++) {151java.lang.reflect.Field fieldDebuger = fieldsDebuger[j];152String nameDebuger = fieldDebuger.getName();153154log.display("debuger> Field from debugee " + name + " and "155+ "field from debuger " + nameDebuger + " read.");156if (fieldDebugee.equals(fieldDebuger)) {157// Field is not equal to any Object which type158// is not not com.sun.jdi.Field159log.complain("debuger FAILURE 4> Field from debugee "160+ name + " and field from debuger "161+ nameDebuger + " are equal. Expected "162+ "result: not equal.");163testFailed = true;164continue;165}166}167}168pipe.println("quit");169debugee.waitFor();170int status = debugee.getStatus();171if (testFailed) {172log.complain("debuger FAILURE> TEST FAILED");173return 2;174} else {175if (status == 95) {176log.display("debuger> expected Debugee's exit "177+ "status - " + status);178return 0;179} else {180log.complain("debuger FAILURE> UNEXPECTED Debugee's exit "181+ "status (not 95) - " + status);182return 2;183}184}185}186}187188class ClassOfFields {189boolean z0, z1[]={z0}, z2[][]={z1};190byte b0, b1[]={b0}, b2[][]={b1};191char c0, c1[]={c0}, c2[][]={c1};192double d0, d1[]={d0}, d2[][]={d1};193float f0, f1[]={f0}, f2[][]={f1};194int i0, i1[]={i0}, i2[][]={i1};195long l0, l1[]={l0}, l2[][]={l1};196197static long lS0, lS1[]={lS0}, lS2[][]={lS1};198private long lP0, lP1[]={lP0}, lP2[][]={lP1};199public long lU0, lU1[]={lU0}, lU2[][]={lU1};200protected long lR0, lR1[]={lR0}, lR2[][]={lR1};201transient long lT0, lT1[]={lT0}, lT2[][]={lT1};202volatile long lV0, lV1[]={lV0}, lV2[][]={lV1};203final long lF0 = 999, lF1[]={lF0}, lF2[][]={lF1};204205Boolean Z0, Z1[]={Z0}, Z2[][]={Z1};206Byte B0, B1[]={B0}, B2[][]={B1};207Character C0, C1[]={C0}, C2[][]={C1};208Double D0, D1[]={D0}, D2[][]={D1};209Float F0, F1[]={F0}, F2[][]={F1};210Integer I0, I1[]={I0}, I2[][]={I1};211Long L0, L1[]={L0}, L2[][]={L1};212String S0, S1[]={S0}, S2[][]={S1};213Object O0, O1[]={O0}, O2[][]={O1};214215static Long LS0, LS1[]={LS0}, LS2[][]={LS1};216private Long LP0, LP1[]={LP0}, LP2[][]={LP1};217public Long LU0, LU1[]={LU0}, LU2[][]={LU1};218protected Long LR0, LR1[]={LR0}, LR2[][]={LR1};219transient Long LT0, LT1[]={LT0}, LT2[][]={LT1};220volatile Long LV0, LV1[]={LV0}, LV2[][]={LV1};221final Long LF0 = Long.valueOf(999), LF1[]={LF0}, LF2[][]={LF1};222223interface Inter {}224Inter E0, E1[]={E0}, E2[][]={E1};225static Inter ES0, ES1[]={ES0}, ES2[][]={ES1};226private Inter EP0, EP1[]={EP0}, EP2[][]={EP1};227public Inter EU0, EU1[]={EU0}, EU2[][]={EU1};228protected Inter ER0, ER1[]={ER0}, ER2[][]={ER1};229transient Inter ET0, ET1[]={ET0}, ET2[][]={ET1};230volatile Inter EV0, EV1[]={EV0}, EV2[][]={EV1};231final Inter EF0 = null, EF1[]={EF0}, EF2[][]={EF1};232}233234235