equal
deleted
inserted
replaced
149 two main classes. This is the class we will run under the debugger. |
149 two main classes. This is the class we will run under the debugger. |
150 Package access so we can define in the same source file for ease of |
150 Package access so we can define in the same source file for ease of |
151 reference. |
151 reference. |
152 */ |
152 */ |
153 class Target { |
153 class Target { |
|
154 |
|
155 static Class<?> topLevelHostA; // Prevent unloading of the class |
|
156 |
154 // We have to load all of the variants of the classes that we will |
157 // We have to load all of the variants of the classes that we will |
155 // attempt to redefine. This requires some in-memory compilation |
158 // attempt to redefine. This requires some in-memory compilation |
156 // and use of additional classloaders. |
159 // and use of additional classloaders. |
|
160 |
157 public static void main(String[] args) throws Throwable { |
161 public static void main(String[] args) throws Throwable { |
158 String origin = args[0]; |
162 String origin = args[0]; |
159 System.out.println("Target: Testing original Host class from " + origin); |
163 System.out.println("Target: Testing original Host class from " + origin); |
160 |
164 |
161 // Make sure the Host class loaded directly is an original version |
165 // Make sure the Host class loaded directly is an original version |
176 // This is compiled as a top-level class: the $ in the name is not |
180 // This is compiled as a top-level class: the $ in the name is not |
177 // significant to the compiler. |
181 // significant to the compiler. |
178 String hostA = "public class " + name + " {}"; |
182 String hostA = "public class " + name + " {}"; |
179 byte[] bytes = InMemoryJavaCompiler.compile(name, hostA); |
183 byte[] bytes = InMemoryJavaCompiler.compile(name, hostA); |
180 // And we have to load this into a new classloader |
184 // And we have to load this into a new classloader |
181 Class<?> topLevelHostA = ByteCodeLoader.load(name, bytes); |
185 topLevelHostA = ByteCodeLoader.load(name, bytes); |
182 // The loaded class has not been linked (as per ClassLoader.resolveClass) |
186 // The loaded class has not been linked (as per ClassLoader.resolveClass) |
183 // and so will be filtered out by VirtualMachine.allClasses(). There are |
187 // and so will be filtered out by VirtualMachine.allClasses(). There are |
184 // a number of ways to force linking - this is the simplest. |
188 // a number of ways to force linking - this is the simplest. |
185 Object o = topLevelHostA.newInstance(); |
189 Object o = topLevelHostA.newInstance(); |
186 |
190 |