8210560: [TEST] convert com/sun/jdi redefineClass-related tests
authoramenkov
Wed, 12 Sep 2018 12:29:40 -0700
changeset 51716 e7459270ca63
parent 51715 13a63d4a3f8d
child 51717 75261571c13d
8210560: [TEST] convert com/sun/jdi redefineClass-related tests Reviewed-by: jcbeyler, sspitsyn
test/jdk/com/sun/jdi/Redefine-g.sh
test/jdk/com/sun/jdi/RedefineAbstractClass.java
test/jdk/com/sun/jdi/RedefineAbstractClass.sh
test/jdk/com/sun/jdi/RedefineAddPrivateMethod.java
test/jdk/com/sun/jdi/RedefineAddPrivateMethod.sh
test/jdk/com/sun/jdi/RedefineAnnotation.java
test/jdk/com/sun/jdi/RedefineAnnotation.sh
test/jdk/com/sun/jdi/RedefineChangeClassOrder.java
test/jdk/com/sun/jdi/RedefineChangeClassOrder.sh
test/jdk/com/sun/jdi/RedefineClasses.java
test/jdk/com/sun/jdi/RedefineClasses.sh
test/jdk/com/sun/jdi/RedefineClearBreakpoint.java
test/jdk/com/sun/jdi/RedefineClearBreakpoint.sh
test/jdk/com/sun/jdi/RedefineG.java
test/jdk/com/sun/jdi/RedefineImplementor.java
test/jdk/com/sun/jdi/RedefineImplementor.sh
test/jdk/com/sun/jdi/lib/jdb/ClassTransformer.java
test/jdk/com/sun/jdi/lib/jdb/JdbCommand.java
test/jdk/com/sun/jdi/lib/jdb/JdbTest.java
--- a/test/jdk/com/sun/jdi/Redefine-g.sh	Wed Sep 12 10:27:03 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-#!/bin/sh
-
-#
-# Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-#  @test
-#  @bug 4777868
-#  @summary Compile with java -g, do a RedefineClasses, and you don't get local vars
-#  @author Jim Holmlund
-#
-#  @run shell Redefine-g.sh
-#pkg=untitled7
-
-# Compile the first version without -g and the 2nd version with -g.
-compileOptions=
-compileOptions2=-g
-#java=java_g
-
-# Uncomment this to see the JDI trace
-# jdbOptions=-dbgtrace
-
-createJavaFile()
-{
-    cat <<EOF > $1.java.1
-
-public class $1 {
-  public $1() {
-  }
-  public static void main(String[] args) {
-    int gus = 22;
-    $1 kk = new $1();
-    kk.m1("ab");
-  }
-
-  void m1(String p1) {
-    int m1l1 = 1;
-    System.out.println("m1(String) called");
-    m1(p1, "2nd");
-    // @1 uncomment System.out.println("Hello Milpitas!");
-  }
-
-  void m1(String p1, String p2) {
-    int m1l2 = 2;
-    System.out.println("m2" + p1 + p2);  // @1 breakpoint
-  }
-
-}
-EOF
-}
-
-# This is called to feed cmds to jdb.
-dojdbCmds()
-{
-    setBkpts @1
-    runToBkpt @1
-    cmd where
-    cmd locals
-
-    redefineClass @1
-    cmd where
-    cmd locals
-
-    cmd pop
-    cmd where
-    cmd locals
-
-    cmd pop
-    cmd where
-    cmd locals
-
-    cmd allowExit cont
-}
-
-
-mysetup()
-{
-    if [ -z "$TESTSRC" ] ; then
-        TESTSRC=.
-    fi
-
-    for ii in . $TESTSRC $TESTSRC/.. ; do
-        if [ -r "$ii/ShellScaffold.sh" ] ; then
-            . $ii/ShellScaffold.sh 
-            break
-        fi
-    done
-}
-
-# You could replace this next line with the contents
-# of ShellScaffold.sh and this script will run just the same.
-mysetup
-
-runit
-
-jdbFailIfNotPresent 'p1 = "ab"'
-jdbFailIfNotPresent 'p2 = "2nd"'
-jdbFailIfNotPresent 'm1l2 = 2'
-jdbFailIfPresent    'm1l1'
-
-jdbFailIfNotPresent 'args = instance of java.lang.String'
-jdbFailIfNotPresent 'gus = 22'
-jdbFailIfNotPresent 'kk = instance of shtest'
-pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jdi/RedefineAbstractClass.java	Wed Sep 12 12:29:40 2018 -0700
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6805864
+ * @summary Redefine an abstract class that is called via a concrete
+ * class and via two interface objects and verify that the right
+ * methods are called.
+ * @comment converted from test/jdk/com/sun/jdi/RedefineAbstractClass.sh
+ *
+ * @library /test/lib
+ * @compile -g RedefineAbstractClass.java
+ * @run main/othervm RedefineAbstractClass
+ */
+
+import jdk.test.lib.process.OutputAnalyzer;
+import lib.jdb.ClassTransformer;
+import lib.jdb.JdbCommand;
+import lib.jdb.JdbTest;
+
+class RedefineAbstractClassTarg {
+    public static void main(String[] args) {
+        System.out.println("This is RedefineAbstractClass");
+
+        MyConcreteClass foo = new MyConcreteClass();
+        // do the work once before redefine
+        foo.doWork();
+
+        System.out.println("stop here for redefine");  // @1 breakpoint
+
+        // do the work again after redefine
+        foo.doWork();
+
+        System.out.println("stop here to check results");  // @2 breakpoint
+    }
+}
+
+interface MyInterface1 {
+    public boolean checkFunc();
+    public boolean isMyInterface1();
+}
+
+interface MyInterface2 {
+    public boolean checkFunc();
+    public boolean isMyInterface2();
+}
+
+abstract class MyAbstractClass implements MyInterface1, MyInterface2 {
+    static int counter = 0;
+    public boolean checkFunc() {
+        counter++;
+        System.out.println("MyAbstractClass.checkFunc() called.");
+        // @1 uncomment System.out.println("This is call " + counter + " to checkFunc");
+        return true;
+    }
+    public boolean isMyInterface1() {
+        System.out.println("MyAbstractClass.isMyInterface1() called.");
+        return true;
+    }
+    public boolean isMyInterface2() {
+        System.out.println("MyAbstractClass.isMyInterface2() called.");
+        return true;
+    }
+}
+
+class MyConcreteClass extends MyAbstractClass {
+    public void doWork() {
+        // checkFunc() is called via invokevirtual here; MyConcreteClass
+        // inherits via MyAbstractClass
+        System.out.println("In doWork() calling checkFunc(): " + checkFunc());
+
+        MyInterface1 if1 = (MyInterface1) this;
+        // checkFunc() is called via invokeinterface here; this call will
+        // use the first itable entry
+        System.out.println("In doWork() calling if1.checkFunc(): " + if1.checkFunc());
+
+        MyInterface2 if2 = (MyInterface2) this;
+        // checkFunc() is called via invokeinterface here; this call will
+        // use the second itable entry
+        System.out.println("In doWork() calling if2.checkFunc(): " + if2.checkFunc());
+    }
+}
+
+
+public class RedefineAbstractClass extends JdbTest {
+    public static void main(String argv[]) {
+        new RedefineAbstractClass().run();
+    }
+
+    private RedefineAbstractClass() {
+        super(DEBUGGEE_CLASS, SOURCE_FILE);
+    }
+
+    private static final String DEBUGGEE_CLASS = RedefineAbstractClassTarg.class.getName();
+    private static final String SOURCE_FILE = "RedefineAbstractClass.java";
+    private static final String ABSTRACT_CLASS = "MyAbstractClass";
+
+    @Override
+    protected void runCases() {
+        setBreakpoints(1);
+        setBreakpoints(2);
+        jdb.command(JdbCommand.run());
+
+        // modified version of redefineClass function
+        String transformedClassFile = ClassTransformer.fromTestSource(SOURCE_FILE)
+                .transform(1, ABSTRACT_CLASS, "-g");
+        jdb.command(JdbCommand.redefine(ABSTRACT_CLASS, transformedClassFile));
+        // end modified version of redefineClass function
+
+        // this will continue to the second breakpoint
+        jdb.command(JdbCommand.cont());
+
+        new OutputAnalyzer(getDebuggeeOutput())
+                .shouldContain("This is call 4 to checkFunc")
+                .shouldContain("This is call 5 to checkFunc")
+                .shouldContain("This is call 6 to checkFunc");
+    }
+}
--- a/test/jdk/com/sun/jdi/RedefineAbstractClass.sh	Wed Sep 12 10:27:03 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,154 +0,0 @@
-#!/bin/sh
-
-#
-# Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-
-# @test
-# @bug 6805864
-# @summary Redefine an abstract class that is called via a concrete
-#   class and via two interface objects and verify that the right
-#   methods are called.
-# @author Daniel D. Daugherty
-#
-# @key intermittent
-# @run shell RedefineAbstractClass.sh
-
-compileOptions=-g
-
-# Uncomment this to see the JDI trace
-#jdbOptions=-dbgtrace
-
-createJavaFile()
-{
-    cat <<EOF > $1.java.1
-
-public class $1 {
-  public static void main(String[] args) {
-    System.out.println("This is RedefineAbstractClass");
-
-    MyConcreteClass foo = new MyConcreteClass();
-    // do the work once before redefine
-    foo.doWork();
-
-    System.out.println("stop here for redefine");  // @1 breakpoint
-
-    // do the work again after redefine
-    foo.doWork();
-
-    System.out.println("stop here to check results");  // @2 breakpoint
-  }
-}
-
-interface MyInterface1 {
-  public boolean checkFunc();
-  public boolean isMyInterface1();
-}
-
-interface MyInterface2 {
-  public boolean checkFunc();
-  public boolean isMyInterface2();
-}
-
-abstract class MyAbstractClass implements MyInterface1, MyInterface2 {
-  static int counter = 0;
-  public boolean checkFunc() {
-    counter++;
-    System.out.println("MyAbstractClass.checkFunc() called.");
-    // @1 uncomment System.out.println("This is call " + counter + " to checkFunc");
-    return true;
-  }
-  public boolean isMyInterface1() {
-    System.out.println("MyAbstractClass.isMyInterface1() called.");
-    return true;
-  }
-  public boolean isMyInterface2() {
-    System.out.println("MyAbstractClass.isMyInterface2() called.");
-    return true;
-  }
-}
-
-class MyConcreteClass extends MyAbstractClass {
-  public void doWork() {
-    // checkFunc() is called via invokevirtual here; MyConcreteClass
-    // inherits via MyAbstractClass
-    System.out.println("In doWork() calling checkFunc(): " + checkFunc());
-
-    MyInterface1 if1 = (MyInterface1) this;
-    // checkFunc() is called via invokeinterface here; this call will
-    // use the first itable entry
-    System.out.println("In doWork() calling if1.checkFunc(): " + if1.checkFunc());
-
-    MyInterface2 if2 = (MyInterface2) this;
-    // checkFunc() is called via invokeinterface here; this call will
-    // use the second itable entry
-    System.out.println("In doWork() calling if2.checkFunc(): " + if2.checkFunc());
-  }
-}
-
-EOF
-}
-
-# This is called to feed cmds to jdb.
-dojdbCmds()
-{
-    setBkpts @1
-    setBkpts @2
-    runToBkpt @1
-    # modified version of redefineClass function
-    vers=2
-    abs_class=MyAbstractClass
-    cmd redefine $pkgDot$abs_class $tmpFileDir/vers$vers/$abs_class.class
-    cp $tmpFileDir/$classname.java.$vers \
-        $tmpFileDir/$classname.java
-    # end modified version of redefineClass function
-
-    # this will continue to the second breakpoint
-    cmd cont
-}
-
-
-mysetup()
-{
-    if [ -z "$TESTSRC" ] ; then
-        TESTSRC=.
-    fi
-
-    for ii in . $TESTSRC $TESTSRC/.. ; do
-        if [ -r "$ii/ShellScaffold.sh" ] ; then
-            . $ii/ShellScaffold.sh 
-            break
-        fi
-    done
-}
-
-# You could replace this next line with the contents
-# of ShellScaffold.sh and this script will run just the same.
-mysetup
-
-runit
-
-debuggeeFailIfNotPresent 'This is call 4 to checkFunc'
-debuggeeFailIfNotPresent 'This is call 5 to checkFunc'
-debuggeeFailIfNotPresent 'This is call 6 to checkFunc'
-pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jdi/RedefineAddPrivateMethod.java	Wed Sep 12 12:29:40 2018 -0700
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8149743
+ * @summary crash when adding a breakpoint after redefining to add a private static method
+ * @comment converted from test/jdk/com/sun/jdi/RedefineAddPrivateMethod.sh
+ *
+ * @library /test/lib
+ * @compile -g RedefineAddPrivateMethod.java
+ * @run main/othervm RedefineAddPrivateMethod
+ */
+
+import jdk.test.lib.process.OutputAnalyzer;
+import lib.jdb.JdbCommand;
+import lib.jdb.JdbTest;
+
+class RedefineAddPrivateMethodTarg {
+    static public void main(String[] args) {
+        System.out.println("@1 breakpoint");
+        System.out.println("@2 breakpoint");
+    }
+
+    // @1 uncomment private static void test() {}
+}
+
+public class RedefineAddPrivateMethod extends JdbTest {
+    public static void main(String argv[]) {
+        new RedefineAddPrivateMethod().run();
+    }
+
+    private RedefineAddPrivateMethod() {
+        super(DEBUGGEE_CLASS, SOURCE_FILE);
+    }
+
+    private static final String DEBUGGEE_CLASS = RedefineAddPrivateMethodTarg.class.getName();
+    private static final String SOURCE_FILE = "RedefineAddPrivateMethod.java";
+
+    @Override
+    protected void runCases() {
+        setBreakpoints(1);
+        jdb.command(JdbCommand.run());
+
+        redefineClass(1, "-g");
+        // ensure "test()" method has been added successfully
+        execCommand(JdbCommand.eval(DEBUGGEE_CLASS + ".test()"))
+                .shouldNotContain("ParseException");
+
+        setBreakpoints(2);
+        jdb.command(JdbCommand.run());
+
+        jdb.quit();
+
+        new OutputAnalyzer(getDebuggeeOutput())
+                .shouldNotContain("Internal exception:");
+    }
+}
--- a/test/jdk/com/sun/jdi/RedefineAddPrivateMethod.sh	Wed Sep 12 10:27:03 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,79 +0,0 @@
-#!/bin/sh
-
-#
-# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-#  @test
-#  @bug 8149743
-#  @summary crash when adding a breakpoint after redefining to add a private static method
-#  @run shell RedefineAddPrivateMethod.sh
-
-compileOptions=-g
-
-createJavaFile()
-{
-    cat <<EOF > $1.java.1
-public class $1 {
-    static public void main(String[] args) {
-        System.out.println("@1 breakpoint");
-        System.out.println("@2 breakpoint");
-    }
-
-    // @1 uncomment private static void test() {}
-}
-EOF
-}
-
-# This is called to feed cmds to jdb.
-dojdbCmds()
-{
-    setBkpts @1
-    runToBkpt @1
-    redefineClass @1
-    setBkpts @2
-    runToBkpt @2
-    cmd exitJdb
-}
-
-
-mysetup()
-{
-    if [ -z "$TESTSRC" ] ; then
-        TESTSRC=.
-    fi
-
-    for ii in . $TESTSRC $TESTSRC/.. ; do
-        if [ -r "$ii/ShellScaffold.sh" ] ; then
-            . $ii/ShellScaffold.sh 
-            break
-        fi
-    done
-}
-
-# You could replace this next line with the contents
-# of ShellScaffold.sh and this script will run just the same.
-mysetup
-
-runit
-debuggeeFailIfPresent "Internal exception:"
-pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jdi/RedefineAnnotation.java	Wed Sep 12 12:29:40 2018 -0700
@@ -0,0 +1,231 @@
+/*
+ * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 5002251 6407335 6412391
+ * @summary Redefine a class that has an annotation and verify that the
+ * new annotation is returned.
+ * @comment converted from test/jdk/com/sun/jdi/RedefineAnnotation.sh
+ *
+ * @library /test/lib
+ * @compile -g RedefineAnnotation.java
+ * @run main/othervm RedefineAnnotation
+ */
+
+import jdk.test.lib.process.OutputAnalyzer;
+import lib.jdb.JdbCommand;
+import lib.jdb.JdbTest;
+
+import java.lang.annotation.*;
+import java.lang.reflect.*;
+
+@Foo(Constants.class_annotation)  // @1 commentout
+// @1 uncomment @Foo(Constants.new_class_annotation)
+class RedefineAnnotationTarg {
+    @Foo(Constants.field_annotation)  // @1 commentout
+    // @1 uncomment @Foo(Constants.new_field_annotation)
+    public int dummy_field;
+
+    public static void main(String[] args) {
+        MySubClass sub = new MySubClass();
+        MySubSubClass subsub = new MySubSubClass();
+        new RedefineAnnotationTarg().hi(false);
+        new RedefineAnnotationTarg().hi(true);  // @1 breakpoint
+        sub.hi(true);
+        subsub.hi(true);
+    }
+
+    @Foo(Constants.method_annotation)  // @1 commentout
+    // @1 uncomment @Foo(Constants.new_method_annotation)
+    public void hi(
+    @Foo(Constants.method_parameter_annotation)  // @1 commentout
+    // @1 uncomment @Foo(Constants.new_method_parameter_annotation)
+                   boolean isNewVersion) {
+
+        if (isNewVersion) {
+            System.out.println("Checking for NEW versions of annotations in "
+                + getClass());
+        }
+
+        // class annotations check:
+        Foo foo = getClass().getAnnotation(Foo.class);
+        if (foo == null) {
+          throw new Error("FAIL: cannot get class_annotation from "
+                        + getClass());
+        }
+
+        String class_annotation = foo.value();
+        System.out.println("class annotation is: " + class_annotation);
+        if (isNewVersion) {
+            if (class_annotation.equals(Constants.new_class_annotation)) {
+                System.out.println("PASS: class_annotation was changed.");
+            } else {
+                System.out.println("FAIL: class_annotation was NOT changed.");
+            }
+        }
+
+        // field annotations check:
+        try {
+            Field my_field = getClass().getField("dummy_field");
+            foo = my_field.getAnnotation(Foo.class);
+            if (foo == null) {
+              throw new Error("FAIL: cannot get field_annotation from "
+                            + getClass() + ".dummy_field");
+            }
+            String field_annotation = foo.value();
+            System.out.println("field annotation is: " + field_annotation);
+            if (isNewVersion) {
+                if (field_annotation.equals(Constants.new_field_annotation)) {
+                    System.out.println("PASS: field_annotation was changed.");
+                } else {
+                    System.out.println(
+                        "FAIL: field_annotation was NOT changed.");
+                }
+        }
+        } catch (NoSuchFieldException nsfe) {
+            throw new Error("FAIL: cannot find field 'dummy_field' in "
+                          + getClass());
+        }
+
+        // method annotations check:
+        try {
+            Class params[] = new Class[1];
+            params[0] = Boolean.TYPE;
+            Method my_method = getClass().getMethod("hi", params);
+            foo = my_method.getAnnotation(Foo.class);
+            if (foo == null) {
+              throw new Error("FAIL: cannot get field_annotation from "
+                            + getClass() + ".hi()");
+            }
+            String method_annotation = foo.value();
+            System.out.println("method annotation is: " + method_annotation);
+            if (isNewVersion) {
+                if (method_annotation.equals(Constants.new_method_annotation)) {
+                    System.out.println("PASS: method_annotation was changed.");
+                } else {
+                    System.out.println(
+                        "FAIL: method_annotation was NOT changed.");
+                }
+            }
+        } catch (NoSuchMethodException nsme) {
+            throw new Error("FAIL: cannot find method 'hi' in " + getClass());
+        }
+
+        // method parameter annotations check:
+        try {
+            Class params[] = new Class[1];
+            params[0] = Boolean.TYPE;
+            Method my_method = getClass().getMethod("hi", params);
+            Annotation my_annotations[][] = my_method.getParameterAnnotations();
+            if (my_annotations.length != 1) {
+                throw new Error("FAIL: unexpected my_annotations.length ("
+                              + my_annotations.length);
+            }
+            Annotation my_annotation[] = my_annotations[0];
+            if (my_annotation.length != 1) {
+                throw new Error("FAIL: unexpected my_annotation.length ("
+                              + my_annotation.length);
+            }
+            foo = (Foo)my_annotation[0];
+            String method_parameter_annotation = foo.value();
+            System.out.println("method parameter annotation is: "
+                + method_parameter_annotation);
+            if (isNewVersion) {
+                if (method_parameter_annotation.equals(
+                    Constants.new_method_parameter_annotation)) {
+                    System.out.println(
+                        "PASS: method_parameter_annotation was changed.");
+                } else {
+                    System.out.println(
+                        "FAIL: method_parameter_annotation was NOT changed.");
+                }
+            }
+        } catch (NoSuchMethodException nsme) {
+            throw new Error("FAIL: cannot find method 'hi' in " + getClass());
+        }
+    }
+}
+
+// this subclass exists just to make the RedefineClasses() code do a
+// subclass walk to update the counter
+class MySubClass extends RedefineAnnotationTarg {
+    int my_int_field_makes_me_different;
+}
+
+// this subclass exists just to make the RedefineClasses() code do a
+// sub-subclass walk to update the counter
+class MySubSubClass extends MySubClass {
+    float my_float_field_makes_me_different;
+}
+
+class Constants {
+    static final String class_annotation     = "Patrick's class comment";
+    static final String new_class_annotation = "*NEW* Patrick's class comment";
+
+    static final String field_annotation     = "dummy_field comment";
+    static final String new_field_annotation = "*NEW* dummy_field comment";
+
+    static final String method_annotation     = "method hi() comment";
+    static final String new_method_annotation = "*NEW* method hi() comment";
+
+    static final String method_parameter_annotation     =
+        "param isNewVersion comment";
+    static final String new_method_parameter_annotation =
+        "*NEW* param isNewVersion comment";
+}
+
+
+/**
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+@interface Foo {
+    String value();
+}
+
+public class RedefineAnnotation extends JdbTest {
+
+    public static void main(String argv[]) {
+        new RedefineAnnotation().run();
+    }
+
+    private RedefineAnnotation() {
+        super(DEBUGGEE_CLASS, SOURCE_FILE);
+    }
+
+    private static final String DEBUGGEE_CLASS = RedefineAnnotationTarg.class.getName();
+    private static final String SOURCE_FILE = "RedefineAnnotation.java";
+
+    @Override
+    protected void runCases() {
+        setBreakpoints(1);
+        jdb.command(JdbCommand.run());
+
+        redefineClass(1, "-g");
+        jdb.contToExit(1);
+
+        new OutputAnalyzer(getDebuggeeOutput())
+                .shouldNotContain("FAIL:");
+    }
+}
--- a/test/jdk/com/sun/jdi/RedefineAnnotation.sh	Wed Sep 12 10:27:03 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,246 +0,0 @@
-#!/bin/sh
-
-#
-# Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-#  @test
-#  @bug 5002251 6407335 6412391
-#  @summary Redefine a class that has an annotation and verify that the
-#    new annotation is returned.
-#
-#  @key intermittent
-#  @run shell RedefineAnnotation.sh
-
-compileOptions=-g
-
-# Uncomment this to see the JDI trace
-#jdbOptions=-dbgtrace
-
-createJavaFile()
-{
-    cat <<EOF > $1.java.1
-
-import java.lang.annotation.*;
-import java.lang.reflect.*;
-
-/**
- */
-@Foo(Constants.class_annotation)  // @1 commentout
-// @1 uncomment @Foo(Constants.new_class_annotation)
-public class $1 {
-@Foo(Constants.field_annotation)  // @1 commentout
-// @1 uncomment @Foo(Constants.new_field_annotation)
-    public int dummy_field;
-
-    public static void main(String[] args) {
-        MySubClass sub = new MySubClass();
-        MySubSubClass subsub = new MySubSubClass();
-        new $1().hi(false);
-        new $1().hi(true);  // @1 breakpoint
-        sub.hi(true);
-        subsub.hi(true);
-    }
-
-@Foo(Constants.method_annotation)  // @1 commentout
-// @1 uncomment @Foo(Constants.new_method_annotation)
-    public void hi(
-@Foo(Constants.method_parameter_annotation)  // @1 commentout
-// @1 uncomment @Foo(Constants.new_method_parameter_annotation)
-                   boolean isNewVersion) {
-
-        if (isNewVersion) {
-            System.out.println("Checking for NEW versions of annotations in "
-                + getClass());
-        }
-
-        // class annotations check:
-        Foo foo = getClass().getAnnotation(Foo.class);
-        if (foo == null) {
-          throw new Error("FAIL: cannot get class_annotation from "
-                        + getClass());
-        }
-
-        String class_annotation = foo.value();
-        System.out.println("class annotation is: " + class_annotation);
-        if (isNewVersion) {
-            if (class_annotation.equals(Constants.new_class_annotation)) {
-                System.out.println("PASS: class_annotation was changed.");
-            } else {
-                System.out.println("FAIL: class_annotation was NOT changed.");
-            }
-        }
-    
-        // field annotations check:
-        try {
-            Field my_field = getClass().getField("dummy_field");
-            foo = my_field.getAnnotation(Foo.class);
-            if (foo == null) {
-              throw new Error("FAIL: cannot get field_annotation from "
-                            + getClass() + ".dummy_field");
-            }
-            String field_annotation = foo.value();
-            System.out.println("field annotation is: " + field_annotation);
-            if (isNewVersion) {
-                if (field_annotation.equals(Constants.new_field_annotation)) {
-                    System.out.println("PASS: field_annotation was changed.");
-                } else {
-                    System.out.println(
-                        "FAIL: field_annotation was NOT changed.");
-                }
-        }
-        } catch (NoSuchFieldException nsfe) {
-            throw new Error("FAIL: cannot find field 'dummy_field' in "
-                          + getClass());
-        }
-    
-        // method annotations check:
-        try {
-            Class params[] = new Class[1];
-            params[0] = Boolean.TYPE;
-            Method my_method = getClass().getMethod("hi", params);
-            foo = my_method.getAnnotation(Foo.class);
-            if (foo == null) {
-              throw new Error("FAIL: cannot get field_annotation from "
-                            + getClass() + ".hi()");
-            }
-            String method_annotation = foo.value();
-            System.out.println("method annotation is: " + method_annotation);
-            if (isNewVersion) {
-                if (method_annotation.equals(Constants.new_method_annotation)) {
-                    System.out.println("PASS: method_annotation was changed.");
-                } else {
-                    System.out.println(
-                        "FAIL: method_annotation was NOT changed.");
-                }
-            }
-        } catch (NoSuchMethodException nsme) {
-            throw new Error("FAIL: cannot find method 'hi' in " + getClass());
-        }
-    
-        // method parameter annotations check:
-        try {
-            Class params[] = new Class[1];
-            params[0] = Boolean.TYPE;
-            Method my_method = getClass().getMethod("hi", params);
-            Annotation my_annotations[][] = my_method.getParameterAnnotations();
-            if (my_annotations.length != 1) {
-                throw new Error("FAIL: unexpected my_annotations.length ("
-                              + my_annotations.length);
-            }
-            Annotation my_annotation[] = my_annotations[0];
-            if (my_annotation.length != 1) {
-                throw new Error("FAIL: unexpected my_annotation.length ("
-                              + my_annotation.length);
-            }
-            foo = (Foo)my_annotation[0];
-            String method_parameter_annotation = foo.value();
-            System.out.println("method parameter annotation is: "
-                + method_parameter_annotation);
-            if (isNewVersion) {
-                if (method_parameter_annotation.equals(
-                    Constants.new_method_parameter_annotation)) {
-                    System.out.println(
-                        "PASS: method_parameter_annotation was changed.");
-                } else {
-                    System.out.println(
-                        "FAIL: method_parameter_annotation was NOT changed.");
-                }
-            }
-        } catch (NoSuchMethodException nsme) {
-            throw new Error("FAIL: cannot find method 'hi' in " + getClass());
-        }
-    }
-}
-
-// this subclass exists just to make the RedefineClasses() code do a
-// subclass walk to update the counter
-class MySubClass extends $1 {
-  int my_int_field_makes_me_different;
-}
-
-// this subclass exists just to make the RedefineClasses() code do a
-// sub-subclass walk to update the counter
-class MySubSubClass extends MySubClass {
-  float my_float_field_makes_me_different;
-}
-
-class Constants {
-    static final String class_annotation     = "Patrick's class comment";
-    static final String new_class_annotation = "*NEW* Patrick's class comment";
-
-    static final String field_annotation     = "dummy_field comment";
-    static final String new_field_annotation = "*NEW* dummy_field comment";
-
-    static final String method_annotation     = "method hi() comment";
-    static final String new_method_annotation = "*NEW* method hi() comment";
-
-    static final String method_parameter_annotation     =
-        "param isNewVersion comment";
-    static final String new_method_parameter_annotation =
-        "*NEW* param isNewVersion comment";
-}
-
-
-/**
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Inherited
-@interface Foo {
-    String value();
-}
-
-EOF
-}
-
-# This is called to feed cmds to jdb.
-dojdbCmds()
-{
-    setBkpts @1
-    runToBkpt @1
-    redefineClass @1
-    cmd allowExit cont
-}
-
-
-mysetup()
-{
-    if [ -z "$TESTSRC" ] ; then
-        TESTSRC=.
-    fi
-
-    for ii in . $TESTSRC $TESTSRC/.. ; do
-        if [ -r "$ii/ShellScaffold.sh" ] ; then
-            . $ii/ShellScaffold.sh 
-            break
-        fi
-    done
-}
-
-# You could replace this next line with the contents
-# of ShellScaffold.sh and this script will run just the same.
-mysetup
-
-runit
-
-debuggeeFailIfPresent 'FAIL:'
-pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jdi/RedefineChangeClassOrder.java	Wed Sep 12 12:29:40 2018 -0700
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6270982
+ * @summary Redefine a class so that the order of external classes in
+ *          the constant pool are changed.
+ * @comment converted from test/jdk/com/sun/jdi/RedefineChangeClassOrder.sh
+ *
+ * @library /test/lib
+ * @compile -g RedefineChangeClassOrder.java
+ * @run main/othervm RedefineChangeClassOrder
+ */
+
+import jdk.test.lib.process.OutputAnalyzer;
+import lib.jdb.JdbCommand;
+import lib.jdb.JdbTest;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+class RedefineChangeClassOrderTarg {
+    public static void main(String[] args) {
+        new RedefineChangeClassOrderTarg().hi(false);
+        new RedefineChangeClassOrderTarg().hi(true);  // @1 breakpoint
+    }
+
+    public void hi(boolean expected) {
+        boolean isNewVersion = false; // @1 commentout
+        // @1 uncomment boolean isNewVersion = true;
+
+        if (expected == isNewVersion) {
+            System.out.println("PASS: expected and isNewVersion match.");
+        } else {
+            System.out.println("FAIL: expected and isNewVersion do not match.");
+            System.out.println("expected=" + expected
+              + "  isNewVersion=" + isNewVersion);
+        }
+
+        Foo1 foo1 = new Foo1();  // @1 commentout
+        foo1.hi();  // @1 commentout
+
+        // This Hack code block exists to force some verification_type_info
+        // objects of subtype Object_variable_info into the StackMapTable.
+        //
+        // In the redefined code, the above Foo1 code is effectively
+        // moved after the Foo2 code below which causes things to be
+        // layed out in a different order in the constant pool. The
+        // cpool_index in the Object_variable_info has to be updated
+        // in the redefined code's StackMapTable to refer to right
+        /// constant pool index in the merged constant pool.
+        Hack hack = getClass().getAnnotation(Hack.class);
+        if (hack != null) {
+            String class_annotation = hack.value();
+            System.out.println("class annotation is: " + class_annotation);
+            if (isNewVersion) {
+                if (class_annotation.equals("JUNK")) {
+                    System.out.println("class_annotation is JUNK.");
+                } else {
+                    System.out.println("class_annotation is NOT JUNK.");
+                }
+            }
+        }
+
+        Foo2 foo2 = new Foo2();
+        foo2.hi();
+
+        // @1 uncomment Foo1 foo1 = new Foo1();
+        // @1 uncomment foo1.hi();
+    }
+}
+
+class Foo1 {
+    public void hi() {
+        System.out.println("Hello from " + getClass());
+    }
+}
+
+class Foo2 {
+    public void hi() {
+        System.out.println("Hello from " + getClass());
+    }
+}
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Hack {
+    String value();
+}
+
+
+public class RedefineChangeClassOrder extends JdbTest {
+
+    public static void main(String argv[]) {
+        new RedefineChangeClassOrder().run();
+    }
+
+    private RedefineChangeClassOrder() {
+        super(DEBUGGEE_CLASS, SOURCE_FILE);
+    }
+
+    private static final String DEBUGGEE_CLASS = RedefineChangeClassOrderTarg.class.getName();
+    private static final String SOURCE_FILE = "RedefineChangeClassOrder.java";
+
+    @Override
+    protected void runCases() {
+        setBreakpoints(1);
+        jdb.command(JdbCommand.run());
+        redefineClass(1, "-g");
+        jdb.contToExit(1);
+
+        new OutputAnalyzer(getDebuggeeOutput())
+                .shouldNotContain("FAIL:");
+    }
+}
--- a/test/jdk/com/sun/jdi/RedefineChangeClassOrder.sh	Wed Sep 12 10:27:03 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,151 +0,0 @@
-#!/bin/sh
-
-#
-# Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-#  @test
-#  @bug 6270982
-#  @summary Redefine a class so that the order of external classes in
-#  the constant pool are changed.
-#  @author dcubed
-#
-#  @run shell RedefineChangeClassOrder.sh
-
-compileOptions=-g
-
-# Would like to run this test with this option:
-# -XX:-FailOverToOldVerifier
-
-# Uncomment this to see the JDI trace
-#jdbOptions=-dbgtrace
-
-createJavaFile()
-{
-    cat <<EOF > $1.java.1
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-public class $1 {
-    public static void main(String[] args) {
-        new $1().hi(false);
-        new $1().hi(true);  // @1 breakpoint
-    }
-
-    public void hi(boolean expected) {
-        boolean isNewVersion = false; // @1 commentout
-        // @1 uncomment boolean isNewVersion = true;
-
-        if (expected == isNewVersion) {
-            System.out.println("PASS: expected and isNewVersion match.");
-        } else {
-            System.out.println("FAIL: expected and isNewVersion do not match.");
-            System.out.println("expected=" + expected
-              + "  isNewVersion=" + isNewVersion);
-        }
-
-        Foo1 foo1 = new Foo1();  // @1 commentout
-        foo1.hi();  // @1 commentout
-
-        // This Hack code block exists to force some verification_type_info
-        // objects of subtype Object_variable_info into the StackMapTable.
-        //
-        // In the redefined code, the above Foo1 code is effectively
-        // moved after the Foo2 code below which causes things to be
-        // layed out in a different order in the constant pool. The
-        // cpool_index in the Object_variable_info has to be updated
-        // in the redefined code's StackMapTable to refer to right
-        /// constant pool index in the merged constant pool.
-        Hack hack = getClass().getAnnotation(Hack.class);
-        if (hack != null) {
-            String class_annotation = hack.value();
-            System.out.println("class annotation is: " + class_annotation);
-            if (isNewVersion) {
-                if (class_annotation.equals("JUNK")) {
-                    System.out.println("class_annotation is JUNK.");
-                } else {
-                    System.out.println("class_annotation is NOT JUNK.");
-                }
-            }
-        }
-
-        Foo2 foo2 = new Foo2();
-        foo2.hi();
-
-        // @1 uncomment Foo1 foo1 = new Foo1();
-        // @1 uncomment foo1.hi();
-    }
-}
-
-class Foo1 {
-    public void hi() {
-        System.out.println("Hello from " + getClass());
-    }
-}
-
-class Foo2 {
-    public void hi() {
-        System.out.println("Hello from " + getClass());
-    }
-}
-
-@Retention(RetentionPolicy.RUNTIME)
-@interface Hack {
-    String value();
-}
-
-EOF
-}
-
-# This is called to feed cmds to jdb.
-dojdbCmds()
-{
-    setBkpts @1
-    runToBkpt @1
-    redefineClass @1
-    cmd allowExit cont
-}
-
-
-mysetup()
-{
-    if [ -z "$TESTSRC" ] ; then
-        TESTSRC=.
-    fi
-
-    for ii in . $TESTSRC $TESTSRC/.. ; do
-        if [ -r "$ii/ShellScaffold.sh" ] ; then
-            . $ii/ShellScaffold.sh
-            break
-        fi
-    done
-}
-
-# You could replace this next line with the contents
-# of ShellScaffold.sh and this script will run just the same.
-mysetup
-
-runit
-
-debuggeeFailIfPresent 'FAIL:'
-pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jdi/RedefineClasses.java	Wed Sep 12 12:29:40 2018 -0700
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4628760
+ * @summary RedefineClasses gets assertion: "Should be a method entry in cpcache!"
+ * @comment converted from test/jdk/com/sun/jdi/RedefineClasses.sh
+ *
+ * @library /test/lib
+ * @run main/othervm RedefineClasses
+ */
+
+/* On windows, with b90, this gets this:
+ * assert(u2_at_bcp >= 0 && u2_at_bcp < old_cache->length(), "Bad cpcache index!")
+ *
+ * Error happened during: VM_RedefineClasses
+ *
+ * Error ID: D:/jdk1.4/hotspot\src\share\vm\prims\jvmdi_hotswap.cpp, 331
+
+ * On solaris, and on windows with 4559100 fixed, this test fails with:
+ *
+ * HotSpot Virtual Machine Error, assertion failure
+ * Please report this error at
+ * http://java.sun.com/cgi-bin/bugreport.cgi
+ *
+ * Java VM: Java HotSpot(TM) Client VM (1.4-internal-debug mixed mode)
+ *
+ * assert(old_cache->entry_at(u2_at_bcp)->is_method_entry(), "Should be a method entry in cpcache!")
+ *
+ * Error happened during: VM_RedefineClasses
+ *
+ * Error ID: M:\ws\m\b2\service_hs_baseline\src\share\vm\prims\jvmdi_hotswap.cpp, 335
+ */
+
+/*
+ * With -Xcomp on solaris this passes, but takes 2 minutes.
+ */
+
+import lib.jdb.ClassTransformer;
+import lib.jdb.JdbCommand;
+import lib.jdb.JdbTest;
+
+import java.lang.Thread;
+import java.util.HashMap;
+import javax.swing.*;
+import java.util.*;
+
+class RedefineClassesTarg {
+    int xxx = 20;
+    //ThreadGroup k = new ThreadGroup("group");
+    int i;
+
+    public RedefineClassesTarg() {
+    }
+
+    public void a1() {
+    a2();
+    }
+
+    public void a2() {
+    a3();
+    }
+
+    public void a3() {
+        System.out.println("out from a3");   // @1 breakpoint
+        //System.out.println("hello world"); // @ 1 delete this isn't even necesary
+    }
+    public void a4() {
+        System.out.println("in a4");
+        int i = 2;
+        int j = 3333;
+        System.out.println("i + j = " + (i + j));
+        System.out.println("out from a4");
+        System.out.println("def");
+        a1();
+    }
+
+    public void aa() {
+        a4();
+        System.out.println("out from aa");
+    }
+
+
+    public static void main(String[] args) {
+        byte xyz[] = new byte[] { 'a', 'b', 'c' };
+
+        int x1 = 100;
+        x1 = 101;
+        x1 = 102;
+        x1 = 103;
+        String m1 = "def";
+        String m2 = "abc";
+        String m3 = "def";
+
+        int[] m = new int[] { 100, 200, 300 };
+
+        RedefineClassesTarg untitled31 = new RedefineClassesTarg();
+        untitled31.aa();
+    }
+}
+
+public class RedefineClasses extends JdbTest {
+
+    public static void main(String argv[]) {
+        new RedefineClasses().run();
+    }
+
+    private RedefineClasses() {
+        super(DEBUGGEE_CLASS, SOURCE_FILE);
+    }
+
+    private static final String DEBUGGEE_CLASS = RedefineClassesTarg.class.getName();
+    private static final String SOURCE_FILE = "RedefineClasses.java";
+
+    @Override
+    protected void runCases() {
+        setBreakpoints(1);
+        jdb.command(JdbCommand.run());
+        String transformedClassFile = ClassTransformer.fromTestSource(SOURCE_FILE)
+                .transform(1, DEBUGGEE_CLASS);
+        jdb.command(JdbCommand.redefine(DEBUGGEE_CLASS, transformedClassFile));
+        jdb.command(JdbCommand.redefine(DEBUGGEE_CLASS, transformedClassFile));
+        jdb.command(JdbCommand.redefine(DEBUGGEE_CLASS, transformedClassFile));
+    }
+}
--- a/test/jdk/com/sun/jdi/RedefineClasses.sh	Wed Sep 12 10:27:03 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,159 +0,0 @@
-#!/bin/sh
-
-#
-# Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-#  @test
-#  @bug 4628760
-#  @summary RedefineClasses gets assertion: "Should be a method entry in cpcache!"
-#  @author jjh
-#
-#  @run shell/timeout=180 RedefineClasses.sh
-
-# On windows, with b90, this gets this:
-# assert(u2_at_bcp >= 0 && u2_at_bcp < old_cache->length(), "Bad cpcache index!")
-#
-# Error happened during: VM_RedefineClasses
-#
-# Error ID: D:/jdk1.4/hotspot\src\share\vm\prims\jvmdi_hotswap.cpp, 331
-
-# On solaris, and on windows with 4559100 fixed, this test fails with:
-#
-# HotSpot Virtual Machine Error, assertion failure
-# Please report this error at
-# http://java.sun.com/cgi-bin/bugreport.cgi
-#
-# Java VM: Java HotSpot(TM) Client VM (1.4-internal-debug mixed mode)
-#
-# assert(old_cache->entry_at(u2_at_bcp)->is_method_entry(), "Should be a method entry in cpcache!")
-#
-# Error happened during: VM_RedefineClasses
-#
-# Error ID: M:\ws\m\b2\service_hs_baseline\src\share\vm\prims\jvmdi_hotswap.cpp, 335
-
-
-# With -Xcomp on solaris this passes, but takes 2 minutes, thus the /timeout above.
-
-# These are variables that can be set to control execution
-
-java=java
-
-createJavaFile()
-{
-    cat <<EOF > $1.java.1
-
-
-import java.lang.Thread;
-import java.util.HashMap;
-import javax.swing.*;
-import java.util.*;
-
-
-public class $1 {
-  int xxx = 20;
-  //ThreadGroup k = new ThreadGroup("group");
-  int i;
-
-  public $1() {
-  }
-
-  public void a1() {
-      a2();
-  }
-
-  public void a2() {
-    a3();
-  }
-
-  public void a3() {
-     System.out.println("out from a3");   // @1 breakpoint
-     //System.out.println("hello world"); // @ 1 delete this isn't even necesary
-  }
-  public void a4() {
-    System.out.println("in a4");
-    int i = 2;
-    int j = 3333;
-    System.out.println("i + j = " + (i + j));
-    System.out.println("out from a4");
-    System.out.println("def");
-    a1();
-  }
-
-  public void aa() {
-    a4();
-    System.out.println("out from aa");
-  }
-
-
-  public static void main(String[] args) {
-    byte xyz[] = new byte[] { 'a', 'b', 'c' };
-
-    int x1 = 100;
-    x1 = 101;
-    x1 = 102;
-    x1 = 103;
-    String m1 = "def";
-    String m2 = "abc";
-    String m3 = "def";
-
-    int[] m = new int[] { 100, 200, 300 };
-
-    $1 untitled31 = new $1();
-    untitled31.aa();
-  }
-}
-
-EOF
-}
-
-# This is called to feed cmds to jdb.
-dojdbCmds()
-{
-    setBkpts @1
-    runToBkpt
-    cmd redefine $classname $tmpFileDir/$classname.class
-    cmd redefine $classname $tmpFileDir/$classname.class
-    cmd redefine $classname $tmpFileDir/$classname.class
-}
-
-
-mysetup()
-{
-    if [ -z "$TESTSRC" ] ; then
-        TESTSRC=.
-    fi
-
-    for ii in . $TESTSRC $TESTSRC/.. ; do
-        if [ -r "$ii/ShellScaffold.sh" ] ; then
-            . $ii/ShellScaffold.sh 
-            break
-        fi
-    done
-}
-
-# You could replace this next line with the contents
-# of ShellScaffold.sh and this script will run just the same.
-mysetup
-
-runit
-pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jdi/RedefineClearBreakpoint.java	Wed Sep 12 12:29:40 2018 -0700
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4705330
+ * @summary Netbeans Fix and Continue crashes JVM
+ * @comment converted from test/jdk/com/sun/jdi/RedefineClearBreakpoint.sh
+ *
+ * @library /test/lib
+ * @compile -g RedefineClearBreakpoint.java
+ * @run main/othervm RedefineClearBreakpoint
+ */
+
+/*
+ * The failure occurs after a breakpoint is set and then cleared
+ * after a class redefinition, in a method that was EMCP.
+ * This sequence creates a state in which subsequent operations
+ * such as accessing local vars via JVMDI, can cause a hotspot crash.
+ */
+
+import jdk.test.lib.Asserts;
+import jdk.test.lib.process.OutputAnalyzer;
+import lib.jdb.JdbCommand;
+import lib.jdb.JdbTest;
+
+import java.util.List;
+
+class RedefineClearBreakpointTarg {
+
+    public RedefineClearBreakpointTarg() {
+        int a=23;
+        a=m(a);
+    }
+    public int m(int b){
+        int bb=89;
+        System.out.println("RedefineClearBreakpointTarg -  constructor" + b); //@1 breakpoint
+        return b*b;
+    }
+
+    public static void main(java.lang.String[] args) {
+        new RedefineClearBreakpointTarg();
+        int jj = 0;   //@1 delete
+    }
+
+}
+
+
+public class RedefineClearBreakpoint extends JdbTest {
+
+    public static void main(String argv[]) {
+        new RedefineClearBreakpoint().run();
+    }
+
+    private RedefineClearBreakpoint() {
+        super(DEBUGGEE_CLASS, SOURCE_FILE);
+    }
+
+    private static final String DEBUGGEE_CLASS = RedefineClearBreakpointTarg.class.getName();
+    private static final String SOURCE_FILE = "RedefineClearBreakpoint.java";
+
+    @Override
+    protected void runCases() {
+        List<Integer> bps = parseBreakpoints(getTestSourcePath(SOURCE_FILE), 1);
+        Asserts.assertEquals(bps.size(), 1, "unexpected breakpoint count");
+        jdb.command(JdbCommand.stopAt(DEBUGGEE_CLASS, bps.get(0)));
+        jdb.command(JdbCommand.run());
+        redefineClass(1, "-g");
+
+        jdb.command(JdbCommand.stopAt(DEBUGGEE_CLASS, bps.get(0)));
+        jdb.command(JdbCommand.next());     // This is needed to make the crash happen at the 'locals' cmd
+
+        jdb.command(JdbCommand.clear(DEBUGGEE_CLASS, bps.get(0)));
+        jdb.command(JdbCommand.locals());   // The crash happens here
+
+        new OutputAnalyzer(getDebuggeeOutput())
+                .shouldNotContain("Internal exception:");
+    }
+}
--- a/test/jdk/com/sun/jdi/RedefineClearBreakpoint.sh	Wed Sep 12 10:27:03 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,102 +0,0 @@
-#!/bin/sh
-
-#
-# Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-#  @test
-#  @bug 4705330
-#  @summary Netbeans Fix and Continue crashes JVM
-#  @author Jim Holmlund/Swamy Venkataramanappa
-#  @key intermittent
-#  @run shell RedefineClearBreakpoint.sh
-
-#  The failure occurs after a bkpt is set and then cleared
-#  after a class redefinition, in a method that was EMCP.
-#  This sequence creates a state in which subsequent operations
-#  such as accessing local vars via JVMDI, can cause a hotspot crash.
-
-# These are variables that can be set to control execution
-
-compileOptions=-g
-createJavaFile()
-{
-    cat <<EOF > $1.java.1
-
-public class $1 {
-        
-        public $1() {
-            int a=23;
-            a=m(a);
-            
-        }
-        public int m(int b){
-            int bb=89;
-            System.out.println("$1 -  constructor" + b); //@1 breakpoint
-            return b*b;
-        }
-        
-        public static void main(java.lang.String[] args) {
-            new $1();        
-            int jj = 0;   //@1 delete
-        }
-            
-}
-EOF
-}
-
-# This is called to feed cmds to jdb.
-dojdbCmds()
-{
-    setBkpts @1
-    runToBkpt @1
-    redefineClass @1
-    #cmd clear    NOTE this shows that jdb thinks the bpt is still set :-(
-    setBkpts @1
-    cmd next     # This is needed to make the crash happen at the 'locals' cmd
-    cmd clear shtest:11
-    cmd locals   # The crash happens here.
-    #where
-}
-
-
-mysetup()
-{
-    if [ -z "$TESTSRC" ] ; then
-        TESTSRC=.
-    fi
-
-    for ii in . $TESTSRC $TESTSRC/.. ; do
-        if [ -r "$ii/ShellScaffold.sh" ] ; then
-            . $ii/ShellScaffold.sh 
-            break
-        fi
-    done
-}
-
-# You could replace this next line with the contents
-# of ShellScaffold.sh and this script will run just the same.
-mysetup
-
-runit
-debuggeeFailIfPresent "Internal exception:"
-pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jdi/RedefineG.java	Wed Sep 12 12:29:40 2018 -0700
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4777868
+ * @summary Compile with java -g, do a RedefineClasses, and you don't get local vars
+ * @comment converted from test/jdk/com/sun/jdi/Redefine-g.sh
+ *
+ * @library /test/lib
+ * @compile RedefineG.java
+ * @run main/othervm RedefineG
+ */
+
+import jdk.test.lib.process.OutputAnalyzer;
+import lib.jdb.JdbCommand;
+import lib.jdb.JdbTest;
+
+
+// Compile the first version without -g and the 2nd version with -g.
+class RedefineGTarg {
+    public RedefineGTarg() {
+    }
+    public static void main(String[] args){
+        int gus=22;
+        RedefineGTarg kk=new RedefineGTarg();
+        kk.m1("ab");
+      }
+
+    void m1(String p1) {
+        int m1l1 = 1;
+        System.out.println("m1(String) called");
+        m1(p1, "2nd");
+        // @1 uncomment System.out.println("Hello Milpitas!");
+    }
+
+    void m1(String p1, String p2) {
+        int m1l2 = 2;
+        System.out.println("m2" + p1 + p2);  // @1 breakpoint
+    }
+
+}
+
+public class RedefineG extends JdbTest {
+    public static void main(String argv[]) {
+        new RedefineG().run();
+    }
+
+    private RedefineG() {
+        super(DEBUGGEE_CLASS,
+                "RedefineG.java");
+    }
+
+    private static final String DEBUGGEE_CLASS = RedefineGTarg.class.getName();
+
+    @Override
+    protected void runCases() {
+        setBreakpoints(1);
+        jdb.command(JdbCommand.run());
+        jdb.command(JdbCommand.where(""));
+        jdb.command(JdbCommand.locals());
+
+        redefineClass(1, "-g");
+        jdb.command(JdbCommand.where(""));
+        jdb.command(JdbCommand.locals());
+
+        jdb.command(JdbCommand.pop());
+        jdb.command(JdbCommand.where(""));
+        jdb.command(JdbCommand.locals());
+
+        jdb.command(JdbCommand.pop());
+        jdb.command(JdbCommand.where(""));
+        jdb.command(JdbCommand.locals());
+
+        jdb.contToExit(1);
+
+        new OutputAnalyzer(getJdbOutput())
+                .shouldContain("p1 = \"ab\"")
+                .shouldContain("p2 = \"2nd\"")
+                .shouldContain("m1l2 = 2")
+                .shouldNotContain("m1l1")
+                .shouldContain("args = instance of java.lang.String")
+                .shouldContain("gus = 22")
+                .shouldContain("kk = instance of " + DEBUGGEE_CLASS);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jdi/RedefineImplementor.java	Wed Sep 12 12:29:40 2018 -0700
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6173560
+ * @summary Redefine a class that implements an interface
+ *          and verify that a subclass calls the right method.
+ * @comment converted from test/jdk/com/sun/jdi/RedefineImplementor.sh
+ *
+ * @library /test/lib
+ * @compile -g RedefineImplementor.java
+ * @run main/othervm RedefineImplementor
+ */
+
+import jdk.test.lib.process.OutputAnalyzer;
+import lib.jdb.JdbCommand;
+import lib.jdb.JdbTest;
+
+class RedefineImplementorTarg implements Runnable {
+    public void run() {
+        System.out.println("RedefineImplementorTarg's run");
+        // @1 uncomment System.out.println("This is the new version of RedefineImplementorTarg");
+    }
+
+    public static void main(String[] args) {
+        Runnable r = new B();
+        B.func(r);
+        B.func(r);  // @1 breakpoint
+    }
+
+}
+
+class B extends RedefineImplementorTarg {
+    static void func(Runnable r) {
+        r.run();
+    }
+}
+
+public class RedefineImplementor extends JdbTest {
+    public static void main(String argv[]) {
+        new RedefineImplementor().run();
+    }
+
+    private RedefineImplementor() {
+        super(RedefineImplementorTarg.class.getName(),
+                "RedefineImplementor.java");
+    }
+
+    @Override
+    protected void runCases() {
+        setBreakpoints(1);
+        jdb.command(JdbCommand.run());
+
+        redefineClass(1, "-g");
+
+        jdb.contToExit(1);
+
+        new OutputAnalyzer(getDebuggeeOutput())
+                .shouldContain("This is the new version of ");
+    }
+}
--- a/test/jdk/com/sun/jdi/RedefineImplementor.sh	Wed Sep 12 10:27:03 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,97 +0,0 @@
-#!/bin/sh
-
-#
-# Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-#  @test
-#  @bug 6173560
-#  @summary Redefine a class that implements an interface
-#    and verify that a subclass calls the right method.
-#
-#
-#  @run shell RedefineImplementor.sh
-
-compileOptions=-g
-
-# Uncomment this to see the JDI trace
-#jdbOptions=-dbgtrace
-
-createJavaFile()
-{
-    cat <<EOF > $1.java.1
-
-public class $1 implements Runnable {
-    public void run() {
-        System.out.println("$1's run");
-        // @1 uncomment System.out.println("This is the new version of $1");
-    }
-
-    public static void main(String[] args) {
-        Runnable r = new B();
-        B.func(r);
-        B.func(r);  // @1 breakpoint
-    }
-
-}
-
-class B extends $1 {
-    static void func(Runnable r) {
-        r.run();
-    }
-}
-
-EOF
-}
-
-# This is called to feed cmds to jdb.
-dojdbCmds()
-{
-    setBkpts @1
-    runToBkpt @1
-    redefineClass @1
-    cmd allowExit cont
-}
-
-
-mysetup()
-{
-    if [ -z "$TESTSRC" ] ; then
-        TESTSRC=.
-    fi
-
-    for ii in . $TESTSRC $TESTSRC/.. ; do
-        if [ -r "$ii/ShellScaffold.sh" ] ; then
-            . $ii/ShellScaffold.sh
-            break
-        fi
-    done
-}
-
-# You could replace this next line with the contents
-# of ShellScaffold.sh and this script will run just the same.
-mysetup
-
-runit
-
-debuggeeFailIfNotPresent 'This is the new version of '
-pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jdi/lib/jdb/ClassTransformer.java	Wed Sep 12 12:29:40 2018 -0700
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package lib.jdb;
+
+import jdk.test.lib.compiler.CompilerUtils;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.text.MessageFormat;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+// ClassTransformer provides functionality to transform java source and compile it.
+// We cannot use InMemoryJavaCompiler as test files usually contain 2 classes (the test itself and debuggee)
+// and InMemoryJavaCompiler cannot compile them.
+public class ClassTransformer {
+
+    private final List<String> lines;
+    private String fileName;
+    private String workDir = "ver{0}";
+    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
+
+    private ClassTransformer(List<String> lines) {
+        this.lines = lines;
+    }
+
+    public ClassTransformer setFileName(String fileName) {
+        this.fileName = fileName;
+        return this;
+    }
+
+    // workDir is a MessageFormat pattern, id (int) is an {0} arg of the pattern.
+    // can be relative (relatively "scratch" dir) or absolute.
+    public ClassTransformer setWorkDir(String dir) {
+        workDir = dir;
+        return this;
+    }
+
+    public static ClassTransformer fromString(String content) {
+        return new ClassTransformer(Arrays.asList(content.split("\\R")));
+    }
+
+    public static ClassTransformer fromFile(Path filePath) {
+        try {
+            return new ClassTransformer(Files.readAllLines(filePath))
+                    .setFileName(filePath.getFileName().toString());
+        } catch (IOException e) {
+            throw new RuntimeException("failed to read " + filePath, e);
+        }
+    }
+    public static ClassTransformer fromFile(String filePath) {
+        return fromFile(Paths.get(filePath));
+    }
+
+    public static ClassTransformer fromTestSource(String fileName) {
+        return fromFile(Paths.get(System.getProperty("test.src")).resolve(fileName));
+    }
+
+    // returns path to the .class file of the transformed class
+    public String transform(int id, String className, String... compilerOptions) {
+        Path subdir = Paths.get(".").resolve(MessageFormat.format(workDir, id));
+        Path transformedSrc = subdir.resolve(fileName);
+        try {
+            Files.createDirectories(subdir);
+            Files.write(transformedSrc, transform(id).getBytes());
+        } catch (IOException e) {
+            throw new RuntimeException("failed to write transformed " + transformedSrc, e);
+        }
+        try {
+            // need to add extra classpath args
+            List<String> args = new LinkedList<>(Arrays.asList(compilerOptions));
+            args.add("-cp");
+            args.add(System.getProperty("java.class.path"));
+            CompilerUtils.compile(subdir, subdir, false, args.toArray(new String[args.size()]));
+        } catch (IOException e) {
+            throw new RuntimeException("failed to compile " + transformedSrc, e);
+        }
+        return subdir.resolve(className + ".class").toString();
+    }
+
+    /*
+    * To do RedefineClasses operations, embed @1 tags in the .java
+    * file to tell this script how to modify it to produce the 2nd
+    * version of the .class file to be used in the redefine operation.
+    * Here are examples of each editing tag and what change
+    * it causes in the new file.  Note that blanks are not preserved
+    * in these editing operations.
+    *
+    * @1 uncomment
+    *  orig:   // @1 uncomment   gus = 89;
+    *  new:         gus = 89;
+    *
+    * @1 commentout
+    *  orig:   gus = 89      // @1 commentout
+    *  new: // gus = 89      // @1 commentout
+    *
+    * @1 delete
+    *  orig:  gus = 89      // @1 delete
+    *  new:   entire line deleted
+    *
+    * @1 newline
+    *  orig:  gus = 89;     // @1 newline gus++;
+    *  new:   gus = 89;     //
+    *         gus++;
+    *
+    * @1 replace
+    *  orig:  gus = 89;     // @1 replace gus = 90;
+    *  new:   gus = 90;
+    */
+    public String transform(int id) {
+        Pattern delete = Pattern.compile("@" + id + " *delete");
+        Pattern uncomment = Pattern.compile("// *@" + id + " *uncomment (.*)");
+        Pattern commentout = Pattern.compile(".* @" + id + " *commentout");
+        Pattern newline = Pattern.compile("(.*) @" + id + " *newline (.*)");
+        Pattern replace = Pattern.compile("@" + id + " *replace (.*)");
+        return lines.stream()
+                .filter(s -> !delete.matcher(s).find())     // @1 delete
+                .map(s -> {
+                    Matcher m = uncomment.matcher(s);       // @1 uncomment
+                    return m.find() ? m.group(1) : s;
+                })
+                .map(s-> {
+                    Matcher m = commentout.matcher(s);      // @1 commentout
+                    return m.find() ? "//" + s : s;
+                })
+                .map(s -> {
+                    Matcher m = newline.matcher(s);         // @1 newline
+                    return m.find() ? m.group(1) + LINE_SEPARATOR + m.group(2) : s;
+                })
+                .map(s -> {
+                    Matcher m = replace.matcher(s);         // @1 replace
+                    return m.find() ? m.group(1) : s;
+                })
+                .collect(Collectors.joining(LINE_SEPARATOR));
+    }
+
+}
--- a/test/jdk/com/sun/jdi/lib/jdb/JdbCommand.java	Wed Sep 12 10:27:03 2018 -0700
+++ b/test/jdk/com/sun/jdi/lib/jdb/JdbCommand.java	Wed Sep 12 12:29:40 2018 -0700
@@ -149,6 +149,11 @@
         return new JdbCommand("stop in " + targetClass + "." + methodName);
     }
 
+    // clear <class id>:<line>   -- clear a breakpoint at a line
+    public static JdbCommand clear(String targetClass, int lineNum) {
+        return new JdbCommand("clear " + targetClass + ":" + lineNum);
+    }
+
     // exception type used by catch/ignore
     public enum ExType{
         uncaught,
@@ -239,4 +244,12 @@
     public static JdbCommand watch(String classId, String fieldName) {
         return new JdbCommand("watch " + classId + "." + fieldName);
     }
+
+    public static JdbCommand pop() {
+        return new JdbCommand("pop");
+    }
+
+    public static JdbCommand redefine(String classId, String classFileName) {
+        return new JdbCommand("redefine " + classId + " " + classFileName);
+    }
 }
--- a/test/jdk/com/sun/jdi/lib/jdb/JdbTest.java	Wed Sep 12 10:27:03 2018 -0700
+++ b/test/jdk/com/sun/jdi/lib/jdb/JdbTest.java	Wed Sep 12 12:29:40 2018 -0700
@@ -44,6 +44,7 @@
     public static class LaunchOptions {
         public final String debuggeeClass;
         public final List<String> debuggeeOptions = new LinkedList<>();
+        public String sourceFilename;
 
         public LaunchOptions(String debuggeeClass) {
             this.debuggeeClass = debuggeeClass;
@@ -56,21 +57,28 @@
             debuggeeOptions.addAll(Arrays.asList(options));
             return this;
         }
+        public LaunchOptions setSourceFilename(String name) {
+            sourceFilename = name;
+            return this;
+        }
     }
 
     public JdbTest(LaunchOptions launchOptions) {
-        this.launchOptions= launchOptions;
-        debuggeeClass = launchOptions.debuggeeClass;
+        this.launchOptions = launchOptions;
     }
     public JdbTest(String debuggeeClass) {
         this(new LaunchOptions(debuggeeClass));
     }
 
+    // sourceFilename is used by setBreakpoints and redefineClass
+    public JdbTest(String debuggeeClass, String sourceFilename) {
+        this(new LaunchOptions(debuggeeClass).setSourceFilename(sourceFilename));
+    }
+
     protected Jdb jdb;
     protected Process debuggee;
     private final List<String> debuggeeOutput = new LinkedList<>();
     private final LaunchOptions launchOptions;
-    protected final String debuggeeClass;   // shortland for launchOptions.debuggeeClass
 
     // returns the whole jdb output as a string
     public String getJdbOutput() {
@@ -201,7 +209,39 @@
     // from the file from test source directory.
     // returns number of the breakpoints set.
     protected int setBreakpointsFromTestSource(String debuggeeFileName, int id) {
-        return setBreakpoints(jdb, debuggeeClass, System.getProperty("test.src") + "/" + debuggeeFileName, id);
+        return setBreakpoints(jdb, launchOptions.debuggeeClass,
+                              getTestSourcePath(debuggeeFileName), id);
+    }
+
+    // sets breakpoints in the class {@code launchOptions.debuggeeClass}
+    // to the lines parsed by {@code parseBreakpoints}
+    // from the file from test source directory specified by {@code launchOptions.sourceFilename}.
+    // returns number of the breakpoints set.
+    protected int setBreakpoints(int id) {
+        verifySourceFilename();
+        return setBreakpointsFromTestSource(launchOptions.sourceFilename, id);
+    }
+
+    // transforms class with the specified id (see {@code ClassTransformer})
+    // and executes "redefine" jdb command for {@code launchOptions.debuggeeClass}.
+    // returns reply for the command.
+    protected List<String> redefineClass(int id, String... compilerOptions) {
+        verifySourceFilename();
+        String transformedClassFile = ClassTransformer.fromTestSource(launchOptions.sourceFilename)
+                .transform(id, launchOptions.debuggeeClass, compilerOptions);
+        return jdb.command(JdbCommand.redefine(launchOptions.debuggeeClass, transformedClassFile));
+    }
+
+    // gets full test source path for the given test filename
+    protected static String getTestSourcePath(String fileName) {
+        return Paths.get(System.getProperty("test.src")).resolve(fileName).toString();
+    }
+
+    // verifies that sourceFilename is specified in ctor
+    private void verifySourceFilename() {
+        if (launchOptions.sourceFilename == null) {
+            throw new RuntimeException("launchOptions.sourceFilename must be specified.");
+        }
     }
 
     protected OutputAnalyzer execCommand(JdbCommand cmd) {