Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BScenarios/multithrd/tc02x002.java
41160 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.BScenarios.multithrd;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.*;3233import java.util.*;34import java.io.*;3536/**37* This test is from the group of so-called Borland's scenarios and38* implements the following test case: <br>39* Suite 2 - Breakpoints (multiple threads) <br>40* Test case: TC2 <br>41* Description: Class breakpoint <br>42* Steps: 1.Add class breakpoint: singlethread.Class1 <br>43* 2.Debug Main <br>44* X. Stops on line 13 in Class1.java <br>45*46* When the test is starting debugee, debugger creates <code>MethodEntryRequest</code>.47* After <code>MethodEntryEvent</code> arrived, debugger checks line number of one's48* location. It should be 80th or 82th lines, that are static initializer and49* constructor of <code>tc02x001aClass1</code> class. Every thread must generate50* <code>MethodEntryEvent</code>.51*52* In case, when at least one event doesn't arrive during waittime53* interval or line number of event is wrong, test fails.54*/5556public class tc02x002 {5758public final static String SGL_READY = "ready";59public final static String SGL_PERFORM = "perform";60public final static String SGL_LOAD = "load";61public final static String SGL_QUIT = "quit";6263private final static String prefix = "nsk.jdi.BScenarios.multithrd.";64private final static String debuggerName = prefix + "tc02x002";65private final static String debugeeName = debuggerName + "a";66private final static String testedClassName = debugeeName + "Class1";6768private static int exitStatus;69private static Log log;70private static Debugee debugee;71private static long waitTime;72private static int eventCount = 0;7374private EventRequestManager evm = null;75private MethodEntryRequest mthdReq = null;76private volatile boolean exit = false;7778private static void display(String msg) {79log.display(msg);80}8182private static void complain(String msg) {83log.complain("debugger FAILURE> " + msg + "\n");84}8586public static void main(String argv[]) {87System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));88}8990public static int run(String argv[], PrintStream out) {9192exitStatus = Consts.TEST_PASSED;93tc02x002 thisTest = new tc02x002();9495ArgumentHandler argHandler = new ArgumentHandler(argv);96log = new Log(out, argHandler);97waitTime = argHandler.getWaitTime() * 60000;9899Binder binder = new Binder(argHandler, log);100debugee = binder.bindToDebugee(debugeeName);101IOPipe pipe = debugee.createIOPipe();102103try {104thisTest.execTest();105} catch (Throwable e) {106complain("Unexpected " + e);107exitStatus = Consts.TEST_FAILED;108e.printStackTrace();109} finally {110debugee.endDebugee();111}112display("Test finished. exitStatus = " + exitStatus);113114return exitStatus;115}116117private void execTest() throws Failure {118evm = debugee.getEventRequestManager();119120ClassPrepareRequest crq = evm.createClassPrepareRequest();121crq.addClassFilter(testedClassName);122crq.enable();123124// event handling thread125Thread eventHandler = new Thread() {126public void run() {127EventQueue eventQueue = debugee.VM().eventQueue();128EventSet eventSet = null;129while (!exit) {130try {131eventSet = eventQueue.remove(1000);132} catch (InterruptedException e) {133new Failure("Event handling thread interrupted:\n\t" + e);134}135if (eventSet == null) {136continue;137}138EventIterator eventIterator = eventSet.eventIterator();139while (eventIterator.hasNext()) {140Event event = eventIterator.nextEvent();141142if (event instanceof ClassPrepareEvent) {143display(" event ===>>> " + event);144mthdReq = evm.createMethodEntryRequest();145mthdReq.addClassFilter(testedClassName);146mthdReq.enable();147debugee.resume();148149} else if (event instanceof MethodEntryEvent) {150display(" event ===>>> " + (eventCount+1) + " MethodEntryEvent arrived");151hitEvent((MethodEntryEvent )event);152debugee.resume();153154} else if (event instanceof VMDeathEvent) {155exit = true;156break;157} else if (event instanceof VMDisconnectEvent) {158exit = true;159break;160} else {161throw new Failure("Unexpected event:\n\t" + event);162} // if163exit = exit || (eventCount >= tc02x002a.threadCount + 1);164} // while165} // while166} // run()167}; // eventHadler168169display("Starting handling event");170eventHandler.start();171172debugee.resume();173debugee.receiveExpectedSignal(SGL_READY);174175display("\nTEST BEGINS");176display("===========");177debugee.sendSignal(SGL_LOAD);178179display("Waiting for all events received");180try {181eventHandler.join(waitTime);182} catch (InterruptedException e) {183throw new Failure("Main thread interrupted while waiting for eventHandler:\n\t"184+ e);185} finally {186crq.disable();187mthdReq.disable();188exit = true;189if (eventHandler.isAlive()) {190display("Interrupting event handling thread");191eventHandler.interrupt();192}193}194195if (eventCount < tc02x002a.threadCount) {196complain("expecting " + tc02x002a.threadCount197+ " breakpoint events, but "198+ eventCount + " events arrived.");199exitStatus = Consts.TEST_FAILED;200}201202display("=============");203display("TEST FINISHES\n");204debugee.sendSignal(SGL_QUIT);205}206207private void hitEvent(MethodEntryEvent event) {208ThreadReference thrd = event.thread();209210display("event info:");211display("\tthread\t- " + event.thread().name());212try {213display("\tsource\t- " + event.location().sourceName());214} catch (AbsentInformationException e) {215}216display("\tmethod\t- " + event.location().method().name());217display("\tline\t- " + event.location().lineNumber());218if (event.location().lineNumber() == tc02x002a.checkClassBrkpLine1 ||219event.location().lineNumber() == tc02x002a.checkClassBrkpLine2) {220display("MethodEntryEvent occurs on the expected line "221+ event.location().lineNumber() + " in method "222+ event.method().name());223} else {224complain("MethodEntryEvent occurs on line " + event.location().lineNumber()225+ " in method " + event.method().name()226+ ", expected line numbers are "227+ tc02x002a.checkClassBrkpLine1 + ", "228+ tc02x002a.checkClassBrkpLine2);229exitStatus = Consts.TEST_FAILED;230}231232display("");233234eventCount++;235}236}237238239