0N/A#!/bin/sh
0N/A
0N/A#
2362N/A# Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
0N/A# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A#
0N/A# This code is free software; you can redistribute it and/or modify it
0N/A# under the terms of the GNU General Public License version 2 only, as
0N/A# published by the Free Software Foundation.
0N/A#
0N/A# This code is distributed in the hope that it will be useful, but WITHOUT
0N/A# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A# version 2 for more details (a copy is included in the LICENSE file that
0N/A# accompanied this code).
0N/A#
0N/A# You should have received a copy of the GNU General Public License version
0N/A# 2 along with this work; if not, write to the Free Software Foundation,
0N/A# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A#
2362N/A# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A# or visit www.oracle.com if you need additional information or have any
2362N/A# questions.
0N/A#
0N/A
0N/A# @test
0N/A# @bug 4724076
0N/A# @summary Redefine does not work in for/while loop
0N/A# @author Jim Holmlund/Swamy Venkataramanappa
0N/A#
0N/A# The failure occurs when a method is active and
0N/A# a method that it calls multiple times is redefined
0N/A# more than once.
0N/A# @run shell/timeout=240 RedefineMulti.sh
0N/A
0N/AcompileOptions=-g
0N/A#java=java_g
0N/A
0N/AcreateJavaFile()
0N/A{
0N/A cat <<EOF > $1.java.1
0N/A
0N/Apublic class $1 {
0N/A
0N/A String field1;
0N/A String field2;
0N/A
0N/A // The first time thru the loop in start,
0N/A // "Before update..." should be printed.
0N/A // After the first redefine, "After update..." should be printed
0N/A // After the 2nd redefine, "abcde..." should be printed.
0N/A // The bug is that "After update..." is printed instead because
0N/A // stat() calls version 2 of doSomething() instead of
0N/A // version 3.
0N/A private void doSomething() {
0N/A System.out.println("Before update..."); // @1 commentout
0N/A // @1 uncomment System.out.println("After update..."); // @2 commentout
0N/A // @2 uncomment System.out.println("abcde...");
0N/A }
0N/A
0N/A public void start() {
0N/A for (int i=0; i < 3; i++) {
0N/A doSomething(); // @1 breakpoint here line 16
0N/A System.out.println("field1 = " + field1);
0N/A System.out.println("field2 = " + field2);
0N/A }
0N/A // Redefinex myx = new Redefinex();
0N/A // for (int i = 0; i < 5; i++) {
0N/A // myx.methodx1(); // line 22
0N/A // System.out.println("fieldx1 = " + myx.fieldx1);
0N/A // System.out.println("fieldx2 = " + myx.fieldx2);
0N/A // }
0N/A }
0N/A
0N/A public static void main(String[] args) {
0N/A $1 xxx = new $1();
0N/A xxx.field1 = "field1";
0N/A xxx.field2 = "field2";
0N/A xxx.start();
0N/A }
0N/A}
0N/A
0N/Aclass Redefinex {
0N/A public String fieldx1;
0N/A public String fieldx2;
0N/A
0N/A Redefinex() {
0N/A fieldx1 = "fieldx1";
0N/A fieldx2 = "fieldx2";
0N/A }
0N/A
0N/A public void methodx1() {
0N/A System.out.println("redefinex 1");
0N/A //System.out.println("redefinex 2");
0N/A //System.out.println("redefinex 3");
0N/A }
0N/A
0N/A}
0N/A
0N/A /*********
0N/ASteps to reproduce this problem:
0N/A a. add line breakpoint in start()
0N/A b. debug
0N/A c. when breakpoint is hit, type continue. You should see output
0N/A"Before update..."
0N/A d. change "Before update" to "After update"
0N/A e. redefine, and set line breakpoint (see step a)
0N/A f. type continue. You should see output "After update"
0N/A g. change "After update" to "abcde"
0N/A h. redefine, and set line breakpoint (see step a)
0N/A i. type continue. The output is shown as "After update"
0N/A
0N/A j. to see "abcde" output, users will have to pop the stack, and
0N/Are-execute method start().
0N/A ************/
0N/AEOF
0N/A}
0N/A
0N/A# This is called to feed cmds to jdb.
0N/AdojdbCmds()
0N/A{
0N/A setBkpts @1
0N/A runToBkpt @1
0N/A contToBkpt
0N/A redefineClass @1
0N/A setBkpts @1
0N/A contToBkpt
0N/A redefineClass @2
0N/A cmd cont
0N/A cmd quit
0N/A}
0N/A
0N/A
0N/Amysetup()
0N/A{
0N/A if [ -z "$TESTSRC" ] ; then
0N/A TESTSRC=.
0N/A fi
0N/A
0N/A for ii in . $TESTSRC $TESTSRC/.. ; do
0N/A if [ -r "$ii/ShellScaffold.sh" ] ; then
0N/A . $ii/ShellScaffold.sh
0N/A break
0N/A fi
0N/A done
0N/A}
0N/A
0N/A# You could replace this next line with the contents
0N/A# of ShellScaffold.sh and this script will run just the same.
0N/Amysetup
0N/A
0N/Arunit
0N/AdebuggeeFailIfPresent "Internal exception:"
0N/AdebuggeeFailIfNotPresent "abcde"
0N/Apass