Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/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.EventRequest.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.EventRequest.hashCode.";57private final static String className = "hashcode001";58private final static String debuggerName = prefix + className;59private final static String debuggeeName = debuggerName + "a";6061//------------------------------------------------------- test specific fields6263private final static String methodName = "main";64private final static String fieldName = "exitStatus";6566//------------------------------------------------------- immutable common methods6768public static void main(String argv[]) {69System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));70}7172private static void display(String msg) {73log.display("debugger > " + msg);74}7576private static void complain(String msg) {77log.complain("debugger FAILURE > " + msg);78}7980public static int run(String argv[], PrintStream out) {8182exitStatus = Consts.TEST_PASSED;8384argHandler = new ArgumentHandler(argv);85log = new Log(out, argHandler);86waitTime = argHandler.getWaitTime() * 60000;8788debuggee = Debugee.prepareDebugee(argHandler, log, debuggeeName);8990debuggeeClass = debuggee.classByName(debuggeeName);91if ( debuggeeClass == null ) {92complain("Class '" + debuggeeName + "' not found.");93exitStatus = Consts.TEST_FAILED;94}9596execTest();9798debuggee.quit();99100return exitStatus;101}102103//------------------------------------------------------ mutable common method104105private static void execTest() {106107EventRequestManager eventRequestManager = debuggee.VM().eventRequestManager();108EventRequest eventRequest;109110display("Checking hashCode() method for EventRequest objects");111112for (int i = 0; i < 12; i++) {113114switch (i) {115116case 0:117ThreadReference thread = debuggee.threadByNameOrThrow(methodName);118119display(".....setting up StepRequest");120eventRequest = eventRequestManager.createStepRequest121(thread, StepRequest.STEP_MIN, StepRequest.STEP_INTO);122break;123124case 1:125display(".....setting up AccessWatchpointRequest");126eventRequest = eventRequestManager.createAccessWatchpointRequest127(debuggeeClass.fieldByName(fieldName));128break;129130case 2:131display(".....setting up ModificationWatchpointRequest");132eventRequest = eventRequestManager.createModificationWatchpointRequest133(debuggeeClass.fieldByName(fieldName));134break;135136case 3:137display(".....setting up ClassPrepareRequest");138eventRequest = eventRequestManager.createClassPrepareRequest();139break;140141case 4:142display(".....setting up ClassUnloadRequest");143eventRequest = eventRequestManager.createClassUnloadRequest();144break;145146case 5:147display(".....setting up MethodEntryRequest");148eventRequest = eventRequestManager.createMethodEntryRequest();149break;150151case 6:152display(".....setting up MethodExitRequest");153eventRequest = eventRequestManager.createMethodExitRequest();154break;155156case 7:157display(".....setting up ThreadDeathRequest");158eventRequest = eventRequestManager.createThreadDeathRequest();159break;160161case 8:162display(".....setting up ThreadStartRequest");163eventRequest = eventRequestManager.createThreadStartRequest();164break;165166case 9:167display(".....setting up VMDeathRequest");168eventRequest = eventRequestManager.createVMDeathRequest();169break;170171case 10:172display(".....setting up ExceptionRequest");173eventRequest = eventRequestManager.createExceptionRequest( null, true, true );174break;175176case 11:177display(".....setting up BreakpointRequest");178Method method = methodByName(debuggeeClass, methodName);179List locs = null;180try {181locs = method.allLineLocations();182} catch(AbsentInformationException e) {183throw new Failure("Unexpected AbsentInformationException while getting ");184}185Location location = (Location)locs.get(0);186eventRequest = eventRequestManager.createBreakpointRequest(location);187break;188189default:190throw new Failure("Wrong test case : " + i);191}192193int hCode = eventRequest.hashCode();194195if (hCode == 0) {196complain("hashCode() returns 0 for EventRequest object " + eventRequest);197exitStatus = Consts.TEST_FAILED;198}199200int hCode1 = eventRequest.hashCode();201if (hCode != hCode1) {202complain("hashCode() is not consistent for EventRequest object " + eventRequest +203"\n\t first value :" + hCode + " ; second value : " + hCode1);204exitStatus = Consts.TEST_FAILED;205}206207display("hashCode() returns " + hCode + " for EventRequest object : " + eventRequest);208eventRequestManager.deleteEventRequest(eventRequest);209}210211212display("Checking completed!");213debuggee.resume();214}215216//--------------------------------------------------------- test specific methods217218private static Method methodByName(ReferenceType refType, String methodName) {219List methodList = refType.methodsByName(methodName);220if (methodList == null) return null;221222Method method = (Method) methodList.get(0);223return method;224}225226}227//--------------------------------------------------------- test specific classes228229230