From 450675ba812d239c66e2796c9871c3f898191b4f Mon Sep 17 00:00:00 2001 From: Alex Menkov Date: Fri, 21 Sep 2018 11:28:14 -0700 Subject: [PATCH] 8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4 Reviewed-by: jcbeyler, sspitsyn, cjplummer --- test/jdk/ProblemList.txt | 2 - test/jdk/com/sun/jdi/RedefineException.java | 104 +++++++++ test/jdk/com/sun/jdi/RedefineException.sh | 119 ---------- test/jdk/com/sun/jdi/RedefineFinal.java | 86 +++++++ test/jdk/com/sun/jdi/RedefineFinal.sh | 103 --------- .../sun/jdi/RedefineIntConstantToLong.java | 101 +++++++++ .../com/sun/jdi/RedefineIntConstantToLong.sh | 118 ---------- test/jdk/com/sun/jdi/RedefineMulti.java | 140 ++++++++++++ test/jdk/com/sun/jdi/RedefineMulti.sh | 154 ------------- test/jdk/com/sun/jdi/RedefinePop.java | 91 ++++++++ test/jdk/com/sun/jdi/RedefinePop.sh | 102 --------- test/jdk/com/sun/jdi/RedefineStep.java | 82 +++++++ test/jdk/com/sun/jdi/RedefineStep.sh | 102 --------- .../com/sun/jdi/RedefineTTYLineNumber.java | 110 +++++++++ test/jdk/com/sun/jdi/RedefineTTYLineNumber.sh | 100 --------- test/jdk/com/sun/jdi/StringConvertTest.java | 198 ++++++++++++++++ test/jdk/com/sun/jdi/StringConvertTest.sh | 211 ------------------ test/jdk/com/sun/jdi/WatchFramePop.java | 93 ++++++++ test/jdk/com/sun/jdi/WatchFramePop.sh | 110 --------- 19 files changed, 1005 insertions(+), 1121 deletions(-) create mode 100644 test/jdk/com/sun/jdi/RedefineException.java delete mode 100644 test/jdk/com/sun/jdi/RedefineException.sh create mode 100644 test/jdk/com/sun/jdi/RedefineFinal.java delete mode 100644 test/jdk/com/sun/jdi/RedefineFinal.sh create mode 100644 test/jdk/com/sun/jdi/RedefineIntConstantToLong.java delete mode 100644 test/jdk/com/sun/jdi/RedefineIntConstantToLong.sh create mode 100644 test/jdk/com/sun/jdi/RedefineMulti.java delete mode 100644 test/jdk/com/sun/jdi/RedefineMulti.sh create mode 100644 test/jdk/com/sun/jdi/RedefinePop.java delete mode 100644 test/jdk/com/sun/jdi/RedefinePop.sh create mode 100644 test/jdk/com/sun/jdi/RedefineStep.java delete mode 100644 test/jdk/com/sun/jdi/RedefineStep.sh create mode 100644 test/jdk/com/sun/jdi/RedefineTTYLineNumber.java delete mode 100644 test/jdk/com/sun/jdi/RedefineTTYLineNumber.sh create mode 100644 test/jdk/com/sun/jdi/StringConvertTest.java delete mode 100644 test/jdk/com/sun/jdi/StringConvertTest.sh create mode 100644 test/jdk/com/sun/jdi/WatchFramePop.java delete mode 100644 test/jdk/com/sun/jdi/WatchFramePop.sh diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index adc336361e4..19de37cc561 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -836,8 +836,6 @@ tools/pack200/CommandLineTests.java 8059906 generic- com/sun/jdi/BasicJDWPConnectionTest.java 8195703 generic-all -com/sun/jdi/RedefineImplementor.sh 8004127 generic-all - com/sun/jdi/RepStep.java 8043571 generic-all com/sun/jdi/sde/SourceDebugExtensionTest.java 8158066 windows-all diff --git a/test/jdk/com/sun/jdi/RedefineException.java b/test/jdk/com/sun/jdi/RedefineException.java new file mode 100644 index 00000000000..9fb46e457d3 --- /dev/null +++ b/test/jdk/com/sun/jdi/RedefineException.java @@ -0,0 +1,104 @@ +/* + * 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 4559100 + * @summary The VM crashes when a method in a redefined class throws an exception. + * @comment converted from test/jdk/com/sun/jdi/RedefineException.sh + * + * @library /test/lib + * @run main/othervm RedefineException + */ + +/* This is another symptomm of 4559100 + * This causes a bus error on solsparc: + * ---- called from signal handler with signal 10 (SIGBUS) ------ + * [11] constantPoolOopDesc::klass_at_if_loaded(0xffbed4d8, 0x16, 0xffbed5cc, 0x0, 0x1, 0xfa40b330), at 0xfe11568c + * [12] methodOopDesc::fast_exception_handler_bci_for(0x6, 0x1, 0xfe400a0c, 0x0, 0x2d1f0, 0x0), at 0xfe12e620 + * [13] jvmdi::post_exception_throw_event(0x2d1f0, 0xf61036f8, 0xf6103752, 0xf20414a8, 0x2e2928, 0xfe12e190), at 0xfe2a4fa4 + */ + +import lib.jdb.JdbCommand; +import lib.jdb.JdbTest; + +class RedefineExceptionTarg { + String str; + int ii; + static public void main(String[] args) { + System.out.println("In Main"); + RedefineExceptionTarg mine = new RedefineExceptionTarg(); + mine.a1(); + } + + public void a1() { + int a1local = 1; + String a1string = "a1"; + + ii = 89; // @1 delete this line + str = "foo"; + System.out.println("a1: Calling the original a2/a3. 'The @@@ deleted lines should appear"); + System.out.println("ii = " + ii); // @1 delete this line + a2(); + } + + public void a2() { + int a2local = 2; + String a2string = "a2"; + //System.out.println("a2: @ @@delete this line"); + try { + a3(); + } catch (Exception ee) { + System.out.println("a2: Exception caught"); + } + System.out.println("a2: done"); + } + + public void a3() throws Exception { + int a3local = 3; + String a3string = "a3"; + System.out.println("a3: @@ delete this line"); // If this line is deleted, the test passes! + System.out.println("a3: @1 breakpoint here a3"); + throw new Exception("This is the exception"); + } +} + +public class RedefineException extends JdbTest { + + public static void main(String argv[]) { + new RedefineException().run(); + } + + private RedefineException() { + super(RedefineExceptionTarg.class.getName(), "RedefineException.java"); + } + + @Override + protected void runCases() { + setBreakpoints(1); + jdb.command(JdbCommand.run()); + redefineClass(1); + jdb.command(JdbCommand.pop()); + jdb.contToExit(1); + } +} diff --git a/test/jdk/com/sun/jdi/RedefineException.sh b/test/jdk/com/sun/jdi/RedefineException.sh deleted file mode 100644 index 19ea8cc70a1..00000000000 --- a/test/jdk/com/sun/jdi/RedefineException.sh +++ /dev/null @@ -1,119 +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 4559100 -# @summary The VM crashes when a method in a redefined class throws an exception. -# @author Jim Holmlund -# -# @key intermittent -# @run shell RedefineException.sh - -# This is another symptomm of 4559100 -# This causes a bus error on solsparc: -# ---- called from signal handler with signal 10 (SIGBUS) ------ -# [11] constantPoolOopDesc::klass_at_if_loaded(0xffbed4d8, 0x16, 0xffbed5cc, 0x0, 0x1, 0xfa40b330), at 0xfe11568c -# [12] methodOopDesc::fast_exception_handler_bci_for(0x6, 0x1, 0xfe400a0c, 0x0, 0x2d1f0, 0x0), at 0xfe12e620 -# [13] jvmdi::post_exception_throw_event(0x2d1f0, 0xf61036f8, 0xf6103752, 0xf20414a8, 0x2e2928, 0xfe12e190), at 0xfe2a4fa4 - -# These are variables that can be set to control execution - -createJavaFile() -{ - cat < $1.java.1 - -public class $1 { - String str; - int ii; - static public void main(String[] args) { - System.out.println("In Main"); - $1 mine = new $1(); - mine.a1(); - } - - public void a1() { - int a1local = 1; - String a1string = "a1"; - - ii = 89; // @1 delete this line - str = "foo"; - System.out.println("a1: Calling the original a2/a3. 'The @@@ deleted lines should appear"); - System.out.println("ii = " + ii); // @1 delete this line - a2(); - } - - public void a2() { - int a2local = 2; - String a2string = "a2"; - //System.out.println("a2: @ @@delete this line"); - try { - a3(); - } catch (Exception ee) { - System.out.println("a2: Exception caught"); - } - System.out.println("a2: done"); - } - - public void a3() throws Exception { - int a3local = 3; - String a3string = "a3"; - System.out.println("a3: @@ delete this line"); // If this line is deleted, the test passes! - System.out.println("a3: @1 breakpoint here a3"); - throw new Exception("This is the exception"); - } -} -EOF -} - -dojdbCmds() -{ - setBkpts @1 - runToBkpt - redefineClass @1 - cmd pop - 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 -pass diff --git a/test/jdk/com/sun/jdi/RedefineFinal.java b/test/jdk/com/sun/jdi/RedefineFinal.java new file mode 100644 index 00000000000..e4f908a67c2 --- /dev/null +++ b/test/jdk/com/sun/jdi/RedefineFinal.java @@ -0,0 +1,86 @@ +/* + * 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 4788344 + * @summary RedefineClasses is an apparent no-op if instance method is final + * @comment converted from test/jdk/com/sun/jdi/RedefineFinal.sh + * + * @library /test/lib + * @compile -g RedefineFinal.java + * @run main/othervm RedefineFinal + */ + +import jdk.test.lib.process.OutputAnalyzer; +import lib.jdb.JdbCommand; +import lib.jdb.JdbTest; + +final class RedefineFinalTarg { + + public int m1(int i) { + // @1 uncomment System.out.println("I'm here"); + return m2(i, 1000); + } + + public int m2(int i, int j) { + if (i < 0 || j < 0) { // @1 breakpoint + throw new IllegalArgumentException(); + } + return i+j; + } + + RedefineFinalTarg() { + m1(0); + m1(0); + } + + public static void main(String args[]) { + new RedefineFinalTarg(); + } +} + +public class RedefineFinal extends JdbTest { + + public static void main(String argv[]) { + new RedefineFinal().run(); + } + + private RedefineFinal() { + super(RedefineFinalTarg.class.getName(), "RedefineFinal.java"); + } + + @Override + protected void runCases() { + setBreakpoints(1); + jdb.command(JdbCommand.run()); + redefineClass(1, "-g"); + setBreakpoints(1); + jdb.command(JdbCommand.cont()); + jdb.command(JdbCommand.where("")); + jdb.contToExit(1); + + new OutputAnalyzer(getJdbOutput()) + .shouldNotContain("obsolete"); + } +} diff --git a/test/jdk/com/sun/jdi/RedefineFinal.sh b/test/jdk/com/sun/jdi/RedefineFinal.sh deleted file mode 100644 index 0ad4e5f500e..00000000000 --- a/test/jdk/com/sun/jdi/RedefineFinal.sh +++ /dev/null @@ -1,103 +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 4788344 -# @summary RedefineClasses is an apparent no-op if instance method is final -# -# @key intermittent -# @run shell RedefineFinal.sh - -compileOptions=-g -compileOptions2=-g - -# Uncomment this to see the JDI trace -#jdbOptions=-dbgtrace - -createJavaFile() -{ - cat < $1.java.1 - -public final class $1 { - - public int m1(int i) { - // @1 uncomment System.out.println("I'm here"); - return m2(i, 1000); - } - - public int m2(int i, int j) { - if (i < 0 || j < 0) { // @1 breakpoint - throw new IllegalArgumentException(); - } - return i+j; - } - - $1() { - m1(0); - m1(0); - } - - public static void main(String args[]) { - new $1(); - } -} -EOF -} - -# This is called to feed cmds to jdb. -dojdbCmds() -{ - setBkpts @1 - runToBkpt @1 - redefineClass @1 - setBkpts @1 - contToBkpt - cmd where - 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 - -jdbFailIfPresent 'obsolete' -pass diff --git a/test/jdk/com/sun/jdi/RedefineIntConstantToLong.java b/test/jdk/com/sun/jdi/RedefineIntConstantToLong.java new file mode 100644 index 00000000000..08e44bcc118 --- /dev/null +++ b/test/jdk/com/sun/jdi/RedefineIntConstantToLong.java @@ -0,0 +1,101 @@ +/* + * 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 6394084 + * @summary Redefine class can't handle addition of 64 bit constants in JDK1.5.0_05 + * @comment converted from test/jdk/com/sun/jdi/RedefineIntConstantToLong.sh + * + * @library /test/lib + * @compile -g RedefineIntConstantToLong.java + * @run main/othervm RedefineIntConstantToLong + */ + +import jdk.test.lib.process.OutputAnalyzer; +import lib.jdb.JdbCommand; +import lib.jdb.JdbTest; + +final class RedefineIntConstantToLongTarg { + + public long m1(int i) { + long r=0; + r = m2(i * 2); // @1 commentout + // @1 uncomment r =m2(i * 2L); + return r; + } + + public long m2(int j) { + System.out.println(System.getProperty("line.separator") + + "**** public long m2(int j) with value: " + j); + return j; + } + + public long m2(long j) { + System.out.println(System.getProperty("line.separator") + + "**** public long m2(long j) with value: " + j); + return j; + } + + public void doit() throws Exception { + long r1 = 0; + long r2; + r1 = m1(1000); + r2 = 0; // @1 breakpoint + r2 = m1(1000); + if (r1 != r2) { // @1 breakpoint + throw new Exception("FAILURE: Expected value: " + r1 + " Actual value: " + r2); + } else { + System.out.println("SUCCESS: Expected value: " + r1 + " Actual value: " + r2); + } + } + + public static void main(String args[]) throws Exception { + new RedefineIntConstantToLongTarg().doit(); + } +} + +public class RedefineIntConstantToLong extends JdbTest { + + public static void main(String argv[]) { + new RedefineIntConstantToLong().run(); + } + + private RedefineIntConstantToLong() { + super(RedefineIntConstantToLongTarg.class.getName(), "RedefineIntConstantToLong.java"); + } + + @Override + protected void runCases() { + setBreakpoints(1); + jdb.command(JdbCommand.run()); + redefineClass(1, "-g"); + setBreakpoints(1); + jdb.command(JdbCommand.cont()); + jdb.command(JdbCommand.where("")); + jdb.contToExit(1); + + new OutputAnalyzer(getJdbOutput()) + .shouldNotContain("FAILURE:"); + } +} diff --git a/test/jdk/com/sun/jdi/RedefineIntConstantToLong.sh b/test/jdk/com/sun/jdi/RedefineIntConstantToLong.sh deleted file mode 100644 index 049d6b6451c..00000000000 --- a/test/jdk/com/sun/jdi/RedefineIntConstantToLong.sh +++ /dev/null @@ -1,118 +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 6394084 -# @summary Redefine class can't handle addition of 64 bit constants in JDK1.5.0_05 -# -# @key intermittent -# @run shell RedefineIntConstantToLong.sh - -compileOptions=-g -compileOptions2=-g - -# Uncomment this to see the JDI trace -#jdbOptions=-dbgtrace - -createJavaFile() -{ - cat < $1.java.1 - -public final class $1 { - - public long m1(int i) { - long r=0; - r = m2(i * 2); // @1 commentout - // @1 uncomment r =m2(i * 2L); - return r; - } - - public long m2(int j) { - System.out.println(System.getProperty("line.separator") + - "**** public long m2(int j) with value: " + j); - return j; - } - - public long m2(long j) { - System.out.println(System.getProperty("line.separator") + - "**** public long m2(long j) with value: " + j); - return j; - } - - public void doit() throws Exception { - long r1 = 0; - long r2; - r1 = m1(1000); - r2 = 0; // @1 breakpoint - r2 = m1(1000); - if (r1 != r2) { // @1 breakpoint - throw new Exception("FAILURE: Expected value: " + r1 + " Actual value: " + r2); - } else { - System.out.println("SUCCESS: Expected value: " + r1 + " Actual value: " + r2); - } - } - - public static void main(String args[]) throws Exception { - new $1().doit(); - } -} -EOF -} - -# This is called to feed cmds to jdb. -dojdbCmds() -{ - setBkpts @1 - runToBkpt @1 - redefineClass @1 - setBkpts @1 - contToBkpt - cmd where - 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 - -jdbFailIfPresent 'FAILURE:' -pass diff --git a/test/jdk/com/sun/jdi/RedefineMulti.java b/test/jdk/com/sun/jdi/RedefineMulti.java new file mode 100644 index 00000000000..b30cd170be2 --- /dev/null +++ b/test/jdk/com/sun/jdi/RedefineMulti.java @@ -0,0 +1,140 @@ +/* + * 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 4724076 + * @summary Redefine does not work in for/while loop + * @comment converted from test/jdk/com/sun/jdi/RedefineMulti.sh + * + * @library /test/lib + * @compile -g RedefineMulti.java + * @run main/othervm RedefineMulti + */ + +/* + * The failure occurs when a method is active and + * a method that it calls multiple times is redefined + * more than once. + */ + +import jdk.test.lib.process.OutputAnalyzer; +import lib.jdb.JdbCommand; +import lib.jdb.JdbTest; + +class RedefineMultiTarg { + + String field1; + String field2; + + // The first time thru the loop in start, + // "Before update..." should be printed. + // After the first redefine, "After update..." should be printed + // After the 2nd redefine, "abcde..." should be printed. + // The bug is that "After update..." is printed instead because + // stat() calls version 2 of doSomething() instead of + // version 3. + private void doSomething() { + System.out.println("Before update..."); // @1 commentout + // @1 uncomment System.out.println("After update..."); // @2 commentout + // @2 uncomment System.out.println("abcde..."); + } + + public void start() { + for (int i=0; i < 3; i++) { + doSomething(); // @1 breakpoint here line 16 + System.out.println("field1 = " + field1); + System.out.println("field2 = " + field2); + } + // Redefinex myx = new Redefinex(); + // for (int i = 0; i < 5; i++) { + // myx.methodx1(); // line 22 + // System.out.println("fieldx1 = " + myx.fieldx1); + // System.out.println("fieldx2 = " + myx.fieldx2); + // } + } + + public static void main(String[] args) { + RedefineMultiTarg xxx = new RedefineMultiTarg(); + xxx.field1 = "field1"; + xxx.field2 = "field2"; + xxx.start(); + } +} + +class Redefinex { + public String fieldx1; + public String fieldx2; + + Redefinex() { + fieldx1 = "fieldx1"; + fieldx2 = "fieldx2"; + } + + public void methodx1() { + System.out.println("redefinex 1"); + //System.out.println("redefinex 2"); + //System.out.println("redefinex 3"); + } +} + +/********* +Steps to reproduce this problem: + a. add line breakpoint in start() + b. debug + c. when breakpoint is hit, type continue. You should see output "Before update..." + d. change "Before update" to "After update" + e. redefine, and set line breakpoint (see step a) + f. type continue. You should see output "After update" + g. change "After update" to "abcde" + h. redefine, and set line breakpoint (see step a) + i. type continue. The output is shown as "After update" + j. to see "abcde" output, users will have to pop the stack, and re-execute method start(). +************/ + +public class RedefineMulti extends JdbTest { + + public static void main(String argv[]) { + new RedefineMulti().run(); + } + + private RedefineMulti() { + super(RedefineMultiTarg.class.getName(), "RedefineMulti.java"); + } + + @Override + protected void runCases() { + setBreakpoints(1); + jdb.command(JdbCommand.run()); + jdb.command(JdbCommand.cont()); + redefineClass(1, "-g"); + setBreakpoints(1); + jdb.command(JdbCommand.cont()); + redefineClass(2, "-g"); + jdb.contToExit(1); + + new OutputAnalyzer(getDebuggeeOutput()) + .shouldNotContain("Internal exception:") + .shouldContain("abcde"); + } +} diff --git a/test/jdk/com/sun/jdi/RedefineMulti.sh b/test/jdk/com/sun/jdi/RedefineMulti.sh deleted file mode 100644 index e2736cb0b5f..00000000000 --- a/test/jdk/com/sun/jdi/RedefineMulti.sh +++ /dev/null @@ -1,154 +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 4724076 -# @summary Redefine does not work in for/while loop -# @author Jim Holmlund/Swamy Venkataramanappa -# -# The failure occurs when a method is active and -# a method that it calls multiple times is redefined -# more than once. -# @run shell/timeout=240 RedefineMulti.sh - -compileOptions=-g -#java=java_g - -createJavaFile() -{ - cat < $1.java.1 - -public class $1 { - - String field1; - String field2; - - // The first time thru the loop in start, - // "Before update..." should be printed. - // After the first redefine, "After update..." should be printed - // After the 2nd redefine, "abcde..." should be printed. - // The bug is that "After update..." is printed instead because - // stat() calls version 2 of doSomething() instead of - // version 3. - private void doSomething() { - System.out.println("Before update..."); // @1 commentout - // @1 uncomment System.out.println("After update..."); // @2 commentout - // @2 uncomment System.out.println("abcde..."); - } - - public void start() { - for (int i=0; i < 3; i++) { - doSomething(); // @1 breakpoint here line 16 - System.out.println("field1 = " + field1); - System.out.println("field2 = " + field2); - } - // Redefinex myx = new Redefinex(); - // for (int i = 0; i < 5; i++) { - // myx.methodx1(); // line 22 - // System.out.println("fieldx1 = " + myx.fieldx1); - // System.out.println("fieldx2 = " + myx.fieldx2); - // } - } - - public static void main(String[] args) { - $1 xxx = new $1(); - xxx.field1 = "field1"; - xxx.field2 = "field2"; - xxx.start(); - } -} - -class Redefinex { - public String fieldx1; - public String fieldx2; - - Redefinex() { - fieldx1 = "fieldx1"; - fieldx2 = "fieldx2"; - } - - public void methodx1() { - System.out.println("redefinex 1"); - //System.out.println("redefinex 2"); - //System.out.println("redefinex 3"); - } - -} - - /********* -Steps to reproduce this problem: - a. add line breakpoint in start() - b. debug - c. when breakpoint is hit, type continue. You should see output -"Before update..." - d. change "Before update" to "After update" - e. redefine, and set line breakpoint (see step a) - f. type continue. You should see output "After update" - g. change "After update" to "abcde" - h. redefine, and set line breakpoint (see step a) - i. type continue. The output is shown as "After update" - - j. to see "abcde" output, users will have to pop the stack, and -re-execute method start(). - ************/ -EOF -} - -# This is called to feed cmds to jdb. -dojdbCmds() -{ - setBkpts @1 - runToBkpt @1 - contToBkpt - redefineClass @1 - setBkpts @1 - contToBkpt - redefineClass @2 - 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 "Internal exception:" -debuggeeFailIfNotPresent "abcde" -pass diff --git a/test/jdk/com/sun/jdi/RedefinePop.java b/test/jdk/com/sun/jdi/RedefinePop.java new file mode 100644 index 00000000000..c3aca3ae974 --- /dev/null +++ b/test/jdk/com/sun/jdi/RedefinePop.java @@ -0,0 +1,91 @@ +/* + * 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 4622663 + * @summary redefine and pop top frame from jdb gets assertion failure + * @comment converted from test/jdk/com/sun/jdi/RedefinePop.sh + * + * @library /test/lib + * @compile -g RedefinePop.java + * @run main/othervm RedefinePop + */ + +/* + * The failure occurs with debug java when the pop deletes the + * line that called the method which is being popped. + */ + +/* + * assert(index $1.java.1 - -public class $1 { - static public void main(String[] args) { - $1 mine = new $1(); - mine.a1(44); // @1 delete the call that we are in when the pop occurs - mine.a4(); - } - - public void a1(int p1) { - System.out.println("a1: @1 breakpoint here"); - } - - public void a4() { - System.out.println("a4: The next line should not say Ni!"); - System.out.println("a4: Ni!"); // @1 delete - } -} -EOF -} - -# This is called to feed cmds to jdb. -dojdbCmds() -{ - setBkpts @1 - runToBkpt @1 - redefineClass @1 - cmd pop - 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 "Internal exception:" -pass diff --git a/test/jdk/com/sun/jdi/RedefineStep.java b/test/jdk/com/sun/jdi/RedefineStep.java new file mode 100644 index 00000000000..def5a30ef3a --- /dev/null +++ b/test/jdk/com/sun/jdi/RedefineStep.java @@ -0,0 +1,82 @@ +/* + * 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 4689395 + * @summary "step over" after a class is redefined acts like "step out" + * @comment converted from test/jdk/com/sun/jdi/RedefineStep.sh + * + * @library /test/lib + * @compile -g RedefineStep.java + * @run main/othervm RedefineStep + */ + +import jdk.test.lib.process.OutputAnalyzer; +import lib.jdb.JdbCommand; +import lib.jdb.JdbTest; + +class RedefineStepTarg { + static int counter; + static public void main(String[] args) { + RedefineStepTarg mine = new RedefineStepTarg(); + mine.a1(10); + System.out.println("done"); // should not see this + } + + public void a1(int p1) { + System.out.println("jj0"); // @1 breakpoint line 10 + a2(); + System.out.println("jj3"); // @1 delete + } + public void a2() { + System.out.println("a2"); + } +} + +public class RedefineStep extends JdbTest { + + public static void main(String argv[]) { + new RedefineStep().run(); + } + + private RedefineStep() { + super(RedefineStepTarg.class.getName(), "RedefineStep.java"); + } + + @Override + protected void runCases() { + setBreakpoints(1); + jdb.command(JdbCommand.run()); + redefineClass(1, "-g"); + + jdb.command(JdbCommand.next()); + jdb.command(JdbCommand.next()); + jdb.command(JdbCommand.next()); + jdb.command(JdbCommand.next()); + jdb.command(JdbCommand.next()); + + new OutputAnalyzer(getJdbOutput()) + .shouldNotContain("should not see this"); + } +} diff --git a/test/jdk/com/sun/jdi/RedefineStep.sh b/test/jdk/com/sun/jdi/RedefineStep.sh deleted file mode 100644 index 0f457f10681..00000000000 --- a/test/jdk/com/sun/jdi/RedefineStep.sh +++ /dev/null @@ -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 4689395 -# @summary "step over" after a class is redefined acts like "step out" -# @author Jim Holmlund -# @key intermittent -# @run shell RedefineStep.sh -# - -#pkg=untitled7 -classname=gus1 -compileOptions=-g -#java=java_g - -# Uncomment this to see the JDI trace -#jdbOptions=-dbgtrace - -createJavaFile() -{ - cat < $1.java.1 - -public class $1 { - static int counter; - static public void main(String[] args) { - $1 mine = new $1(); - mine.a1(10); - System.out.println("done"); // should not see this - } - - public void a1(int p1) { - System.out.println("jj0"); // @1 breakpoint line 10 - a2(); - System.out.println("jj3"); // @1 delete - } - public void a2() { - System.out.println("a2"); - } -} -EOF -} - -# This is called to feed cmds to jdb. -dojdbCmds() -{ - setBkpts @1 - runToBkpt @1 - redefineClass @1 - - cmd next - cmd next - cmd next - cmd next - cmd next -} - - -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 - -jdbFailIfPresent 'should not see this' -pass diff --git a/test/jdk/com/sun/jdi/RedefineTTYLineNumber.java b/test/jdk/com/sun/jdi/RedefineTTYLineNumber.java new file mode 100644 index 00000000000..b16aec046db --- /dev/null +++ b/test/jdk/com/sun/jdi/RedefineTTYLineNumber.java @@ -0,0 +1,110 @@ +/* + * 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 4660756 + * @summary TTY: Need to clear source cache after doing a redefine class + * @comment converted from test/jdk/com/sun/jdi/RedefineTTYLineNumber.sh + * + * @library /test/lib + * @compile -g RedefineTTYLineNumber.java + * @run main/othervm RedefineTTYLineNumber + */ + +import jdk.test.lib.Asserts; +import jdk.test.lib.process.OutputAnalyzer; +import lib.jdb.JdbCommand; +import lib.jdb.JdbTest; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +class RedefineTTYLineNumberTarg { + + public void B() { + System.out.println("in B: @1 delete"); // delete 1 line before A method + } + + public void A() { + System.out.println("expected statement printed by jdb"); + } + + public static void main(String[] args) { + RedefineTTYLineNumberTarg untitled41 = new RedefineTTYLineNumberTarg(); + untitled41.A(); + System.out.println("done"); + } +} + +public class RedefineTTYLineNumber extends JdbTest { + + public static void main(String argv[]) { + new RedefineTTYLineNumber().run(); + } + + private RedefineTTYLineNumber() { + super(DEBUGGEE_CLASS, SOURCE_FILE); + } + + private final static String DEBUGGEE_CLASS = RedefineTTYLineNumberTarg.class.getName(); + private final static String SOURCE_FILE = "RedefineTTYLineNumber.java"; + + // parses line number from the jdb "Breakpoint hit" message + private static int parseLineNum(String s) { + // Breakpoint hit: "thread=main", RedefineTTYLineNumberTarg.A(), line=49 bci=0 + // 49 System.out.println("expected statement printed by jdb"); + Matcher m = Pattern.compile("\\bline=(\\d+)\\b").matcher(s); + if (!m.find()) { + throw new RuntimeException("could not parse line number"); + } + return Integer.parseInt(m.group(1)); + } + + private void verifyBPSource(int n, String reply) { + if (!reply.contains("expected statement printed by jdb")) { + throw new RuntimeException("Breakpoint source (" + n + ") is not correct"); + } + } + + @Override + protected void runCases() { + jdb.command(JdbCommand.stopIn(DEBUGGEE_CLASS, "A")); + String bp1Reply = execCommand(JdbCommand.run()).getStdout(); + int bp1Line = parseLineNum(bp1Reply); + redefineClass(1, "-g"); + jdb.command(JdbCommand.pop()); + jdb.command(JdbCommand.stopIn(DEBUGGEE_CLASS, "A")); + String bp2Reply = execCommand(JdbCommand.cont()).getStdout(); + int bp2Line = parseLineNum(bp2Reply); + + new OutputAnalyzer(getDebuggeeOutput()) + .shouldNotContain("Internal exception:"); + // 1 line is deleted before RedefineTTYLineNumberTarg.A(), + // so bp2Line should be equals bp1Line-1 + Asserts.assertEquals(bp2Line, bp1Line - 1, "BP line numbers"); + verifyBPSource(1, bp1Reply); + // uncomment the following line to reproduce JDK-8210927 + //verifyBPSource(2, bp2Reply); + } +} diff --git a/test/jdk/com/sun/jdi/RedefineTTYLineNumber.sh b/test/jdk/com/sun/jdi/RedefineTTYLineNumber.sh deleted file mode 100644 index ba0c658db4d..00000000000 --- a/test/jdk/com/sun/jdi/RedefineTTYLineNumber.sh +++ /dev/null @@ -1,100 +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 4660756 -# @summary TTY: Need to clear source cache after doing a redefine class -# @author Jim Holmlund -# @key intermittent -# @run shell/timeout=240 RedefineTTYLineNumber.sh - -#set -x -# These are variables that can be set to control execution - -#pkg=untitled7 -#classname=Untitled3 -compileOptions=-g -#java=java_g - -createJavaFile() -{ - cat < $1.java.1 - -public class $1 { - - public void B() { - System.out.println("in B"); - System.out.println("in B: @1 delete"); - } - - // line number sensitive!!! Next line must be line 10. - public void A() { - System.out.println("in A, about to call B"); // 11 before, 10 afterward - System.out.println("out from B"); - } - - public static void main(String[] args) { - $1 untitled41 = new $1(); - untitled41.A(); - System.out.println("done"); - } -} -EOF -} - -# This is called to feed cmds to jdb. -dojdbCmds() -{ - cmd stop in shtest.A - runToBkpt - #jdbFailIfNotPresent "System\.out\.println" 3 - redefineClass @1 - cmd pop - cmd stop in shtest.A - contToBkpt - #jdbFailIfNotPresent "System\.out\.println" 3 -} - - -mysetup() -{ - if [ -z "$TESTSRC" ] ; then - TESTSRC=. - fi - - if [ -r $TESTSRC/ShellScaffold.sh ] ; then - . $TESTSRC/ShellScaffold.sh - elif [ -r $TESTSRC/../ShellScaffold.sh ] ; then - . $TESTSRC/../ShellScaffold.sh - fi -} - -# 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 diff --git a/test/jdk/com/sun/jdi/StringConvertTest.java b/test/jdk/com/sun/jdi/StringConvertTest.java new file mode 100644 index 00000000000..7a8eda7ee35 --- /dev/null +++ b/test/jdk/com/sun/jdi/StringConvertTest.java @@ -0,0 +1,198 @@ +/* + * 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 4511950 4843082 + * @summary 1. jdb's expression evaluation doesn't perform string conversion properly + * 2. TTY: run on expression evaluation + * @comment converted from test/jdk/com/sun/jdi/StringConvertTest.sh + * + * @library /test/lib + * @compile -g StringConvertTest.java + * @run main/othervm StringConvertTest + */ + +import jdk.test.lib.process.OutputAnalyzer; +import lib.jdb.JdbCommand; +import lib.jdb.JdbTest; + +class StringConvertTarg { + String me; + static JJ1 x1; + static JJ2 x2; + static JJ2[] x3 = new JJ2[2]; + static String x4 = "abc"; + static int ii = 89; + static String grower = "grower"; + static StringBuffer sbGrower = new StringBuffer("sbGrower"); + int ivar = 89; + StringConvertTarg(String xx) { + me = xx; + } + + static String fred() { + return "a static method"; + } + + void gus() { + int gusLoc = 1; + StringBuffer sbTim = new StringBuffer("tim"); + int kk = 1; //@1 breakpoint + } + + static String growit(String extra) { + grower += extra; + return grower; + } + + static String sbGrowit(String extra) { + sbGrower.append(extra); + return sbGrower.toString(); + } + + public static void main(String[] args) { + x1 = new JJ1("first JJ1"); + x2 = new JJ2("first JJ2"); + x3[0] = new JJ2("array0"); + x3[1] = new JJ2("array1"); + StringConvertTarg loc1 = new StringConvertTarg("first me"); + + // These just show what output should look like + System.out.println("x1 = " + x1); + System.out.println("x2 = " + x2); + System.out.println("x3.toString = " + x3.toString()); + System.out.println("x4.toString = " + x4.toString()); + + // Dont want to call growit since it would change + // the value. + + System.out.println("loc1 = " + loc1); + System.out.println("-" + loc1); + loc1.gus(); + } + + // This does not have a toString method + static class JJ1 { + String me; + + JJ1(String whoAmI) { + me = whoAmI; + } + } + + // This has a toString method + static class JJ2 { + String me; + + JJ2(String whoAmI) { + me = whoAmI; + } + public String toString() { + return me; + } + + public int meth1() { + return 89; + } + } +} + +public class StringConvertTest extends JdbTest { + public static void main(String argv[]) { + new StringConvertTest().run(); + } + + private StringConvertTest() { + super(DEBUGGEE_CLASS, SOURCE_FILE); + } + + private static final String DEBUGGEE_CLASS = StringConvertTarg.class.getName(); + private static final String SOURCE_FILE = "StringConvertTest.java"; + + @Override + protected void runCases() { + setBreakpoints(1); + // Run to breakpoint #1 + jdb.command(JdbCommand.run()); + + // Each print without the 'toString()' should print the + // same thing as the following print with the toString(). + // The "print 1"s are just spacers + jdb.command(JdbCommand.print("StringConvertTarg.x1")); + jdb.command(JdbCommand.print("StringConvertTarg.x1.toString()")); + jdb.command(JdbCommand.print("1")); + + jdb.command(JdbCommand.print("StringConvertTarg.x2")); + jdb.command(JdbCommand.print("StringConvertTarg.x2.toString()")); + jdb.command(JdbCommand.print("1")); + + // arrays is a special case. + // StringConvertTarg prints: + // x3.toString = [LStringConvertTarg$JJ2;@61443d8f + // jdb "print ((Object)StringConvertTarg.x3).toString()" prints: + // com.sun.tools.example.debug.expr.ParseException: + // No instance field or method with the name toString in StringConvertTarg$JJ2[] + // ((Object)StringConvertTarg.x3).toString() = null + // jdb "print (Object)(StringConvertTarg.x3)" prints: + // (Object)(StringConvertTarg.x3) = instance of StringConvertTarg$JJ2[2] (id=624) + /* + jdb.command(JdbCommand.print("(Object)(StringConvertTarg.x3)")); + jdb.command(JdbCommand.print("((Object)StringConvertTarg.x3).toString()")); + jdb.command(JdbCommand.print("1")); + */ + + jdb.command(JdbCommand.print("StringConvertTarg.x4")); + jdb.command(JdbCommand.print("StringConvertTarg.x4.toString()")); + jdb.command(JdbCommand.print("1")); + + // Make sure jdb doesn't call a method multiple times. + jdb.command(JdbCommand.print("StringConvertTarg.growit(\"xyz\")")); + jdb.command(JdbCommand.eval("StringConvertTarg.sbGrower.append(\"xyz\")")); + jdb.command(JdbCommand.print("1")); + + jdb.command(JdbCommand.eval("sbTim.toString()")); + jdb.command(JdbCommand.print("1")); + + jdb.command(JdbCommand.print("this")); + jdb.command(JdbCommand.print("this.toString()")); + jdb.command(JdbCommand.print("1")); + + // A possible bug is that this ends up with multiple "s + jdb.command(JdbCommand.print("\"--\"StringConvertTarg.x1")); + jdb.command(JdbCommand.print("1")); + + // This too + jdb.command(JdbCommand.print("StringConvertTarg.x4 + 2")); + jdb.command(JdbCommand.print("1")); + + jdb.command(JdbCommand.print("this.ivar")); + jdb.command(JdbCommand.print("gusLoc")); + jdb.command(JdbCommand.print("1")); + + new OutputAnalyzer(jdb.getJdbOutput()) + .shouldNotContain("\"\"") + .shouldNotContain("instance of") + .shouldNotContain("xyzxyz"); + } +} diff --git a/test/jdk/com/sun/jdi/StringConvertTest.sh b/test/jdk/com/sun/jdi/StringConvertTest.sh deleted file mode 100644 index 50924cd7f7f..00000000000 --- a/test/jdk/com/sun/jdi/StringConvertTest.sh +++ /dev/null @@ -1,211 +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 4511950 4843082 -# @summary 1. jdb's expression evaluation doesn't perform string conversion properly -# 2. TTY: run on expression evaluation -# @author jim/suvasis mukherjee -# -# @key intermittent -# @run shell StringConvertTest.sh - -# Run this script to see the bug. See comments at the end -# of the .java file for info on what the bug looks like. - -# These are variables that can be set to control execution - -#pkg=untitled7 -classname=StringConvertTest -compileOptions=-g -#java=java_g -#mode=-Xcomp - -#jdbOptions=-dbgtrace -createJavaFile() -{ - cat < $1.java.1 - -class $classname { - String me; - static JJ1 x1; - static JJ2 x2; - static JJ2[] x3 = new JJ2[2]; - static String x4 = "abc"; - static int ii = 89; - static String grower = "grower"; - static StringBuffer sbGrower = new StringBuffer("sbGrower"); - int ivar = 89; - $classname(String xx) { - me = xx; - } - - static String fred() { - return "a static method"; - } - - void gus() { - int gusLoc = 1; - StringBuffer sbTim = new StringBuffer("tim"); - int kk = 1; //@1 breakpoint - } - - static String growit(String extra) { - grower += extra; - return grower; - } - - static String sbGrowit(String extra) { - sbGrower.append(extra); - return sbGrower.toString(); - } - - public static void main(String[] args) { - x1 = new JJ1("first JJ1"); - x2 = new JJ2("first JJ2"); - x3[0] = new JJ2("array0"); - x3[1] = new JJ2("array1"); - $classname loc1 = new $classname("first me"); - - // These just show what output should look like - System.out.println("x1 = " + x1); - System.out.println("x2 = " + x2); - System.out.println("x3.toString = " + x3.toString()); - System.out.println("x4.toString = " + x4.toString()); - - // Dont want to call growit since it would change - // the value. - - System.out.println("loc1 = " + loc1); - System.out.println("-" + loc1); - loc1.gus(); - } - - // This does not have a toString method - static class JJ1 { - String me; - - JJ1(String whoAmI) { - me = whoAmI; - } - } - - // This has a toString method - static class JJ2 { - String me; - - JJ2(String whoAmI) { - me = whoAmI; - } - public String toString() { - return me; - } - - public int meth1() { - return 89; - } - } -} - -EOF -} - -# This is called to feed cmds to jdb. -dojdbCmds() -{ - setBkpts @1 - runToBkpt @1 - - # Each print without the 'toString()' should print the - # same thing as the following print with the toString(). - # The print 1s are just spacers - - cmd print $classname.x1 - cmd print "$classname.x1.toString()" - cmd print 1 - - cmd print $classname.x2 - cmd print "$classname.x2.toString()" - cmd print 1 - - # An unreported bug: this isn't handled correctly. - # If we uncomment this line, we will get an 'instance of...' line - # which will cause the test to fail. - #cmd print "(Object)($classname.x3)" - cmd print "((Object)$classname.x3).toString()" - cmd print 1 - - cmd print $classname.x4 - cmd print "$classname.x4.toString()" - cmd print 1 - - # Make sure jdb doesn't call a method multiple times. - cmd print "$classname.growit(\"xyz\")" - cmd eval "$classname.sbGrower.append(\"xyz\")" - cmd print 1 - - cmd eval "sbTim.toString()" - cmd print 1 - - cmd print this - cmd print "this.toString()" - cmd print 1 - - # A possible bug is that this ends up with multiple "s - cmd print '"--" + '$classname.x1 - cmd print 1 - - # This too - cmd print "$classname.x4 + 2" - cmd print 1 - - cmd print "this.ivar" - cmd print gusLoc - cmd print 1 -} - -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 -jdbFailIfPresent '""' -jdbFailIfPresent 'instance of' -jdbFailIfPresent 'xyzxyz' -pass diff --git a/test/jdk/com/sun/jdi/WatchFramePop.java b/test/jdk/com/sun/jdi/WatchFramePop.java new file mode 100644 index 00000000000..b9a4d1c6a25 --- /dev/null +++ b/test/jdk/com/sun/jdi/WatchFramePop.java @@ -0,0 +1,93 @@ +/* + * 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 4546478 + * @summary Enabling a watchpoint can kill following NotifyFramePops + * @comment converted from test/jdk/com/sun/jdi/WatchFramePop.sh + * + * @library /test/lib + * @run main/othervm WatchFramePop + */ + +import jdk.test.lib.process.OutputAnalyzer; +import lib.jdb.JdbCommand; +import lib.jdb.JdbTest; + +class WatchFramePopTarg { + int watchMe; + static public void main(String[] args) { + System.out.println("In Main"); + WatchFramePopTarg mine = new WatchFramePopTarg(); + mine.a1(); + System.out.println("Test completed"); + } + + public void a1() { + a2(); // @1 breakpoint. We'll do a watch of watchMe here + } + + public void a2() { + System.out.println("in a2"); + a3(); + } // line 18 + + public void a3() { + System.out.println("in a3"); // After the watch, we'll run to here, line 21 + a4(); // We'll do a 'next' to here. The failure is that this + } // runs to completion, or asserts with java_g + + public void a4() { + System.out.println("in a4"); + } + +} + +public class WatchFramePop extends JdbTest { + public static void main(String argv[]) { + new WatchFramePop().run(); + } + + private WatchFramePop() { + super(DEBUGGEE_CLASS, SOURCE_FILE); + } + + private static final String DEBUGGEE_CLASS = WatchFramePopTarg.class.getName(); + private static final String SOURCE_FILE = "WatchFramePop.java"; + + @Override + protected void runCases() { + setBreakpoints(1); + jdb.command(JdbCommand.run()); + jdb.command(JdbCommand.watch(DEBUGGEE_CLASS, "watchMe")); + jdb.command(JdbCommand.stopIn(DEBUGGEE_CLASS, "a3")); + jdb.command(JdbCommand.cont()); // stops at the bkpt + jdb.command(JdbCommand.next()); // The bug is that this next runs to completion + // In which case, so does jdb + // so we never get here. + + new OutputAnalyzer(jdb.getJdbOutput()) + .shouldNotContain("The application exited"); + } +} diff --git a/test/jdk/com/sun/jdi/WatchFramePop.sh b/test/jdk/com/sun/jdi/WatchFramePop.sh deleted file mode 100644 index 870f32f0a3c..00000000000 --- a/test/jdk/com/sun/jdi/WatchFramePop.sh +++ /dev/null @@ -1,110 +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 4546478 -# @summary Enabling a watchpoint can kill following NotifyFramePops -# @author Jim Holmlund -# -# @run shell WatchFramePop.sh - -# These are variables that can be set to control execution - -#pkg=untitled7 -#classname=Untitled3 -#compileOptions=-g -#java="java_g" - -createJavaFile() -{ - cat < $1.java.1 - -public class $1 { - int watchMe; - static public void main(String[] args) { - System.out.println("In Main"); - $1 mine = new $1(); - mine.a1(); - System.out.println("Test completed"); - } - - public void a1() { - a2(); // @1 breakpoint. We'll do a watch of watchMe here - } - - public void a2() { - System.out.println("in a2"); - a3(); - } // line 18 - - public void a3() { - System.out.println("in a3"); // After the watch, we'll run to here, line 21 - a4(); // We'll do a 'next' to here. The failure is that this - } // runs to completion, or asserts with java_g - - - public void a4() { - System.out.println("in a4"); - } - -} -EOF -} - -# drive jdb by sending cmds to it and examining its output -dojdbCmds() -{ - setBkpts @1 - runToBkpt @1 - cmd watch shtest.watchMe - cmd stop in shtest.a3 # bkpt at line 17 - contToBkpt # stops at the bkpt at - cmd next # The bug is that this next runs to completion - # In which case, so does jdb - # so we never get here. -} - - -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 -jdbFailIfPresent 'The application exited' -pass