Mercurial > hg > graal-compiler
annotate test/compiler/jsr292/RedefineMethodUsedByMultipleMethodHandles.java @ 21773:0df7d7d6c25b
AMD64HotSpotMove: split HotSpotLoadConstantOp into HotSpotLoadObjectConstantOp and HotSpotLoadMetaspaceConstantOp.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Mon, 01 Jun 2015 12:16:53 +0200 |
parents | fe34c5ab0b35 |
children |
rev | line source |
---|---|
20677
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
1 /* |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
4 * |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
8 * |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
13 * accompanied this code). |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
14 * |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
18 * |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
21 * questions. |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
22 */ |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
23 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
24 /** |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
25 * @test |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
26 * @bug 8042235 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
27 * @summary redefining method used by multiple MethodHandles crashes VM |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
28 * @compile -XDignore.symbol.file RedefineMethodUsedByMultipleMethodHandles.java |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
29 * @run main RedefineMethodUsedByMultipleMethodHandles |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
30 */ |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
31 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
32 import java.io.*; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
33 import java.lang.instrument.*; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
34 import java.lang.invoke.*; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
35 import java.lang.invoke.MethodHandles.Lookup; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
36 import java.lang.management.*; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
37 import java.lang.reflect.*; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
38 import java.nio.file.*; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
39 import java.security.*; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
40 import java.util.jar.*; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
41 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
42 import javax.tools.*; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
43 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
44 import jdk.internal.org.objectweb.asm.*; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
45 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
46 public class RedefineMethodUsedByMultipleMethodHandles { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
47 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
48 static class Foo { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
49 public static Object getName() { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
50 return "foo"; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
51 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
52 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
53 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
54 public static void main(String[] args) throws Throwable { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
55 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
56 Lookup lookup = MethodHandles.lookup(); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
57 Method fooMethod = Foo.class.getDeclaredMethod("getName"); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
58 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
59 // fooMH2 displaces fooMH1 from the MemberNamesTable |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
60 MethodHandle fooMH1 = lookup.unreflect(fooMethod); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
61 MethodHandle fooMH2 = lookup.unreflect(fooMethod); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
62 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
63 System.out.println("fooMH1.invoke = " + fooMH1.invokeExact()); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
64 System.out.println("fooMH2.invoke = " + fooMH2.invokeExact()); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
65 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
66 // Redefining Foo.getName() causes vmtarget to be updated |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
67 // in fooMH2 but not fooMH1 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
68 redefineFoo(); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
69 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
70 // Full GC causes fooMH1.vmtarget to be deallocated |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
71 System.gc(); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
72 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
73 // Calling fooMH1.vmtarget crashes the VM |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
74 System.out.println("fooMH1.invoke = " + fooMH1.invokeExact()); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
75 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
76 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
77 /** |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
78 * Adds the class file bytes for {@code c} to {@code jar}. |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
79 */ |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
80 static void add(JarOutputStream jar, Class<?> c) throws IOException { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
81 String classAsPath = c.getName().replace('.', '/') + ".class"; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
82 jar.putNextEntry(new JarEntry(classAsPath)); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
83 InputStream stream = c.getClassLoader().getResourceAsStream(classAsPath); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
84 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
85 int b; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
86 while ((b = stream.read()) != -1) { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
87 jar.write(b); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
88 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
89 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
90 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
91 static void redefineFoo() throws Exception { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
92 Manifest manifest = new Manifest(); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
93 manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
94 Attributes mainAttrs = manifest.getMainAttributes(); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
95 mainAttrs.putValue("Agent-Class", FooAgent.class.getName()); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
96 mainAttrs.putValue("Can-Redefine-Classes", "true"); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
97 mainAttrs.putValue("Can-Retransform-Classes", "true"); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
98 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
99 Path jar = Files.createTempFile("myagent", ".jar"); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
100 try { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
101 JarOutputStream jarStream = new JarOutputStream(new FileOutputStream(jar.toFile()), manifest); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
102 add(jarStream, FooAgent.class); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
103 add(jarStream, FooTransformer.class); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
104 jarStream.close(); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
105 runAgent(jar); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
106 } finally { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
107 Files.deleteIfExists(jar); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
108 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
109 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
110 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
111 public static void runAgent(Path agent) throws Exception { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
112 String vmName = ManagementFactory.getRuntimeMXBean().getName(); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
113 int p = vmName.indexOf('@'); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
114 assert p != -1 : "VM name not in <pid>@<host> format: " + vmName; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
115 String pid = vmName.substring(0, p); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
116 ClassLoader cl = ToolProvider.getSystemToolClassLoader(); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
117 Class<?> c = Class.forName("com.sun.tools.attach.VirtualMachine", true, cl); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
118 Method attach = c.getDeclaredMethod("attach", String.class); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
119 Method loadAgent = c.getDeclaredMethod("loadAgent", String.class); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
120 Method detach = c.getDeclaredMethod("detach"); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
121 Object vm = attach.invoke(null, pid); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
122 loadAgent.invoke(vm, agent.toString()); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
123 detach.invoke(vm); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
124 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
125 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
126 public static class FooAgent { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
127 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
128 public static void agentmain(@SuppressWarnings("unused") String args, Instrumentation inst) throws Exception { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
129 assert inst.isRedefineClassesSupported(); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
130 assert inst.isRetransformClassesSupported(); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
131 inst.addTransformer(new FooTransformer(), true); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
132 Class<?>[] classes = inst.getAllLoadedClasses(); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
133 for (int i = 0; i < classes.length; i++) { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
134 Class<?> c = classes[i]; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
135 if (c == Foo.class) { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
136 inst.retransformClasses(new Class[]{c}); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
137 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
138 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
139 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
140 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
141 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
142 static class FooTransformer implements ClassFileTransformer { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
143 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
144 @Override |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
145 public byte[] transform(ClassLoader cl, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
146 if (Foo.class.equals(classBeingRedefined)) { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
147 System.out.println("redefining " + classBeingRedefined); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
148 ClassReader cr = new ClassReader(classfileBuffer); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
149 ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
150 ClassVisitor adapter = new ClassVisitor(Opcodes.ASM5, cw) { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
151 @Override |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
152 public MethodVisitor visitMethod(int access, String base, String desc, String signature, String[] exceptions) { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
153 MethodVisitor mv = cv.visitMethod(access, base, desc, signature, exceptions); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
154 if (mv != null) { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
155 mv = new MethodVisitor(Opcodes.ASM5, mv) { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
156 @Override |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
157 public void visitLdcInsn(Object cst) { |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
158 System.out.println("replacing \"" + cst + "\" with \"bar\""); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
159 mv.visitLdcInsn("bar"); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
160 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
161 }; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
162 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
163 return mv; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
164 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
165 }; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
166 |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
167 cr.accept(adapter, ClassReader.SKIP_FRAMES); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
168 cw.visitEnd(); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
169 return cw.toByteArray(); |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
170 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
171 return classfileBuffer; |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
172 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
173 } |
fe34c5ab0b35
8042235: redefining method used by multiple MethodHandles crashes VM
coleenp
parents:
diff
changeset
|
174 } |