author | ykantser |
Thu, 26 Mar 2015 16:36:56 +0100 | |
changeset 29678 | dd2f3932c21e |
parent 22742 | 441a4617a9f4 |
permissions | -rw-r--r-- |
17373 | 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 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
import java.security.*; |
|
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 | 26 |
|
27 |
public class Agent implements ClassFileTransformer { |
|
28 |
public synchronized byte[] transform(final ClassLoader classLoader, |
|
29 |
final String className, |
|
30 |
Class<?> classBeingRedefined, |
|
31 |
ProtectionDomain protectionDomain, |
|
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 | 34 |
return classfileBuffer; |
35 |
} |
|
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 | 47 |
public static void premain(String agentArgs, Instrumentation instrumentation) { |
48 |
Agent transformer = new Agent(); |
|
49 |
instrumentation.addTransformer(transformer, true); |
|
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 | 61 |
|
62 |
instrumentation.removeTransformer(transformer); |
|
63 |
} |
|
64 |
||
65 |
public static void main(String[] args) { |
|
66 |
byte[] ba = new byte[0]; |
|
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 | 70 |
System.gc(); |
71 |
ba.clone(); |
|
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 | 82 |
} |
83 |
} |