use of org.objectweb.asm.FieldVisitor in project spring-loaded by spring-projects.
the class SystemClassReflectionGenerator method generateJLCGDC.
public static void generateJLCGDC(ClassWriter cw, String classname) {
FieldVisitor fv = cw.visitField(ACC_PUBLIC + ACC_STATIC, "__sljlcgdc", "Ljava/lang/reflect/Method;", null, null);
fv.visitEnd();
MethodVisitor mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC + ACC_VARARGS, "__sljlcgdc", "(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/lang/reflect/Constructor;", null, new String[] { "java/lang/NoSuchMethodException" });
mv.visitCode();
Label l0 = new Label();
Label l1 = new Label();
Label l2 = new Label();
mv.visitTryCatchBlock(l0, l1, l2, "java/lang/reflect/InvocationTargetException");
Label l3 = new Label();
mv.visitTryCatchBlock(l0, l1, l3, "java/lang/Exception");
Label l4 = new Label();
mv.visitLabel(l4);
mv.visitFieldInsn(GETSTATIC, classname, "__sljlcgdc", "Ljava/lang/reflect/Method;");
mv.visitJumpInsn(IFNONNULL, l0);
Label l5 = new Label();
mv.visitLabel(l5);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getDeclaredConstructor", "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;", false);
mv.visitInsn(ARETURN);
mv.visitLabel(l0);
mv.visitFieldInsn(GETSTATIC, classname, "__sljlcgdc", "Ljava/lang/reflect/Method;");
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ICONST_2);
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
mv.visitInsn(DUP);
mv.visitInsn(ICONST_0);
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(AASTORE);
mv.visitInsn(DUP);
mv.visitInsn(ICONST_1);
mv.visitVarInsn(ALOAD, 1);
mv.visitInsn(AASTORE);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Method", "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", false);
mv.visitTypeInsn(CHECKCAST, "java/lang/reflect/Constructor");
mv.visitLabel(l1);
mv.visitInsn(ARETURN);
mv.visitLabel(l2);
mv.visitVarInsn(ASTORE, 2);
Label l6 = new Label();
mv.visitLabel(l6);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/InvocationTargetException", "printStackTrace", "()V", false);
Label l7 = new Label();
mv.visitLabel(l7);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/InvocationTargetException", "getCause", "()Ljava/lang/Throwable;", false);
mv.visitTypeInsn(INSTANCEOF, "java/lang/NoSuchMethodException");
Label l8 = new Label();
mv.visitJumpInsn(IFEQ, l8);
Label l9 = new Label();
mv.visitLabel(l9);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/InvocationTargetException", "getCause", "()Ljava/lang/Throwable;", false);
mv.visitTypeInsn(CHECKCAST, "java/lang/NoSuchMethodException");
mv.visitInsn(ATHROW);
mv.visitLabel(l3);
mv.visitVarInsn(ASTORE, 2);
Label l10 = new Label();
mv.visitLabel(l10);
// mv.visitVarInsn(ALOAD, 2);
// mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V");
mv.visitLabel(l8);
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ARETURN);
Label l11 = new Label();
mv.visitLabel(l11);
// mv.visitLocalVariable("clazz", "Ljava/lang/Class;", "Ljava/lang/Class<*>;", l4, l11, 0);
// mv.visitLocalVariable("parameterTypes", "[Ljava/lang/Class;", null, l4, l11, 1);
// mv.visitLocalVariable("ite", "Ljava/lang/reflect/InvocationTargetException;", null, l6, l3, 2);
// mv.visitLocalVariable("e", "Ljava/lang/Exception;", null, l10, l8, 2);
mv.visitMaxs(6, 3);
mv.visitEnd();
}
use of org.objectweb.asm.FieldVisitor in project spring-loaded by spring-projects.
the class SystemClassReflectionGenerator method generateJLCGMODS.
public static void generateJLCGMODS(ClassWriter cw, String classname) {
FieldVisitor fv = cw.visitField(ACC_PUBLIC + ACC_STATIC, "__sljlcgmods", "Ljava/lang/reflect/Method;", null, null);
fv.visitEnd();
MethodVisitor mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC, "__sljlcgmods", "(Ljava/lang/Class;)I", "(Ljava/lang/Class<*>;)I", null);
mv.visitCode();
Label l0 = new Label();
Label l1 = new Label();
Label l2 = new Label();
mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
Label l3 = new Label();
mv.visitLabel(l3);
mv.visitFieldInsn(GETSTATIC, classname, "__sljlcgmods", "Ljava/lang/reflect/Method;");
mv.visitJumpInsn(IFNONNULL, l0);
Label l4 = new Label();
mv.visitLabel(l4);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getModifiers", "()I", false);
mv.visitInsn(IRETURN);
mv.visitLabel(l0);
mv.visitFieldInsn(GETSTATIC, classname, "__sljlcgmods", "Ljava/lang/reflect/Method;");
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ICONST_1);
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
mv.visitInsn(DUP);
mv.visitInsn(ICONST_0);
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(AASTORE);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Method", "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", false);
mv.visitTypeInsn(CHECKCAST, "java/lang/Integer");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false);
mv.visitLabel(l1);
mv.visitInsn(IRETURN);
mv.visitLabel(l2);
mv.visitVarInsn(ASTORE, 1);
Label l5 = new Label();
mv.visitLabel(l5);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V", false);
Label l6 = new Label();
mv.visitLabel(l6);
mv.visitInsn(ICONST_0);
mv.visitInsn(IRETURN);
Label l7 = new Label();
mv.visitLabel(l7);
// mv.visitLocalVariable("clazz", "Ljava/lang/Class;", "Ljava/lang/Class<*>;", l3, l7, 0);
// mv.visitLocalVariable("e", "Ljava/lang/Exception;", null, l5, l7, 1);
mv.visitMaxs(6, 2);
mv.visitEnd();
}
use of org.objectweb.asm.FieldVisitor in project spring-loaded by spring-projects.
the class SystemClassReflectionGenerator method generateJLRF_GetLong.
// public static Method __sljlcgdfs;
// @SuppressWarnings("unused")
// private static Field[] __sljlcgdfs(Class<?> clazz) {
// if (__sljlcgdfs == null) {
// return clazz.getDeclaredFields();
// }
// try {
// return (Field[]) __sljlcgdfs.invoke(null, clazz);
// } catch (Exception e) {
// return null;
// }
// }
// public static Method __sljlcgdms;
// @SuppressWarnings("unused")
// private static Method[] __sljlcgdms(Class<?> clazz) {
// if (__sljlcgdms == null) {
// return clazz.getDeclaredMethods();
// }
// try {
// return (Method[]) __sljlcgdms.invoke(null, clazz);
// } catch (Exception e) {
// return null;
// }
// }
// public static Method __sljlcgdf;
// @SuppressWarnings("unused")
// private static Field __sljlcgdf(Class<?> clazz, String fieldname) throws NoSuchFieldException {
// if (__sljlcgdf == null) {
// return clazz.getDeclaredField(fieldname);
// }
// try {
// return (Field) __sljlcgdf.invoke(null, clazz, fieldname);
// } catch (InvocationTargetException ite) {
// if (ite.getCause() instanceof NoSuchFieldException) {
// throw (NoSuchFieldException) ite.getCause();
// }
// } catch (Exception e) {
// }
// return null;
// }
// public static Method __sljlcgdm;
//
// @SuppressWarnings("unused")
// private static Method __sljlcgdm(Class<?> clazz, String methodname, Class... parameterTypes) throws NoSuchMethodException {
// if (__sljlcgdm == null) {
// return clazz.getDeclaredMethod(methodname, parameterTypes);
// }
// try {
// // if (parameterTypes == null) {
// return (Method) __sljlcgdm.invoke(null, clazz, methodname, parameterTypes);
// // } else {
// // Object[] params = new Object[2 + parameterTypes.length];
// // System.arraycopy(parameterTypes, 0, params, 2, parameterTypes.length);
// // params[0] = clazz;
// // params[1] = methodname;
// // return (Method) __sljlcgdm.invoke(null, clazz, methodname, parameterTypes);
// // }
// } catch (InvocationTargetException ite) {
// ite.printStackTrace();
// if (ite.getCause() instanceof NoSuchMethodException) {
// throw (NoSuchMethodException) ite.getCause();
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// return null;
// }
// public static Method __sljlcgdc;
//
// @SuppressWarnings("unused")
// private static Constructor __sljlcgdc(Class<?> clazz, Class... parameterTypes) throws NoSuchMethodException {
// if (__sljlcgdc == null) {
// return clazz.getDeclaredConstructor(parameterTypes);
// }
// try {
// return (Constructor) __sljlcgdc.invoke(null, clazz, parameterTypes);
// } catch (InvocationTargetException ite) {
// ite.printStackTrace();
// if (ite.getCause() instanceof NoSuchMethodException) {
// throw (NoSuchMethodException) ite.getCause();
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// return null;
// }
// public static Method __sljlcgmods;
//
// @SuppressWarnings("unused")
// private static int __sljlcgmods(Class<?> clazz) {
// if (__sljlcgmods == null) {
// return clazz.getModifiers();
// }
// try {
// return (Integer) __sljlcgmods.invoke(null, clazz);
// } catch (Exception e) {
// e.printStackTrace();
// return 0;
// }
// }
// public static Method __sljlcgdcs;
// private static Constructor[] __sljlcgdcs(Class<?> clazz) {
// if (__sljlcgdcs == null) {
// return clazz.getDeclaredConstructors();
// }
// try {
// return (Constructor[])__sljlcgdcs.invoke(null,clazz);
// } catch (Exception e) {
// return null;
// }
// }
// public static Method __sljlrmi;
// private static Object __sljlrmi(Method method, Object instance, Object[] args) throws InvocationTargetException, IllegalAccessException {
// if (__sljlrmi == null) {
// return method.invoke(instance,args);
// }
// try {
// return __sljlrmi.invoke(null, method, instance, args);
// } catch (Exception e) {
// return null;
// }
// }
// public static Method __sljlrfg;
// private static Object __sljlrfg(Field field, Object instance) throws IllegalArgumentException, IllegalAccessException {
// if (__sljlrfg == null) {
// return field.get(instance);
// }
// try {
// return __sljlrfg.invoke(null, field,instance);
// } catch (Exception e) {
// return null;
// }
// }
// public static Method __sljlrfgl;
// private static long __sljlrfgl(Field field, Object instance) throws IllegalArgumentException, IllegalAccessException {
// if (__sljlrfgl == null) {
// return field.getLong(instance);
// }
// try {
// return (Long)__sljlrfgl.invoke(null, field, instance);
// } catch (Exception e) {
// return 0;
// }
// }
public static void generateJLRF_GetLong(ClassWriter cw, String classname) {
FieldVisitor fv = cw.visitField(ACC_PUBLIC + ACC_STATIC, jlrfGetLongMember, "Ljava/lang/reflect/Method;", null, null);
fv.visitEnd();
MethodVisitor mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC, jlrfGetLongMember, jlrfGetLongDescriptor, null, new String[] { "java/lang/IllegalAccessException", "java/lang/IllegalArgumentException" });
mv.visitCode();
Label l0 = new Label();
Label l1 = new Label();
Label l2 = new Label();
mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
Label l3 = new Label();
mv.visitLabel(l3);
mv.visitFieldInsn(GETSTATIC, classname, jlrfGetLongMember, "Ljava/lang/reflect/Method;");
mv.visitJumpInsn(IFNONNULL, l0);
Label l4 = new Label();
mv.visitLabel(l4);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Field", "getLong", "(Ljava/lang/Object;)J");
mv.visitInsn(LRETURN);
mv.visitLabel(l0);
mv.visitFieldInsn(GETSTATIC, classname, jlrfGetLongMember, "Ljava/lang/reflect/Method;");
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ICONST_2);
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
mv.visitInsn(DUP);
mv.visitInsn(ICONST_0);
// target field
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(AASTORE);
mv.visitInsn(DUP);
mv.visitInsn(ICONST_1);
// instance on which to get the field
mv.visitVarInsn(ALOAD, 1);
mv.visitInsn(AASTORE);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Method", "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;");
mv.visitLabel(l1);
mv.visitTypeInsn(CHECKCAST, "java/lang/Long");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J");
mv.visitInsn(LRETURN);
mv.visitLabel(l2);
mv.visitVarInsn(ASTORE, 2);
Label l5 = new Label();
mv.visitLabel(l5);
Label l6 = new Label();
mv.visitLabel(l6);
mv.visitLdcInsn(0L);
mv.visitInsn(LRETURN);
Label l7 = new Label();
mv.visitLabel(l7);
mv.visitMaxs(8, 4);
mv.visitEnd();
}
use of org.objectweb.asm.FieldVisitor in project spring-loaded by spring-projects.
the class SystemClassReflectionGenerator method generateJLCGC.
public static void generateJLCGC(ClassWriter cw, String classname) {
FieldVisitor fv = cw.visitField(ACC_PUBLIC + ACC_STATIC, "__sljlcgc", "Ljava/lang/reflect/Method;", null, null);
fv.visitEnd();
MethodVisitor mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC + ACC_VARARGS, "__sljlcgc", "(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/lang/reflect/Constructor;", null, new String[] { "java/lang/NoSuchMethodException" });
mv.visitCode();
Label l0 = new Label();
Label l1 = new Label();
Label l2 = new Label();
mv.visitTryCatchBlock(l0, l1, l2, "java/lang/reflect/InvocationTargetException");
Label l3 = new Label();
mv.visitTryCatchBlock(l0, l1, l3, "java/lang/Exception");
Label l4 = new Label();
mv.visitLabel(l4);
mv.visitFieldInsn(GETSTATIC, classname, "__sljlcgc", "Ljava/lang/reflect/Method;");
mv.visitJumpInsn(IFNONNULL, l0);
Label l5 = new Label();
mv.visitLabel(l5);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getConstructor", "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;", false);
mv.visitInsn(ARETURN);
mv.visitLabel(l0);
mv.visitFieldInsn(GETSTATIC, classname, "__sljlcgc", "Ljava/lang/reflect/Method;");
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ICONST_2);
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
mv.visitInsn(DUP);
mv.visitInsn(ICONST_0);
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(AASTORE);
mv.visitInsn(DUP);
mv.visitInsn(ICONST_1);
mv.visitVarInsn(ALOAD, 1);
mv.visitInsn(AASTORE);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Method", "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", false);
mv.visitTypeInsn(CHECKCAST, "java/lang/reflect/Constructor");
mv.visitLabel(l1);
mv.visitInsn(ARETURN);
mv.visitLabel(l2);
mv.visitVarInsn(ASTORE, 2);
Label l6 = new Label();
mv.visitLabel(l6);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/InvocationTargetException", "printStackTrace", "()V", false);
Label l7 = new Label();
mv.visitLabel(l7);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/InvocationTargetException", "getCause", "()Ljava/lang/Throwable;", false);
mv.visitTypeInsn(INSTANCEOF, "java/lang/NoSuchMethodException");
Label l8 = new Label();
mv.visitJumpInsn(IFEQ, l8);
Label l9 = new Label();
mv.visitLabel(l9);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/InvocationTargetException", "getCause", "()Ljava/lang/Throwable;", false);
mv.visitTypeInsn(CHECKCAST, "java/lang/NoSuchMethodException");
mv.visitInsn(ATHROW);
mv.visitLabel(l3);
mv.visitVarInsn(ASTORE, 2);
Label l10 = new Label();
mv.visitLabel(l10);
// mv.visitVarInsn(ALOAD, 2);
// mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V");
mv.visitLabel(l8);
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ARETURN);
Label l11 = new Label();
mv.visitLabel(l11);
// mv.visitLocalVariable("clazz", "Ljava/lang/Class;", "Ljava/lang/Class<*>;", l4, l11, 0);
// mv.visitLocalVariable("parameterTypes", "[Ljava/lang/Class;", null, l4, l11, 1);
// mv.visitLocalVariable("ite", "Ljava/lang/reflect/InvocationTargetException;", null, l6, l3, 2);
// mv.visitLocalVariable("e", "Ljava/lang/Exception;", null, l10, l8, 2);
mv.visitMaxs(6, 3);
mv.visitEnd();
}
use of org.objectweb.asm.FieldVisitor in project spring-loaded by spring-projects.
the class SystemClassReflectionGenerator method generateJLCGDMS.
// TODO remove extraneous visits to things like lvar names
public static void generateJLCGDMS(ClassWriter cw, String classname, String field, String methodname) {
FieldVisitor fv = cw.visitField(ACC_PUBLIC + ACC_STATIC, field, "Ljava/lang/reflect/Method;", null, null);
fv.visitEnd();
MethodVisitor mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC, field, "(Ljava/lang/Class;)[Ljava/lang/reflect/Method;", null, null);
mv.visitCode();
Label l0 = new Label();
Label l1 = new Label();
Label l2 = new Label();
mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
Label l3 = new Label();
mv.visitLabel(l3);
mv.visitFieldInsn(GETSTATIC, classname, field, "Ljava/lang/reflect/Method;");
mv.visitJumpInsn(IFNONNULL, l0);
Label l4 = new Label();
mv.visitLabel(l4);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", methodname, "()[Ljava/lang/reflect/Method;", false);
mv.visitInsn(ARETURN);
mv.visitLabel(l0);
mv.visitFieldInsn(GETSTATIC, classname, field, "Ljava/lang/reflect/Method;");
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ICONST_1);
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
mv.visitInsn(DUP);
mv.visitInsn(ICONST_0);
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(AASTORE);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Method", "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", false);
mv.visitTypeInsn(CHECKCAST, "[Ljava/lang/reflect/Method;");
mv.visitLabel(l1);
mv.visitInsn(ARETURN);
mv.visitLabel(l2);
mv.visitVarInsn(ASTORE, 1);
Label l5 = new Label();
mv.visitLabel(l5);
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ARETURN);
Label l6 = new Label();
mv.visitLabel(l6);
// mv.visitLocalVariable("clazz", "Ljava/lang/Class;", "Ljava/lang/Class<*>;", l3, l6, 0);
// mv.visitLocalVariable("e", "Ljava/lang/Exception;", null, l5, l6, 1);
mv.visitMaxs(6, 2);
mv.visitEnd();
}
Aggregations