Merge
This commit is contained in:
commit
b89a834019
@ -4359,9 +4359,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
|
||||
|
@ -1501,6 +1501,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,
|
||||
|
@ -754,6 +754,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
|
||||
{
|
||||
@ -811,8 +816,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;
|
||||
}
|
||||
|
||||
|
94
hotspot/test/runtime/RedefineFinalizer/Agent.java
Normal file
94
hotspot/test/runtime/RedefineFinalizer/Agent.java
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
34
hotspot/test/runtime/RedefineFinalizer/Main.java
Normal file
34
hotspot/test/runtime/RedefineFinalizer/Main.java
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
}
|
33
hotspot/test/runtime/RedefineFinalizer/Martyr.java
Normal file
33
hotspot/test/runtime/RedefineFinalizer/Martyr.java
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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
|
||||
}
|
||||
|
||||
}
|
28
hotspot/test/runtime/RedefineFinalizer/MartyrSon.java
Normal file
28
hotspot/test/runtime/RedefineFinalizer/MartyrSon.java
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
5
hotspot/test/runtime/RedefineFinalizer/manifest.mf
Normal file
5
hotspot/test/runtime/RedefineFinalizer/manifest.mf
Normal file
@ -0,0 +1,5 @@
|
||||
Main-Class: Main
|
||||
Agent-Class: Agent
|
||||
Can-Redefine-Classes: true
|
||||
Can-Retransform-Classes: true
|
||||
Premain-Class: Agent
|
49
hotspot/test/runtime/RedefineFinalizer/testme.sh
Normal file
49
hotspot/test/runtime/RedefineFinalizer/testme.sh
Normal file
@ -0,0 +1,49 @@
|
||||
#!/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
|
Loading…
Reference in New Issue
Block a user