private void writeWithQualifierMethod(ClassWriter proxyClassWriter) { GeneratorAdapter withQualifierMethod = startPublicMethod(proxyClassWriter, "$withBeanQualifier", void.class.getName(), Qualifier.class.getName()); withQualifierMethod.loadThis(); withQualifierMethod.loadArg(0); withQualifierMethod.putField(proxyType, FIELD_BEAN_QUALIFIER, Type.getType(Qualifier.class)); withQualifierMethod.visitInsn(RETURN); withQualifierMethod.visitEnd(); withQualifierMethod.visitMaxs(1, 1); }
GeneratorAdapter bridgeGenerator = new GeneratorAdapter(bridgeWriter, ACC_STATIC + ACC_SYNTHETIC, bridgeName, bridgeDesc); for (int i = 0; i < bridgeArguments.size(); i++) { bridgeGenerator.loadArg(i);
private void writeConstructor() { org.objectweb.asm.commons.Method initMethod = new org.objectweb.asm.commons.Method("<init>", Type.VOID_TYPE, new Type[] {targetType}); GeneratorAdapter init = new GeneratorAdapter(ACC_PUBLIC, initMethod, null, null, this); init.loadThis(); init.invokeConstructor(OBJECT_TYPE, OBJECT_INIT); init.loadThis(); init.loadArg(0); init.putField(reflectorType, TARGET_FIELD, targetType); init.returnValue(); init.endMethod(); }
@Override protected void buildInvokeMethod(Type declaringTypeObject, String methodName, Object returnType, Collection<Object> argumentTypes, GeneratorAdapter invokeMethodVisitor) { // load this invokeMethodVisitor.loadThis(); // first argument to static bridge is reference to parent invokeMethodVisitor.getField(methodType, FIELD_PARENT, proxyType); // now remaining arguments for (int i = 0; i < argumentTypeList.size(); i++) { invokeMethodVisitor.loadArg(1); invokeMethodVisitor.push(i); invokeMethodVisitor.visitInsn(AALOAD); AopProxyWriter.pushCastToType(invokeMethodVisitor, argumentTypeList.get(i)); } invokeMethodVisitor.visitMethodInsn(INVOKESTATIC, proxyInternalName, bridgeName, bridgeDesc, false); if (isVoidReturn) { invokeMethodVisitor.visitInsn(ACONST_NULL); } else { AopProxyWriter.pushBoxPrimitiveIfNecessary(returnType, invokeMethodVisitor); } invokeMethodVisitor.visitInsn(ARETURN); invokeMethodVisitor.visitMaxs(AbstractClassFileWriter.DEFAULT_MAX_STACK, 1); invokeMethodVisitor.visitEnd(); }
private void pushResolveInterceptorsCall(GeneratorAdapter proxyConstructorGenerator, int i) { // The following will initialize the array of interceptor instances // eg. this.interceptors[0] = InterceptorChain.resolveAroundInterceptors(beanContext, proxyMethods[0], interceptors); proxyConstructorGenerator.loadThis(); proxyConstructorGenerator.getField(proxyType, FIELD_INTERCEPTORS, FIELD_TYPE_INTERCEPTORS); proxyConstructorGenerator.push(i); // First argument. The bean context proxyConstructorGenerator.loadArg(beanContextArgumentIndex); // Second argument ie. proxyMethods[0] proxyConstructorGenerator.loadThis(); proxyConstructorGenerator.getField(proxyType, FIELD_PROXY_METHODS, FIELD_TYPE_PROXY_METHODS); proxyConstructorGenerator.push(i); proxyConstructorGenerator.visitInsn(AALOAD); // Third argument ie. interceptors proxyConstructorGenerator.loadArg(interceptorArgumentIndex); if (isIntroduction) { proxyConstructorGenerator.invokeStatic(TYPE_INTERCEPTOR_CHAIN, Method.getMethod(RESOLVE_INTRODUCTION_INTERCEPTORS_METHOD)); } else { proxyConstructorGenerator.invokeStatic(TYPE_INTERCEPTOR_CHAIN, Method.getMethod(RESOLVE_AROUND_INTERCEPTORS_METHOD)); } proxyConstructorGenerator.visitInsn(AASTORE); }
Collection<Object> existingArguments = constructorArgumentTypes.values(); for (int i = 0; i < existingArguments.size(); i++) { proxyConstructorGenerator.loadArg(i); proxyConstructorGenerator.loadArg(beanContextArgumentIndex); proxyConstructorGenerator.putField(proxyType, FIELD_BEAN_LOCATOR, TYPE_BEAN_LOCATOR); proxyConstructorGenerator.loadArg(beanContextArgumentIndex);
Object argType = argumentTypeList.get(i); overriddenMethodGenerator.push(i); overriddenMethodGenerator.loadArg(i); pushBoxPrimitiveIfNecessary(argType, overriddenMethodGenerator); overriddenMethodGenerator.visitInsn(AASTORE);
@Override public void compile(GeneratorAdapter ga, int narg) { ga.loadArg(narg); }
@Override public void compile(GeneratorAdapter ga, int narg) { ga.loadArg(narg); }
@Override public void addGuard(Label returnFalse, GeneratorAdapter gm, GeneratorAdapter cm, GeneratorAdapter sm, ClassWriter cw, AtomicInteger atomicId, List<Object> cargs, Type thisType) { // If objects is null return false gm.loadArg(0); gm.ifNull(returnFalse); // If they are not equal return false gm.loadArg(0); gm.invokeInterface(LIST_TYPE, Method.getMethod("int size()")); gm.push(length); gm.ifICmp(GeneratorAdapter.NE, returnFalse); }
/** * Generates method body for encoding an compile time int value. * @param mg Method body generator * @param intValue The integer constant value to encode * @param encoder Method argument index of the encoder */ private void encodeInt(GeneratorAdapter mg, int intValue, int encoder) { mg.loadArg(encoder); mg.push(intValue); mg.invokeInterface(Type.getType(Encoder.class), getMethod(Encoder.class, "writeInt", int.class)); mg.pop(); }
/** * Generates method body for encoding an compile time int value. * @param mg Method body generator * @param intValue The integer constant value to encode * @param encoder Method argument index of the encoder */ private void encodeInt(GeneratorAdapter mg, int intValue, int encoder) { mg.loadArg(encoder); mg.push(intValue); mg.invokeInterface(Type.getType(Encoder.class), getMethod(Encoder.class, "writeInt", int.class)); mg.pop(); }
/** * Generates method body for encoding an compile time int value. * @param mg Method body generator * @param intValue The integer constant value to encode * @param encoder Method argument index of the encoder */ private void encodeInt(GeneratorAdapter mg, int intValue, int encoder) { mg.loadArg(encoder); mg.push(intValue); mg.invokeInterface(Type.getType(Encoder.class), getMethod(Encoder.class, "writeInt", int.class)); mg.pop(); }
@Override public void addGuard(Label returnFalse, GeneratorAdapter gm, GeneratorAdapter cm, GeneratorAdapter sm, ClassWriter cw, AtomicInteger atomicId, List<Object> cargs, Type thisType) { gm.loadArg(0); gm.push(0); gm.invokeInterface(LIST_TYPE, Method.getMethod("Object get(int)")); gm.ifNonNull(returnFalse); } }
/** * Generates the instructions to load all the method arguments on the stack, as a single object * array. */ public void loadArgArray() { push(argumentTypes.length); newArray(OBJECT_TYPE); for (int i = 0; i < argumentTypes.length; i++) { dup(); push(i); loadArg(i); box(argumentTypes[i]); arrayStore(OBJECT_TYPE); } }
/** * Generates the instructions to load all the method arguments on the stack, * as a single object array. */ public void loadArgArray() { push(argumentTypes.length); newArray(OBJECT_TYPE); for (int i = 0; i < argumentTypes.length; i++) { dup(); push(i); loadArg(i); box(argumentTypes[i]); arrayStore(OBJECT_TYPE); } }
/** * Generates the instructions to load all the method arguments on the stack, as a single object * array. */ public void loadArgArray() { push(argumentTypes.length); newArray(OBJECT_TYPE); for (int i = 0; i < argumentTypes.length; i++) { dup(); push(i); loadArg(i); box(argumentTypes[i]); arrayStore(OBJECT_TYPE); } }
/** * Generates the instructions to load all the method arguments on the stack, as a single object * array. */ public void loadArgArray() { push(argumentTypes.length); newArray(OBJECT_TYPE); for (int i = 0; i < argumentTypes.length; i++) { dup(); push(i); loadArg(i); box(argumentTypes[i]); arrayStore(OBJECT_TYPE); } }
private void writeConstructor() { org.objectweb.asm.commons.Method initMethod = new org.objectweb.asm.commons.Method("<init>", Type.VOID_TYPE, new Type[] {targetType}); GeneratorAdapter init = new GeneratorAdapter(ACC_PUBLIC, initMethod, null, null, this); init.loadThis(); init.invokeConstructor(OBJECT_TYPE, OBJECT_INIT); init.loadThis(); init.loadArg(0); init.putField(reflectorType, TARGET_FIELD, targetType); init.returnValue(); init.endMethod(); }
private static void init(ClassWriter cw, Type proxyType, Type superType) { GeneratorAdapter mg = new GeneratorAdapter(ACC_PUBLIC, new org.objectweb.asm.commons.Method("<init>", Type.VOID_TYPE, new Type[] {INVOKER_TYPE}), null, null, cw); // invoke super constructor: mg.loadThis(); mg.invokeConstructor(superType, org.objectweb.asm.commons.Method.getMethod("void <init> ()")); // assign handler: mg.loadThis(); mg.loadArg(0); mg.putField(proxyType, HANDLER_NAME, INVOKER_TYPE); mg.returnValue(); mg.endMethod(); }