Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Event/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*/22package nsk.jdi.Event.hashCode;2324import nsk.share.*;25import nsk.share.jpda.*;26import nsk.share.jdi.*;2728import com.sun.jdi.*;29import com.sun.jdi.request.*;30import com.sun.jdi.event.*;31import com.sun.jdi.connect.*;32import java.io.*;33import java.util.*;3435/**36* The debugger application of the test.37*/38public class hashcode001 {3940//------------------------------------------------------- immutable common fields4142final static String SIGNAL_READY = "ready";43final static String SIGNAL_GO = "go";44final static String SIGNAL_QUIT = "quit";4546private static int waitTime;47private static int exitStatus;48private static ArgumentHandler argHandler;49private static Log log;50private static Debugee debuggee;51private static ReferenceType debuggeeClass;5253//------------------------------------------------------- mutable common fields5455private final static String prefix = "nsk.jdi.Event.hashCode.";56private final static String className = "hashcode001";57private final static String debuggerName = prefix + className;58private final static String debuggeeName = debuggerName + "a";5960//------------------------------------------------------- test specific fields6162private final static String threadClassName = prefix + "hashcode001aThread";63private final static String threadName = "thread1";64private final static String methodName = "foo";65private final static String fieldName = "name";66private final static int brkpLineNumber = 145;6768//------------------------------------------------------- immutable common methods6970public static void main(String argv[]) {71System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));72}7374private static void display(String msg) {75log.display("debugger > " + msg);76}7778private static void complain(String msg) {79log.complain("debugger FAILURE > " + msg);80}8182public static int run(String argv[], PrintStream out) {8384exitStatus = Consts.TEST_PASSED;8586argHandler = new ArgumentHandler(argv);87log = new Log(out, argHandler);88waitTime = argHandler.getWaitTime() * 60000;8990debuggee = Debugee.prepareDebugee(argHandler, log, debuggeeName);9192debuggeeClass = debuggee.classByName(debuggeeName);93if ( debuggeeClass == null ) {94throw new Failure("Class '" + debuggeeName + "' not found.");95}9697execTest();9899int status = debuggee.endDebugee();100if ( status != Consts.JCK_STATUS_BASE ) {101throw new Failure("UNEXPECTED Debugee's exit status : " + status);102}103display("expected Debugee's exit status : " + status);104105return exitStatus;106}107108//------------------------------------------------------ mutable common method109110private static void execTest() {111112EventRequestManager eventRequestManager = debuggee.VM().eventRequestManager();113EventRequest eventRequest;114115ReferenceType testedClass = debuggee.classByName(threadClassName);116if ( testedClass == null ) {117throw new Failure("Class '" + threadClassName + "' not found.");118}119120for (int i = 0; i < 11; i++) {121eventRequest = null;122switch (i) {123124case 0:125ThreadReference thread = debuggee.threadByName(threadName);126127display(".....setting up StepRequest");128eventRequest = eventRequestManager.createStepRequest129(thread, StepRequest.STEP_MIN, StepRequest.STEP_INTO);130break;131132case 1:133display(".....setting up AccessWatchpointRequest");134eventRequest = eventRequestManager.createAccessWatchpointRequest135(testedClass.fieldByName(fieldName));136break;137138case 2:139display(".....setting up ModificationWatchpointRequest");140eventRequest = eventRequestManager.createModificationWatchpointRequest141(testedClass.fieldByName(fieldName));142break;143144case 3:145display(".....setting up ClassPrepareRequest");146eventRequest = eventRequestManager.createClassPrepareRequest();147break;148149case 4:150display(".....setting up ClassUnloadRequest");151eventRequest = eventRequestManager.createClassUnloadRequest();152break;153154case 5:155display(".....setting up MethodEntryRequest");156eventRequest = eventRequestManager.createMethodEntryRequest();157break;158159case 6:160display(".....setting up MethodExitRequest");161eventRequest = eventRequestManager.createMethodExitRequest();162break;163164case 7:165display(".....setting up ThreadDeathRequest");166eventRequest = eventRequestManager.createThreadDeathRequest();167break;168169case 8:170display(".....setting up ThreadStartRequest");171eventRequest = eventRequestManager.createThreadStartRequest();172break;173174case 9:175display(".....setting up ExceptionRequest");176eventRequest = eventRequestManager.createExceptionRequest( null, true, true );177break;178179case 10:180display(".....setting up BreakpointRequest");181eventRequest = debuggee.makeBreakpoint(testedClass, methodName, brkpLineNumber);182break;183184default:185throw new Failure("Wrong test case : " + i);186}187188if (eventRequest == null) {189throw new Failure("Cannot create request case : " + i);190}191eventRequest.addCountFilter(1);192eventRequest.enable();193}194195debuggee.sendSignal(SIGNAL_GO);196197display("Checking hashCode() method for Event objects");198199boolean exit = false;200boolean connected = true;201while (!exit) {202EventSet eventSet = getEventSet();203EventIterator eventIterator = eventSet.eventIterator();204205while (eventIterator.hasNext()) {206Event event = eventIterator.nextEvent();207String eventName = null;208209if (event instanceof VMDeathEvent) {210eventName = "VMDeathEvent";211connected = false;212} else if (event instanceof VMDisconnectEvent) {213eventName = "VMDisconnectEvent";214connected = false;215exit = true;216} else {217eventName = "" + event;218}219220try {221int hCode = event.hashCode();222display("hashCode() returns " + hCode + " for Event object : " + eventName);223224if (hCode == 0) {225complain("hashCode() returns 0 for Event object " + eventName);226exitStatus = Consts.TEST_FAILED;227}228229int hCode1 = event.hashCode();230if (hCode != hCode1) {231complain("hashCode() is not consistent for Event object " + eventName +232"\n\t first value :" + hCode + " ; second value : " + hCode1);233exitStatus = Consts.TEST_FAILED;234}235236} catch (VMDisconnectedException e) {237// skip error message if already disconnected238if (connected) {239throw new Failure("Caught unexpected VMDisconnectedException:\n\t" + e);240}241}242}243if (connected) {244eventSet.resume();245}246}247display("Checking completed!");248}249250//--------------------------------------------------------- test specific methods251252private static EventSet getEventSet() {253EventSet eventSet;254try {255eventSet = debuggee.VM().eventQueue().remove(waitTime);256if (eventSet == null) {257throw new Failure("TIMEOUT while waiting for event");258}259} catch ( Exception e ) {260throw new Failure("Unexpected exception while waiting for event " + e);261}262return eventSet;263}264}265//--------------------------------------------------------- test specific classes266267268