Tue, 10 Sep 2019 09:08:52 -0700
8230303: JDB hangs when running monitor command
Reviewed-by: sspitsyn
igerasim@9962 | 1 | /* |
igerasim@9962 | 2 | * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
igerasim@9962 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
igerasim@9962 | 4 | * |
igerasim@9962 | 5 | * This code is free software; you can redistribute it and/or modify it |
igerasim@9962 | 6 | * under the terms of the GNU General Public License version 2 only, as |
igerasim@9962 | 7 | * published by the Free Software Foundation. |
igerasim@9962 | 8 | * |
igerasim@9962 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
igerasim@9962 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
igerasim@9962 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
igerasim@9962 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
igerasim@9962 | 13 | * accompanied this code). |
igerasim@9962 | 14 | * |
igerasim@9962 | 15 | * You should have received a copy of the GNU General Public License version |
igerasim@9962 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
igerasim@9962 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
igerasim@9962 | 18 | * |
igerasim@9962 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
igerasim@9962 | 20 | * or visit www.oracle.com if you need additional information or have any |
igerasim@9962 | 21 | * questions. |
igerasim@9962 | 22 | */ |
igerasim@9962 | 23 | |
igerasim@9962 | 24 | |
igerasim@9962 | 25 | /* |
igerasim@9962 | 26 | * @test |
igerasim@9962 | 27 | * |
igerasim@9962 | 28 | * @summary JDB problem running monitor command |
igerasim@9962 | 29 | * VM Testbase keywords: [jpda, jdb] |
igerasim@9962 | 30 | * VM Testbase readme: |
igerasim@9962 | 31 | * DESCRIPTION |
igerasim@9962 | 32 | * Make sure 'monitor unmonitor 1' does not cause ConcurrentModificationException |
igerasim@9962 | 33 | * in the debugger. |
igerasim@9962 | 34 | * The jdb sets up line breakpoint at the debugged application. Then one command |
igerasim@9962 | 35 | * 'monitor unmonitor 1' is set. After resuming the debuggee stops at the breakpoint. |
igerasim@9962 | 36 | * The test passes if correct reply for "unmonitor 1" commanda is found in jdb stdout |
igerasim@9962 | 37 | * stream. |
igerasim@9962 | 38 | * The test consists of two program: |
igerasim@9962 | 39 | * monitor002.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output, |
igerasim@9962 | 40 | * monitor002a.java - the debugged application. |
igerasim@9962 | 41 | * |
igerasim@9962 | 42 | * @library /vmTestbase |
igerasim@9962 | 43 | * /test/lib |
igerasim@9962 | 44 | * @run driver jdk.test.lib.FileInstaller . . |
igerasim@9962 | 45 | * @build nsk.jdb.monitor.monitor002.monitor002 |
igerasim@9962 | 46 | * nsk.jdb.monitor.monitor002.monitor002a |
igerasim@9962 | 47 | * @run main/othervm PropertyResolvingWrapper nsk.jdb.monitor.monitor002.monitor002 |
igerasim@9962 | 48 | * -arch=${os.family}-${os.simpleArch} |
igerasim@9962 | 49 | * -waittime=5 |
igerasim@9962 | 50 | * -debugee.vmkind=java |
igerasim@9962 | 51 | * -transport.address=dynamic |
igerasim@9962 | 52 | * -jdb=${test.jdk}/bin/jdb |
igerasim@9962 | 53 | * -java.options="${test.vm.opts} ${test.java.opts}" |
igerasim@9962 | 54 | * -workdir=. |
igerasim@9962 | 55 | * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" |
igerasim@9962 | 56 | */ |
igerasim@9962 | 57 | |
igerasim@9962 | 58 | package nsk.jdb.monitor.monitor002; |
igerasim@9962 | 59 | |
igerasim@9962 | 60 | import nsk.share.*; |
igerasim@9962 | 61 | import nsk.share.jdb.*; |
igerasim@9962 | 62 | |
igerasim@9962 | 63 | import java.io.*; |
igerasim@9962 | 64 | import java.util.*; |
igerasim@9962 | 65 | |
igerasim@9962 | 66 | public class monitor002 extends JdbTest { |
igerasim@9962 | 67 | |
igerasim@9962 | 68 | public static void main (String argv[]) { |
igerasim@9962 | 69 | System.exit(run(argv, System.out) + JCK_STATUS_BASE); |
igerasim@9962 | 70 | } |
igerasim@9962 | 71 | |
igerasim@9962 | 72 | public static int run(String argv[], PrintStream out) { |
igerasim@9962 | 73 | debuggeeClass = DEBUGGEE_CLASS; |
igerasim@9962 | 74 | firstBreak = FIRST_BREAK; |
igerasim@9962 | 75 | lastBreak = LAST_BREAK; |
igerasim@9962 | 76 | return new monitor002().runTest(argv, out); |
igerasim@9962 | 77 | } |
igerasim@9962 | 78 | |
igerasim@9962 | 79 | static final String PACKAGE_NAME = "nsk.jdb.monitor.monitor002"; |
igerasim@9962 | 80 | static final String TEST_CLASS = PACKAGE_NAME + ".monitor002"; |
igerasim@9962 | 81 | static final String DEBUGGEE_CLASS = TEST_CLASS + "a"; |
igerasim@9962 | 82 | static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main"; |
igerasim@9962 | 83 | static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak"; |
igerasim@9962 | 84 | static final int LINE_NUMBER = 47; |
igerasim@9962 | 85 | |
igerasim@9962 | 86 | static final String[] CHECKED_COMMANDS = { |
igerasim@9962 | 87 | JdbCommand.unmonitor + "1" |
igerasim@9962 | 88 | }; |
igerasim@9962 | 89 | |
igerasim@9962 | 90 | protected void runCases() { |
igerasim@9962 | 91 | String[] reply; |
igerasim@9962 | 92 | Paragrep grep; |
igerasim@9962 | 93 | int count; |
igerasim@9962 | 94 | Vector v; |
igerasim@9962 | 95 | String found; |
igerasim@9962 | 96 | |
igerasim@9962 | 97 | reply = jdb.receiveReplyFor(JdbCommand.stop_at + DEBUGGEE_CLASS + ":" + LINE_NUMBER); |
igerasim@9962 | 98 | |
igerasim@9962 | 99 | for (int i = 0; i < CHECKED_COMMANDS.length; i++) { |
igerasim@9962 | 100 | reply = jdb.receiveReplyFor(JdbCommand.monitor + CHECKED_COMMANDS[i]); |
igerasim@9962 | 101 | } |
igerasim@9962 | 102 | |
igerasim@9962 | 103 | int repliesCount = CHECKED_COMMANDS.length + 1; |
igerasim@9962 | 104 | reply = jdb.receiveReplyFor(JdbCommand.cont, true, repliesCount); |
igerasim@9962 | 105 | |
igerasim@9962 | 106 | reply = jdb.receiveReplyFor(JdbCommand.monitor); |
igerasim@9962 | 107 | if (reply.length != 1) { |
igerasim@9962 | 108 | log.complain("Expected no active monitors after exectuting monitored command: " + CHECKED_COMMANDS[0]); |
igerasim@9962 | 109 | success = false; |
igerasim@9962 | 110 | } |
igerasim@9962 | 111 | |
igerasim@9962 | 112 | jdb.contToExit(1); |
igerasim@9962 | 113 | |
igerasim@9962 | 114 | reply = jdb.getTotalReply(); |
igerasim@9962 | 115 | |
igerasim@9962 | 116 | if (!checkCommands(reply)) { |
igerasim@9962 | 117 | success = false; |
igerasim@9962 | 118 | } |
igerasim@9962 | 119 | } |
igerasim@9962 | 120 | |
igerasim@9962 | 121 | private boolean checkCommands(String[] reply) { |
igerasim@9962 | 122 | Paragrep grep; |
igerasim@9962 | 123 | boolean result = true; |
igerasim@9962 | 124 | int count; |
igerasim@9962 | 125 | |
igerasim@9962 | 126 | grep = new Paragrep(reply); |
igerasim@9962 | 127 | |
igerasim@9962 | 128 | if ((count = grep.find("Unmonitoring 1: unmonitor 1")) != 1) { |
igerasim@9962 | 129 | log.complain("Wrong number of execution of monitored command: " + CHECKED_COMMANDS[0]); |
igerasim@9962 | 130 | log.complain(" Expected: 1; found: " + count); |
igerasim@9962 | 131 | result = false; |
igerasim@9962 | 132 | } |
igerasim@9962 | 133 | |
igerasim@9962 | 134 | return result; |
igerasim@9962 | 135 | } |
igerasim@9962 | 136 | } |