test/jdk/com/sun/jdi/RedefineMulti.java
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 51837 46ca82c15f6c
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51837
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
     1
/*
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
     2
 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
     4
 *
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
     7
 * published by the Free Software Foundation.
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
     8
 *
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    13
 * accompanied this code).
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    14
 *
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    18
 *
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    21
 * questions.
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    22
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
51837
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    24
/*
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    25
 * @test
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    26
 * @bug 4724076
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    27
 * @summary Redefine does not work in for/while loop
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    28
 * @comment converted from test/jdk/com/sun/jdi/RedefineMulti.sh
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    29
 *
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    30
 * @library /test/lib
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    31
 * @compile -g RedefineMulti.java
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    32
 * @run main/othervm RedefineMulti
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    33
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
51837
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    35
/*
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    36
 * The failure occurs when a method is active and
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    37
 * a method that it calls multiple times is redefined
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    38
 * more than once.
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    39
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
51837
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    41
import jdk.test.lib.process.OutputAnalyzer;
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    42
import lib.jdb.JdbCommand;
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    43
import lib.jdb.JdbTest;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
51837
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    45
class RedefineMultiTarg {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    String field1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    String field2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    // The first time thru the loop in start,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    // "Before update..." should be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // After the first redefine, "After update..." should be printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // After the 2nd redefine, "abcde..." should be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // The bug is that "After update..." is printed instead because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // stat() calls version 2 of doSomething() instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    // version 3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private void doSomething()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        System.out.println("Before update...");  // @1 commentout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        // @1 uncomment System.out.println("After update...");  // @2 commentout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        // @2 uncomment System.out.println("abcde...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public void start() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        for (int i=0; i < 3; i++)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            doSomething();      // @1 breakpoint here  line 16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            System.out.println("field1 = " + field1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            System.out.println("field2 = " + field2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        // Redefinex myx = new Redefinex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        //  for (int i = 0; i < 5; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        //    myx.methodx1();                     // line 22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        //    System.out.println("fieldx1 = " + myx.fieldx1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        //    System.out.println("fieldx2 = " + myx.fieldx2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        //  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static void main(String[] args) {
51837
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
    78
        RedefineMultiTarg xxx = new RedefineMultiTarg();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        xxx.field1 = "field1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        xxx.field2 = "field2";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        xxx.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
class Redefinex {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public String fieldx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public String fieldx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    Redefinex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        fieldx1 = "fieldx1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        fieldx2 = "fieldx2";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public void methodx1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        System.out.println("redefinex 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        //System.out.println("redefinex 2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        //System.out.println("redefinex 3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
51837
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   101
/*********
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
Steps to reproduce this problem:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
   a. add line breakpoint  in start()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
   b. debug
51837
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   105
   c. when breakpoint is hit, type continue. You should see output "Before update..."
2
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"
51837
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   112
   j. to see "abcde" output,  users will have to pop the stack, and re-execute method start().
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   113
************/
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
51837
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   115
public class RedefineMulti extends JdbTest {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
51837
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   117
    public static void main(String argv[]) {
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   118
        new RedefineMulti().run();
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   119
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
51837
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   121
    private RedefineMulti() {
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   122
        super(RedefineMultiTarg.class.getName(), "RedefineMulti.java");
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   123
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
51837
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   125
    @Override
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   126
    protected void runCases() {
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   127
        setBreakpoints(1);
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   128
        jdb.command(JdbCommand.run());
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   129
        jdb.command(JdbCommand.cont());
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   130
        redefineClass(1, "-g");
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   131
        setBreakpoints(1);
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   132
        jdb.command(JdbCommand.cont());
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   133
        redefineClass(2, "-g");
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   134
        jdb.contToExit(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
51837
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   136
        new OutputAnalyzer(getDebuggeeOutput())
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   137
                .shouldNotContain("Internal exception:")
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   138
                .shouldContain("abcde");
46ca82c15f6c 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4
amenkov
parents: 47216
diff changeset
   139
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
}