Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/breakpointRequests/breakpreq001.java
41161 views
/*1* Copyright (c) 2001, 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.EventRequestManager.breakpointRequests;2425import com.sun.jdi.AbsentInformationException;26import com.sun.jdi.ClassNotPreparedException;27import com.sun.jdi.ObjectCollectedException;28//import com.sun.jdi.InvalidLineNumberException;29import com.sun.jdi.VMDisconnectedException;30import com.sun.jdi.Location;31import com.sun.jdi.ReferenceType;32import com.sun.jdi.VirtualMachine;33import com.sun.jdi.request.BreakpointRequest;34import com.sun.jdi.request.EventRequestManager;35import com.sun.jdi.event.*;3637import java.util.Iterator;38import java.util.List;39import java.io.*;4041import nsk.share.*;42import nsk.share.jpda.*;43import nsk.share.jdi.*;4445/**46* The test checks that the JDI method47* <code>com.sun.jdi.request.EventRequestManager.breakpointRequests()</code>48* properly returns all previously created BreakpointRequest objects when:49* <li>event requests are disabled50* <li>event requests are enabled<br>51* EventHandler was added as workaround for the bug 4430096.52* This prevents the target VM from potential hangup.53*/54public class breakpreq001 {55public static final int PASSED = 0;56public static final int FAILED = 2;57public static final int JCK_STATUS_BASE = 95;58static final String DEBUGGEE_CLASS =59"nsk.jdi.EventRequestManager.breakpointRequests.breakpreq001t";60static final String COMMAND_READY = "ready";61static final String COMMAND_QUIT = "quit";6263static final int BPS_NUM = 10;64static final String DEBUGGEE_BPS[][] = {65{"main", "void", "breakpreq001t.java"},66{"byteMeth", "byte", "breakpreq001t.java"},67{"shortMeth", "short", "breakpreq001t.java"},68{"prMeth", "int", "breakpreq001t.java"},69{"protMeth", "long", "breakpreq001t.java"},70{"floatMeth", "float", "breakpreq001t.java"},71{"doubleMeth", "double", "breakpreq001t.java"},72{"charMeth", "char", "breakpreq001t.java"},73{"boolMeth", "boolean", "breakpreq001t.java"},74{"pubMeth", "java.lang.String", "breakpreq001t.java"}75};76static final int DEBUGGEE_LNS[] = {7737, 54, 57, 60, 63, 66, 69, 72, 75, 7878};7980private Log log;81private IOPipe pipe;82private Debugee debuggee;83private VirtualMachine vm;84private EventListener elThread;85private volatile int tot_res = PASSED;8687public static void main (String argv[]) {88System.exit(run(argv,System.out) + JCK_STATUS_BASE);89}9091public static int run(String argv[], PrintStream out) {92return new breakpreq001().runIt(argv, out);93}9495private int runIt(String args[], PrintStream out) {96ArgumentHandler argHandler = new ArgumentHandler(args);97log = new Log(out, argHandler);98Binder binder = new Binder(argHandler, log);99ReferenceType rType;100List loctns;101BreakpointRequest bpRequest[] = new BreakpointRequest[BPS_NUM];102String cmd;103104debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);105pipe = debuggee.createIOPipe();106debuggee.redirectStderr(log, "breakpreq001t.err> ");107vm = debuggee.VM();108EventRequestManager erManager = vm.eventRequestManager();109debuggee.resume();110cmd = pipe.readln();111if (!cmd.equals(COMMAND_READY)) {112log.complain("TEST BUG: unknown debuggee's command: " + cmd);113tot_res = FAILED;114return quitDebuggee();115}116if ((rType = debuggee.classByName(DEBUGGEE_CLASS)) == null) {117log.complain("TEST FAILURE: Method Debugee.classByName() returned null");118tot_res = FAILED;119return quitDebuggee();120}121122for (int i=0; i<BPS_NUM; i++) {123try {124loctns = rType.locationsOfLine(DEBUGGEE_LNS[i]);125} catch(AbsentInformationException e) {126log.complain("TEST FAILURE: ReferenceType.locationsOfLine(): " + e);127tot_res = FAILED;128return quitDebuggee();129} catch(ClassNotPreparedException e) {130log.complain("TEST FAILURE: ReferenceType.locationsOfLine(): " + e);131tot_res = FAILED;132return quitDebuggee();133} catch(ObjectCollectedException e) {134log.complain("TEST FAILURE: ReferenceType.locationsOfLine(): " + e);135tot_res = FAILED;136return quitDebuggee();137/* } catch(InvalidLineNumberException e) {138log.complain("TEST FAILURE: ReferenceType.locationsOfLine(): " + e);139tot_res = FAILED;140return quitDebuggee();*/141}142if (loctns.size() == 0) {143log.complain("TEST FAILED: ReferenceType.locationsOfLine() returned 0 JDI Locations\n"144+ "\tfor the valid debuggee's line #" + DEBUGGEE_LNS[i]);145tot_res = FAILED;146return quitDebuggee();147}148Iterator iter = loctns.iterator();149while (iter.hasNext()) {150Location loc = (Location) iter.next();151try {152log.display("Creating BreakpointRequest for the location:\n\t"153+ loc.sourceName() + ":" + loc.lineNumber() + "\tmethod: "154+ loc.method().returnTypeName()155+ " " + loc.method().name());156} catch(AbsentInformationException e) {157log.complain("TEST FAILURE: Location.sourceName(): " + e);158tot_res = FAILED;159return quitDebuggee();160}161try {162bpRequest[i] = erManager.createBreakpointRequest(loc);163} catch (Exception e) {164log.complain("TEST FAILURE: EventRequestManager.createBreakpointRequest(): "165+ e);166tot_res = FAILED;167return quitDebuggee();168}169}170}171elThread = new EventListener();172elThread.start();173174// Check Breakpoint requests when event requests are disabled175log.display("\n1) Getting BreakpointRequest objects with disabled event requests...");176checkRequests(erManager, 1);177178// Check Breakpoint requests when event requests are enabled179for (int i=0; i<BPS_NUM; i++) {180bpRequest[i].enable();181}182log.display("\n2) Getting BreakpointRequest objects with enabled event requests...");183checkRequests(erManager, 2);184185// Finish the test186for (int i=0; i<BPS_NUM; i++) {187bpRequest[i].disable();188}189return quitDebuggee();190}191192private void checkRequests(EventRequestManager erManager, int t_case) {193List reqL = erManager.breakpointRequests();194if (reqL.size() != BPS_NUM) {195log.complain("\nTEST CASE #" + t_case + " FAILED: found " + reqL.size()196+ " Breakpoint requests\n\texpected: " + BPS_NUM);197tot_res = FAILED;198return;199}200for (int i=0; i<BPS_NUM; i++) {201BreakpointRequest bpReq =202(BreakpointRequest) reqL.get(i);203Location loc = bpReq.location();204boolean notFound = true;205try {206for (int j=0; j<BPS_NUM; j++) {207if (loc.lineNumber() == DEBUGGEE_LNS[j]) {208if (loc.method().name().equals(DEBUGGEE_BPS[j][0]) &&209loc.method().returnTypeName().equals(DEBUGGEE_BPS[j][1]) &&210loc.sourceName().equals(DEBUGGEE_BPS[j][2])) {211log.display("Found expected Breakpoint request for the location:\n\t"212+ DEBUGGEE_BPS[j][2] + ":" + DEBUGGEE_LNS[j]213+ "\tmethod: " + DEBUGGEE_BPS[j][1] + " " + DEBUGGEE_BPS[j][0]);214} else {215log.complain("\nTEST CASE #" + t_case216+ " FAILED: found a Breakpoint request for the location:\n\t"217+ loc.sourceName() + ":" + loc.lineNumber()218+ "\tmethod: " + loc.method().returnTypeName() + " "219+ loc.method().name()220+ "\n\tmismatched with the expected location: "221+ DEBUGGEE_BPS[j][2] + ":"222+ DEBUGGEE_LNS[j] + "\tmethod: " + DEBUGGEE_BPS[j][1]223+ " " + DEBUGGEE_BPS[j][0]);224tot_res = FAILED;225}226notFound = false;227break;228}229}230if (notFound) {231log.complain("\nTEST CASE #" + t_case232+ " FAILED: found a Breakpoint request for the unexpected location:\n\t"233+ loc.sourceName() + ":" + loc.lineNumber() + "\tmethod: "234+ loc.method().returnTypeName() + " "235+ loc.method().name());236tot_res = FAILED;237}238} catch(AbsentInformationException e) {239log.complain("TEST FAILURE: checkRequests: Location.sourceName(): "240+ e);241tot_res = FAILED;242return;243}244}245}246247private int quitDebuggee() {248if (elThread != null) {249elThread.isConnected = false;250try {251if (elThread.isAlive())252elThread.join();253} catch (InterruptedException e) {254log.complain("TEST INCOMPLETE: caught InterruptedException "255+ e);256tot_res = FAILED;257}258}259260pipe.println(COMMAND_QUIT);261debuggee.waitFor();262int debStat = debuggee.getStatus();263if (debStat != (JCK_STATUS_BASE + PASSED)) {264log.complain("TEST FAILED: debuggee's process finished with status: "265+ debStat);266tot_res = FAILED;267} else268log.display("Debuggee's process finished with status: "269+ debStat);270271return tot_res;272}273274class EventListener extends Thread {275public volatile boolean isConnected = true;276277public void run() {278try {279do {280EventSet eventSet = vm.eventQueue().remove(1000);281if (eventSet != null) { // there is not a timeout282EventIterator it = eventSet.eventIterator();283while (it.hasNext()) {284Event event = it.nextEvent();285if (event instanceof VMDeathEvent) {286tot_res = FAILED;287isConnected = false;288log.complain("TEST FAILED: unexpected VMDeathEvent");289} else if (event instanceof VMDisconnectEvent) {290tot_res = FAILED;291isConnected = false;292log.complain("TEST FAILED: unexpected VMDisconnectEvent");293} else294log.display("EventListener: following JDI event occured: "295+ event.toString());296}297if (isConnected) {298eventSet.resume();299}300}301} while (isConnected);302} catch (InterruptedException e) {303tot_res = FAILED;304log.complain("FAILURE in EventListener: caught unexpected "305+ e);306} catch (VMDisconnectedException e) {307tot_res = FAILED;308log.complain("FAILURE in EventListener: caught unexpected "309+ e);310e.printStackTrace();311}312log.display("EventListener: exiting");313}314}315}316317318