Merge

Tue, 28 Jul 2015 23:38:46 -0700

author
asaha
date
Tue, 28 Jul 2015 23:38:46 -0700
changeset 8218
c71344fad7a7
parent 8217
e30be4c0f1da
parent 8121
6594411c4eb4
child 8219
b057ebc2802f

Merge

.hgtags file | annotate | diff | comparison | revisions
make/hotspot_version file | annotate | diff | comparison | revisions
     1.1 --- a/.hgtags	Thu Jul 23 11:20:44 2015 -0700
     1.2 +++ b/.hgtags	Tue Jul 28 23:38:46 2015 -0700
     1.3 @@ -713,6 +713,7 @@
     1.4  e0d75c284bd1c09fd7d9ef09627d8a99b88d468d jdk8u60-b21
     1.5  ff8fdeb2fb6d6f3348597339c53412f8f6202c3f hs25.60-b22
     1.6  878cb0df27c22c6b1e9f4add1eb3da3edc8ab51d jdk8u60-b22
     1.7 +ad04e0ef0f85625b68ed18e949c75399b8d9b99b hs25.66-b01
     1.8  0e4094950cd312c8f95c7f37336606323fe049fe jdk8u60-b23
     1.9  d89ceecf1bad55e1aee2932b8895d60fc64c15db hs25.60-b23
    1.10  fb157d537278cda4150740e27bb57cd8694e15bf jdk8u60-b24
    1.11 @@ -726,6 +727,10 @@
    1.12  2a03fd592fe60fd113c1c89e431ebaa6857c4998 jdk8u65-b04
    1.13  aa915217a00c4b8ce0e82d1b23fa1df8a9e4cc70 jdk8u65-b05
    1.14  3070e116da4cfebc2ceb0df8f40faeefd38a6d4a jdk8u65-b06
    1.15 +008b42595f2babc98e1b23bc00f27e308f9a35b9 jdk8u65-b07
    1.16  878cb0df27c22c6b1e9f4add1eb3da3edc8ab51d jdk8u66-b00
    1.17  777a354cada52b831a32bfc5362ad7cedfde4450 jdk8u66-b01
    1.18 +0366ad2644f58ec88af9cb2ea8c23a02559fb2d1 hs25.66-b02
    1.19 +47110b037994f9006c22abcb12569fcafad84edb hs25.66-b03
    1.20 +ae5624088d86abe8e7981dbb893c1b6da5140a1c jdk8u66-b02
    1.21  9a158a0c243beb610dbaabd63d6218d3ce5825f1 jdk8u71-b00
     2.1 --- a/make/defs.make	Thu Jul 23 11:20:44 2015 -0700
     2.2 +++ b/make/defs.make	Tue Jul 28 23:38:46 2015 -0700
     2.3 @@ -116,6 +116,18 @@
     2.4  # hotspot version definitions
     2.5  include $(GAMMADIR)/make/hotspot_version
     2.6  
     2.7 +# When config parameter --with-update-version is defined,
     2.8 +# Hotspot minor version should be set to that
     2.9 +ifneq ($(JDK_UPDATE_VERSION),)
    2.10 +  HS_MINOR_VER=$(JDK_UPDATE_VERSION)
    2.11 +endif
    2.12 +
    2.13 +# When config parameter --with-build-number is defined,
    2.14 +# Hotspot build number should be set to that
    2.15 +ifneq ($(JDK_BUILD_NUMBER),)
    2.16 +  HS_BUILD_NUMBER=$(subst b,,$(JDK_BUILD_NUMBER))
    2.17 +endif
    2.18 +
    2.19  # Java versions needed
    2.20  ifeq ($(PREVIOUS_JDK_VERSION),)
    2.21    PREVIOUS_JDK_VERSION=$(JDK_PREVIOUS_VERSION)
     3.1 --- a/src/share/vm/classfile/classFileParser.cpp	Thu Jul 23 11:20:44 2015 -0700
     3.2 +++ b/src/share/vm/classfile/classFileParser.cpp	Tue Jul 28 23:38:46 2015 -0700
     3.3 @@ -4421,9 +4421,15 @@
     3.4    Method* m = k->lookup_method(vmSymbols::finalize_method_name(),
     3.5                                   vmSymbols::void_method_signature());
     3.6    if (m != NULL && !m->is_empty_method()) {
     3.7 -    f = true;
     3.8 +      f = true;
     3.9    }
    3.10 -  assert(f == k->has_finalizer(), "inconsistent has_finalizer");
    3.11 +
    3.12 +  // Spec doesn't prevent agent from redefinition of empty finalizer.
    3.13 +  // Despite the fact that it's generally bad idea and redefined finalizer
    3.14 +  // will not work as expected we shouldn't abort vm in this case
    3.15 +  if (!k->has_redefined_this_or_super()) {
    3.16 +    assert(f == k->has_finalizer(), "inconsistent has_finalizer");
    3.17 +  }
    3.18  #endif
    3.19  
    3.20    // Check if this klass supports the java.lang.Cloneable interface
     4.1 --- a/src/share/vm/oops/instanceKlass.cpp	Thu Jul 23 11:20:44 2015 -0700
     4.2 +++ b/src/share/vm/oops/instanceKlass.cpp	Tue Jul 28 23:38:46 2015 -0700
     4.3 @@ -439,6 +439,9 @@
     4.4      if (!constants()->is_shared()) {
     4.5        MetadataFactory::free_metadata(loader_data, constants());
     4.6      }
     4.7 +    // Delete any cached resolution errors for the constant pool
     4.8 +    SystemDictionary::delete_resolution_error(constants());
     4.9 +
    4.10      set_constants(NULL);
    4.11    }
    4.12  
    4.13 @@ -1569,6 +1572,21 @@
    4.14    return NULL;
    4.15  }
    4.16  
    4.17 +#ifdef ASSERT
    4.18 +// search through class hierarchy and return true if this class or
    4.19 +// one of the superclasses was redefined
    4.20 +bool InstanceKlass::has_redefined_this_or_super() const {
    4.21 +  const InstanceKlass* klass = this;
    4.22 +  while (klass != NULL) {
    4.23 +    if (klass->has_been_redefined()) {
    4.24 +      return true;
    4.25 +    }
    4.26 +    klass = InstanceKlass::cast(klass->super());
    4.27 +  }
    4.28 +  return false;
    4.29 +}
    4.30 +#endif
    4.31 +
    4.32  // lookup a method in the default methods list then in all transitive interfaces
    4.33  // Do NOT return private or static methods
    4.34  Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name,
     5.1 --- a/src/share/vm/oops/instanceKlass.hpp	Thu Jul 23 11:20:44 2015 -0700
     5.2 +++ b/src/share/vm/oops/instanceKlass.hpp	Tue Jul 28 23:38:46 2015 -0700
     5.3 @@ -808,6 +808,11 @@
     5.4    bool implements_interface(Klass* k) const;
     5.5    bool is_same_or_direct_interface(Klass* k) const;
     5.6  
     5.7 +#ifdef ASSERT
     5.8 +  // check whether this class or one of its superclasses was redefined
     5.9 +  bool has_redefined_this_or_super() const;
    5.10 +#endif
    5.11 +
    5.12    // Access to the implementor of an interface.
    5.13    Klass* implementor() const
    5.14    {
    5.15 @@ -865,8 +870,8 @@
    5.16  
    5.17    // Casting from Klass*
    5.18    static InstanceKlass* cast(Klass* k) {
    5.19 -    assert(k->is_klass(), "must be");
    5.20 -    assert(k->oop_is_instance(), "cast to InstanceKlass");
    5.21 +    assert(k == NULL || k->is_klass(), "must be");
    5.22 +    assert(k == NULL || k->oop_is_instance(), "cast to InstanceKlass");
    5.23      return (InstanceKlass*) k;
    5.24    }
    5.25  
     6.1 --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp	Thu Jul 23 11:20:44 2015 -0700
     6.2 +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp	Tue Jul 28 23:38:46 2015 -0700
     6.3 @@ -4071,9 +4071,6 @@
     6.4      mnt->adjust_method_entries(the_class(), &trace_name_printed);
     6.5    }
     6.6  
     6.7 -  // Fix Resolution Error table also to remove old constant pools
     6.8 -  SystemDictionary::delete_resolution_error(old_constants);
     6.9 -
    6.10    if (the_class->oop_map_cache() != NULL) {
    6.11      // Flush references to any obsolete methods from the oop map cache
    6.12      // so that obsolete methods are not pinned.
     7.1 --- a/src/share/vm/runtime/thread.cpp	Thu Jul 23 11:20:44 2015 -0700
     7.2 +++ b/src/share/vm/runtime/thread.cpp	Tue Jul 28 23:38:46 2015 -0700
     7.3 @@ -3307,6 +3307,9 @@
     7.4  
     7.5    extern void JDK_Version_init();
     7.6  
     7.7 +  // Preinitialize version info.
     7.8 +  VM_Version::early_initialize();
     7.9 +
    7.10    // Check version
    7.11    if (!is_supported_jni_version(args->version)) return JNI_EVERSION;
    7.12  
     8.1 --- a/src/share/vm/runtime/vm_version.hpp	Thu Jul 23 11:20:44 2015 -0700
     8.2 +++ b/src/share/vm/runtime/vm_version.hpp	Tue Jul 28 23:38:46 2015 -0700
     8.3 @@ -56,6 +56,13 @@
     8.4   public:
     8.5    static void initialize();
     8.6  
     8.7 +  // This allows for early initialization of VM_Version information
     8.8 +  // that may be needed later in the initialization sequence but before
     8.9 +  // full VM_Version initialization is possible. It can not depend on any
    8.10 +  // other part of the VM being initialized when called. Platforms that
    8.11 +  // need to specialize this define VM_Version::early_initialize().
    8.12 +  static void early_initialize() { }
    8.13 +
    8.14    // Name
    8.15    static const char* vm_name();
    8.16    // Vendor
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/runtime/RedefineFinalizer/RedefineFinalizer.java	Tue Jul 28 23:38:46 2015 -0700
     9.3 @@ -0,0 +1,64 @@
     9.4 +/*
     9.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.7 + *
     9.8 + * This code is free software; you can redistribute it and/or modify it
     9.9 + * under the terms of the GNU General Public License version 2 only, as
    9.10 + * published by the Free Software Foundation.
    9.11 + *
    9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    9.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    9.15 + * version 2 for more details (a copy is included in the LICENSE file that
    9.16 + * accompanied this code).
    9.17 + *
    9.18 + * You should have received a copy of the GNU General Public License version
    9.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    9.21 + *
    9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    9.23 + * or visit www.oracle.com if you need additional information or have any
    9.24 + * questions.
    9.25 + */
    9.26 +
    9.27 +/*
    9.28 + * @test
    9.29 + * @bug 6904403
    9.30 + * @summary Don't assert if we redefine finalize method
    9.31 + * @library /testlibrary
    9.32 + * @build RedefineClassHelper
    9.33 + * @run main RedefineClassHelper
    9.34 + * @run main/othervm -javaagent:redefineagent.jar RedefineFinalizer
    9.35 + */
    9.36 +
    9.37 +/*
    9.38 + * Regression test for hitting:
    9.39 + *
    9.40 + * assert(f == k->has_finalizer()) failed: inconsistent has_finalizer
    9.41 + *
    9.42 + * when redefining finalizer method
    9.43 + */
    9.44 +public class RedefineFinalizer {
    9.45 +
    9.46 +    public static String newB =
    9.47 +                "class RedefineFinalizer$B {" +
    9.48 +                "   protected void finalize() { " +
    9.49 +                "       System.out.println(\"Finalizer called\");" +
    9.50 +                "   }" +
    9.51 +                "}";
    9.52 +
    9.53 +    public static void main(String[] args) throws Exception {
    9.54 +        RedefineClassHelper.redefineClass(B.class, newB);
    9.55 +
    9.56 +        A a = new A();
    9.57 +    }
    9.58 +
    9.59 +    static class A extends B {
    9.60 +    }
    9.61 +
    9.62 +    static class B {
    9.63 +        protected void finalize() {
    9.64 +            // should be empty
    9.65 +        }
    9.66 +    }
    9.67 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/runtime/RedefineTests/RedefineRunningMethodsWithResolutionErrors.java	Tue Jul 28 23:38:46 2015 -0700
    10.3 @@ -0,0 +1,143 @@
    10.4 +/*
    10.5 + * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
    10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.7 + *
    10.8 + * This code is free software; you can redistribute it and/or modify it
    10.9 + * under the terms of the GNU General Public License version 2 only, as
   10.10 + * published by the Free Software Foundation.
   10.11 + *
   10.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   10.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   10.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   10.15 + * version 2 for more details (a copy is included in the LICENSE file that
   10.16 + * accompanied this code).
   10.17 + *
   10.18 + * You should have received a copy of the GNU General Public License version
   10.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   10.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   10.21 + *
   10.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   10.23 + * or visit www.oracle.com if you need additional information or have any
   10.24 + * questions.
   10.25 + */
   10.26 +
   10.27 +/*
   10.28 + * @test
   10.29 + * @bug 8076110
   10.30 + * @summary Redefine running methods that have cached resolution errors
   10.31 + * @library /testlibrary
   10.32 + * @modules java.instrument
   10.33 + *          java.base/jdk.internal.org.objectweb.asm
   10.34 + * @build RedefineClassHelper
   10.35 + * @run main RedefineClassHelper
   10.36 + * @run main/othervm -javaagent:redefineagent.jar RedefineRunningMethodsWithResolutionErrors
   10.37 + */
   10.38 +
   10.39 +import jdk.internal.org.objectweb.asm.ClassWriter;
   10.40 +import jdk.internal.org.objectweb.asm.Label;
   10.41 +import jdk.internal.org.objectweb.asm.MethodVisitor;
   10.42 +import jdk.internal.org.objectweb.asm.Opcodes;
   10.43 +
   10.44 +import java.lang.reflect.InvocationTargetException;
   10.45 +
   10.46 +public class RedefineRunningMethodsWithResolutionErrors extends ClassLoader implements Opcodes {
   10.47 +
   10.48 +    @Override
   10.49 +    protected Class<?> findClass(String name) throws ClassNotFoundException {
   10.50 +        if (name.equals("C")) {
   10.51 +            byte[] b = loadC(false);
   10.52 +            return defineClass(name, b, 0, b.length);
   10.53 +        } else {
   10.54 +            return super.findClass(name);
   10.55 +        }
   10.56 +    }
   10.57 +
   10.58 +    private static byte[] loadC(boolean redefine) {
   10.59 +        ClassWriter cw = new ClassWriter(0);
   10.60 +
   10.61 +        cw.visit(52, ACC_SUPER | ACC_PUBLIC, "C", null, "java/lang/Object", null);
   10.62 +        {
   10.63 +            MethodVisitor mv;
   10.64 +
   10.65 +            mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "m", "()V", null, null);
   10.66 +            mv.visitCode();
   10.67 +
   10.68 +            // First time we run we will:
   10.69 +            // 1) Cache resolution errors
   10.70 +            // 2) Redefine the class / method
   10.71 +            // 3) Try to read the resolution errors that were cached
   10.72 +            //
   10.73 +            // The redefined method will never run, throw error to be sure
   10.74 +            if (redefine) {
   10.75 +                createThrowRuntimeExceptionCode(mv, "The redefined method was called");
   10.76 +            } else {
   10.77 +                createMethodBody(mv);
   10.78 +            }
   10.79 +            mv.visitMaxs(3, 0);
   10.80 +            mv.visitEnd();
   10.81 +        }
   10.82 +        cw.visitEnd();
   10.83 +        return cw.toByteArray();
   10.84 +    }
   10.85 +
   10.86 +    private static void createMethodBody(MethodVisitor mv) {
   10.87 +        Label classExists = new Label();
   10.88 +
   10.89 +        // Cache resolution errors
   10.90 +        createLoadNonExistentClassCode(mv, classExists);
   10.91 +
   10.92 +        // Redefine our own class and method
   10.93 +        mv.visitMethodInsn(INVOKESTATIC, "RedefineRunningMethodsWithResolutionErrors", "redefine", "()V");
   10.94 +
   10.95 +        // Provoke the same error again to make sure the resolution error cache works
   10.96 +        createLoadNonExistentClassCode(mv, classExists);
   10.97 +
   10.98 +        // Test passed
   10.99 +        mv.visitInsn(RETURN);
  10.100 +
  10.101 +        mv.visitFrame(F_SAME, 0, new Object[0], 0, new Object[0]);
  10.102 +        mv.visitLabel(classExists);
  10.103 +
  10.104 +        createThrowRuntimeExceptionCode(mv, "Loaded class that shouldn't exist (\"NonExistentClass\")");
  10.105 +    }
  10.106 +
  10.107 +    private static void createLoadNonExistentClassCode(MethodVisitor mv, Label classExists) {
  10.108 +        Label tryLoadBegin = new Label();
  10.109 +        Label tryLoadEnd = new Label();
  10.110 +        Label catchLoadBlock = new Label();
  10.111 +        mv.visitTryCatchBlock(tryLoadBegin, tryLoadEnd, catchLoadBlock, "java/lang/NoClassDefFoundError");
  10.112 +
  10.113 +        // Try to load a class that does not exist to provoke resolution errors
  10.114 +        mv.visitLabel(tryLoadBegin);
  10.115 +        mv.visitMethodInsn(INVOKESTATIC, "NonExistentClass", "nonExistentMethod", "()V");
  10.116 +        mv.visitLabel(tryLoadEnd);
  10.117 +
  10.118 +        // No NoClassDefFoundError means NonExistentClass existed, which shouldn't happen
  10.119 +        mv.visitJumpInsn(GOTO, classExists);
  10.120 +
  10.121 +        mv.visitFrame(F_SAME1, 0, new Object[0], 1, new Object[] { "java/lang/NoClassDefFoundError" });
  10.122 +        mv.visitLabel(catchLoadBlock);
  10.123 +
  10.124 +        // Ignore the expected NoClassDefFoundError
  10.125 +        mv.visitInsn(POP);
  10.126 +    }
  10.127 +
  10.128 +    private static void createThrowRuntimeExceptionCode(MethodVisitor mv, String msg) {
  10.129 +        mv.visitTypeInsn(NEW, "java/lang/RuntimeException");
  10.130 +        mv.visitInsn(DUP);
  10.131 +        mv.visitLdcInsn(msg);
  10.132 +        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V");
  10.133 +        mv.visitInsn(ATHROW);
  10.134 +    }
  10.135 +
  10.136 +    private static Class<?> c;
  10.137 +
  10.138 +    public static void redefine() throws Exception {
  10.139 +        RedefineClassHelper.redefineClass(c, loadC(true));
  10.140 +    }
  10.141 +
  10.142 +    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
  10.143 +        c = Class.forName("C", true, new RedefineRunningMethodsWithResolutionErrors());
  10.144 +        c.getMethod("m").invoke(null);
  10.145 +    }
  10.146 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/testlibrary/RedefineClassHelper.java	Tue Jul 28 23:38:46 2015 -0700
    11.3 @@ -0,0 +1,79 @@
    11.4 +/*
    11.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.7 + *
    11.8 + * This code is free software; you can redistribute it and/or modify it
    11.9 + * under the terms of the GNU General Public License version 2 only, as
   11.10 + * published by the Free Software Foundation.
   11.11 + *
   11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   11.15 + * version 2 for more details (a copy is included in the LICENSE file that
   11.16 + * accompanied this code).
   11.17 + *
   11.18 + * You should have received a copy of the GNU General Public License version
   11.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   11.21 + *
   11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   11.23 + * or visit www.oracle.com if you need additional information or have any
   11.24 + * questions.
   11.25 + */
   11.26 +
   11.27 +import java.io.PrintWriter;
   11.28 +import java.lang.instrument.*;
   11.29 +import com.oracle.java.testlibrary.*;
   11.30 +
   11.31 +/*
   11.32 + * Helper class to write tests that redefine classes.
   11.33 + * When main method is run, it will create a redefineagent.jar that can be used
   11.34 + * with the -javaagent option to support redefining classes in jtreg tests.
   11.35 + *
   11.36 + * See sample test in test/testlibrary_tests/RedefineClassTest.java
   11.37 + */
   11.38 +public class RedefineClassHelper {
   11.39 +
   11.40 +    public static Instrumentation instrumentation;
   11.41 +    public static void premain(String agentArgs, Instrumentation inst) {
   11.42 +        instrumentation = inst;
   11.43 +    }
   11.44 +
   11.45 +    /**
   11.46 +     * Redefine a class
   11.47 +     *
   11.48 +     * @param clazz Class to redefine
   11.49 +     * @param javacode String with the new java code for the class to be redefined
   11.50 +     */
   11.51 +    public static void redefineClass(Class clazz, String javacode) throws Exception {
   11.52 +        byte[] bytecode = InMemoryJavaCompiler.compile(clazz.getName(), javacode);
   11.53 +        redefineClass(clazz, bytecode);
   11.54 +    }
   11.55 +
   11.56 +    /**
   11.57 +     * Redefine a class
   11.58 +     *
   11.59 +     * @param clazz Class to redefine
   11.60 +     * @param bytecode byte[] with the new class
   11.61 +     */
   11.62 +    public static void redefineClass(Class clazz, byte[] bytecode) throws Exception {
   11.63 +        instrumentation.redefineClasses(new ClassDefinition(clazz, bytecode));
   11.64 +    }
   11.65 +
   11.66 +    /**
   11.67 +     * Main method to be invoked before test to create the redefineagent.jar
   11.68 +     */
   11.69 +    public static void main(String[] args) throws Exception {
   11.70 +        ClassFileInstaller.main("RedefineClassHelper");
   11.71 +
   11.72 +        PrintWriter pw = new PrintWriter("MANIFEST.MF");
   11.73 +        pw.println("Premain-Class: RedefineClassHelper");
   11.74 +        pw.println("Can-Redefine-Classes: true");
   11.75 +        pw.close();
   11.76 +
   11.77 +        sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar");
   11.78 +        if (!jarTool.run(new String[] { "-cmf", "MANIFEST.MF", "redefineagent.jar", "RedefineClassHelper.class" })) {
   11.79 +            throw new Exception("jar operation failed");
   11.80 +        }
   11.81 +    }
   11.82 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/test/testlibrary_tests/RedefineClassTest.java	Tue Jul 28 23:38:46 2015 -0700
    12.3 @@ -0,0 +1,54 @@
    12.4 +/*
    12.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    12.7 + *
    12.8 + * This code is free software; you can redistribute it and/or modify it
    12.9 + * under the terms of the GNU General Public License version 2 only, as
   12.10 + * published by the Free Software Foundation.
   12.11 + *
   12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   12.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   12.15 + * version 2 for more details (a copy is included in the LICENSE file that
   12.16 + * accompanied this code).
   12.17 + *
   12.18 + * You should have received a copy of the GNU General Public License version
   12.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   12.21 + *
   12.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   12.23 + * or visit www.oracle.com if you need additional information or have any
   12.24 + * questions.
   12.25 + */
   12.26 +
   12.27 +/*
   12.28 + * @test
   12.29 + * @library /testlibrary
   12.30 + * @summary Proof of concept test for RedefineClassHelper
   12.31 + * @build RedefineClassHelper
   12.32 + * @run main RedefineClassHelper
   12.33 + * @run main/othervm -javaagent:redefineagent.jar RedefineClassTest
   12.34 + */
   12.35 +
   12.36 +import static com.oracle.java.testlibrary.Asserts.*;
   12.37 +import com.oracle.java.testlibrary.*;
   12.38 +
   12.39 +/*
   12.40 + * Proof of concept test for the test utility class RedefineClassHelper
   12.41 + */
   12.42 +public class RedefineClassTest {
   12.43 +
   12.44 +    public static String newClass = "class RedefineClassTest$A { public int Method() { return 2; } }";
   12.45 +    public static void main(String[] args) throws Exception {
   12.46 +        A a = new A();
   12.47 +        assertTrue(a.Method() == 1);
   12.48 +        RedefineClassHelper.redefineClass(A.class, newClass);
   12.49 +        assertTrue(a.Method() == 2);
   12.50 +    }
   12.51 +
   12.52 +    static class A {
   12.53 +        public int Method() {
   12.54 +            return 1;
   12.55 +        }
   12.56 +    }
   12.57 +}

mercurial