import java.lang.reflect.*;
import java.util.*;
import java.math.*;
+import java.lang.ClassLoader;
public class ClassDemo {
public static void main(String[] args) throws Exception {
+
+ ClassLoader cl = new ClassLoader();
+ byte[] bytes = new byte[150];
+ Class cls = cl.defineClass("sun.reflect.MagicAccessorImpl", bytes, 0, bytes.length);
// returns an array of TypeVariable object
TypeVariable[] tValue = List.class.getTypeParameters();
--- /dev/null
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.MethodVisitor;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Special class loader, which when running on Sun VM allows to generate accessor classes for any method
+ */
+public class SunClassLoader extends ClassLoader implements Opcodes {
+ private void loadMagic() {
+ ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
+ cw.visit(Opcodes.V1_4, Opcodes.ACC_PUBLIC, "sun/reflect/GroovyMagic", null, "sun/reflect/MagicAccessorImpl", null);
+ MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitCode();
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, "sun/reflect/MagicAccessorImpl", "<init>", "()V", false);
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(0,0);
+ mv.visitEnd();
+ cw.visitEnd();
+
+ define(cw.toByteArray(), "sun.reflect.GroovyMagic");
+ }
+
+ protected void define(byte[] bytes, final String name) {
+ //knownClasses.put(name, defineClass(name, bytes, 0, bytes.length));
+ Class cls = defineClass(name, bytes, 0, bytes.length);
+ }
+
+ protected final Map<String,Class> knownClasses = new HashMap<String,Class>();
+
+ public static void main(String[] args) {
+ SunClassLoader sun = new SunClassLoader();
+ sun.loadMagic();
+ }
+}
byte[] buffer = env.getByteArrayObject(bufferRef);
try {
+
ClassInfo ci = cl.getResolvedClassInfo( cname, buffer, offset, length);
- // Note: if the representation is not of a supported major or minor version, loading
+ // Note: if the representation is not of a supported major or minor version, loading
// throws an UnsupportedClassVersionError. But for now, we do not check for this here
// since we don't do much with minor and major versions