6667089: 3/3 multiple redefinitions of a class break reflection

Add regression test for multiple redefinitions of a class break reflection.

Reviewed-by: sspitsyn
This commit is contained in:
Daniel D. Daugherty 2008-03-24 17:20:54 -07:00
parent a6edacebb8
commit afd0a54dd0
6 changed files with 324 additions and 0 deletions

@ -0,0 +1,82 @@
#
# Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
# @test
# @bug 6667089
# @summary Reflexive invocation of newly added methods broken.
# @author Daniel D. Daugherty
#
# @run shell MakeJAR3.sh RedefineMethodAddInvokeAgent 'Can-Redefine-Classes: true'
# @run build RedefineMethodAddInvokeApp
# @run shell RedefineMethodAddInvoke.sh
#
if [ "${TESTJAVA}" = "" ]
then
echo "TESTJAVA not set. Test cannot execute. Failed."
exit 1
fi
if [ "${TESTSRC}" = "" ]
then
echo "TESTSRC not set. Test cannot execute. Failed."
exit 1
fi
if [ "${TESTCLASSES}" = "" ]
then
echo "TESTCLASSES not set. Test cannot execute. Failed."
exit 1
fi
JAVAC="${TESTJAVA}"/bin/javac
JAVA="${TESTJAVA}"/bin/java
cp "${TESTSRC}"/RedefineMethodAddInvokeTarget_1.java \
RedefineMethodAddInvokeTarget.java
"${JAVAC}" -d . RedefineMethodAddInvokeTarget.java
mv RedefineMethodAddInvokeTarget.java RedefineMethodAddInvokeTarget_1.java
mv RedefineMethodAddInvokeTarget.class RedefineMethodAddInvokeTarget_1.class
cp "${TESTSRC}"/RedefineMethodAddInvokeTarget_2.java \
RedefineMethodAddInvokeTarget.java
"${JAVAC}" -d . RedefineMethodAddInvokeTarget.java
mv RedefineMethodAddInvokeTarget.java RedefineMethodAddInvokeTarget_2.java
mv RedefineMethodAddInvokeTarget.class RedefineMethodAddInvokeTarget_2.class
"${JAVA}" ${TESTVMOPTS} -javaagent:RedefineMethodAddInvokeAgent.jar \
-classpath "${TESTCLASSES}" RedefineMethodAddInvokeApp > output.log 2>&1
cat output.log
MESG="Exception"
grep "$MESG" output.log
result=$?
if [ "$result" = 0 ]; then
echo "FAIL: found '$MESG' in the test output"
result=1
else
echo "PASS: did NOT find '$MESG' in the test output"
result=0
fi
exit $result

@ -0,0 +1,43 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import java.lang.instrument.Instrumentation;
public class RedefineMethodAddInvokeAgent {
private static Instrumentation instrumentation;
private RedefineMethodAddInvokeAgent() {
}
public static void premain(String agentArgs, Instrumentation inst) {
System.out.println("Hello from RedefineMethodAddInvokeAgent!");
System.out.println("isRedefineClassesSupported()=" +
inst.isRedefineClassesSupported());
instrumentation = inst;
}
public static Instrumentation getInstrumentation() {
return instrumentation;
}
}

@ -0,0 +1,70 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import java.io.*;
import java.lang.instrument.*;
public class RedefineMethodAddInvokeApp {
public static void main(String args[]) throws Exception {
System.out.println("Hello from RedefineMethodAddInvokeApp!");
new RedefineMethodAddInvokeApp().doTest();
System.exit(0);
}
private void doTest() throws Exception {
RedefineMethodAddInvokeTarget target =
new RedefineMethodAddInvokeTarget();
System.out.println("RedefineMethodAddInvokeApp: invoking myMethod()");
target.test(0); // invoke the original myMethod()
// add myMethod1()
do_redefine(1);
System.out.println("RedefineMethodAddInvokeApp: invoking myMethod1()");
target.test(1); // invoke myMethod1()
// add myMethod2()
do_redefine(2);
System.out.println("RedefineMethodAddInvokeApp: invoking myMethod2()");
target.test(2); // invoke myMethod2()
}
private static void do_redefine(int counter) throws Exception {
File f = new File("RedefineMethodAddInvokeTarget_" + counter +
".class");
System.out.println("Reading test class from " + f);
InputStream redefineStream = new FileInputStream(f);
byte[] redefineBuffer = NamedBuffer.loadBufferFromStream(redefineStream);
ClassDefinition redefineParamBlock = new ClassDefinition(
RedefineMethodAddInvokeTarget.class, redefineBuffer);
RedefineMethodAddInvokeAgent.getInstrumentation().redefineClasses(
new ClassDefinition[] {redefineParamBlock});
}
}

@ -0,0 +1,37 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import java.lang.reflect.Method;
public class RedefineMethodAddInvokeTarget {
public void test(int counter) throws Exception {
Method method = getClass().getDeclaredMethod("myMethod" +
(counter == 0 ? "" : counter));
method.setAccessible(true);
method.invoke(this);
}
public void myMethod() {
System.out.println("Hello from the original myMethod()!");
}
}

@ -0,0 +1,43 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import java.lang.reflect.Method;
public class RedefineMethodAddInvokeTarget {
public void test(int counter) throws Exception {
Method method = getClass().getDeclaredMethod("myMethod" +
(counter == 0 ? "" : counter));
method.setAccessible(true);
method.invoke(this);
}
public void myMethod() {
System.out.println("Hello from the non-EMCP myMethod()!");
}
private final void myMethod1() {
System.out.println("Hello from myMethod1()!");
System.out.println("Calling myMethod() from myMethod1():");
myMethod();
}
}

@ -0,0 +1,49 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import java.lang.reflect.Method;
public class RedefineMethodAddInvokeTarget {
public void test(int counter) throws Exception {
Method method = getClass().getDeclaredMethod("myMethod" +
(counter == 0 ? "" : counter));
method.setAccessible(true);
method.invoke(this);
}
public void myMethod() {
System.out.println("Hello from the non-EMCP again myMethod()!");
}
private final void myMethod1() {
System.out.println("Hello from myMethod1()!");
System.out.println("Calling myMethod() from myMethod1():");
myMethod();
}
private final void myMethod2() {
System.out.println("Hello from myMethod2()!");
System.out.println("Calling myMethod1() from myMethod2():");
myMethod1();
}
}