Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Field/equals/equals002.java
41161 views
/*1* Copyright (c) 2000, 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.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 equals002 {35final static int TOTAL_FIELDS = 117;36final static String FIELDS_TYPE_NAME[][] = {37{"boolean", "z0"},38{"boolean", "z1"},39{"boolean", "z2"},40{"byte", "b0"},41{"byte", "b1"},42{"byte", "b2"},43{"char", "c0"},44{"char", "c1"},45{"char", "c2"},46{"double", "d0"},47{"double", "d1"},48{"double", "d2"},49{"float", "f0"},50{"float", "f1"},51{"float", "f2"},52{"int", "i0"},53{"int", "i1"},54{"int", "i2"},55{"long", "l0"},56{"long", "l1"},57{"long", "l2"},5859{"long", "lS0"},60{"long", "lS1"},61{"long", "lS2"},62{"long", "lP0"},63{"long", "lP1"},64{"long", "lP2"},65{"long", "lU0"},66{"long", "lU1"},67{"long", "lU2"},68{"long", "lR0"},69{"long", "lR1"},70{"long", "lR2"},71{"long", "lT0"},72{"long", "lT1"},73{"long", "lT2"},74{"long", "lV0"},75{"long", "lV1"},76{"long", "lV2"},77{"long", "lF0"},78{"long", "lF1"},79{"long", "lF2"},8081{"Class", "X0"},82{"Class", "X1"},83{"Class", "X2"},84{"Boolean", "Z0"},85{"Boolean", "Z1"},86{"Boolean", "Z2"},87{"Byte", "B0"},88{"Byte", "B1"},89{"Byte", "B2"},90{"Char", "C0"},91{"Char", "C1"},92{"Char", "C2"},93{"Double", "D0"},94{"Double", "D1"},95{"Double", "D2"},96{"Float", "F0"},97{"Float", "F1"},98{"Float", "F2"},99{"Int", "I0"},100{"Int", "I1"},101{"Int", "I2"},102{"Long", "L0"},103{"Long", "L1"},104{"Long", "L2"},105{"String", "S0"},106{"String", "S1"},107{"String", "S2"},108{"Object", "O0"},109{"Object", "O1"},110{"Object", "O2"},111112{"Long", "LS0"},113{"Long", "LS1"},114{"Long", "LS2"},115{"Long", "LP0"},116{"Long", "LP1"},117{"Long", "LP2"},118{"Long", "LU0"},119{"Long", "LU1"},120{"Long", "LU2"},121{"Long", "LR0"},122{"Long", "LR1"},123{"Long", "LR2"},124{"Long", "LT0"},125{"Long", "LT1"},126{"Long", "LT2"},127{"Long", "LV0"},128{"Long", "LV1"},129{"Long", "LV2"},130{"Long", "LF0"},131{"Long", "LF1"},132{"Long", "LF2"},133134{"Inter", "E0"},135{"Inter", "E1"},136{"Inter", "E2"},137{"Inter", "ES0"},138{"Inter", "ES1"},139{"Inter", "ES2"},140{"Inter", "EP0"},141{"Inter", "EP1"},142{"Inter", "EP2"},143{"Inter", "EU0"},144{"Inter", "EU1"},145{"Inter", "EU2"},146{"Inter", "ER0"},147{"Inter", "ER1"},148{"Inter", "ER2"},149{"Inter", "ET0"},150{"Inter", "ET1"},151{"Inter", "ET2"},152{"Inter", "EV0"},153{"Inter", "EV1"},154{"Inter", "EV2"},155{"Inter", "EF0"},156{"Inter", "EF1"},157{"Inter", "EF2"}158};159private static Log log;160private final static String prefix = "nsk.jdi.Field.equals.";161private final static String className = "equals002";162private final static String debugerName = prefix + className;163private final static String debugeeName = debugerName + "a";164165public static void main(String argv[]) {166System.exit(95 + run(argv, System.out));167}168169public static int run(String argv[], PrintStream out) {170ArgumentHandler argHandler = new ArgumentHandler(argv);171log = new Log(out, argHandler);172Binder binder = new Binder(argHandler, log);173Debugee debugee = binder.bindToDebugee(debugeeName174+ (argHandler.verbose() ? " -verbose" : ""));175IOPipe pipe = new IOPipe(debugee);176boolean testFailed = false;177List fields;178179// Connect with debugee and resume it180debugee.redirectStderr(out);181debugee.resume();182String line = pipe.readln();183if (line == null) {184log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null");185return 2;186}187if (!line.equals("ready")) {188log.complain("debuger FAILURE> UNEXPECTED debugee's signal - "189+ line);190return 2;191}192else {193log.display("debuger> debugee's \"ready\" signal recieved.");194}195196// Get all fields from debugee197ReferenceType refType = debugee.classByName(debugeeName);198if (refType == null) {199log.complain("debuger FAILURE> Class " + debugeeName200+ " not found.");201return 2;202}203try {204fields = refType.allFields();205} catch (Exception e) {206log.complain("debuger FAILURE> Can't get fields from class");207log.complain("debuger FAILURE> Exception: " + e);208return 2;209}210int totalFields = fields.size();211if (totalFields < 1) {212log.complain("debuger FAILURE> Total number of fields read "213+ totalFields + ", should be " + TOTAL_FIELDS);214return 2;215}216log.display("debuger> Total fields found: " + totalFields);217Iterator fieldsIterator = fields.iterator();218for (int i = 0; fieldsIterator.hasNext(); i++) {219Field srcField = (Field)fieldsIterator.next();220String name = srcField.name();221222// Compare all fields with each other but srcField223if (name == null) {224log.complain("debuger FAILURE 1> Name is null for " + i225+ " field");226testFailed = true;227continue;228}229for (int j = 0; j < TOTAL_FIELDS; j++) {230String checkFieldName = FIELDS_TYPE_NAME[j][1];231Field checkField;232233if (!name.equals(checkFieldName)) {234try {235checkField = refType.fieldByName(checkFieldName);236} catch (Exception e) {237log.complain("debuger FAILURE 2> Can't get field "238+ "by name " + checkFieldName);239log.complain("debuger FAILURE 2> Exception: " + e);240testFailed = true;241continue;242}243244// Compare two different Fields, result should be false245boolean fieldsEqual = srcField.equals(checkField);246log.display("debuger> Compared fields " + name + " and "247+ checkFieldName + ", result is " + fieldsEqual);248if (fieldsEqual) {249// Fields in the same class that mirror different250// fields are not equal251log.complain("debuger FAILURE 3> Different fields "252+ "(" + name + " and " + checkFieldName + ")"253+ " are equal. Expected result: not equal.");254testFailed = true;255continue;256}257}258}259}260pipe.println("quit");261debugee.waitFor();262int status = debugee.getStatus();263if (testFailed) {264log.complain("debuger FAILURE> TEST FAILED");265return 2;266} else {267if (status == 95) {268log.display("debuger> expected Debugee's exit "269+ "status - " + status);270return 0;271} else {272log.complain("debuger FAILURE> UNEXPECTED Debugee's exit "273+ "status (not 95) - " + status);274return 2;275}276}277}278}279280281