Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventSet/virtualMachine/virtualmachine001.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.EventSet.virtualMachine;2425import nsk.share.*;26import nsk.share.jdi.*;27import com.sun.jdi.*;28import com.sun.jdi.request.*;29import com.sun.jdi.event.*;30import java.io.*;3132/**33* The debugger application of the test.34*/35public class virtualmachine001 {3637//------------------------------------------------------- immutable common fields3839final static String SIGNAL_READY = "ready";40final static String SIGNAL_GO = "go";41final static String SIGNAL_QUIT = "quit";4243private static int waitTime;44private static int exitStatus;45private static ArgumentHandler argHandler;46private static Log log;47private static Debugee debuggee;48private static ReferenceType debuggeeClass;4950//------------------------------------------------------- mutable common fields5152private final static String prefix = "nsk.jdi.EventSet.virtualMachine.";53private final static String className = "virtualmachine001";54private final static String debuggerName = prefix + className;55private final static String debuggeeName = debuggerName + "a";5657//------------------------------------------------------- test specific fields5859private static VirtualMachine vm;6061//------------------------------------------------------- immutable common methods6263public static void main(String argv[]) {64System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));65}6667private static void display(String msg) {68log.display("debugger > " + msg);69}7071private static void complain(String msg) {72log.complain("debugger FAILURE > " + msg);73}7475public static int run(String argv[], PrintStream out) {7677exitStatus = Consts.TEST_PASSED;7879argHandler = new ArgumentHandler(argv);80log = new Log(out, argHandler);81waitTime = argHandler.getWaitTime() * 60000;8283debuggee = Debugee.prepareDebugee(argHandler, log, debuggeeName);8485debuggeeClass = debuggee.classByName(debuggeeName);86if ( debuggeeClass == null ) {87complain("Class '" + debuggeeName + "' not found.");88exitStatus = Consts.TEST_FAILED;89}9091execTest();9293debuggee.quit();9495return exitStatus;96}9798//------------------------------------------------------ mutable common method99100private static void execTest() {101102BreakpointRequest brkp = debuggee.setBreakpoint(debuggeeClass,103virtualmachine001a.brkpMethodName,104virtualmachine001a.brkpLineNumber);105debuggee.resume();106107// get expected reference for comparison.108vm = debuggee.VM();109110debuggee.sendSignal(SIGNAL_GO);111EventSet eventSet = null;112113// waiting the breakpoint event114try {115eventSet = waitEventSet(brkp, waitTime);116} catch (InterruptedException e) {117throw new Failure("unexpected InterruptedException while waiting for Breakpoint event");118}119if (eventSet == null)120throw new Failure("Expected EventSet didn't arrive");121122if (!(eventSet.eventIterator().nextEvent() instanceof BreakpointEvent)) {123debuggee.resume();124throw new Failure("BreakpointEvent didn't arrive");125}126127display("Checking virtualMachine() method for eventSet of Breakpoint event");128checkVM (eventSet);129130display("Checking completed!");131debuggee.resume();132}133134//--------------------------------------------------------- test specific methods135136private static EventSet waitEventSet(EventRequest request, long timeout)137throws InterruptedException {138Event event;139long totalTime = timeout;140long tmp, begin = System.currentTimeMillis(),141delta = 0;142boolean exit = false;143EventIterator eventIterator = null;144EventSet eventSet = null;145146while (totalTime > 0 && !exit) {147if (eventIterator == null || !eventIterator.hasNext()) {148eventSet = debuggee.VM().eventQueue().remove(totalTime);149if (eventSet != null) {150eventIterator = eventSet.eventIterator();151} else {152eventIterator = null;153}154}155if (eventIterator != null) {156while (eventIterator.hasNext()) {157event = eventIterator.nextEvent();158display(" event ===>>> " + event);159if (event.request() != null && event.request().equals(request)) {160return eventSet;161} else if (request == null && event instanceof VMStartEvent) {162return eventSet;163} else if (event instanceof VMDisconnectEvent) {164exit = true;165break;166} // if167} // while168} // if169tmp = System.currentTimeMillis();170delta = tmp - begin;171totalTime -= delta;172begin = tmp;173}174return null;175}176177private static void checkVM (EventSet eventSet) {178VirtualMachine vm1 = eventSet.virtualMachine();179if (vm1 == null) {180complain("virtualMachine() returns null for event set");181exitStatus = Consts.TEST_FAILED;182} else if (vm1 != vm) {183complain("virtualMachine() returns different VirtualMachine object");184exitStatus = Consts.TEST_FAILED;185}186}187}188//--------------------------------------------------------- test specific classes189190191