From a13264592218a77b79e7113a6bc4855316e0ebc2 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Sun, 31 May 2020 20:59:30 +0200 Subject: [PATCH] Add assigner. --- .../main/java/net/bytebuddy/asm/Advice.java | 63 ++++++++++++++----- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java index 9f6d7fc684f..3371c8ce4f0 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java @@ -4467,11 +4467,12 @@ public interface PostProcessor { * * @param instrumentedType The instrumented type. * @param instrumentedMethod The instrumented method. + * @param assigner The assigner to use. * @param offset The offset that stores the advice method's return value or {@link PostProcessor#NO_RETURN} * if the advice method does not return a value. * @return The stack manipulation to apply. */ - StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, int offset); + StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, int offset); /** * A factory for creating a {@link PostProcessor}. @@ -4549,7 +4550,7 @@ enum NoOp implements PostProcessor, Factory { /** * {@inheritDoc} */ - public StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, int offset) { + public StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, int offset) { return StackManipulation.Trivial.INSTANCE; } @@ -4584,10 +4585,10 @@ protected Compound(List postProcessors) { /** * {@inheritDoc} */ - public StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, int offset) { + public StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, int offset) { List stackManipulations = new ArrayList(postProcessors.size()); for (PostProcessor postProcessor : postProcessors) { - stackManipulations.add(postProcessor.resolve(instrumentedType, instrumentedMethod, offset)); + stackManipulations.add(postProcessor.resolve(instrumentedType, instrumentedMethod, assigner, offset)); } return new StackManipulation.Compound(stackManipulations); } @@ -8052,6 +8053,7 @@ protected MethodVisitor doApply(MethodVisitor methodVisitor, stackMapFrameHandler, instrumentedType, instrumentedMethod, + assigner, adviceMethod, offsetMappings, suppressionHandler, @@ -8295,6 +8297,7 @@ private MethodVisitor doApply(MethodVisitor methodVisitor, stackMapFrameHandler, instrumentedType, instrumentedMethod, + assigner, adviceMethod, offsetMappings, suppressionHandler, @@ -8466,6 +8469,11 @@ protected abstract static class CodeTranslationVisitor extends MethodVisitor { */ private final MethodDescription instrumentedMethod; + /** + * The assigner to use. + */ + private final Assigner assigner; + /** * The advice method. */ @@ -8506,6 +8514,7 @@ protected abstract static class CodeTranslationVisitor extends MethodVisitor { * @param stackMapFrameHandler A handler for translating and injecting stack map frames. * @param instrumentedType The instrumented type. * @param instrumentedMethod The instrumented method. + * @param assigner The assigner to use. * @param adviceMethod The advice method. * @param offsetMappings A mapping of offsets to resolved target offsets in the instrumented method. * @param suppressionHandler A bound suppression handler that is used for suppressing exceptions of this advice method. @@ -8519,6 +8528,7 @@ protected CodeTranslationVisitor(MethodVisitor methodVisitor, StackMapFrameHandler.ForAdvice stackMapFrameHandler, TypeDescription instrumentedType, MethodDescription instrumentedMethod, + Assigner assigner, MethodDescription.InDefinedShape adviceMethod, Map offsetMappings, SuppressionHandler.Bound suppressionHandler, @@ -8532,6 +8542,7 @@ protected CodeTranslationVisitor(MethodVisitor methodVisitor, this.stackMapFrameHandler = stackMapFrameHandler; this.instrumentedType = instrumentedType; this.instrumentedMethod = instrumentedMethod; + this.assigner = assigner; this.adviceMethod = adviceMethod; this.offsetMappings = offsetMappings; this.suppressionHandler = suppressionHandler; @@ -8694,9 +8705,9 @@ public void visitEnd() { } methodSizeHandler.requireStackSize(relocationHandler.apply(methodVisitor, getReturnValueOffset())); stackMapFrameHandler.injectCompletionFrame(methodVisitor); - methodSizeHandler.recordMaxima(postProcessor.resolve(instrumentedType, instrumentedMethod, adviceMethod.getReturnType().represents(void.class) + methodSizeHandler.recordMaxima(postProcessor.resolve(instrumentedType, instrumentedMethod, assigner, adviceMethod.getReturnType().represents(void.class) ? PostProcessor.NO_RETURN - : getReturnValueOffset()).apply(methodVisitor, implementationContext).getMaximalSize(), EMPTY); + : getReturnValueOffset()).apply(mv, implementationContext).getMaximalSize(), EMPTY); } @Override @@ -8727,6 +8738,7 @@ protected static class ForMethodEnter extends CodeTranslationVisitor { * @param stackMapFrameHandler A handler for translating and injecting stack map frames. * @param instrumentedType The instrumented type. * @param instrumentedMethod The instrumented method. + * @param assigner The assigner to use. * @param adviceMethod The advice method. * @param offsetMappings A mapping of offsets to resolved target offsets in the instrumented method. * @param suppressionHandler A bound suppression handler that is used for suppressing exceptions of this advice method. @@ -8740,6 +8752,7 @@ protected ForMethodEnter(MethodVisitor methodVisitor, StackMapFrameHandler.ForAdvice stackMapFrameHandler, TypeDescription instrumentedType, MethodDescription instrumentedMethod, + Assigner assigner, MethodDescription.InDefinedShape adviceMethod, Map offsetMappings, SuppressionHandler.Bound suppressionHandler, @@ -8752,6 +8765,7 @@ protected ForMethodEnter(MethodVisitor methodVisitor, stackMapFrameHandler, instrumentedType, instrumentedMethod, + assigner, adviceMethod, offsetMappings, suppressionHandler, @@ -8780,6 +8794,7 @@ protected static class ForMethodExit extends CodeTranslationVisitor { * @param stackMapFrameHandler A handler for translating and injecting stack map frames. * @param instrumentedType The instrumented type. * @param instrumentedMethod The instrumented method. + * @param assigner The assigner to use. * @param adviceMethod The advice method. * @param offsetMappings A mapping of offsets to resolved target offsets in the instrumented method. * @param suppressionHandler A bound suppression handler that is used for suppressing exceptions of this advice method. @@ -8793,6 +8808,7 @@ protected ForMethodExit(MethodVisitor methodVisitor, StackMapFrameHandler.ForAdvice stackMapFrameHandler, TypeDescription instrumentedType, MethodDescription instrumentedMethod, + Assigner assigner, MethodDescription.InDefinedShape adviceMethod, Map offsetMappings, SuppressionHandler.Bound suppressionHandler, @@ -8805,6 +8821,7 @@ protected ForMethodExit(MethodVisitor methodVisitor, stackMapFrameHandler, instrumentedType, instrumentedMethod, + assigner, adviceMethod, offsetMappings, suppressionHandler, @@ -9015,6 +9032,11 @@ protected abstract static class AdviceMethodWriter implements Bound { */ private final MethodDescription instrumentedMethod; + /** + * The assigner to use. + */ + private final Assigner assigner; + /** * The offset mappings available to this advice. */ @@ -9071,6 +9093,8 @@ protected abstract static class AdviceMethodWriter implements Bound { * @param adviceMethod The advice method. * @param instrumentedType The instrumented type. * @param instrumentedMethod The instrumented method. + * @param assigner The assigner to use. + * @param postProcessor The post processor to apply. * @param offsetMappings The offset mappings available to this advice. * @param methodVisitor The method visitor for writing the instrumented method. * @param implementationContext The implementation context to use. @@ -9079,12 +9103,13 @@ protected abstract static class AdviceMethodWriter implements Bound { * @param stackMapFrameHandler A handler for translating and injecting stack map frames. * @param suppressionHandler A bound suppression handler that is used for suppressing exceptions of this advice method. * @param relocationHandler A bound relocation handler that is responsible for considering a non-standard control flow. - * @param postProcessor The post processor to apply. * @param delegator The delegator to use. */ protected AdviceMethodWriter(MethodDescription.InDefinedShape adviceMethod, TypeDescription instrumentedType, MethodDescription instrumentedMethod, + Assigner assigner, + PostProcessor postProcessor, List offsetMappings, MethodVisitor methodVisitor, Context implementationContext, @@ -9093,11 +9118,12 @@ protected AdviceMethodWriter(MethodDescription.InDefinedShape adviceMethod, StackMapFrameHandler.ForAdvice stackMapFrameHandler, SuppressionHandler.Bound suppressionHandler, RelocationHandler.Bound relocationHandler, - PostProcessor postProcessor, Delegator delegator) { this.adviceMethod = adviceMethod; this.instrumentedType = instrumentedType; this.instrumentedMethod = instrumentedMethod; + this.assigner = assigner; + this.postProcessor = postProcessor; this.offsetMappings = offsetMappings; this.methodVisitor = methodVisitor; this.implementationContext = implementationContext; @@ -9106,7 +9132,6 @@ protected AdviceMethodWriter(MethodDescription.InDefinedShape adviceMethod, this.stackMapFrameHandler = stackMapFrameHandler; this.suppressionHandler = suppressionHandler; this.relocationHandler = relocationHandler; - this.postProcessor = postProcessor; this.delegator = delegator; } @@ -9153,7 +9178,7 @@ public void apply() { methodSizeHandler.requireStackSize(relocationHandler.apply(methodVisitor, getReturnValueOffset())); stackMapFrameHandler.injectCompletionFrame(methodVisitor); methodSizeHandler.recordMaxima(Math.max(maximumStackSize, adviceMethod.getReturnType().getStackSize().getSize()), EMPTY); - methodSizeHandler.recordMaxima(postProcessor.resolve(instrumentedType, instrumentedMethod, adviceMethod.getReturnType().represents(void.class) + methodSizeHandler.recordMaxima(postProcessor.resolve(instrumentedType, instrumentedMethod, assigner, adviceMethod.getReturnType().represents(void.class) ? PostProcessor.NO_RETURN : getReturnValueOffset()).apply(methodVisitor, implementationContext).getMaximalSize(), EMPTY); } @@ -9184,6 +9209,8 @@ protected static class ForMethodEnter extends AdviceMethodWriter { * @param adviceMethod The advice method. * @param instrumentedType The instrumented type. * @param instrumentedMethod The instrumented method. + * @param assigner The assigner to use. + * @param postProcessor The post processor to apply. * @param offsetMappings The offset mappings available to this advice. * @param methodVisitor The method visitor for writing the instrumented method. * @param implementationContext The implementation context to use. @@ -9192,12 +9219,13 @@ protected static class ForMethodEnter extends AdviceMethodWriter { * @param stackMapFrameHandler A handler for translating and injecting stack map frames. * @param suppressionHandler A bound suppression handler that is used for suppressing exceptions of this advice method. * @param relocationHandler A bound relocation handler that is responsible for considering a non-standard control flow. - * @param postProcessor The post processor to apply. * @param delegator The delegator to use. */ protected ForMethodEnter(MethodDescription.InDefinedShape adviceMethod, TypeDescription instrumentedType, MethodDescription instrumentedMethod, + Assigner assigner, + PostProcessor postProcessor, List offsetMappings, MethodVisitor methodVisitor, Implementation.Context implementationContext, @@ -9206,11 +9234,12 @@ protected ForMethodEnter(MethodDescription.InDefinedShape adviceMethod, StackMapFrameHandler.ForAdvice stackMapFrameHandler, SuppressionHandler.Bound suppressionHandler, RelocationHandler.Bound relocationHandler, - PostProcessor postProcessor, Delegator delegator) { super(adviceMethod, instrumentedType, instrumentedMethod, + assigner, + postProcessor, offsetMappings, methodVisitor, implementationContext, @@ -9219,7 +9248,6 @@ protected ForMethodEnter(MethodDescription.InDefinedShape adviceMethod, stackMapFrameHandler, suppressionHandler, relocationHandler, - postProcessor, delegator); } @@ -9252,6 +9280,7 @@ protected static class ForMethodExit extends AdviceMethodWriter { * @param adviceMethod The advice method. * @param instrumentedType The instrumented type. * @param instrumentedMethod The instrumented method. + * @param assigner The assigner to use. * @param postProcessor The post processor to apply. * @param offsetMappings The offset mappings available to this advice. * @param methodVisitor The method visitor for writing the instrumented method. @@ -9266,6 +9295,7 @@ protected static class ForMethodExit extends AdviceMethodWriter { protected ForMethodExit(MethodDescription.InDefinedShape adviceMethod, TypeDescription instrumentedType, MethodDescription instrumentedMethod, + Assigner assigner, PostProcessor postProcessor, List offsetMappings, MethodVisitor methodVisitor, @@ -9279,6 +9309,8 @@ protected ForMethodExit(MethodDescription.InDefinedShape adviceMethod, super(adviceMethod, instrumentedType, instrumentedMethod, + assigner, + postProcessor, offsetMappings, methodVisitor, implementationContext, @@ -9287,7 +9319,6 @@ protected ForMethodExit(MethodDescription.InDefinedShape adviceMethod, stackMapFrameHandler, suppressionHandler, relocationHandler, - postProcessor, delegator); } @@ -9471,6 +9502,8 @@ protected Bound doResolve(TypeDescription instrumentedType, return new AdviceMethodWriter.ForMethodEnter(adviceMethod, instrumentedType, instrumentedMethod, + assigner, + postProcessor, offsetMappings, methodVisitor, implementationContext, @@ -9479,7 +9512,6 @@ protected Bound doResolve(TypeDescription instrumentedType, stackMapFrameHandler, suppressionHandler, relocationHandler, - postProcessor, delegator); } @@ -9705,6 +9737,7 @@ private Bound doResolve(TypeDescription instrumentedType, return new AdviceMethodWriter.ForMethodExit(adviceMethod, instrumentedType, instrumentedMethod, + assigner, postProcessor, offsetMappings, methodVisitor,