提交 b8f37b32 编写于 作者: D dsamersoff

6904403: assert(f == k->has_finalizer(),"inconsistent has_finalizer") with debug VM

Summary: Don't assert if one of classes in hierarhy was redefined
Reviewed-by: coleenp, sspitsyn
上级 ccf745ed
......@@ -4421,9 +4421,15 @@ void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
Method* m = k->lookup_method(vmSymbols::finalize_method_name(),
vmSymbols::void_method_signature());
if (m != NULL && !m->is_empty_method()) {
f = true;
f = true;
}
// Spec doesn't prevent agent from redefinition of empty finalizer.
// Despite the fact that it's generally bad idea and redefined finalizer
// will not work as expected we shouldn't abort vm in this case
if (!k->has_redefined_this_or_super()) {
assert(f == k->has_finalizer(), "inconsistent has_finalizer");
}
assert(f == k->has_finalizer(), "inconsistent has_finalizer");
#endif
// Check if this klass supports the java.lang.Cloneable interface
......
......@@ -1572,6 +1572,21 @@ Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature, M
return NULL;
}
#ifdef ASSERT
// search through class hierarchy and return true if this class or
// one of the superclasses was redefined
bool InstanceKlass::has_redefined_this_or_super() const {
const InstanceKlass* klass = this;
while (klass != NULL) {
if (klass->has_been_redefined()) {
return true;
}
klass = InstanceKlass::cast(klass->super());
}
return false;
}
#endif
// lookup a method in the default methods list then in all transitive interfaces
// Do NOT return private or static methods
Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name,
......
......@@ -808,6 +808,11 @@ class InstanceKlass: public Klass {
bool implements_interface(Klass* k) const;
bool is_same_or_direct_interface(Klass* k) const;
#ifdef ASSERT
// check whether this class or one of its superclasses was redefined
bool has_redefined_this_or_super() const;
#endif
// Access to the implementor of an interface.
Klass* implementor() const
{
......@@ -865,8 +870,8 @@ class InstanceKlass: public Klass {
// Casting from Klass*
static InstanceKlass* cast(Klass* k) {
assert(k->is_klass(), "must be");
assert(k->oop_is_instance(), "cast to InstanceKlass");
assert(k == NULL || k->is_klass(), "must be");
assert(k == NULL || k->oop_is_instance(), "cast to InstanceKlass");
return (InstanceKlass*) k;
}
......
/*
* Copyright (c) 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.lang.instrument.Instrumentation;
import java.lang.instrument.ClassDefinition;
import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.Label;
import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;
public class Agent implements Opcodes {
private static byte[] makeNewMartyr() {
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "Martyr", null, "java/lang/Object", null);
cw.visitSource(null, null);
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
Label lab0 = new Label();
mv.visitLabel(lab0);
mv.visitLineNumber(1, lab0);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC, "getName", "()Ljava/lang/String;", null, null);
mv.visitCode();
Label lab0 = new Label();
mv.visitLabel(lab0);
mv.visitLineNumber(6, lab0);
mv.visitLdcInsn("Redefinition done");
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PROTECTED, "finalize", "()V", null, null);
mv.visitCode();
Label lab0 = new Label();
mv.visitLabel(lab0);
mv.visitLineNumber(8, lab0);
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
mv.visitLdcInsn("Finalizer called");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
mv.visitInsn(RETURN);
mv.visitMaxs(2, 1);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
public static void premain(String args, Instrumentation inst) throws Exception {
agentmain(args, inst);
}
public static void agentmain(String args, Instrumentation inst) throws Exception {
ClassDefinition martyrDef =
new ClassDefinition(Class.forName("Martyr"), makeNewMartyr());
inst.redefineClasses(martyrDef);
}
}
/*
* Copyright (c) 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public class Main {
public static void main(String[] args) {
try {
MartyrSon m = new MartyrSon();
System.out.println(m.getName());
System.runFinalization();
} catch (Throwable e) {
e.printStackTrace();
}
}
}
/*
* Copyright (c) 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public class Martyr {
public String getName() {
return "Redefinition NOT done";
}
protected void finalize() {
// should be empty
}
}
/*
* Copyright (c) 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class MartyrSon extends Martyr {
public String getName() {
return super.getName();
}
}
Main-Class: Main
Agent-Class: Agent
Can-Redefine-Classes: true
Can-Retransform-Classes: true
Premain-Class: Agent
#!/bin/sh
# Copyright (c) 2014 Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
# @test
# @bug 6904403
# @summary Don't assert if we redefine finalize method
# @run shell testme.sh
# This test shouldn't provoke and assert(f == k->has_finalizer()) failed: inconsistent has_finalizer
. ${TESTSRC}/../../test_env.sh
JAVAC=${COMPILEJAVA}${FS}bin${FS}javac
JAR=${COMPILEJAVA}${FS}bin${FS}jar
JAVA=${TESTJAVA}${FS}bin${FS}java
TOOLS_JAR=${TESTJAVA}${FS}lib${FS}tools.jar
cp ${TESTSRC}${FS}*.java .
${JAVAC} -XDignore.symbol.file -classpath ${TOOLS_JAR} -sourcepath ${TESTSRC} *.java
if [ $? -eq 1 ]
then
echo "Compilation failed"
exit
fi
${JAR} cvfm testcase.jar ${TESTSRC}/manifest.mf .
${JAVA} -Xbootclasspath/a:${TOOLS_JAR} -javaagent:${PWD}/testcase.jar Main
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册