1 import org.objectweb.asm.Opcodes;
2 import org.objectweb.asm.ClassWriter;
3 import org.objectweb.asm.MethodVisitor;
6 import java.util.HashMap;
9 * Special class loader, which when running on Sun VM allows to generate accessor classes for any method
11 public class SunClassLoader extends ClassLoader implements Opcodes {
12 private void loadMagic() {
13 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
14 cw.visit(Opcodes.V1_4, Opcodes.ACC_PUBLIC, "sun/reflect/GroovyMagic", null, "sun/reflect/MagicAccessorImpl", null);
15 MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
17 mv.visitVarInsn(ALOAD, 0);
18 mv.visitMethodInsn(INVOKESPECIAL, "sun/reflect/MagicAccessorImpl", "<init>", "()V", false);
24 define(cw.toByteArray(), "sun.reflect.GroovyMagic");
27 protected void define(byte[] bytes, final String name) {
28 //knownClasses.put(name, defineClass(name, bytes, 0, bytes.length));
29 Class cls = defineClass(name, bytes, 0, bytes.length);
32 protected final Map<String,Class> knownClasses = new HashMap<String,Class>();
34 public static void main(String[] args) {
35 SunClassLoader sun = new SunClassLoader();