hotspot/test/runtime/RedefineObject/Agent.java
author ykantser
Thu, 26 Mar 2015 16:36:56 +0100
changeset 29678 dd2f3932c21e
parent 22742 441a4617a9f4
permissions -rw-r--r--
8075586: Add @modules as needed to the open hotspot tests Reviewed-by: sla, ctornqvi, lfoltan, mchung, alanb Contributed-by: alexander.kulyakhtin@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17373
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
     1
/*
22742
441a4617a9f4 8028735: runtime/RedefineObject/TestRedefineObject.java interrupted (timed out?) on solaris_sparcv9-fastdebug-c2-runtime and solaris_x64-debugOpen-c2-runtime
coleenp
parents: 22234
diff changeset
     2
 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
17373
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
     4
 *
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
     8
 *
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    13
 * accompanied this code).
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    14
 *
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    18
 *
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    21
 * questions.
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    22
 */
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    23
import java.security.*;
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    24
import java.lang.instrument.*;
19278
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    25
import java.lang.reflect.*;
17373
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    26
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    27
public class Agent implements ClassFileTransformer {
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    28
    public synchronized byte[] transform(final ClassLoader classLoader,
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    29
                                         final String className,
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    30
                                         Class<?> classBeingRedefined,
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    31
                                         ProtectionDomain protectionDomain,
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    32
                                         byte[] classfileBuffer) {
19278
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    33
        System.out.println("Transforming class " + className);
17373
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    34
        return classfileBuffer;
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    35
    }
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    36
19278
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    37
    public static void redefine(String agentArgs, Instrumentation instrumentation, Class to_redefine) {
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    38
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    39
        try {
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    40
            instrumentation.retransformClasses(to_redefine);
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    41
        } catch (Exception e) {
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    42
            e.printStackTrace();
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    43
        }
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    44
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    45
    }
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    46
17373
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    47
    public static void premain(String agentArgs, Instrumentation instrumentation) {
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    48
        Agent transformer = new Agent();
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    49
        instrumentation.addTransformer(transformer, true);
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    50
19278
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    51
        // Redefine java/lang/Object and java/lang/reflect/Method.invoke and
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    52
        // java/lang/ClassLoader
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    53
        Class object_class = Object.class;
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    54
        redefine(agentArgs, instrumentation, object_class);
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    55
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    56
        Class method_class = Method.class;
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    57
        redefine(agentArgs, instrumentation, method_class);
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    58
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    59
        Class loader_class = ClassLoader.class;
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    60
        redefine(agentArgs, instrumentation, loader_class);
17373
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    61
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    62
        instrumentation.removeTransformer(transformer);
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    63
    }
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    64
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    65
    public static void main(String[] args) {
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    66
        byte[] ba = new byte[0];
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    67
22742
441a4617a9f4 8028735: runtime/RedefineObject/TestRedefineObject.java interrupted (timed out?) on solaris_sparcv9-fastdebug-c2-runtime and solaris_x64-debugOpen-c2-runtime
coleenp
parents: 22234
diff changeset
    68
        // If it survives 100 GC's, it's good.
441a4617a9f4 8028735: runtime/RedefineObject/TestRedefineObject.java interrupted (timed out?) on solaris_sparcv9-fastdebug-c2-runtime and solaris_x64-debugOpen-c2-runtime
coleenp
parents: 22234
diff changeset
    69
        for (int i = 0; i < 100 ; i++) {
17373
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    70
            System.gc();
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    71
            ba.clone();
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    72
        }
19278
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    73
        try {
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    74
            // Use java/lang/reflect/Method.invoke to call
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    75
            WalkThroughInvoke a = new WalkThroughInvoke();
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    76
            Class aclass = WalkThroughInvoke.class;
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    77
            Method m = aclass.getMethod("stackWalk");
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    78
            m.invoke(a);
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    79
        } catch (Exception x) {
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    80
            x.printStackTrace();
c4355bebb414 8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents: 17373
diff changeset
    81
        }
17373
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    82
    }
7d8bb2a8787e 8005056: NPG: Crash after redefining java.lang.Object
coleenp
parents:
diff changeset
    83
}