1 # 2 # Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 # 5 # This code is free software; you can redistribute it and/or modify it 6 # under the terms of the GNU General Public License version 2 only, as 7 # published by the Free Software Foundation. 8 # 9 # This code is distributed in the hope that it will be useful, but WITHOUT 10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 # version 2 for more details (a copy is included in the LICENSE file that 13 # accompanied this code). 14 # 15 # You should have received a copy of the GNU General Public License version 16 # 2 along with this work; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 # 19 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 # or visit www.oracle.com if you need additional information or have any 21 # questions. 22 # 23 24 # @test 25 # @bug 7182152 26 # @summary Redefine a subclass that implements two interfaces and 27 # verify that the right methods are called. 28 # @author Daniel D. Daugherty 29 # 30 # @run shell MakeJAR3.sh RedefineSubclassWithTwoInterfacesAgent 'Can-Redefine-Classes: true' 31 # @run build RedefineSubclassWithTwoInterfacesApp 32 # @run shell RedefineSubclassWithTwoInterfaces.sh 33 # 34 35 if [ "${TESTJAVA}" = "" ] 36 then 37 echo "TESTJAVA not set. Test cannot execute. Failed." 38 exit 1 39 fi 40 41 if [ "${TESTSRC}" = "" ] 42 then 43 echo "TESTSRC not set. Test cannot execute. Failed." 44 exit 1 45 fi 46 47 if [ "${TESTCLASSES}" = "" ] 48 then 49 echo "TESTCLASSES not set. Test cannot execute. Failed." 50 exit 1 51 fi 52 53 JAVAC="${TESTJAVA}"/bin/javac 54 JAVA="${TESTJAVA}"/bin/java 55 56 echo "INFO: building the replacement classes." 57 58 cp "${TESTSRC}"/RedefineSubclassWithTwoInterfacesTarget_1.java \ 59 RedefineSubclassWithTwoInterfacesTarget.java 60 cp "${TESTSRC}"/RedefineSubclassWithTwoInterfacesImpl_1.java \ 61 RedefineSubclassWithTwoInterfacesImpl.java 62 "${JAVAC}" -cp "${TESTCLASSES}" -d . \ 63 RedefineSubclassWithTwoInterfacesTarget.java \ 64 RedefineSubclassWithTwoInterfacesImpl.java 65 status="$?" 66 if [ "$status" != 0 ]; then 67 echo "FAIL: compile of *_1.java files failed." 68 exit "$status" 69 fi 70 71 mv RedefineSubclassWithTwoInterfacesTarget.java \ 72 RedefineSubclassWithTwoInterfacesTarget_1.java 73 mv RedefineSubclassWithTwoInterfacesTarget.class \ 74 RedefineSubclassWithTwoInterfacesTarget_1.class 75 mv RedefineSubclassWithTwoInterfacesImpl.java \ 76 RedefineSubclassWithTwoInterfacesImpl_1.java 77 mv RedefineSubclassWithTwoInterfacesImpl.class \ 78 RedefineSubclassWithTwoInterfacesImpl_1.class 79 80 echo "INFO: launching RedefineSubclassWithTwoInterfacesApp" 81 82 # TraceRedefineClasses options: 83 # 84 # 0x00000001 | 1 - name each target class before loading, after 85 # loading and after redefinition is completed 86 # 0x00000002 | 2 - print info if parsing, linking or 87 # verification throws an exception 88 # 0x00000004 | 4 - print timer info for the VM operation 89 # 0x00001000 | 4096 - detect calls to obsolete methods 90 # 0x00002000 | 8192 - fail a guarantee() in addition to detection 91 # 0x00004000 | 16384 - detect old/obsolete methods in metadata 92 # 0x00100000 | 1048576 - impl details: vtable updates 93 # 0x00200000 | 2097152 - impl details: itable updates 94 # 95 # 1+2+4+4096+8192+16384+1048576+2097152 == 3174407 96 97 "${JAVA}" ${TESTVMOPTS} \ 98 -XX:TraceRedefineClasses=3174407 \ 99 -javaagent:RedefineSubclassWithTwoInterfacesAgent.jar \ 100 -classpath "${TESTCLASSES}" \ 101 RedefineSubclassWithTwoInterfacesApp > output.log 2>&1 102 status="$?" 103 104 echo "INFO: <begin output.log>" 105 cat output.log 106 echo "INFO: <end output.log>" 107 108 if [ "$status" != 0 ]; then 109 echo "FAIL: RedefineSubclassWithTwoInterfacesApp failed." 110 exit "$status" 111 fi 112 113 # When this bug manifests, RedefineClasses() will fail to update 114 # one of the itable entries to refer to the new method. The log 115 # will include the following line when the bug occurs: 116 # 117 # guarantee(false) failed: OLD and/or OBSOLETE method(s) found 118 # 119 # If this guarantee happens, the test should fail in the status 120 # check above, but just in case it doesn't, we check for "guarantee". 121 # 122 123 FAIL_MESG="guarantee" 124 grep "$FAIL_MESG" output.log 125 status=$? 126 if [ "$status" = 0 ]; then 127 echo "FAIL: found '$FAIL_MESG' in the test output." 128 result=1 129 else 130 echo "INFO: did NOT find '$FAIL_MESG' in the test output." 131 # be optimistic here 132 result=0 133 fi 134 135 PASS1_MESG="before any redefines" 136 cnt=`grep "$PASS1_MESG" output.log | grep 'version-0' | wc -l` 137 case "$cnt" in 138 2) 139 echo "INFO: found 2 version-0 '$PASS1_MESG' mesgs." 140 ;; 141 *) 142 echo "FAIL: did NOT find 2 version-0 '$PASS1_MESG' mesgs." 143 echo "INFO: grep '$PASS1_MESG' output:" 144 grep "$PASS1_MESG" output.log 145 result=1 146 esac 147 148 PASS2_MESG="after redefine" 149 cnt=`grep "$PASS2_MESG" output.log | grep 'version-1' | wc -l` 150 case "$cnt" in 151 2) 152 echo "INFO: found 2 version-1 '$PASS2_MESG' mesgs." 153 ;; 154 *) 155 echo "FAIL: did NOT find 2 version-1 '$PASS2_MESG' mesgs." 156 echo "INFO: grep '$PASS2_MESG' output:" 157 grep "$PASS2_MESG" output.log 158 result=1 159 esac 160 161 if [ "$result" = 0 ]; then 162 echo "PASS: test passed both positive and negative output checks." 163 fi 164 165 exit $result