/** * {@inheritDoc} */ public InvocationProvider.Target.Resolved resolve(TypeDescription instrumentedType, Assigner assigner, Assigner.Typing typing) { StackManipulation[] stackManipulation = new StackManipulation[argumentProviders.size()]; List<TypeDescription> parameterTypes = new ArrayList<TypeDescription>(); int index = 0; for (ArgumentProvider argumentProvider : argumentProviders) { ArgumentProvider.Resolved resolved = argumentProvider.resolve(instrumentedType, instrumentedMethod, assigner, typing); parameterTypes.addAll(resolved.getLoadedTypes()); stackManipulation[index++] = resolved.getLoadInstruction(); } return new Resolved.Simple(new StackManipulation.Compound(stackManipulation), internalName, returnType, parameterTypes); } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod) { StackManipulation superMethodCall = implementationTarget.invokeDominant(instrumentedMethod.asSignatureToken()); if (!superMethodCall.isValid()) { throw new IllegalStateException("Cannot call super (or default) method for " + instrumentedMethod); } StackManipulation.Size stackSize = new StackManipulation.Compound( MethodVariableAccess.allArgumentsOf(instrumentedMethod).prependThisReference(), superMethodCall, terminationHandler.of(instrumentedMethod) ).apply(methodVisitor, implementationContext); return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize()); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { TypeDescription proxyType = implementationContext.register(new TypeProxy(proxiedType, implementationTarget, InvocationFactory.Default.SUPER_METHOD, ignoreFinalizer, serializableProxy)); return new Compound( MethodInvocation.invoke(proxyType.getDeclaredMethods().filter(named(REFLECTION_METHOD).and(takesArguments(0))).getOnly()), Duplication.SINGLE, MethodVariableAccess.loadThis(), FieldAccess.forField(proxyType.getDeclaredFields().filter((named(INSTANCE_FIELD))).getOnly()).write() ).apply(methodVisitor, implementationContext); } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { TypeDescription auxiliaryType = implementationContext.register(PrivilegedMemberLookupAction.of(methodDescription)); return new Compound( TypeCreation.of(auxiliaryType), Duplication.SINGLE, ClassConstant.of(methodDescription.getDeclaringType()), methodName, ArrayFactory.forType(TypeDescription.Generic.OfNonGenericType.CLASS) .withValues(typeConstantsFor(methodDescription.getParameters().asTypeList().asErasures())), MethodInvocation.invoke(auxiliaryType.getDeclaredMethods().filter(isConstructor()).getOnly()), MethodInvocation.invoke(DO_PRIVILEGED), TypeCasting.to(TypeDescription.ForLoadedType.of(methodDescription.isConstructor() ? Constructor.class : Method.class)) ).apply(methodVisitor, implementationContext); }
/** * {@inheritDoc} */ public StackManipulation resolveWrite() { StackManipulation preparation; if (fieldDescription.isStatic()) { preparation = StackManipulation.Trivial.INSTANCE; } else { preparation = new StackManipulation.Compound( MethodVariableAccess.loadThis(), Duplication.SINGLE.flipOver(fieldDescription.getType()), Removal.SINGLE ); } return new StackManipulation.Compound(writeAssignment, preparation, FieldAccess.forField(fieldDescription).write()); }
/** * {@inheritDoc} */ public StackManipulation toStackManipulation(MethodDescription invokedMethod, Assigner assigner, Assigner.Typing typing) { if (!invokedMethod.isInvokableOn(fieldDescription.getType().asErasure())) { throw new IllegalStateException("Cannot invoke " + invokedMethod + " on " + fieldDescription); } StackManipulation stackManipulation = assigner.assign(fieldDescription.getType(), invokedMethod.getDeclaringType().asGenericType(), typing); if (!stackManipulation.isValid()) { throw new IllegalStateException("Cannot invoke " + invokedMethod + " on " + fieldDescription); } return new StackManipulation.Compound(invokedMethod.isStatic() || fieldDescription.isStatic() ? StackManipulation.Trivial.INSTANCE : MethodVariableAccess.loadThis(), FieldAccess.forField(fieldDescription).read(), stackManipulation); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) { StackManipulation.Size stackSize = new StackManipulation.Compound( MethodVariableAccess.loadThis(), MethodInvocation.invoke(StaticFieldConstructor.INSTANCE.objectTypeDefaultConstructor), MethodVariableAccess.allArgumentsOf(instrumentedMethod).prependThisReference(), FieldAccess.forField(fieldDescription).write(), MethodReturn.VOID ).apply(methodVisitor, implementationContext); return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize()); } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) { InvocationProvider.Target.Resolved target = invocationProvider.make(instrumentedMethod).resolve(instrumentedType, assigner, typing); StackManipulation.Size size = new StackManipulation.Compound( target.getStackManipulation(), MethodInvocation.invoke(bootstrapMethod).dynamic(target.getInternalName(), target.getReturnType(), target.getParameterTypes(), handleArguments), terminationHandler.resolve(instrumentedMethod, target.getReturnType(), assigner, typing) ).apply(methodVisitor, implementationContext); return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize()); } }
/** * {@inheritDoc} */ protected StackManipulation resolve(Void unused, FieldDescription fieldDescription, TypeDescription instrumentedType, MethodDescription instrumentedMethod) { if (instrumentedMethod.getParameters().size() <= index) { throw new IllegalStateException(instrumentedMethod + " does not define a parameter with index " + index); } else { return new StackManipulation.Compound( MethodVariableAccess.load(instrumentedMethod.getParameters().get(index)), assigner.assign(instrumentedMethod.getParameters().get(index).getType(), fieldDescription.getType(), typing) ); } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) { StackManipulation.Size stackSize = new StackManipulation.Compound( MethodVariableAccess.loadThis(), MethodInvocation.invoke(StaticFieldConstructor.INSTANCE.objectTypeDefaultConstructor), MethodVariableAccess.allArgumentsOf(instrumentedMethod.asDefined()).prependThisReference(), FieldAccess.forField(fieldDescription).write(), MethodReturn.VOID ).apply(methodVisitor, implementationContext); return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize()); } }
@Override protected MethodDelegationBinder.ParameterBinding<?> makeBinding(TypeDescription.Generic source, TypeDescription.Generic target, int sourceParameterIndex, Assigner assigner, Assigner.Typing typing, int parameterOffset) { return MethodDelegationBinder.ParameterBinding.Unique.of( new StackManipulation.Compound( MethodVariableAccess.of(source).loadFrom(parameterOffset), assigner.assign(source, target, typing)), new ArgumentTypeResolver.ParameterIndexToken(sourceParameterIndex) ); } },
/** * {@inheritDoc} */ protected StackManipulation resolve(FieldDescription.InDefinedShape target, FieldDescription fieldDescription, TypeDescription instrumentedType, MethodDescription instrumentedMethod) { if (fieldDescription.isFinal() && instrumentedMethod.isMethod()) { throw new IllegalArgumentException("Cannot set final field " + fieldDescription + " from " + instrumentedMethod); } return new StackManipulation.Compound( FieldAccess.forField(target).read(), assigner.assign(TypeDescription.ForLoadedType.of(value.getClass()).asGenericType(), fieldDescription.getType(), typing) ); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { TypeDescription auxiliaryType = implementationContext.register(this); return new Compound( TypeCreation.of(auxiliaryType), Duplication.SINGLE, fieldDescription.isStatic() ? Trivial.INSTANCE : MethodVariableAccess.loadThis(), MethodInvocation.invoke(auxiliaryType.getDeclaredMethods().filter(isConstructor()).getOnly()) ).apply(methodVisitor, implementationContext); } }
/** * {@inheritDoc} */ public StackManipulation toStackManipulation(ParameterDescription target, Assigner assigner, Assigner.Typing typing) { StackManipulation stackManipulation = new StackManipulation.Compound( MethodVariableAccess.load(parameterDescription), IntegerConstant.forValue(index), ArrayAccess.of(parameterDescription.getType().getComponentType()).load(), assigner.assign(parameterDescription.getType().getComponentType(), target.getType(), typing) ); if (!stackManipulation.isValid()) { throw new IllegalStateException("Cannot assign " + parameterDescription.getType().getComponentType() + " to " + target); } return stackManipulation; }
/** * {@inheritDoc} */ public Target resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, ArgumentHandler argumentHandler, Sort sort) { StackManipulation assignment = assigner.assign(typeDescription.asGenericType(), target, Assigner.Typing.DYNAMIC); if (!assignment.isValid()) { throw new IllegalStateException("Cannot assign " + typeDescription + " to " + target); } return new Target.ForStackManipulation(new StackManipulation.Compound(deserialization, assignment)); }
/** * {@inheritDoc} */ public Target resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, ArgumentHandler argumentHandler, Sort sort) { StackManipulation assignment = assigner.assign(typeDescription, targetType, typing); if (!assignment.isValid()) { throw new IllegalStateException("Cannot assign " + typeDescription + " to " + targetType); } return new Target.ForStackManipulation(new StackManipulation.Compound(stackManipulation, assignment)); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { MethodDescription.InDefinedShape proxyMethod = methodAccessorFactory.registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT); return new StackManipulation.Compound( MethodVariableAccess.loadThis(), fieldLoadingInstruction, MethodVariableAccess.allArgumentsOf(instrumentedMethod).asBridgeOf(proxyMethod), MethodInvocation.invoke(proxyMethod), MethodReturn.of(instrumentedMethod.getReturnType()) ).apply(methodVisitor, implementationContext); } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { TypeDescription auxiliaryType = implementationContext .register(new MethodCallProxy(specialMethodInvocation, serializable)); return new Compound( TypeCreation.of(auxiliaryType), Duplication.SINGLE, MethodVariableAccess.allArgumentsOf(specialMethodInvocation.getMethodDescription()).prependThisReference(), MethodInvocation.invoke(auxiliaryType.getDeclaredMethods().filter(isConstructor()).getOnly()) ).apply(methodVisitor, implementationContext); } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { TypeDescription forwardingType = implementationContext.register(this); return new Compound( TypeCreation.of(forwardingType), Duplication.SINGLE, specialMethodInvocation.getMethodDescription().isStatic() ? Trivial.INSTANCE : MethodVariableAccess.loadThis(), MethodInvocation.invoke(forwardingType.getDeclaredMethods().filter(isConstructor()).getOnly()) ).apply(methodVisitor, implementationContext); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) { StackManipulation.Size stackSize = new StackManipulation.Compound( fieldDescription.isStatic() ? StackManipulation.Trivial.INSTANCE : MethodVariableAccess.loadThis(), FieldAccess.forField(fieldDescription).read(), MethodReturn.of(fieldDescription.getType()) ).apply(methodVisitor, implementationContext); return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize()); } }