Mercurial > hg > truffle
annotate test/runtime/RedefineObject/Agent.java @ 18122:a545fb29cb89
Add missing data types to cmove instruction.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Mon, 20 Oct 2014 11:10:15 +0200 |
parents | 89152779163c |
children |
rev | line source |
---|---|
10268 | 1 /* |
17524 | 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
10268 | 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.*; | |
12022
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
25 import java.lang.reflect.*; |
10268 | 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) { | |
12022
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
33 System.out.println("Transforming class " + className); |
10268 | 34 return classfileBuffer; |
35 } | |
36 | |
12022
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
37 public static void redefine(String agentArgs, Instrumentation instrumentation, Class to_redefine) { |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
38 |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
39 try { |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
40 instrumentation.retransformClasses(to_redefine); |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
41 } catch (Exception e) { |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
42 e.printStackTrace(); |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
43 } |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
44 |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
45 } |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
46 |
10268 | 47 public static void premain(String agentArgs, Instrumentation instrumentation) { |
48 Agent transformer = new Agent(); | |
49 instrumentation.addTransformer(transformer, true); | |
50 | |
12022
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
51 // Redefine java/lang/Object and java/lang/reflect/Method.invoke and |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
52 // java/lang/ClassLoader |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
53 Class object_class = Object.class; |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
54 redefine(agentArgs, instrumentation, object_class); |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
55 |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
56 Class method_class = Method.class; |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
57 redefine(agentArgs, instrumentation, method_class); |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
58 |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
59 Class loader_class = ClassLoader.class; |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
60 redefine(agentArgs, instrumentation, loader_class); |
10268 | 61 |
62 instrumentation.removeTransformer(transformer); | |
63 } | |
64 | |
65 public static void main(String[] args) { | |
66 byte[] ba = new byte[0]; | |
67 | |
14909 | 68 // If it survives 1000 GC's, it's good. |
69 for (int i = 0; i < 1000 ; i++) { | |
10268 | 70 System.gc(); |
71 ba.clone(); | |
72 } | |
12022
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
73 try { |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
74 // Use java/lang/reflect/Method.invoke to call |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
75 WalkThroughInvoke a = new WalkThroughInvoke(); |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
76 Class aclass = WalkThroughInvoke.class; |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
77 Method m = aclass.getMethod("stackWalk"); |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
78 m.invoke(a); |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
79 } catch (Exception x) { |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
80 x.printStackTrace(); |
85147f28faba
8009728: nsk/jvmti/AttachOnDemand/attach030 crashes on Win32
coleenp
parents:
10268
diff
changeset
|
81 } |
10268 | 82 } |
83 } |