1 #!/bin/sh
   2 
   3 #
   4 # Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
   5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6 #
   7 # This code is free software; you can redistribute it and/or modify it
   8 # under the terms of the GNU General Public License version 2 only, as
   9 # published by the Free Software Foundation.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 
  27 #  @test
  28 #  @bug 6805864
  29 #  @summary Redefine an abstract class that is called via a concrete
  30 #    class and via two interface objects and verify that the right
  31 #    methods are called.
  32 #
  33 #  @run shell RedefineAbstractClass.sh
  34 
  35 compileOptions=-g
  36 
  37 # Uncomment this to see the JDI trace
  38 #jdbOptions=-dbgtrace
  39 
  40 createJavaFile()
  41 {
  42     cat <<EOF > $1.java.1
  43 
  44 public class $1 {
  45   public static void main(String[] args) {
  46     System.out.println("This is RedefineAbstractClass");
  47 
  48     MyConcreteClass foo = new MyConcreteClass();
  49     // do the work once before redefine
  50     foo.doWork();
  51 
  52     System.out.println("stop here for redefine");  // @1 breakpoint
  53 
  54     // do the work again after redefine
  55     foo.doWork();
  56 
  57     System.out.println("stop here to check results");  // @2 breakpoint
  58   }
  59 }
  60 
  61 interface MyInterface1 {
  62   public boolean checkFunc();
  63   public boolean isMyInterface1();
  64 }
  65 
  66 interface MyInterface2 {
  67   public boolean checkFunc();
  68   public boolean isMyInterface2();
  69 }
  70 
  71 abstract class MyAbstractClass implements MyInterface1, MyInterface2 {
  72   static int counter = 0;
  73   public boolean checkFunc() {
  74     counter++;
  75     System.out.println("MyAbstractClass.checkFunc() called.");
  76     // @1 uncomment System.out.println("This is call " + counter + " to checkFunc");
  77     return true;
  78   }
  79   public boolean isMyInterface1() {
  80     System.out.println("MyAbstractClass.isMyInterface1() called.");
  81     return true;
  82   }
  83   public boolean isMyInterface2() {
  84     System.out.println("MyAbstractClass.isMyInterface2() called.");
  85     return true;
  86   }
  87 }
  88 
  89 class MyConcreteClass extends MyAbstractClass {
  90   public void doWork() {
  91     // checkFunc() is called via invokevirtual here; MyConcreteClass
  92     // inherits via MyAbstractClass
  93     System.out.println("In doWork() calling checkFunc(): " + checkFunc());
  94 
  95     MyInterface1 if1 = (MyInterface1) this;
  96     // checkFunc() is called via invokeinterface here; this call will
  97     // use the first itable entry
  98     System.out.println("In doWork() calling if1.checkFunc(): " + if1.checkFunc());
  99 
 100     MyInterface2 if2 = (MyInterface2) this;
 101     // checkFunc() is called via invokeinterface here; this call will
 102     // use the second itable entry
 103     System.out.println("In doWork() calling if2.checkFunc(): " + if2.checkFunc());
 104   }
 105 }
 106 
 107 EOF
 108 }
 109 
 110 # This is called to feed cmds to jdb.
 111 dojdbCmds()
 112 {
 113     setBkpts @1
 114     setBkpts @2
 115     runToBkpt @1
 116     # modified version of redefineClass function
 117     vers=2
 118     abs_class=MyAbstractClass
 119     cmd redefine $pkgDot$abs_class $tmpFileDir/vers$vers/$abs_class.class
 120     cp $tmpFileDir/$classname.java.$vers \
 121         $tmpFileDir/$classname.java
 122     # end modified version of redefineClass function
 123 
 124     # this will continue to the second breakpoint
 125     cmd cont
 126 }
 127 
 128 
 129 mysetup()
 130 {
 131     if [ -z "$TESTSRC" ] ; then
 132         TESTSRC=.
 133     fi
 134 
 135     for ii in . $TESTSRC $TESTSRC/.. ; do
 136         if [ -r "$ii/ShellScaffold.sh" ] ; then
 137             . $ii/ShellScaffold.sh 
 138             break
 139         fi
 140     done
 141 }
 142 
 143 # You could replace this next line with the contents
 144 # of ShellScaffold.sh and this script will run just the same.
 145 mysetup
 146 
 147 runit
 148 
 149 debuggeeFailIfNotPresent 'This is call 4 to checkFunc'
 150 debuggeeFailIfNotPresent 'This is call 5 to checkFunc'
 151 debuggeeFailIfNotPresent 'This is call 6 to checkFunc'
 152 pass