提交 efb81c96 编写于 作者: A asaha

Merge

......@@ -713,6 +713,7 @@ e01a710549a962cee94728271248a7d89fb56c49 hs25.60-b20
e0d75c284bd1c09fd7d9ef09627d8a99b88d468d jdk8u60-b21
ff8fdeb2fb6d6f3348597339c53412f8f6202c3f hs25.60-b22
878cb0df27c22c6b1e9f4add1eb3da3edc8ab51d jdk8u60-b22
ad04e0ef0f85625b68ed18e949c75399b8d9b99b hs25.66-b01
0e4094950cd312c8f95c7f37336606323fe049fe jdk8u60-b23
d89ceecf1bad55e1aee2932b8895d60fc64c15db hs25.60-b23
fb157d537278cda4150740e27bb57cd8694e15bf jdk8u60-b24
......@@ -728,3 +729,6 @@ aa915217a00c4b8ce0e82d1b23fa1df8a9e4cc70 jdk8u65-b05
3070e116da4cfebc2ceb0df8f40faeefd38a6d4a jdk8u65-b06
878cb0df27c22c6b1e9f4add1eb3da3edc8ab51d jdk8u66-b00
777a354cada52b831a32bfc5362ad7cedfde4450 jdk8u66-b01
0366ad2644f58ec88af9cb2ea8c23a02559fb2d1 hs25.66-b02
47110b037994f9006c22abcb12569fcafad84edb hs25.66-b03
ae5624088d86abe8e7981dbb893c1b6da5140a1c jdk8u66-b02
......@@ -116,6 +116,18 @@ endif
# hotspot version definitions
include $(GAMMADIR)/make/hotspot_version
# When config parameter --with-update-version is defined,
# Hotspot minor version should be set to that
ifneq ($(JDK_UPDATE_VERSION),)
HS_MINOR_VER=$(JDK_UPDATE_VERSION)
endif
# When config parameter --with-build-number is defined,
# Hotspot build number should be set to that
ifneq ($(JDK_BUILD_NUMBER),)
HS_BUILD_NUMBER=$(subst b,,$(JDK_BUILD_NUMBER))
endif
# Java versions needed
ifeq ($(PREVIOUS_JDK_VERSION),)
PREVIOUS_JDK_VERSION=$(JDK_PREVIOUS_VERSION)
......
......@@ -35,7 +35,7 @@ HOTSPOT_VM_COPYRIGHT=Copyright 2015
HS_MAJOR_VER=25
HS_MINOR_VER=66
HS_BUILD_NUMBER=01
HS_BUILD_NUMBER=00
JDK_MAJOR_VER=1
JDK_MINOR_VER=8
......
......@@ -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
......
......@@ -439,6 +439,9 @@ void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) {
if (!constants()->is_shared()) {
MetadataFactory::free_metadata(loader_data, constants());
}
// Delete any cached resolution errors for the constant pool
SystemDictionary::delete_resolution_error(constants());
set_constants(NULL);
}
......@@ -1569,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;
}
......
......@@ -4071,9 +4071,6 @@ void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
mnt->adjust_method_entries(the_class(), &trace_name_printed);
}
// Fix Resolution Error table also to remove old constant pools
SystemDictionary::delete_resolution_error(old_constants);
if (the_class->oop_map_cache() != NULL) {
// Flush references to any obsolete methods from the oop map cache
// so that obsolete methods are not pinned.
......
......@@ -3307,6 +3307,9 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
extern void JDK_Version_init();
// Preinitialize version info.
VM_Version::early_initialize();
// Check version
if (!is_supported_jni_version(args->version)) return JNI_EVERSION;
......
......@@ -56,6 +56,13 @@ class Abstract_VM_Version: AllStatic {
public:
static void initialize();
// This allows for early initialization of VM_Version information
// that may be needed later in the initialization sequence but before
// full VM_Version initialization is possible. It can not depend on any
// other part of the VM being initialized when called. Platforms that
// need to specialize this define VM_Version::early_initialize().
static void early_initialize() { }
// Name
static const char* vm_name();
// Vendor
......
/*
* 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
* @library /testlibrary
* @build RedefineClassHelper
* @run main RedefineClassHelper
* @run main/othervm -javaagent:redefineagent.jar RedefineFinalizer
*/
/*
* Regression test for hitting:
*
* assert(f == k->has_finalizer()) failed: inconsistent has_finalizer
*
* when redefining finalizer method
*/
public class RedefineFinalizer {
public static String newB =
"class RedefineFinalizer$B {" +
" protected void finalize() { " +
" System.out.println(\"Finalizer called\");" +
" }" +
"}";
public static void main(String[] args) throws Exception {
RedefineClassHelper.redefineClass(B.class, newB);
A a = new A();
}
static class A extends B {
}
static class B {
protected void finalize() {
// should be empty
}
}
}
/*
* Copyright (c) 2014, 2015, 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 8076110
* @summary Redefine running methods that have cached resolution errors
* @library /testlibrary
* @modules java.instrument
* java.base/jdk.internal.org.objectweb.asm
* @build RedefineClassHelper
* @run main RedefineClassHelper
* @run main/othervm -javaagent:redefineagent.jar RedefineRunningMethodsWithResolutionErrors
*/
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;
import java.lang.reflect.InvocationTargetException;
public class RedefineRunningMethodsWithResolutionErrors extends ClassLoader implements Opcodes {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
if (name.equals("C")) {
byte[] b = loadC(false);
return defineClass(name, b, 0, b.length);
} else {
return super.findClass(name);
}
}
private static byte[] loadC(boolean redefine) {
ClassWriter cw = new ClassWriter(0);
cw.visit(52, ACC_SUPER | ACC_PUBLIC, "C", null, "java/lang/Object", null);
{
MethodVisitor mv;
mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "m", "()V", null, null);
mv.visitCode();
// First time we run we will:
// 1) Cache resolution errors
// 2) Redefine the class / method
// 3) Try to read the resolution errors that were cached
//
// The redefined method will never run, throw error to be sure
if (redefine) {
createThrowRuntimeExceptionCode(mv, "The redefined method was called");
} else {
createMethodBody(mv);
}
mv.visitMaxs(3, 0);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
private static void createMethodBody(MethodVisitor mv) {
Label classExists = new Label();
// Cache resolution errors
createLoadNonExistentClassCode(mv, classExists);
// Redefine our own class and method
mv.visitMethodInsn(INVOKESTATIC, "RedefineRunningMethodsWithResolutionErrors", "redefine", "()V");
// Provoke the same error again to make sure the resolution error cache works
createLoadNonExistentClassCode(mv, classExists);
// Test passed
mv.visitInsn(RETURN);
mv.visitFrame(F_SAME, 0, new Object[0], 0, new Object[0]);
mv.visitLabel(classExists);
createThrowRuntimeExceptionCode(mv, "Loaded class that shouldn't exist (\"NonExistentClass\")");
}
private static void createLoadNonExistentClassCode(MethodVisitor mv, Label classExists) {
Label tryLoadBegin = new Label();
Label tryLoadEnd = new Label();
Label catchLoadBlock = new Label();
mv.visitTryCatchBlock(tryLoadBegin, tryLoadEnd, catchLoadBlock, "java/lang/NoClassDefFoundError");
// Try to load a class that does not exist to provoke resolution errors
mv.visitLabel(tryLoadBegin);
mv.visitMethodInsn(INVOKESTATIC, "NonExistentClass", "nonExistentMethod", "()V");
mv.visitLabel(tryLoadEnd);
// No NoClassDefFoundError means NonExistentClass existed, which shouldn't happen
mv.visitJumpInsn(GOTO, classExists);
mv.visitFrame(F_SAME1, 0, new Object[0], 1, new Object[] { "java/lang/NoClassDefFoundError" });
mv.visitLabel(catchLoadBlock);
// Ignore the expected NoClassDefFoundError
mv.visitInsn(POP);
}
private static void createThrowRuntimeExceptionCode(MethodVisitor mv, String msg) {
mv.visitTypeInsn(NEW, "java/lang/RuntimeException");
mv.visitInsn(DUP);
mv.visitLdcInsn(msg);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V");
mv.visitInsn(ATHROW);
}
private static Class<?> c;
public static void redefine() throws Exception {
RedefineClassHelper.redefineClass(c, loadC(true));
}
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
c = Class.forName("C", true, new RedefineRunningMethodsWithResolutionErrors());
c.getMethod("m").invoke(null);
}
}
/*
* 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.io.PrintWriter;
import java.lang.instrument.*;
import com.oracle.java.testlibrary.*;
/*
* Helper class to write tests that redefine classes.
* When main method is run, it will create a redefineagent.jar that can be used
* with the -javaagent option to support redefining classes in jtreg tests.
*
* See sample test in test/testlibrary_tests/RedefineClassTest.java
*/
public class RedefineClassHelper {
public static Instrumentation instrumentation;
public static void premain(String agentArgs, Instrumentation inst) {
instrumentation = inst;
}
/**
* Redefine a class
*
* @param clazz Class to redefine
* @param javacode String with the new java code for the class to be redefined
*/
public static void redefineClass(Class clazz, String javacode) throws Exception {
byte[] bytecode = InMemoryJavaCompiler.compile(clazz.getName(), javacode);
redefineClass(clazz, bytecode);
}
/**
* Redefine a class
*
* @param clazz Class to redefine
* @param bytecode byte[] with the new class
*/
public static void redefineClass(Class clazz, byte[] bytecode) throws Exception {
instrumentation.redefineClasses(new ClassDefinition(clazz, bytecode));
}
/**
* Main method to be invoked before test to create the redefineagent.jar
*/
public static void main(String[] args) throws Exception {
ClassFileInstaller.main("RedefineClassHelper");
PrintWriter pw = new PrintWriter("MANIFEST.MF");
pw.println("Premain-Class: RedefineClassHelper");
pw.println("Can-Redefine-Classes: true");
pw.close();
sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar");
if (!jarTool.run(new String[] { "-cmf", "MANIFEST.MF", "redefineagent.jar", "RedefineClassHelper.class" })) {
throw new Exception("jar operation failed");
}
}
}
/*
* 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
* @library /testlibrary
* @summary Proof of concept test for RedefineClassHelper
* @build RedefineClassHelper
* @run main RedefineClassHelper
* @run main/othervm -javaagent:redefineagent.jar RedefineClassTest
*/
import static com.oracle.java.testlibrary.Asserts.*;
import com.oracle.java.testlibrary.*;
/*
* Proof of concept test for the test utility class RedefineClassHelper
*/
public class RedefineClassTest {
public static String newClass = "class RedefineClassTest$A { public int Method() { return 2; } }";
public static void main(String[] args) throws Exception {
A a = new A();
assertTrue(a.Method() == 1);
RedefineClassHelper.redefineClass(A.class, newClass);
assertTrue(a.Method() == 2);
}
static class A {
public int Method() {
return 1;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册