Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/reenter/reenter001/reenter001.java
40951 views
/*1* Copyright (c) 2002, 2020, 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*/222324/*25* @test26*27* @summary converted from VM Testbase nsk/jdb/reenter/reenter001.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DESCRIPTION31* A positive test case for the 'reenter' command.32* The debugged application (reenter001a.java) starts additional thread of MyThread33* class. The 'run()' method of the this class invokes recursively a number of34* int methods. The jdb sets breakpoint in the last called 'func5()' method35* to suspend the debugged VM when all the methods, i.e. from 'func1()' to36* 'func5()', are in MyThread's stack. Then jdb steps up three frame on stack37* by 'up 3' command. At this moment frame with 'func2()' is current.38* Then the 'reenter' command is called. The test passes if after execution of39* tested command the 'func2()' frame reentered, i.e. top frame of the stack.40* The test consists of two program:41* reenter001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,42* reenter001a.java - the debugged application.43* COMMENTS44*45* @library /vmTestbase46* /test/lib47* @build nsk.jdb.reenter.reenter001.reenter001a48* @run main/othervm49* nsk.jdb.reenter.reenter001.reenter00150* -arch=${os.family}-${os.simpleArch}51* -waittime=552* -debugee.vmkind=java53* -transport.address=dynamic54* -jdb=${test.jdk}/bin/jdb55* -java.options="${test.vm.opts} ${test.java.opts}"56* -workdir=.57* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"58*/5960package nsk.jdb.reenter.reenter001;6162import nsk.share.*;63import nsk.share.jdb.*;6465import java.io.*;66import java.util.*;6768public class reenter001 extends JdbTest {6970public static void main (String argv[]) {71System.exit(run(argv, System.out) + JCK_STATUS_BASE);72}7374public static int run(String argv[], PrintStream out) {75debuggeeClass = DEBUGGEE_CLASS;76firstBreak = FIRST_BREAK;77lastBreak = LAST_BREAK;78return new reenter001().runTest(argv, out);79}8081static final String PACKAGE_NAME = "nsk.jdb.reenter.reenter001";82static final String TEST_CLASS = PACKAGE_NAME + ".reenter001";83static final String DEBUGGEE_CLASS = TEST_CLASS + "a";84static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";85static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";8687static final String MYTHREAD = "MyThread";88static final String DEBUGGEE_THREAD = PACKAGE_NAME + "." + MYTHREAD;89static final String[] CHECKED_METHODS = {"func1", "func2", "func3", "func4", "func5"};9091protected void runCases() {92String[] reply;93Paragrep grep;94int count;95Vector v;96String found;9798jdb.setBreakpointInMethod(LAST_BREAK);99reply = jdb.receiveReplyFor(JdbCommand.cont);100101while (true) {102String[] threads = jdb.getThreadIds(DEBUGGEE_THREAD);103if (threads.length != 1) {104log.complain("jdb should report 1 instance of " + DEBUGGEE_THREAD);105log.complain("Found: " + threads.length);106success = false;107break;108}109110reply = jdb.receiveReplyFor(JdbCommand.thread + threads[0]);111112reply = jdb.receiveReplyFor(JdbCommand.step); // to get out of lastBreak()113114reply = jdb.receiveReplyFor(JdbCommand.where);115if (!checkStack(reply, "func5", "[1]", "lastBreak", false)) {116success = false;117}118119reply = jdb.receiveReplyFor(JdbCommand.up + " 3");120121reply = jdb.receiveReplyFor(JdbCommand.where);122if (!checkStack(reply, "func2", "[4]", "func3", false)) {123success = false;124}125126reply = jdb.receiveReplyFor(JdbCommand.reenter);127128reply = jdb.receiveReplyFor(JdbCommand.where);129if (!checkStack(reply, "func2", "[1]", "func3", true)) {130success = false;131}132133reply = jdb.receiveReplyFor(JdbCommand.locals);134grep = new Paragrep(reply);135if (grep.find("Internal exception") > 0) {136log.complain("Internal exception was thrown while 'locals' command");137for (int i = 0; i < reply.length; i++) {138log.complain(reply[i]);139}140success = false;141}142143break;144}145146jdb.contToExit(2);147}148149private boolean checkStack (String[] reply, String shouldBe, String frameNum, String shouldNotBe, boolean reenter ) {150Paragrep grep;151String found;152Vector v = new Vector();153boolean result = true;154int count;155156grep = new Paragrep(reply);157v.add(frameNum);158v.add(DEBUGGEE_THREAD + "." + shouldBe);159if ((count = grep.find(v)) != 1) {160log.complain("Contents of stack trace is incorrect " + ( reenter? "after 'reenter' command": ""));161log.complain("Searched for: " + DEBUGGEE_THREAD + "." + shouldBe);162log.complain("Count : " + count);163result = false;164}165166if (grep.find(DEBUGGEE_THREAD + "." + shouldNotBe) > 0) {167log.complain("Contents of stack trace is incorrect " + ( reenter? "after 'reenter' command": ""));168log.complain("Found wrong frame: " + DEBUGGEE_THREAD + "." + shouldNotBe);169result = false;170}171172return result;173}174}175176177