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