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 # @author Daniel D. Daugherty
  33 #
  34 # @run shell RedefineAbstractClass.sh
  35 
  36 compileOptions=-g
  37 
  38 # Uncomment this to see the JDI trace
  39 #jdbOptions=-dbgtrace
  40 
  41 createJavaFile()
  42 {
  43     cat <<EOF > $1.java.1
  44 
  45 public class $1 {
  46   public static void main(String[] args) {
  47     System.out.println("This is RedefineAbstractClass");
  48 
  49     MyConcreteClass foo = new MyConcreteClass();
  50     // do the work once before redefine
  51     foo.doWork();
  52 
  53     System.out.println("stop here for redefine");  // @1 breakpoint
  54 
  55     // do the work again after redefine
  56     foo.doWork();
  57 
  58     System.out.println("stop here to check results");  // @2 breakpoint
  59   }
  60 }
  61 
  62 interface MyInterface1 {
  63   public boolean checkFunc();
  64   public boolean isMyInterface1();
  65 }
  66 
  67 interface MyInterface2 {
  68   public boolean checkFunc();
  69   public boolean isMyInterface2();
  70 }
  71 
  72 abstract class MyAbstractClass implements MyInterface1, MyInterface2 {
  73   static int counter = 0;
  74   public boolean checkFunc() {
  75     counter++;
  76     System.out.println("MyAbstractClass.checkFunc() called.");
  77     // @1 uncomment System.out.println("This is call " + counter + " to checkFunc");
  78     return true;
  79   }
  80   public boolean isMyInterface1() {
  81     System.out.println("MyAbstractClass.isMyInterface1() called.");
  82     return true;
  83   }
  84   public boolean isMyInterface2() {
  85     System.out.println("MyAbstractClass.isMyInterface2() called.");
  86     return true;
  87   }
  88 }
  89 
  90 class MyConcreteClass extends MyAbstractClass {
  91   public void doWork() {
  92     // checkFunc() is called via invokevirtual here; MyConcreteClass
  93     // inherits via MyAbstractClass
  94     System.out.println("In doWork() calling checkFunc(): " + checkFunc());
  95 
  96     MyInterface1 if1 = (MyInterface1) this;
  97     // checkFunc() is called via invokeinterface here; this call will
  98     // use the first itable entry
  99     System.out.println("In doWork() calling if1.checkFunc(): " + if1.checkFunc());
 100 
 101     MyInterface2 if2 = (MyInterface2) this;
 102     // checkFunc() is called via invokeinterface here; this call will
 103     // use the second itable entry
 104     System.out.println("In doWork() calling if2.checkFunc(): " + if2.checkFunc());
 105   }
 106 }
 107 
 108 EOF
 109 }
 110 
 111 # This is called to feed cmds to jdb.
 112 dojdbCmds()
 113 {
 114     setBkpts @1
 115     setBkpts @2
 116     runToBkpt @1
 117     # modified version of redefineClass function
 118     vers=2
 119     abs_class=MyAbstractClass
 120     cmd redefine $pkgDot$abs_class $tmpFileDir/vers$vers/$abs_class.class
 121     cp $tmpFileDir/$classname.java.$vers \
 122         $tmpFileDir/$classname.java
 123     # end modified version of redefineClass function
 124 
 125     # this will continue to the second breakpoint
 126     cmd cont
 127 }
 128 
 129 
 130 mysetup()
 131 {
 132     if [ -z "$TESTSRC" ] ; then
 133         TESTSRC=.
 134     fi
 135 
 136     for ii in . $TESTSRC $TESTSRC/.. ; do
 137         if [ -r "$ii/ShellScaffold.sh" ] ; then
 138             . $ii/ShellScaffold.sh 
 139             break
 140         fi
 141     done
 142 }
 143 
 144 # You could replace this next line with the contents
 145 # of ShellScaffold.sh and this script will run just the same.
 146 mysetup
 147 
 148 runit
 149 
 150 debuggeeFailIfNotPresent 'This is call 4 to checkFunc'
 151 debuggeeFailIfNotPresent 'This is call 5 to checkFunc'
 152 debuggeeFailIfNotPresent 'This is call 6 to checkFunc'
 153 pass