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);
private void addInitMethod(final String declaringClass, final String methodName, final String[] parameterTypes, String weldMethodName, ClassFile classFile) { ClassMethod initMethod = classFile.addMethod(AccessFlag.of(AccessFlag.PRIVATE, AccessFlag.STATIC), weldMethodName, LJAVA_LANG_REFLECT_METHOD); final CodeAttribute code = initMethod.getCodeAttribute(); BytecodeUtils.pushClassType(code, declaringClass); // now we have the class on the stack code.ldc(methodName); // now we need to load the parameter types into an array code.iconst(parameterTypes.length); code.anewarray(Class.class.getName()); for (int i = 0; i < parameterTypes.length; ++i) { code.dup(); // duplicate the array reference code.iconst(i); // now load the class object String type = parameterTypes[i]; BytecodeUtils.pushClassType(code, type); // and store it in the array code.aastore(); } code.invokestatic(DefaultBytecodeMethodResolver.class.getName(), "getMethod", "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"); code.returnInstruction(); }
final CodeAttribute b = method.getCodeAttribute(); b.aload(0); getMethodHandlerField(method.getClassFile(), b); b.dup(); b.invokestatic(InterceptionDecorationContext.class.getName(), "getStack", "()" + DescriptorUtils.makeDescriptor(Stack.class)); b.loadMethodParameters(); b.invokespecial(methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getDescriptor()); b.returnInstruction(); b.branchEnd(invokeSuperDirectly); staticConstructor); } else { bytecodeMethodResolver.getDeclaredMethod(method, method.getClassFile().getName(), methodInfo.getName() + SUPER_DELEGATE_SUFFIX, methodInfo.getParameterTypes(), staticConstructor); b.iconst(i); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); b.returnInstruction(); } else { b.checkcast(BytecodeUtils.getName(methodInfo.getReturnType())); b.returnInstruction();
private void createNotInterceptedMethod(ClassMethod classMethod, final MethodInformation methodInfo, Method method, ClassMethod staticConstructor) { final CodeAttribute b = classMethod.getCodeAttribute(); b.aload(0); getMethodHandlerField(classMethod.getClassFile(), b); b.aload(0); DEFAULT_METHOD_RESOLVER.getDeclaredMethod(classMethod, methodInfo.getDeclaringClass(), method.getName(), methodInfo.getParameterTypes(), staticConstructor); b.aconstNull(); b.iconst(method.getParameterTypes().length); String typeString = methodInfo.getParameterTypes()[i]; b.dup(); // duplicate the array reference b.iconst(i); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); if (methodInfo.getReturnType().equals(BytecodeUtils.VOID_CLASS_DESCRIPTOR)) { b.returnInstruction(); } else if (isPrimitive(methodInfo.getReturnType())) { Boxing.unbox(b, classMethod.getReturnType()); b.returnInstruction(); } else { b.checkcast(BytecodeUtils.getName(methodInfo.getReturnType())); b.returnInstruction();
private void invokePrivateMethodHandler(CodeAttribute b, ClassMethod classMethod, MethodInformation methodInfo, ClassMethod staticConstructor) { try { classMethod.getClassFile().addField(AccessFlag.PRIVATE, PRIVATE_METHOD_HANDLER_FIELD_NAME, MethodHandler.class); } catch (DuplicateMemberException ignored) { b.aload(0); b.getfield(classMethod.getClassFile().getName(), PRIVATE_METHOD_HANDLER_FIELD_NAME, DescriptorUtils.makeDescriptor(MethodHandler.class)); b.aload(0); DEFAULT_METHOD_RESOLVER.getDeclaredMethod(classMethod, methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getParameterTypes(), staticConstructor); b.iconst(i); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); b.aastore(); if (isWide(typeString)) { localVariableCount = localVariableCount + 2; } else { 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 static void generateGetTargetClassBody(ClassMethod method) { final CodeAttribute b = method.getCodeAttribute(); BytecodeUtils.pushClassType(b, method.getClassFile().getSuperclass()); b.returnInstruction(); }
final CodeAttribute b = method.getCodeAttribute(); b.aload(0); getMethodHandlerField(method.getClassFile(), b); b.dup(); b.invokestatic(InterceptionDecorationContext.class.getName(), "getStack", "()" + DescriptorUtils.makeDescriptor(Stack.class)); b.loadMethodParameters(); b.invokespecial(methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getDescriptor()); b.returnInstruction(); b.branchEnd(invokeSuperDirectly); staticConstructor); } else { bytecodeMethodResolver.getDeclaredMethod(method, method.getClassFile().getName(), methodInfo.getName() + SUPER_DELEGATE_SUFFIX, methodInfo.getParameterTypes(), staticConstructor); b.iconst(i); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); b.returnInstruction(); } else { b.checkcast(BytecodeUtils.getName(methodInfo.getReturnType())); b.returnInstruction();
private void createNotInterceptedMethod(ClassMethod classMethod, final MethodInformation methodInfo, Method method, ClassMethod staticConstructor) { final CodeAttribute b = classMethod.getCodeAttribute(); b.aload(0); getMethodHandlerField(classMethod.getClassFile(), b); b.aload(0); DEFAULT_METHOD_RESOLVER.getDeclaredMethod(classMethod, methodInfo.getDeclaringClass(), method.getName(), methodInfo.getParameterTypes(), staticConstructor); b.aconstNull(); b.iconst(method.getParameterTypes().length); String typeString = methodInfo.getParameterTypes()[i]; b.dup(); // duplicate the array reference b.iconst(i); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); if (methodInfo.getReturnType().equals(BytecodeUtils.VOID_CLASS_DESCRIPTOR)) { b.returnInstruction(); } else if (isPrimitive(methodInfo.getReturnType())) { Boxing.unbox(b, classMethod.getReturnType()); b.returnInstruction(); } else { b.checkcast(BytecodeUtils.getName(methodInfo.getReturnType())); b.returnInstruction();
private void invokePrivateMethodHandler(CodeAttribute b, ClassMethod classMethod, MethodInformation methodInfo, ClassMethod staticConstructor) { try { classMethod.getClassFile().addField(AccessFlag.PRIVATE, PRIVATE_METHOD_HANDLER_FIELD_NAME, MethodHandler.class); } catch (DuplicateMemberException ignored) { b.aload(0); b.getfield(classMethod.getClassFile().getName(), PRIVATE_METHOD_HANDLER_FIELD_NAME, DescriptorUtils.makeDescriptor(MethodHandler.class)); b.aload(0); DEFAULT_METHOD_RESOLVER.getDeclaredMethod(classMethod, methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getParameterTypes(), staticConstructor); b.iconst(i); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); b.aastore(); if (isWide(typeString)) { localVariableCount = localVariableCount + 2; } else { 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 static void generateGetTargetClassBody(ClassMethod method) { final CodeAttribute b = method.getCodeAttribute(); BytecodeUtils.pushClassType(b, method.getClassFile().getSuperclass()); b.returnInstruction(); }
final CodeAttribute b = method.getCodeAttribute(); b.aload(0); getMethodHandlerField(method.getClassFile(), b); b.dup(); b.invokestatic(InterceptionDecorationContext.class.getName(), "getStack", "()" + DescriptorUtils.makeDescriptor(Stack.class)); b.loadMethodParameters(); b.invokespecial(methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getDescriptor()); b.returnInstruction(); b.branchEnd(invokeSuperDirectly); staticConstructor); } else { bytecodeMethodResolver.getDeclaredMethod(method, method.getClassFile().getName(), methodInfo.getName() + SUPER_DELEGATE_SUFFIX, methodInfo.getParameterTypes(), staticConstructor); b.iconst(i); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); b.returnInstruction(); } else { b.checkcast(BytecodeUtils.getName(methodInfo.getReturnType())); b.returnInstruction();
private void createInterceptedMethod(ClassMethod classMethod, final MethodInformation methodInfo, Method method, ClassMethod staticConstructor) { final CodeAttribute b = classMethod.getCodeAttribute(); b.aload(0); getMethodHandlerField(classMethod.getClassFile(), b); b.invokestatic(InterceptionDecorationContext.class.getName(), "getStack", "()" + DescriptorUtils.makeDescriptor(Stack.class)); b.aload(0); DEFAULT_METHOD_RESOLVER.getDeclaredMethod(classMethod, methodInfo.getDeclaringClass(), method.getName(), methodInfo.getParameterTypes(), staticConstructor); b.dup(); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); b.aastore(); if (isWide(typeString)) { localVariableCount = localVariableCount + 2; } else { if (methodInfo.getReturnType().equals(BytecodeUtils.VOID_CLASS_DESCRIPTOR)) { b.returnInstruction(); } else if (isPrimitive(methodInfo.getReturnType())) { Boxing.unbox(b, classMethod.getReturnType()); b.returnInstruction(); } else { b.checkcast(BytecodeUtils.getName(methodInfo.getReturnType())); b.returnInstruction();
private void invokePrivateMethodHandler(CodeAttribute b, ClassMethod classMethod, MethodInformation methodInfo, ClassMethod staticConstructor) { try { classMethod.getClassFile().addField(AccessFlag.PRIVATE, PRIVATE_METHOD_HANDLER_FIELD_NAME, MethodHandler.class); } catch (DuplicateMemberException ignored) { b.aload(0); b.getfield(classMethod.getClassFile().getName(), PRIVATE_METHOD_HANDLER_FIELD_NAME, DescriptorUtils.makeDescriptor(MethodHandler.class)); b.aload(0); DEFAULT_METHOD_RESOLVER.getDeclaredMethod(classMethod, methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getParameterTypes(), staticConstructor); b.iconst(i); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); b.aastore(); if (isWide(typeString)) { localVariableCount = localVariableCount + 2; } else { 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()));
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);
private void addInitMethod(final String declaringClass, final String methodName, final String[] parameterTypes, String weldMethodName, ClassFile classFile) { ClassMethod initMethod = classFile.addMethod(AccessFlag.of(AccessFlag.PRIVATE, AccessFlag.STATIC), weldMethodName, LJAVA_LANG_REFLECT_METHOD); final CodeAttribute code = initMethod.getCodeAttribute(); BytecodeUtils.pushClassType(code, declaringClass); // now we have the class on the stack code.ldc(methodName); // now we need to load the parameter types into an array code.iconst(parameterTypes.length); code.anewarray(Class.class.getName()); for (int i = 0; i < parameterTypes.length; ++i) { code.dup(); // duplicate the array reference code.iconst(i); // now load the class object String type = parameterTypes[i]; BytecodeUtils.pushClassType(code, type); // and store it in the array code.aastore(); } code.invokestatic(DefaultBytecodeMethodResolver.class.getName(), "getMethod", "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"); code.returnInstruction(); }
private static void generateGetTargetClassBody(ClassMethod method) { final CodeAttribute b = method.getCodeAttribute(); BytecodeUtils.pushClassType(b, method.getClassFile().getSuperclass()); b.returnInstruction(); }
final CodeAttribute b = method.getCodeAttribute(); b.aload(0); getMethodHandlerField(method.getClassFile(), b); b.dup(); b.invokestatic(InterceptionDecorationContext.class.getName(), "getStack", "()" + DescriptorUtils.makeDescriptor(Stack.class)); if (!Reflections.isDefault(methodInfo.getMethod()) && !Modifier.isPrivate(method.getAccessFlags())) { b.dupX1(); // Handler, Stack -> Stack, Handler, Stack b.invokevirtual(COMBINED_INTERCEPTOR_AND_DECORATOR_STACK_METHOD_HANDLER_CLASS_NAME, "isDisabledHandler", "(" + DescriptorUtils.makeDescriptor(Stack.class) + ")" + BytecodeUtils.BOOLEAN_CLASS_DESCRIPTOR); b.iconst(0); b.loadMethodParameters(); b.invokespecial(methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getDescriptor()); b.returnInstruction(); b.branchEnd(invokeSuperDirectly); b.iconst(i); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); b.returnInstruction(); } else { b.checkcast(BytecodeUtils.getName(methodInfo.getReturnType())); b.returnInstruction();
private void createInterceptedMethod(ClassMethod classMethod, final MethodInformation methodInfo, Method method, ClassMethod staticConstructor) { final CodeAttribute b = classMethod.getCodeAttribute(); b.aload(0); getMethodHandlerField(classMethod.getClassFile(), b); b.invokestatic(InterceptionDecorationContext.class.getName(), "getStack", "()" + DescriptorUtils.makeDescriptor(Stack.class)); b.aload(0); DEFAULT_METHOD_RESOLVER.getDeclaredMethod(classMethod, methodInfo.getDeclaringClass(), method.getName(), methodInfo.getParameterTypes(), staticConstructor); b.dup(); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); b.aastore(); if (isWide(typeString)) { localVariableCount = localVariableCount + 2; } else { if (methodInfo.getReturnType().equals(BytecodeUtils.VOID_CLASS_DESCRIPTOR)) { b.returnInstruction(); } else if (isPrimitive(methodInfo.getReturnType())) { Boxing.unbox(b, classMethod.getReturnType()); b.returnInstruction(); } else { b.checkcast(BytecodeUtils.getName(methodInfo.getReturnType())); b.returnInstruction();
private void invokePrivateMethodHandler(CodeAttribute b, ClassMethod classMethod, MethodInformation methodInfo, ClassMethod staticConstructor) { try { classMethod.getClassFile().addField(AccessFlag.PRIVATE, PRIVATE_METHOD_HANDLER_FIELD_NAME, MethodHandler.class); } catch (DuplicateMemberException ignored) { b.aload(0); b.getfield(classMethod.getClassFile().getName(), PRIVATE_METHOD_HANDLER_FIELD_NAME, DescriptorUtils.makeDescriptor(MethodHandler.class)); b.aload(0); DEFAULT_METHOD_RESOLVER.getDeclaredMethod(classMethod, methodInfo.getDeclaringClass(), methodInfo.getName(), methodInfo.getParameterTypes(), staticConstructor); b.iconst(i); BytecodeUtils.addLoadInstruction(b, typeString, localVariableCount); b.aastore(); if (isWide(typeString)) { localVariableCount = localVariableCount + 2; } else { 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()));
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);