@Override void doWork(CodeAttribute b, ClassMethod classMethod) { loadBeanInstance(classMethod.getClassFile(), methodInfo, b); //now we should have the target bean instance on top of the stack // we need to dup it so we still have it to compare to the return value b.dup(); //lets create the method invocation String methodDescriptor = methodInfo.getDescriptor(); b.loadMethodParameters(); if (method.getDeclaringClass().isInterface()) { b.invokeinterface(methodInfo.getDeclaringClass(), methodInfo.getName(), methodDescriptor); } else { b.invokevirtual(methodInfo.getDeclaringClass(), methodInfo.getName(), methodDescriptor); } }
final CodeAttribute b = classMethod.getCodeAttribute(); b.aload(0); // load this int localVariables = 1; int actualDelegateParameterPosition = 0; for (int i = 0; i < initializerMethodInfo.getMethod().getParameterTypes().length; ++i) { if (i == delegateParameterPosition) { Class<?> type = initializerMethodInfo.getMethod().getParameterTypes()[i]; BytecodeUtils.addLoadInstruction(b, DescriptorUtils.makeDescriptor(type), localVariables); if (type == long.class || type == double.class) { localVariables = localVariables + 2; b.invokespecial(classMethod.getClassFile().getSuperclass(), initializerMethodInfo.getName(), initializerMethodInfo.getDescriptor()); b.aload(0); // load this b.aload(actualDelegateParameterPosition); // load the delegate b.invokevirtual(classMethod.getClassFile().getName(), INIT_MH_METHOD_NAME, "(" + LJAVA_LANG_OBJECT + ")" + BytecodeUtils.VOID_CLASS_DESCRIPTOR);
@Override void doWork(CodeAttribute b, ClassMethod classMethod) { if (Modifier.isPrivate(classMethod.getAccessFlags())) { // Weld cannot use invokespecial to invoke a private method from the superclass invokePrivateMethodHandler(b, classMethod, methodInfo, staticConstructor); } else { // build the bytecode that invokes the super class method directly b.aload(0); // create the method invocation b.loadMethodParameters(); b.invokespecial(methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getDescriptor()); } // leave the result on top of the stack }
private void createDelegateToSuper(ClassMethod classMethod, MethodInformation method, String className) { CodeAttribute b = classMethod.getCodeAttribute(); // first generate the invokespecial call to the super class method b.aload(0); b.loadMethodParameters(); b.invokespecial(className, method.getName(), method.getDescriptor()); b.returnInstruction(); }
b.dup(); b.invokestatic(InterceptionDecorationContext.class.getName(), "getStack", "()" + DescriptorUtils.makeDescriptor(Stack.class)); if (!Reflections.isDefault(methodInfo.getMethod()) && !Modifier.isPrivate(method.getAccessFlags())) { b.invokespecial(methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getDescriptor()); bytecodeMethodResolver.getDeclaredMethod(method, methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getParameterTypes(), staticConstructor); bytecodeMethodResolver.getDeclaredMethod(method, methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getParameterTypes(), staticConstructor); } else { bytecodeMethodResolver.getDeclaredMethod(method, method.getClassFile().getName(), methodInfo.getName() + SUPER_DELEGATE_SUFFIX, methodInfo.getParameterTypes(), staticConstructor); b.iconst(methodInfo.getParameterTypes().length); for (int i = 0; i < methodInfo.getParameterTypes().length; ++i) { String typeString = methodInfo.getParameterTypes()[i]; if (methodInfo.getReturnType().equals(BytecodeUtils.VOID_CLASS_DESCRIPTOR)) { b.returnInstruction(); } else if (isPrimitive(methodInfo.getReturnType())) { } else { b.checkcast(BytecodeUtils.getName(methodInfo.getReturnType()));
final CodeAttribute b = classMethod.getCodeAttribute(); b.aload(0); getMethodHandlerField(classMethod.getClassFile(), b); b.aload(0); bytecodeMethodResolver.getDeclaredMethod(classMethod, method.getDeclaringClass(), method.getName(), method.getParameterTypes(), staticConstructor); b.aconstNull(); b.iconst(method.getParameterTypes().length); b.anewarray("java.lang.Object"); for (int i = 0; i < method.getParameterTypes().length; ++i) { String typeString = method.getParameterTypes()[i]; b.dup(); // duplicate the array reference b.iconst(i); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); if (addReturnInstruction) { if (method.getReturnType().equals(BytecodeUtils.VOID_CLASS_DESCRIPTOR)) { b.returnInstruction(); } else if(isPrimitive(method.getReturnType())) { Boxing.unbox(b, method.getReturnType()); b.returnInstruction(); } else { b.checkcast(BytecodeUtils.getName(method.getReturnType())); b.returnInstruction();
b.aload(0); DEFAULT_METHOD_RESOLVER.getDeclaredMethod(classMethod, methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getParameterTypes(), staticConstructor); b.aconstNull(); b.iconst(methodInfo.getParameterTypes().length); b.anewarray(Object.class.getName()); int localVariableCount = 1; for (int i = 0; i < methodInfo.getParameterTypes().length; ++i) { String typeString = methodInfo.getParameterTypes()[i]; b.dup(); // duplicate the array reference b.iconst(i); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); b.invokeinterface(MethodHandler.class.getName(), INVOKE_METHOD_NAME, LJAVA_LANG_OBJECT, new String[] { LJAVA_LANG_OBJECT, LJAVA_LANG_REFLECT_METHOD, LJAVA_LANG_REFLECT_METHOD, "[" + LJAVA_LANG_OBJECT }); if (methodInfo.getReturnType().equals(BytecodeUtils.VOID_CLASS_DESCRIPTOR)) { } else if (isPrimitive(methodInfo.getReturnType())) { Boxing.unbox(b, methodInfo.getReturnType()); } else { b.checkcast(BytecodeUtils.getName(methodInfo.getReturnType()));
private void createAbstractMethodCode(ClassMethod classMethod, MethodInformation method, ClassMethod staticConstructor) { if ((delegateField != null) && (!Modifier.isPrivate(delegateField.getModifiers()))) { // Call the corresponding method directly on the delegate final CodeAttribute b = classMethod.getCodeAttribute(); // load the delegate field b.aload(0); b.getfield(classMethod.getClassFile().getName(), delegateField.getName(), DescriptorUtils.makeDescriptor(delegateField.getType())); // load the parameters b.loadMethodParameters(); // invoke the delegate method b.invokeinterface(delegateField.getType().getName(), method.getName(), method.getDescriptor()); // return the value if applicable b.returnInstruction(); } else { if (!Modifier.isPrivate(method.getMethod().getModifiers())) { // if it is a parameter injection point we need to initialize the // injection point then handle the method with the method handler // this is slightly different to a normal method handler call, as we pass // in a TargetInstanceBytecodeMethodResolver. This resolver uses the // method handler to call getTargetClass to get the correct class type to // resolve the method with, and then resolves this method invokeMethodHandler(classMethod, method, true, targetInstanceBytecodeMethodResolver, staticConstructor); } else { // if the delegate is private we need to use the method handler createInterceptorBody(classMethod, method, staticConstructor); } } }
@Override void doReturn(CodeAttribute b, ClassMethod classMethod) { // assumes doWork() result is on top of the stack // if this method returns a primitive we just return if (method.getReturnType().isPrimitive()) { b.returnInstruction(); } else { // otherwise we have to check that the proxy is not returning 'this; // now we need to check if the proxy has return 'this' and if so return // an // instance of the proxy. // currently we have result, beanInstance on the stack. b.dupX1(); // now we have result, beanInstance, result // we need to compare result and beanInstance // first we need to build up the inner conditional that just returns // the // result final BranchEnd returnInstruction = b.ifAcmpeq(); b.returnInstruction(); b.branchEnd(returnInstruction); // now add the case where the proxy returns 'this'; b.aload(0); b.checkcast(methodInfo.getMethod().getReturnType().getName()); b.returnInstruction(); } } }.runStartIfNotEmpty();
private void loadBeanInstance(ClassFile file, MethodInformation methodInfo, CodeAttribute b) { b.aload(0); getMethodHandlerField(file, b); // lets invoke the method b.invokevirtual(ProxyMethodHandler.class.getName(), "getInstance", EMPTY_PARENTHESES + LJAVA_LANG_OBJECT); b.checkcast(methodInfo.getDeclaringClass()); }
final Method method = methodInfo.getMethod();
b.dup(); b.invokestatic(InterceptionDecorationContext.class.getName(), "getStack", "()" + DescriptorUtils.makeDescriptor(Stack.class)); if (!Reflections.isDefault(methodInfo.getMethod()) && !Modifier.isPrivate(method.getAccessFlags())) { b.invokespecial(methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getDescriptor()); bytecodeMethodResolver.getDeclaredMethod(method, methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getParameterTypes(), staticConstructor); bytecodeMethodResolver.getDeclaredMethod(method, methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getParameterTypes(), staticConstructor); } else { bytecodeMethodResolver.getDeclaredMethod(method, method.getClassFile().getName(), methodInfo.getName() + SUPER_DELEGATE_SUFFIX, methodInfo.getParameterTypes(), staticConstructor); b.iconst(methodInfo.getParameterTypes().length); for (int i = 0; i < methodInfo.getParameterTypes().length; ++i) { String typeString = methodInfo.getParameterTypes()[i]; if (methodInfo.getReturnType().equals(BytecodeUtils.VOID_CLASS_DESCRIPTOR)) { b.returnInstruction(); } else if (isPrimitive(methodInfo.getReturnType())) { } else { b.checkcast(BytecodeUtils.getName(methodInfo.getReturnType()));
final CodeAttribute b = classMethod.getCodeAttribute(); b.aload(0); getMethodHandlerField(classMethod.getClassFile(), b); b.aload(0); bytecodeMethodResolver.getDeclaredMethod(classMethod, method.getDeclaringClass(), method.getName(), method.getParameterTypes(), staticConstructor); b.aconstNull(); b.iconst(method.getParameterTypes().length); b.anewarray("java.lang.Object"); for (int i = 0; i < method.getParameterTypes().length; ++i) { String typeString = method.getParameterTypes()[i]; b.dup(); // duplicate the array reference b.iconst(i); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); if (addReturnInstruction) { if (method.getReturnType().equals(BytecodeUtils.VOID_CLASS_DESCRIPTOR)) { b.returnInstruction(); } else if(isPrimitive(method.getReturnType())) { Boxing.unbox(b, method.getReturnType()); b.returnInstruction(); } else { b.checkcast(BytecodeUtils.getName(method.getReturnType())); b.returnInstruction();
b.aload(0); DEFAULT_METHOD_RESOLVER.getDeclaredMethod(classMethod, methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getParameterTypes(), staticConstructor); b.aconstNull(); b.iconst(methodInfo.getParameterTypes().length); b.anewarray(Object.class.getName()); int localVariableCount = 1; for (int i = 0; i < methodInfo.getParameterTypes().length; ++i) { String typeString = methodInfo.getParameterTypes()[i]; b.dup(); // duplicate the array reference b.iconst(i); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); b.invokeinterface(MethodHandler.class.getName(), INVOKE_METHOD_NAME, LJAVA_LANG_OBJECT, new String[] { LJAVA_LANG_OBJECT, LJAVA_LANG_REFLECT_METHOD, LJAVA_LANG_REFLECT_METHOD, "[" + LJAVA_LANG_OBJECT }); if (methodInfo.getReturnType().equals(BytecodeUtils.VOID_CLASS_DESCRIPTOR)) { } else if (isPrimitive(methodInfo.getReturnType())) { Boxing.unbox(b, methodInfo.getReturnType()); } else { b.checkcast(BytecodeUtils.getName(methodInfo.getReturnType()));
private void createAbstractMethodCode(ClassMethod classMethod, MethodInformation method, ClassMethod staticConstructor) { if ((delegateField != null) && (!Modifier.isPrivate(delegateField.getModifiers()))) { // Call the corresponding method directly on the delegate final CodeAttribute b = classMethod.getCodeAttribute(); // load the delegate field b.aload(0); b.getfield(classMethod.getClassFile().getName(), delegateField.getName(), DescriptorUtils.makeDescriptor(delegateField.getType())); // load the parameters b.loadMethodParameters(); // invoke the delegate method b.invokeinterface(delegateField.getType().getName(), method.getName(), method.getDescriptor()); // return the value if applicable b.returnInstruction(); } else { if (!Modifier.isPrivate(method.getMethod().getModifiers())) { // if it is a parameter injection point we need to initialize the // injection point then handle the method with the method handler // this is slightly different to a normal method handler call, as we pass // in a TargetInstanceBytecodeMethodResolver. This resolver uses the // method handler to call getTargetClass to get the correct class type to // resolve the method with, and then resolves this method invokeMethodHandler(classMethod, method, true, targetInstanceBytecodeMethodResolver, staticConstructor); } else { // if the delegate is private we need to use the method handler createInterceptorBody(classMethod, method, staticConstructor); } } }
private void createDelegateToSuper(ClassMethod classMethod, MethodInformation method, String className) { CodeAttribute b = classMethod.getCodeAttribute(); // first generate the invokespecial call to the super class method b.aload(0); b.loadMethodParameters(); b.invokespecial(className, method.getName(), method.getDescriptor()); b.returnInstruction(); }
@Override void doReturn(CodeAttribute b, ClassMethod classMethod) { // assumes doWork() result is on top of the stack // if this method returns a primitive we just return if (method.getReturnType().isPrimitive()) { b.returnInstruction(); } else { // otherwise we have to check that the proxy is not returning 'this; // now we need to check if the proxy has return 'this' and if so return // an // instance of the proxy. // currently we have result, beanInstance on the stack. b.dupX1(); // now we have result, beanInstance, result // we need to compare result and beanInstance // first we need to build up the inner conditional that just returns // the // result final BranchEnd returnInstruction = b.ifAcmpeq(); b.returnInstruction(); b.branchEnd(returnInstruction); // now add the case where the proxy returns 'this'; b.aload(0); b.checkcast(methodInfo.getMethod().getReturnType().getName()); b.returnInstruction(); } } }.runStartIfNotEmpty();
@Override void doWork(CodeAttribute b, ClassMethod classMethod) { if (Modifier.isPrivate(classMethod.getAccessFlags())) { // Weld cannot use invokespecial to invoke a private method from the superclass invokePrivateMethodHandler(b, classMethod, methodInfo, staticConstructor); } else { // build the bytecode that invokes the super class method directly b.aload(0); // create the method invocation b.loadMethodParameters(); b.invokespecial(methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getDescriptor()); } // leave the result on top of the stack }
private void loadBeanInstance(ClassFile file, MethodInformation methodInfo, CodeAttribute b) { b.aload(0); getMethodHandlerField(file, b); // lets invoke the method b.invokevirtual(ProxyMethodHandler.class.getName(), "getInstance", EMPTY_PARENTHESES + LJAVA_LANG_OBJECT); b.checkcast(methodInfo.getDeclaringClass()); }
final Method method = methodInfo.getMethod();