Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Field/hashCode/hashcode001.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.hashCode;2526import nsk.share.*;27import nsk.share.jpda.*;28import nsk.share.jdi.*;2930import com.sun.jdi.*;31import java.util.*;32import java.io.*;3334public class hashcode001 {35private static Log log;36private final static String prefix = "nsk.jdi.Field.hashCode.";37private final static String className = "hashcode001";38private final static String debugerName = prefix + className;39private final static String debugeeName = debugerName + "a";4041public static void main(String argv[]) {42System.exit(95 + run(argv, System.out));43}4445public static int run(String argv[], PrintStream out) {46ArgumentHandler argHandler = new ArgumentHandler(argv);47log = new Log(out, argHandler);48Binder binder = new Binder(argHandler, log);49Debugee debugee = binder.bindToDebugee(debugeeName50+ (argHandler.verbose() ? " -verbose" : ""));51IOPipe pipe = new IOPipe(debugee);52boolean testFailed = false;53List fields;5455// Connect with debugee and resume it56debugee.redirectStderr(out);57debugee.resume();58String line = pipe.readln();59if (line == null) {60log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null");61return 2;62}63if (!line.equals("ready")) {64log.complain("debuger FAILURE> UNEXPECTED debugee's signal - "65+ line);66return 2;67}68else {69log.display("debuger> debugee's \"ready\" signal recieved.");70}7172// Get all fields from debugee73ReferenceType refType = debugee.classByName(debugeeName);74if (refType == null) {75log.complain("debuger FAILURE> Class " + debugeeName76+ " not found.");77return 2;78}79try {80fields = refType.allFields();81} catch (Exception e) {82log.complain("debuger FAILURE> Can't get fields from class");83log.complain("debuger FAILURE> Exception: " + e);84return 2;85}86int totalFields = fields.size();87if (totalFields < 1) {88log.complain("debuger FAILURE> Total number of fields read "89+ totalFields);90return 2;91}92log.display("debuger> Total fields found: " + fields.size());93Iterator fieldsIterator = fields.iterator();94for (int i = 0; fieldsIterator.hasNext(); i++) {95Field field = (Field)fieldsIterator.next();96int hash1 = field.hashCode();97int hash2 = field.hashCode();98// hashCode() returns int value and always should be the same99// for one field100log.display("debuger> " + i + " field " + field.name()101+ "(" + field.typeName() + ") has hashCode = " + hash1);102if (hash1 != hash2) {103log.complain("debuger FAILURE> Two different hash codes for "104+ "field " + field.name() + " (" + field.typeName()105+ "): " + hash1 + " and " + hash2 + ". Should be "106+ "the same");107testFailed = true;108}109}110pipe.println("quit");111debugee.waitFor();112113int status = debugee.getStatus();114if (testFailed) {115log.complain("debuger FAILURE> TEST FAILED");116return 2;117} else {118if (status == 95) {119log.display("debuger> expected Debugee's exit "120+ "status - " + status);121return 0;122} else {123log.complain("debuger FAILURE> UNEXPECTED Debugee's exit "124+ "status (not 95) - " + status);125return 2;126}127}128}129}130131132