jdk/test/com/sun/jdi/RedefineMulti.sh
author xdono
Thu, 30 Apr 2009 15:04:39 -0700
changeset 2691 bad7bbf42755
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Added tag jdk7-b57 for changeset 93833fce07e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
#!/bin/sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
# Copyright 2002-2003 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
# This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
# under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
# published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
# This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
# version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
# accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
# You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
# 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
# CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
# have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#  @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#  @bug 4724076
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#  @summary Redefine does not work in for/while loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#  @author Jim Holmlund/Swamy Venkataramanappa
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#  The failure occurs when a method is active and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#  a method that it calls multiple times is redefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#  more than once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#  @run shell/timeout=240 RedefineMulti.sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
compileOptions=-g
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#java=java_g
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
createJavaFile()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    cat <<EOF > $1.java.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class $1 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    String field1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    String field2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    // The first time thru the loop in start,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    // "Before update..." should be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    // After the first redefine, "After update..." should be printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    // After the 2nd redefine, "abcde..." should be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // The bug is that "After update..." is printed instead because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // stat() calls version 2 of doSomething() instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // version 3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private void doSomething()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        System.out.println("Before update...");  // @1 commentout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        // @1 uncomment System.out.println("After update...");  // @2 commentout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        // @2 uncomment System.out.println("abcde...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public void start() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        for (int i=0; i < 3; i++)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            doSomething();      // @1 breakpoint here  line 16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            System.out.println("field1 = " + field1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            System.out.println("field2 = " + field2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        // Redefinex myx = new Redefinex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        //  for (int i = 0; i < 5; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        //    myx.methodx1();                     // line 22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        //    System.out.println("fieldx1 = " + myx.fieldx1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        //    System.out.println("fieldx2 = " + myx.fieldx2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        //  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        $1 xxx = new $1();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        xxx.field1 = "field1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        xxx.field2 = "field2";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        xxx.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
class Redefinex {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public String fieldx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public String fieldx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    Redefinex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        fieldx1 = "fieldx1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        fieldx2 = "fieldx2";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public void methodx1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        System.out.println("redefinex 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        //System.out.println("redefinex 2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        //System.out.println("redefinex 3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /*********
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
Steps to reproduce this problem:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
   a. add line breakpoint  in start()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
   b. debug
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
   c. when breakpoint is hit, type continue. You should see output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
"Before update..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
   d. change "Before update" to  "After update"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
   e. redefine,  and set line breakpoint (see step a)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
   f. type continue. You should see output "After update"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
   g. change "After update" to "abcde"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
   h. redefine, and set line breakpoint (see step a)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
   i.  type continue. The output is shown as "After update"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
   j. to see "abcde" output,  users will have to pop the stack, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
re-execute method start().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    ************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
EOF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
# This is called to feed cmds to jdb.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
dojdbCmds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    setBkpts @1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    runToBkpt @1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    contToBkpt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    redefineClass @1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    setBkpts @1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    contToBkpt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    redefineClass @2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    cmd cont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    cmd quit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
mysetup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    if [ -z "$TESTSRC" ] ; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        TESTSRC=.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    for ii in . $TESTSRC $TESTSRC/.. ; do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if [ -r "$ii/ShellScaffold.sh" ] ; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            . $ii/ShellScaffold.sh 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            break
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
# You could replace this next line with the contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
# of ShellScaffold.sh and this script will run just the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
mysetup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
runit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
debuggeeFailIfPresent "Internal exception:"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
debuggeeFailIfNotPresent "abcde"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
pass