1 /* 2 * Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 /* 26 * @test 27 * 28 * @summary converted from VM Testbase nsk/jdb/redefine/redefine001. 29 * VM Testbase keywords: [jpda, jdb] 30 * VM Testbase readme: 31 * DECSRIPTION 32 * A positive test for the 'redefine <class id> <class file name>' command. 33 * The debuggee program invokes three times method 'foo()' of RedefinedClass 34 * class. This class in redefined with checked command each time before last 35 * two invocations. If redefinitions occurs then the value returned by 'foo()' 36 * method must be different from one returned previous invocation. 37 * The test passes if method 'foo()' of the RedefinedClass returns expected 38 * values. 39 * The test consists of three program: 40 * redefine001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output, 41 * redefine001a.java - the debugged application. 42 * RedefinedClass.java - the class to be redefined. 43 * newclass_g/RedefinedClass.java - the redefining class. 44 * COMMENTS 45 * 46 * @library /vmTestbase 47 * /test/lib 48 * @build nsk.jdb.redefine.redefine001.redefine001a 49 * 50 * @comment compile newclass_g/RedefinedClass.java to newclass_g 51 * @run driver 52 * ExecDriver --cmd 53 * ${compile.jdk}/bin/javac 54 * -d ${test.classes}/newclass_g 55 * -g:lines,source,vars 56 * -cp ${test.class.path} 57 * ${test.src}/newclass_g/RedefinedClass.java 58 * 59 * @run main/othervm 60 * nsk.jdb.redefine.redefine001.redefine001 61 * -arch=${os.family}-${os.simpleArch} 62 * -waittime=5 63 * -debugee.vmkind=java 64 * -transport.address=dynamic 65 * -jdb=${test.jdk}/bin/jdb 66 * -java.options="${test.vm.opts} ${test.java.opts}" 67 * -workdir=. 68 * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" 69 */ 70 71 package nsk.jdb.redefine.redefine001; 72 73 import nsk.share.*; 74 import nsk.share.jdb.*; 75 import nsk.share.classload.ClassLoadUtils; 76 77 import java.io.*; 78 import java.util.*; 79 80 public class redefine001 extends JdbTest { 81 main(String argv[])82 public static void main (String argv[]) { 83 System.exit(run(argv, System.out) + JCK_STATUS_BASE); 84 } 85 run(String argv[], PrintStream out)86 public static int run(String argv[], PrintStream out) { 87 debuggeeClass = DEBUGGEE_CLASS; 88 firstBreak = FIRST_BREAK; 89 lastBreak = LAST_BREAK; 90 return new redefine001().runTest(argv, out); 91 } 92 93 static final String PACKAGE_NAME = "nsk.jdb.redefine.redefine001"; 94 static final String TEST_CLASS = PACKAGE_NAME + ".redefine001"; 95 static final String DEBUGGEE_CLASS = TEST_CLASS + "a"; 96 static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main"; 97 static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak"; 98 99 static final String REDEFINED_CLASS = PACKAGE_NAME + ".RedefinedClass"; 100 static final String BEFORE_REDEFINITION = "BEFORE_REDEFINITION"; 101 static final String FIRST_REDEFINITION = "AFTER_REDEFINITION"; 102 static final String SECOND_REDEFINITION = BEFORE_REDEFINITION; 103 runCases()104 protected void runCases() { 105 String[] reply; 106 Paragrep grep; 107 int count; 108 Vector v; 109 String found; 110 111 jdb.setBreakpointInMethod(LAST_BREAK); 112 reply = jdb.receiveReplyFor(JdbCommand.cont); 113 114 reply = jdb.receiveReplyFor(JdbCommand.step); // to get out of lastBreak() 115 116 reply = jdb.receiveReplyFor(JdbCommand.eval + DEBUGGEE_CLASS + ".flag"); 117 grep = new Paragrep(reply); 118 if (grep.find(BEFORE_REDEFINITION) == 0) { 119 log.complain("Wrong value of redefine001a.flag before redefinition: " + (reply.length > 0? reply[0]: "")); 120 success = false; 121 } 122 123 String className = RedefinedClass.class.getName(); 124 String pathToRedefFile1 = ClassLoadUtils.getRedefineClassFileName("newclass_g", className); 125 if (new File(pathToRedefFile1).exists()) { 126 reply = jdb.receiveReplyFor(JdbCommand.redefine + REDEFINED_CLASS + " " + pathToRedefFile1); 127 128 reply = jdb.receiveReplyFor(JdbCommand.cont); 129 130 reply = jdb.receiveReplyFor(JdbCommand.eval + DEBUGGEE_CLASS + ".flag"); 131 grep = new Paragrep(reply); 132 if (grep.find(FIRST_REDEFINITION) == 0) { 133 log.complain("Wrong value of redefine001a.flag after first redefinition: " + (reply.length > 0? reply[0]: "")); 134 success = false; 135 } 136 } else { 137 log.complain("File does not exists: " + pathToRedefFile1); 138 success = false; 139 } 140 141 String pathToRedefFile2 = ClassLoadUtils.getClassPathFileName(className); 142 if (new File(pathToRedefFile2).exists()) { 143 reply = jdb.receiveReplyFor(JdbCommand.redefine + REDEFINED_CLASS + " " + pathToRedefFile2); 144 145 reply = jdb.receiveReplyFor(JdbCommand.cont); 146 147 reply = jdb.receiveReplyFor(JdbCommand.eval + DEBUGGEE_CLASS + ".flag"); 148 grep = new Paragrep(reply); 149 if (grep.find(SECOND_REDEFINITION) == 0) { 150 log.complain("Wrong value of redefine001a.flag after second redefinition: " + (reply.length > 0? reply[0]: "")); 151 success = false; 152 } 153 } else { 154 log.complain("File does not exists: " + pathToRedefFile2); 155 success = false; 156 } 157 158 jdb.contToExit(2); 159 } 160 checkStop()161 private boolean checkStop () { 162 Paragrep grep; 163 String[] reply; 164 String found; 165 Vector v; 166 boolean result = true; 167 168 return result; 169 } 170 } 171