test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineObject.java
author redestad
Thu, 24 Oct 2019 09:57:29 +0200
changeset 58775 ba524a5f7cc2
permissions -rw-r--r--
8232613: Move Object.registerNatives into HotSpot Reviewed-by: dholmes, adinn, coleenp, lfoltan, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58775
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
     1
/*
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
     4
 *
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
     8
 *
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    13
 * accompanied this code).
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    14
 *
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    18
 *
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    21
 * questions.
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    22
 */
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    23
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    24
/*
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    25
 * @test
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    26
 * @bug 8232613
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    27
 * @summary Ensure Object natives stay registered after redefinition
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    28
 * @library /test/lib
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    29
 * @modules java.base/jdk.internal.misc
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    30
 *          java.base/jdk.internal.org.objectweb.asm
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    31
 *          java.compiler
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    32
 *          java.instrument
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    33
 *          jdk.jartool/sun.tools.jar
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    34
 * @run main RedefineObject buildagent
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    35
 * @run main/othervm -javaagent:redefineagent.jar RedefineObject
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    36
 */
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    37
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    38
import static jdk.test.lib.Asserts.assertTrue;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    39
import java.io.FileNotFoundException;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    40
import java.io.PrintWriter;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    41
import java.lang.RuntimeException;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    42
import java.lang.instrument.ClassFileTransformer;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    43
import java.lang.instrument.IllegalClassFormatException;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    44
import java.lang.instrument.Instrumentation;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    45
import java.lang.instrument.UnmodifiableClassException;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    46
import java.security.ProtectionDomain;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    47
import java.util.Arrays;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    48
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    49
import jdk.internal.org.objectweb.asm.ClassReader;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    50
import jdk.internal.org.objectweb.asm.ClassVisitor;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    51
import jdk.internal.org.objectweb.asm.ClassWriter;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    52
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    53
import static jdk.internal.org.objectweb.asm.Opcodes.ASM6;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    54
import static jdk.internal.org.objectweb.asm.Opcodes.V1_8;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    55
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    56
public class RedefineObject {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    57
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    58
    static Instrumentation inst;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    59
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    60
    public static void premain(String agentArgs, Instrumentation inst) {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    61
        RedefineObject.inst = inst;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    62
    }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    63
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    64
    static class Transformer implements ClassFileTransformer {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    65
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    66
        public byte[] asm(ClassLoader loader, String className,
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    67
                          Class<?> classBeingRedefined,
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    68
                          ProtectionDomain protectionDomain, byte[] classfileBuffer)
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    69
                throws IllegalClassFormatException {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    70
            ClassWriter cw = new ClassWriter(0);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    71
            // Force an older ASM to force a bytecode update
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    72
            ClassVisitor cv = new DummyClassVisitor(ASM6, cw) { };
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    73
            ClassReader cr = new ClassReader(classfileBuffer);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    74
            cr.accept(cv, 0);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    75
            byte[] bytes = cw.toByteArray();
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    76
            return bytes;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    77
        }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    78
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    79
        public class DummyClassVisitor extends ClassVisitor {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    80
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    81
            public DummyClassVisitor(int api, ClassVisitor cv) {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    82
                super(api, cv);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    83
            }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    84
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    85
            public void visit(
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    86
                    final int version,
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    87
                    final int access,
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    88
                    final String name,
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    89
                    final String signature,
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    90
                    final String superName,
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    91
                    final String[] interfaces) {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    92
                // Artificially lower to JDK 8 version to force a redefine
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    93
                cv.visit(V1_8, access, name, signature, superName, interfaces);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    94
            }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    95
        }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    96
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    97
        @Override public byte[] transform(ClassLoader loader, String className,
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    98
                                          Class<?> classBeingRedefined,
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
    99
                                          ProtectionDomain protectionDomain, byte[] classfileBuffer)
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   100
                throws IllegalClassFormatException {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   101
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   102
            if (className.contains("java/lang/Object")) {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   103
                try {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   104
                    // Here we remove and re-add the dummy fields. This shuffles the constant pool
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   105
                    return asm(loader, className, classBeingRedefined, protectionDomain, classfileBuffer);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   106
                } catch (Throwable e) {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   107
                    // The retransform native code that called this method does not propagate
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   108
                    // exceptions. Instead of getting an uninformative generic error, catch
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   109
                    // problems here and print it, then exit.
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   110
                    e.printStackTrace();
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   111
                    System.exit(1);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   112
                }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   113
            }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   114
            return null;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   115
        }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   116
    }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   117
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   118
    private static void buildAgent() {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   119
        try {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   120
            ClassFileInstaller.main("RedefineObject");
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   121
        } catch (Exception e) {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   122
            throw new RuntimeException("Could not write agent classfile", e);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   123
        }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   124
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   125
        try {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   126
            PrintWriter pw = new PrintWriter("MANIFEST.MF");
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   127
            pw.println("Premain-Class: RedefineObject");
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   128
            pw.println("Agent-Class: RedefineObject");
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   129
            pw.println("Can-Retransform-Classes: true");
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   130
            pw.close();
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   131
        } catch (FileNotFoundException e) {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   132
            throw new RuntimeException("Could not write manifest file for the agent", e);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   133
        }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   134
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   135
        sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar");
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   136
        if (!jarTool.run(new String[] { "-cmf", "MANIFEST.MF", "redefineagent.jar", "RedefineObject.class" })) {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   137
            throw new RuntimeException("Could not write the agent jar file");
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   138
        }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   139
    }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   140
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   141
    public static void main(String[] args) throws Exception {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   142
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   143
        int objHash = System.identityHashCode(Object.class);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   144
        System.out.println("Object hashCode: " + objHash);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   145
        if (args.length == 1 && args[0].equals("buildagent")) {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   146
            buildAgent();
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   147
            return;
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   148
        }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   149
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   150
        if (inst == null) {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   151
            throw new RuntimeException("Instrumentation object was null");
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   152
        }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   153
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   154
        try {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   155
            inst.addTransformer(new RedefineObject.Transformer(), true);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   156
            inst.retransformClasses(Object.class);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   157
        } catch (UnmodifiableClassException e) {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   158
            throw new RuntimeException(e);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   159
        }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   160
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   161
        // Exercise native methods on Object after transform
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   162
        Object b = new Object();
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   163
        b.hashCode();
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   164
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   165
        C c = new C();
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   166
        assertTrue(c.hashCode() != c.clone().hashCode() || c != c.clone());
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   167
        assertTrue(c.clone() instanceof C);
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   168
        c = (C)c.clone(); // native method on new Object
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   169
    }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   170
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   171
    private static class C implements Cloneable {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   172
        @Override
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   173
        protected Object clone() throws CloneNotSupportedException {
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   174
            return super.clone();
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   175
        }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   176
    }
ba524a5f7cc2 8232613: Move Object.registerNatives into HotSpot
redestad
parents:
diff changeset
   177
}