Skip to content

Commit

Permalink
Supply argument handler to post processor.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jun 1, 2020
1 parent a132645 commit 51cf839
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java
Original file line number Diff line number Diff line change
Expand Up @@ -4457,22 +4457,19 @@ protected abstract ForInstrumentedMethod resolve(MethodDescription instrumentedM
*/
public interface PostProcessor {

/**
* Indicates that an advice method has no return value stored at a given offset.
*/
int NO_RETURN = -1;

/**
* Resolves this post processor for a given instrumented method.
*
* @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.
* @param argumentHandler The argument handler for the instrumented method.
* @return The stack manipulation to apply.
*/
StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, int offset);
StackManipulation resolve(TypeDescription instrumentedType,
MethodDescription instrumentedMethod,
Assigner assigner,
ArgumentHandler argumentHandler);

/**
* A factory for creating a {@link PostProcessor}.
Expand Down Expand Up @@ -4550,7 +4547,10 @@ enum NoOp implements PostProcessor, Factory {
/**
* {@inheritDoc}
*/
public StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, int offset) {
public StackManipulation resolve(TypeDescription instrumentedType,
MethodDescription instrumentedMethod,
Assigner assigner,
ArgumentHandler argumentHandler) {
return StackManipulation.Trivial.INSTANCE;
}

Expand Down Expand Up @@ -4585,10 +4585,13 @@ protected Compound(List<PostProcessor> postProcessors) {
/**
* {@inheritDoc}
*/
public StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, int offset) {
public StackManipulation resolve(TypeDescription instrumentedType,
MethodDescription instrumentedMethod,
Assigner assigner,
ArgumentHandler argumentHandler) {
List<StackManipulation> stackManipulations = new ArrayList<StackManipulation>(postProcessors.size());
for (PostProcessor postProcessor : postProcessors) {
stackManipulations.add(postProcessor.resolve(instrumentedType, instrumentedMethod, assigner, offset));
stackManipulations.add(postProcessor.resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler));
}
return new StackManipulation.Compound(stackManipulations);
}
Expand Down Expand Up @@ -8705,9 +8708,9 @@ public void visitEnd() {
}
methodSizeHandler.requireStackSize(relocationHandler.apply(methodVisitor, getReturnValueOffset()));
stackMapFrameHandler.injectCompletionFrame(methodVisitor);
methodSizeHandler.recordMaxima(postProcessor.resolve(instrumentedType, instrumentedMethod, assigner, adviceMethod.getReturnType().represents(void.class)
? PostProcessor.NO_RETURN
: getReturnValueOffset()).apply(mv, implementationContext).getMaximalSize(), EMPTY);
methodSizeHandler.recordMaxima(postProcessor
.resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler)
.apply(mv, implementationContext).getMaximalSize(), EMPTY);
}

@Override
Expand Down Expand Up @@ -9178,9 +9181,9 @@ 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, assigner, adviceMethod.getReturnType().represents(void.class)
? PostProcessor.NO_RETURN
: getReturnValueOffset()).apply(methodVisitor, implementationContext).getMaximalSize(), EMPTY);
methodSizeHandler.recordMaxima(postProcessor
.resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler)
.apply(methodVisitor, implementationContext).getMaximalSize(), EMPTY);
}

/**
Expand Down

0 comments on commit 51cf839

Please sign in to comment.