Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventQueue/hashCode/hashcode001.java
41161 views
/*1* Copyright (c) 2002, 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*/2223package nsk.jdi.EventQueue.hashCode;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import com.sun.jdi.request.*;31import com.sun.jdi.event.*;32import com.sun.jdi.connect.*;33import java.io.*;34import java.util.*;3536/**37* The debugger application of the test.38*/39public class hashcode001 {4041//------------------------------------------------------- immutable common fields4243final static String SIGNAL_READY = "ready";44final static String SIGNAL_GO = "go";45final static String SIGNAL_QUIT = "quit";4647private static int waitTime;48private static int exitStatus;49private static ArgumentHandler argHandler;50private static Log log;51private static Debugee debuggee;52private static ReferenceType debuggeeClass;5354//------------------------------------------------------- mutable common fields5556private final static String prefix = "nsk.jdi.EventQueue.hashCode.";57private final static String className = "hashcode001";58private final static String debuggerName = prefix + className;59private final static String debuggeeName = debuggerName + "a";6061//------------------------------------------------------- test specific fields6263//------------------------------------------------------- immutable common methods6465public static void main(String argv[]) {66System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));67}6869private static void display(String msg) {70log.display("debugger > " + msg);71}7273private static void complain(String msg) {74log.complain("debugger FAILURE > " + msg);75}7677public static int run(String argv[], PrintStream out) {7879exitStatus = Consts.TEST_PASSED;8081argHandler = new ArgumentHandler(argv);82log = new Log(out, argHandler);83waitTime = argHandler.getWaitTime() * 60000;8485debuggee = Debugee.prepareDebugee(argHandler, log, debuggeeName);8687debuggeeClass = debuggee.classByName(debuggeeName);88if ( debuggeeClass == null ) {89complain("Class '" + debuggeeName + "' not found.");90exitStatus = Consts.TEST_FAILED;91}9293execTest();9495debuggee.quit();9697return exitStatus;98}99100//------------------------------------------------------ mutable common method101102private static void execTest() {103104display("Checking hashCode() method for EventQueue object");105106EventQueue eventQueue = debuggee.VM().eventQueue();107int hCode = eventQueue.hashCode();108109if (hCode == 0) {110complain("hashCode() returns 0 for EventQueue object");111exitStatus = Consts.TEST_FAILED;112}113114int hCode1 = eventQueue.hashCode();115if (hCode != hCode1) {116complain("hashCode() is not consistent for EventQueue object" +117"\n\t first value :" + hCode + " ; second value : " + hCode1);118exitStatus = Consts.TEST_FAILED;119}120121// get new reference to the same EventQueue and get hash code.122hCode1 = debuggee.VM().eventQueue().hashCode();123if (hCode != hCode1) {124complain("hashCode() does not return same value for equal EventQueue object " +125"\n\t first value :" + hCode + " ; second value : " + hCode1);126exitStatus = Consts.TEST_FAILED;127}128129display("hashCode() returns for EventQueue object : " + hCode);130131display("Checking completed!");132debuggee.resume();133}134135//--------------------------------------------------------- test specific methods136137}138//--------------------------------------------------------- test specific classes139140141