Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/redefine/redefine001/redefine001.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/redefine/redefine001.28* VM Testbase keywords: [jpda, jdb]29* VM Testbase readme:30* DECSRIPTION31* A positive test for the 'redefine <class id> <class file name>' command.32* The debuggee program invokes three times method 'foo()' of RedefinedClass33* class. This class in redefined with checked command each time before last34* two invocations. If redefinitions occurs then the value returned by 'foo()'35* method must be different from one returned previous invocation.36* The test passes if method 'foo()' of the RedefinedClass returns expected37* values.38* The test consists of three program:39* redefine001.java - launches jdb and debuggee, writes commands to jdb, reads the jdb output,40* redefine001a.java - the debugged application.41* RedefinedClass.java - the class to be redefined.42* newclass_g/RedefinedClass.java - the redefining class.43* COMMENTS44*45* @library /vmTestbase46* /test/lib47* @build nsk.jdb.redefine.redefine001.redefine001a48*49* @comment compile newclass_g/RedefinedClass.java to newclass_g50* @run driver51* ExecDriver --cmd52* ${compile.jdk}/bin/javac53* -d ${test.classes}/newclass_g54* -g:lines,source,vars55* -cp ${test.class.path}56* ${test.src}/newclass_g/RedefinedClass.java57*58* @run main/othervm59* nsk.jdb.redefine.redefine001.redefine00160* -arch=${os.family}-${os.simpleArch}61* -waittime=562* -debugee.vmkind=java63* -transport.address=dynamic64* -jdb=${test.jdk}/bin/jdb65* -java.options="${test.vm.opts} ${test.java.opts}"66* -workdir=.67* -debugee.vmkeys="${test.vm.opts} ${test.java.opts}"68*/6970package nsk.jdb.redefine.redefine001;7172import nsk.share.*;73import nsk.share.jdb.*;74import nsk.share.classload.ClassLoadUtils;7576import java.io.*;77import java.util.*;7879public class redefine001 extends JdbTest {8081public static void main (String argv[]) {82System.exit(run(argv, System.out) + JCK_STATUS_BASE);83}8485public static int run(String argv[], PrintStream out) {86debuggeeClass = DEBUGGEE_CLASS;87firstBreak = FIRST_BREAK;88lastBreak = LAST_BREAK;89return new redefine001().runTest(argv, out);90}9192static final String PACKAGE_NAME = "nsk.jdb.redefine.redefine001";93static final String TEST_CLASS = PACKAGE_NAME + ".redefine001";94static final String DEBUGGEE_CLASS = TEST_CLASS + "a";95static final String FIRST_BREAK = DEBUGGEE_CLASS + ".main";96static final String LAST_BREAK = DEBUGGEE_CLASS + ".lastBreak";9798static final String REDEFINED_CLASS = PACKAGE_NAME + ".RedefinedClass";99static final String BEFORE_REDEFINITION = "BEFORE_REDEFINITION";100static final String FIRST_REDEFINITION = "AFTER_REDEFINITION";101static final String SECOND_REDEFINITION = BEFORE_REDEFINITION;102103protected void runCases() {104String[] reply;105Paragrep grep;106int count;107Vector v;108String found;109110jdb.setBreakpointInMethod(LAST_BREAK);111reply = jdb.receiveReplyFor(JdbCommand.cont);112113reply = jdb.receiveReplyFor(JdbCommand.step); // to get out of lastBreak()114115reply = jdb.receiveReplyFor(JdbCommand.eval + DEBUGGEE_CLASS + ".flag");116grep = new Paragrep(reply);117if (grep.find(BEFORE_REDEFINITION) == 0) {118log.complain("Wrong value of redefine001a.flag before redefinition: " + (reply.length > 0? reply[0]: ""));119success = false;120}121122String className = RedefinedClass.class.getName();123String pathToRedefFile1 = ClassLoadUtils.getRedefineClassFileName("newclass_g", className);124if (new File(pathToRedefFile1).exists()) {125reply = jdb.receiveReplyFor(JdbCommand.redefine + REDEFINED_CLASS + " " + pathToRedefFile1);126127reply = jdb.receiveReplyFor(JdbCommand.cont);128129reply = jdb.receiveReplyFor(JdbCommand.eval + DEBUGGEE_CLASS + ".flag");130grep = new Paragrep(reply);131if (grep.find(FIRST_REDEFINITION) == 0) {132log.complain("Wrong value of redefine001a.flag after first redefinition: " + (reply.length > 0? reply[0]: ""));133success = false;134}135} else {136log.complain("File does not exists: " + pathToRedefFile1);137success = false;138}139140String pathToRedefFile2 = ClassLoadUtils.getClassPathFileName(className);141if (new File(pathToRedefFile2).exists()) {142reply = jdb.receiveReplyFor(JdbCommand.redefine + REDEFINED_CLASS + " " + pathToRedefFile2);143144reply = jdb.receiveReplyFor(JdbCommand.cont);145146reply = jdb.receiveReplyFor(JdbCommand.eval + DEBUGGEE_CLASS + ".flag");147grep = new Paragrep(reply);148if (grep.find(SECOND_REDEFINITION) == 0) {149log.complain("Wrong value of redefine001a.flag after second redefinition: " + (reply.length > 0? reply[0]: ""));150success = false;151}152} else {153log.complain("File does not exists: " + pathToRedefFile2);154success = false;155}156157jdb.contToExit(2);158}159160private boolean checkStop () {161Paragrep grep;162String[] reply;163String found;164Vector v;165boolean result = true;166167return result;168}169}170171172