From b0afd033b09c283413a62bd1508b6154b811c098 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Sun, 17 Apr 2016 03:05:38 +0200 Subject: [PATCH] Added missing documentation. --- .../main/java/net/bytebuddy/asm/Advice.java | 578 ++++++++++++------ .../java/net/bytebuddy/asm/AdviceTest.java | 8 +- 2 files changed, 404 insertions(+), 182 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 f500532a64d..4d5537ecc0d 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 @@ -336,16 +336,32 @@ public String toString() { '}'; } - protected interface StackSizeHandler { + /** + * A handler for computing the instrumented method's size. + */ + protected interface MethodSizeHandler { /** * Indicates that a size is not computed but handled directly by ASM. */ int UNDEFINED_SIZE = Short.MAX_VALUE; + /** + * Binds a method size handler for the entry advice. + * + * @param adviceMethod The method representing the entry advice. + * @return A method size handler for the entry advice. + */ ForAdvice bindEntry(MethodDescription.InDefinedShape adviceMethod); - ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod, boolean onThrowable); + /** + * Binds the method size handler for the exit advice. + * + * @param adviceMethod The method representing the exit advice. + * @param skipThrowable {@code true} if the exit advice is not invoked on an exception. + * @return A method size handler for the exit advice. + */ + ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod, boolean skipThrowable); /** * Computes a compound stack size for the advice and the translated instrumented method. @@ -363,8 +379,16 @@ protected interface StackSizeHandler { */ int compoundLocalVariableLength(int localVariableLength); + /** + * A method size handler for an advice method. + */ interface ForAdvice { + /** + * Records a minimum stack size required by the represented advice method. + * + * @param stackSize The minimum size required by the represented advice method. + */ void recordMinimum(int stackSize); /** @@ -384,8 +408,14 @@ interface ForAdvice { void recordPadding(int padding); } - enum NoOp implements StackSizeHandler, ForAdvice { + /** + * A non-operational method size handler. + */ + enum NoOp implements MethodSizeHandler, ForAdvice { + /** + * The singleton instance. + */ INSTANCE; @Override @@ -394,7 +424,7 @@ public ForAdvice bindEntry(MethodDescription.InDefinedShape adviceMethod) { } @Override - public ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod, boolean onThrowable) { + public ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod, boolean skipThrowable) { return this; } @@ -423,14 +453,31 @@ public void recordMaxima(int stackSize, int localVariableLength) { public void recordPadding(int padding) { /* do nothing */ } + + @Override + public String toString() { + return "Advice.MethodSizeHandler.NoOp." + name(); + } } - class Default implements StackSizeHandler { + /** + * A default implementation for a method size handler. + */ + class Default implements MethodSizeHandler { + /** + * The instrumented method. + */ private final MethodDescription.InDefinedShape instrumentedMethod; + /** + * The list of types that the instrumented method requires in addition to the method parameters. + */ private final TypeList requiredTypes; + /** + * A list of types that are yielded by the instrumented method and available to the exit advice. + */ private final TypeList yieldedTypes; /** @@ -456,24 +503,33 @@ protected Default(MethodDescription.InDefinedShape instrumentedMethod, TypeList this.yieldedTypes = yieldedTypes; } - protected static StackSizeHandler of(MethodDescription.InDefinedShape instrumentedMethod, - List requiredTypes, - List yieldedTypes, - int writerFlags) { + /** + * Creates a method size handler applicable for the given instrumented method. + * + * @param instrumentedMethod The instrumented method. + * @param requiredTypes The list of types that the instrumented method requires in addition to the method parameters. + * @param yieldedTypes A list of types that are yielded by the instrumented method and available to the exit advice. + * @param writerFlags The flags supplied to the ASM class writer. + * @return An appropriate method size handler. + */ + protected static MethodSizeHandler of(MethodDescription.InDefinedShape instrumentedMethod, + List requiredTypes, + List yieldedTypes, + int writerFlags) { return (writerFlags & (ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES)) != 0 ? NoOp.INSTANCE : new Default(instrumentedMethod, new TypeList.Explicit(requiredTypes), new TypeList.Explicit(yieldedTypes)); } @Override - public StackSizeHandler.ForAdvice bindEntry(MethodDescription.InDefinedShape adviceMethod) { + public MethodSizeHandler.ForAdvice bindEntry(MethodDescription.InDefinedShape adviceMethod) { stackSize = Math.max(stackSize, adviceMethod.getReturnType().getStackSize().getSize()); return new ForAdvice(adviceMethod, new TypeList.Empty(), new TypeList.Explicit(requiredTypes)); } @Override - public StackSizeHandler.ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod, boolean onThrowable) { - stackSize = Math.max(stackSize, adviceMethod.getReturnType().getStackSize().maximum(onThrowable + public MethodSizeHandler.ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod, boolean skipThrowable) { + stackSize = Math.max(stackSize, adviceMethod.getReturnType().getStackSize().maximum(skipThrowable ? StackSize.ZERO : StackSize.SINGLE).getSize()); return new ForAdvice(adviceMethod, new TypeList.Explicit(CompoundList.of(requiredTypes, yieldedTypes)), new TypeList.Empty()); @@ -491,12 +547,35 @@ public int compoundLocalVariableLength(int localVariableLength) { + yieldedTypes.getStackSize()); } - protected class ForAdvice implements StackSizeHandler.ForAdvice { + @Override + public String toString() { + return "Advice.MethodSizeHandler.Default{" + + "instrumentedMethod=" + instrumentedMethod + + ", requiredTypes=" + requiredTypes + + ", yieldedTypes=" + yieldedTypes + + ", stackSize=" + stackSize + + ", localVariableLength=" + localVariableLength + + '}'; + } + + /** + * A method size handler for an advice method. + */ + protected class ForAdvice implements MethodSizeHandler.ForAdvice { + /** + * The advice method. + */ private final MethodDescription.InDefinedShape adviceMethod; + /** + * A list of types required by this advice method. + */ private final TypeList requiredTypes; + /** + * A list of types yielded by this advice method. + */ private final TypeList yieldedTypes; /** @@ -504,6 +583,13 @@ protected class ForAdvice implements StackSizeHandler.ForAdvice { */ private int padding; + /** + * Creates a new method size handler for an advice method. + * + * @param adviceMethod The advice method. + * @param requiredTypes A list of types required by this advice method. + * @param yieldedTypes A list of types yielded by this advice method. + */ protected ForAdvice(MethodDescription.InDefinedShape adviceMethod, TypeList requiredTypes, TypeList yieldedTypes) { this.adviceMethod = adviceMethod; this.requiredTypes = requiredTypes; @@ -530,11 +616,24 @@ public void recordMaxima(int stackSize, int localVariableLength) { public void recordPadding(int padding) { this.padding = Math.max(this.padding, padding); } + + @Override + public String toString() { + return "Advice.MethodSizeHandler.Default.ForAdvice{" + + "adviceMethod=" + adviceMethod + + ", requiredTypes=" + requiredTypes + + ", yieldedTypes=" + yieldedTypes + + ", padding=" + padding + + '}'; + } } } } - protected interface StackFrameHandler { + /** + * A handler for computing and translating stack map frames. + */ + protected interface StackMapFrameHandler { /** * Translates a frame. @@ -563,7 +662,10 @@ protected interface StackFrameHandler { */ void injectCompletionFrame(MethodVisitor methodVisitor, boolean secondary); - interface ForInstrumentedMethod extends StackFrameHandler { + /** + * A stack map frame handler for an instrumented method. + */ + interface ForInstrumentedMethod extends StackMapFrameHandler { /** * Binds this meta data handler for the entry advice. @@ -581,24 +683,38 @@ interface ForInstrumentedMethod extends StackFrameHandler { */ ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod); + /** + * Returns a hint to supply to a {@link ClassReader} when parsing an advice method. + * + * @return The reader hint to supply to an ASM class reader. + */ int getReaderHint(); } - interface ForAdvice extends StackFrameHandler { + /** + * A stack map frame handler for an advice method. + */ + interface ForAdvice extends StackMapFrameHandler { /* marker interface */ } + /** + * A non-operational stack map frame handler. + */ enum NoOp implements ForInstrumentedMethod, ForAdvice { + /** + * The singleton instance. + */ INSTANCE; @Override - public StackFrameHandler.ForAdvice bindEntry(MethodDescription.InDefinedShape adviceMethod) { + public StackMapFrameHandler.ForAdvice bindEntry(MethodDescription.InDefinedShape adviceMethod) { return this; } @Override - public StackFrameHandler.ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod) { + public StackMapFrameHandler.ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod) { return this; } @@ -626,21 +742,18 @@ public void injectHandlerFrame(MethodVisitor methodVisitor) { public void injectCompletionFrame(MethodVisitor methodVisitor, boolean secondary) { /* do nothing */ } + + @Override + public String toString() { + return "Advice.StackMapFrameHandler.NoOp." + name(); + } } + /** + * A default implementation of a stack map frame handler for an instrumented method. + */ class Default implements ForInstrumentedMethod { - protected static ForInstrumentedMethod of(MethodDescription.InDefinedShape instrumentedMethod, - List requiredTypes, - List yieldedTypes, - ClassFileVersion classFileVersion, - int writerFlags, - int readerFlags) { - return (writerFlags & ClassWriter.COMPUTE_FRAMES) != 0 || classFileVersion.isLessThan(ClassFileVersion.JAVA_V6) - ? NoOp.INSTANCE - : new Default(instrumentedMethod, new TypeList.Explicit(requiredTypes), new TypeList.Explicit(yieldedTypes), (readerFlags & ClassReader.EXPAND_FRAMES) != 0); - } - /** * An empty array indicating an empty frame. */ @@ -689,6 +802,28 @@ protected Default(MethodDescription.InDefinedShape instrumentedMethod, this.expandFrames = expandFrames; } + /** + * Creates an appropriate stack map frame handler for an instrumented method. + * + * @param instrumentedMethod The instrumented method. + * @param requiredTypes A list of intermediate types to be considered as part of the instrumented method's steady signature. + * @param yieldedTypes The types that are expected to be added after the instrumented method returns. + * @param classFileVersion The instrumented type's class file version. + * @param writerFlags The flags supplied to the ASM writier. + * @param readerFlags The reader flags supplied to the ASM reader. + * @return An approrpiate stack map frame handler for an instrumented method. + */ + protected static ForInstrumentedMethod of(MethodDescription.InDefinedShape instrumentedMethod, + List requiredTypes, + List yieldedTypes, + ClassFileVersion classFileVersion, + int writerFlags, + int readerFlags) { + return (writerFlags & ClassWriter.COMPUTE_FRAMES) != 0 || classFileVersion.isLessThan(ClassFileVersion.JAVA_V6) + ? NoOp.INSTANCE + : new Default(instrumentedMethod, new TypeList.Explicit(requiredTypes), new TypeList.Explicit(yieldedTypes), (readerFlags & ClassReader.EXPAND_FRAMES) != 0); + } + /** * Translates a type into a representation of its form inside a stack map frame. * @@ -714,12 +849,12 @@ protected static Object toFrame(TypeDescription typeDescription) { } @Override - public StackFrameHandler.ForAdvice bindEntry(MethodDescription.InDefinedShape adviceMethod) { + public StackMapFrameHandler.ForAdvice bindEntry(MethodDescription.InDefinedShape adviceMethod) { return new ForAdvice(adviceMethod, new TypeList.Empty(), requiredTypes, TranslationMode.ENTRY); } @Override - public StackFrameHandler.ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod) { + public StackMapFrameHandler.ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod) { return new ForAdvice(adviceMethod, new TypeList.Explicit(CompoundList.of(requiredTypes, yieldedTypes)), new TypeList.Empty(), TranslationMode.EXIT); } @@ -862,6 +997,17 @@ protected void injectFullFrame(MethodVisitor methodVisitor, List requiredTypes = methodEnter.getEnterType().represents(void.class) ? Collections.emptyList() : Collections.singletonList(methodEnter.getEnterType()); - stackSizeHandler = StackSizeHandler.Default.of(instrumentedMethod, requiredTypes, yieldedTypes, writerFlags); - stackFrameHandler = StackFrameHandler.Default.of(instrumentedMethod, requiredTypes, yieldedTypes, classFileVersion, writerFlags, readerFlags); - this.methodEnter = methodEnter.bind(instrumentedMethod, methodVisitor, stackSizeHandler, stackFrameHandler); - this.methodExit = methodExit.bind(instrumentedMethod, methodVisitor, stackSizeHandler, stackFrameHandler); + methodSizeHandler = MethodSizeHandler.Default.of(instrumentedMethod, requiredTypes, yieldedTypes, writerFlags); + stackMapFrameHandler = StackMapFrameHandler.Default.of(instrumentedMethod, requiredTypes, yieldedTypes, classFileVersion, writerFlags, readerFlags); + this.methodEnter = methodEnter.bind(instrumentedMethod, methodVisitor, methodSizeHandler, stackMapFrameHandler); + this.methodExit = methodExit.bind(instrumentedMethod, methodVisitor, methodSizeHandler, stackMapFrameHandler); } @Override @@ -1148,13 +1319,13 @@ protected void variable(int opcode, int offset) { @Override public void visitFrame(int frameType, int localVariableLength, Object[] localVariable, int stackSize, Object[] stack) { - stackFrameHandler.translateFrame(mv, frameType, localVariableLength, localVariable, stackSize, stack); + stackMapFrameHandler.translateFrame(mv, frameType, localVariableLength, localVariable, stackSize, stack); } @Override public void visitMaxs(int stackSize, int localVariableLength) { onUserEnd(); - mv.visitMaxs(stackSizeHandler.compoundStackSize(stackSize), stackSizeHandler.compoundLocalVariableLength(localVariableLength)); + mv.visitMaxs(methodSizeHandler.compoundStackSize(stackSize), methodSizeHandler.compoundLocalVariableLength(localVariableLength)); } /** @@ -1173,6 +1344,7 @@ protected static class WithoutExitAdvice extends AdviceVisitor { * @param methodVisitor The method visitor for the instrumented method. * @param instrumentedMethod A description of the instrumented method. * @param methodEnter The dispatcher to be used for method entry. + * @param classFileVersion The instrumented type's class file version. * @param writerFlags The ASM writer flags that were set. * @param readerFlags The ASM reader flags that were set. */ @@ -1233,6 +1405,7 @@ protected abstract static class WithExitAdvice extends AdviceVisitor { * @param methodEnter The dispatcher to be used for method entry. * @param methodExit The dispatcher to be used for method exit. * @param yieldedTypes The types that are expected to be added after the instrumented method returns. + * @param classFileVersion The instrumented type's class file version. * @param writerFlags The ASM writer flags that were set. * @param readerFlags The ASM reader flags that were set. */ @@ -1280,7 +1453,7 @@ protected void onVisitInsn(int opcode) { protected void onUserEnd() { onUserExit(); mv.visitLabel(endOfMethod); - stackFrameHandler.injectCompletionFrame(mv, false); + stackMapFrameHandler.injectCompletionFrame(mv, false); methodExit.apply(); onAdviceExit(); if (instrumentedMethod.getReturnType().represents(void.class)) { @@ -1345,6 +1518,7 @@ protected static class WithExceptionHandling extends WithExitAdvice { * @param instrumentedMethod A description of the instrumented method. * @param methodEnter The dispatcher to be used for method entry. * @param methodExit The dispatcher to be used for method exit. + * @param classFileVersion The instrumented type's class file version. * @param writerFlags The ASM writer flags that were set. * @param readerFlags The ASM reader flags that were set. */ @@ -1389,7 +1563,7 @@ protected void onUserReturn() { @Override protected void onUserExit() { mv.visitLabel(userEnd); - stackFrameHandler.injectHandlerFrame(mv); + stackMapFrameHandler.injectHandlerFrame(mv); variable(Opcodes.ASTORE, instrumentedMethod.getReturnType().getStackSize().getSize()); storeDefaultReturn(); mv.visitJumpInsn(Opcodes.GOTO, endOfMethod); @@ -1404,7 +1578,7 @@ protected void onAdviceExit() { @Override protected void onMethodExit() { mv.visitLabel(exceptionalReturn); - stackFrameHandler.injectCompletionFrame(mv, true); + stackMapFrameHandler.injectCompletionFrame(mv, true); variable(Opcodes.ALOAD, instrumentedMethod.getReturnType().getStackSize().getSize()); mv.visitInsn(Opcodes.ATHROW); } @@ -1455,6 +1629,7 @@ protected static class WithoutExceptionHandling extends WithExitAdvice { * @param instrumentedMethod A description of the instrumented method. * @param methodEnter The dispatcher to be used for method entry. * @param methodExit The dispatcher to be used for method exit. + * @param classFileVersion The instrumented type's class file version. * @param writerFlags The ASM writer flags that were set. * @param readerFlags The ASM reader flags that were set. */ @@ -4242,25 +4417,28 @@ interface Bound { /** * Invoked at the start of a method. * - * @param methodVisitor The method visitor of the instrumented method. + * @param methodVisitor The method visitor of the instrumented method. + * @param methodSizeHandler A handler for computing the method size requirements. */ - void onStart(MethodVisitor methodVisitor, StackSizeHandler.ForAdvice stackSizeHandler); + void onStart(MethodVisitor methodVisitor, MethodSizeHandler.ForAdvice methodSizeHandler); /** * Invoked at the end of a method. * - * @param methodVisitor The method visitor of the instrumented method. - * @param returnValueProducer A producer for defining a default return value of the advised method. + * @param methodVisitor The method visitor of the instrumented method. + * @param stackMapFrameHandler A handler for translating and injecting stack map frames. + * @param returnValueProducer A producer for defining a default return value of the advised method. */ - void onEnd(MethodVisitor methodVisitor, StackFrameHandler.ForAdvice stackFrameHandler, ReturnValueProducer returnValueProducer); + void onEnd(MethodVisitor methodVisitor, StackMapFrameHandler.ForAdvice stackMapFrameHandler, ReturnValueProducer returnValueProducer); /** * Invoked at the end of a method. Additionally indicates that the handler block should be surrounding by a skipping instruction. * - * @param methodVisitor The method visitor of the instrumented method. - * @param returnValueProducer A producer for defining a default return value of the advised method. + * @param methodVisitor The method visitor of the instrumented method. + * @param stackMapFrameHandler A handler for translating and injecting stack map frames. + * @param returnValueProducer A producer for defining a default return value of the advised method. */ - void onEndSkipped(MethodVisitor methodVisitor, StackFrameHandler.ForAdvice stackFrameHandler, ReturnValueProducer returnValueProducer); + void onEndSkipped(MethodVisitor methodVisitor, StackMapFrameHandler.ForAdvice stackMapFrameHandler, ReturnValueProducer returnValueProducer); } /** @@ -4284,17 +4462,17 @@ public void onPrepare(MethodVisitor methodVisitor) { } @Override - public void onStart(MethodVisitor methodVisitor, StackSizeHandler.ForAdvice stackSizeHandler) { + public void onStart(MethodVisitor methodVisitor, MethodSizeHandler.ForAdvice methodSizeHandler) { /* do nothing */ } @Override - public void onEnd(MethodVisitor methodVisitor, StackFrameHandler.ForAdvice stackFrameHandler, ReturnValueProducer returnValueProducer) { + public void onEnd(MethodVisitor methodVisitor, StackMapFrameHandler.ForAdvice stackMapFrameHandler, ReturnValueProducer returnValueProducer) { /* do nothing */ } @Override - public void onEndSkipped(MethodVisitor methodVisitor, StackFrameHandler.ForAdvice stackFrameHandler, ReturnValueProducer returnValueProducer) { + public void onEndSkipped(MethodVisitor methodVisitor, StackMapFrameHandler.ForAdvice stackMapFrameHandler, ReturnValueProducer returnValueProducer) { /* do nothing */ } @@ -4385,24 +4563,24 @@ public void onPrepare(MethodVisitor methodVisitor) { } @Override - public void onStart(MethodVisitor methodVisitor, StackSizeHandler.ForAdvice stackSizeHandler) { + public void onStart(MethodVisitor methodVisitor, MethodSizeHandler.ForAdvice methodSizeHandler) { methodVisitor.visitLabel(startOfMethod); - stackSizeHandler.recordMinimum(StackSize.SINGLE.getSize()); + methodSizeHandler.recordMinimum(StackSize.SINGLE.getSize()); } @Override - public void onEnd(MethodVisitor methodVisitor, StackFrameHandler.ForAdvice stackFrameHandler, ReturnValueProducer returnValueProducer) { + public void onEnd(MethodVisitor methodVisitor, StackMapFrameHandler.ForAdvice stackMapFrameHandler, ReturnValueProducer returnValueProducer) { methodVisitor.visitLabel(endOfMethod); - stackFrameHandler.injectHandlerFrame(methodVisitor); + stackMapFrameHandler.injectHandlerFrame(methodVisitor); methodVisitor.visitInsn(Opcodes.POP); returnValueProducer.storeDefaultValue(methodVisitor); } @Override - public void onEndSkipped(MethodVisitor methodVisitor, StackFrameHandler.ForAdvice stackFrameHandler, ReturnValueProducer returnValueProducer) { + public void onEndSkipped(MethodVisitor methodVisitor, StackMapFrameHandler.ForAdvice stackMapFrameHandler, ReturnValueProducer returnValueProducer) { Label endOfHandler = new Label(); methodVisitor.visitJumpInsn(Opcodes.GOTO, endOfHandler); - onEnd(methodVisitor, stackFrameHandler, returnValueProducer); + onEnd(methodVisitor, stackMapFrameHandler, returnValueProducer); methodVisitor.visitLabel(endOfHandler); } @@ -4426,14 +4604,16 @@ interface Resolved extends Dispatcher { /** * Binds this dispatcher for resolution to a specific method. * - * @param instrumentedMethod The instrumented method. - * @param methodVisitor The method visitor for writing the instrumented method. + * @param instrumentedMethod The instrumented method. + * @param methodVisitor The method visitor for writing the instrumented method. + * @param methodSizeHandler A handler for computing the method size requirements. + * @param stackMapFrameHandler A handler for translating and injecting stack map frames. * @return A dispatcher that is bound to the instrumented method. */ Bound bind(MethodDescription.InDefinedShape instrumentedMethod, MethodVisitor methodVisitor, - StackSizeHandler stackSizeHandler, - StackFrameHandler.ForInstrumentedMethod stackFrameHandler); + MethodSizeHandler methodSizeHandler, + StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler); /** * Represents a resolved dispatcher for entering a method. @@ -4535,8 +4715,8 @@ public void apply() { @Override public Bound bind(MethodDescription.InDefinedShape instrumentedMethod, MethodVisitor methodVisitor, - StackSizeHandler stackSizeHandler, - StackFrameHandler.ForInstrumentedMethod stackFrameHandler) { + MethodSizeHandler methodSizeHandler, + StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler) { return this; } @@ -4679,12 +4859,12 @@ public boolean isAlive() { @Override public Bound bind(MethodDescription.InDefinedShape instrumentedMethod, MethodVisitor methodVisitor, - StackSizeHandler stackSizeHandler, - StackFrameHandler.ForInstrumentedMethod stackFrameHandler) { + MethodSizeHandler methodSizeHandler, + StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler) { return new AdviceMethodInliner(instrumentedMethod, methodVisitor, - stackSizeHandler, - stackFrameHandler, + methodSizeHandler, + stackMapFrameHandler, suppressionHandler.bind(), new ClassReader(binaryRepresentation)); } @@ -4692,14 +4872,16 @@ public Bound bind(MethodDescription.InDefinedShape instrumentedMethod, /** * Applies a resolution for a given instrumented method. * - * @param methodVisitor A method visitor for writing byte code to the instrumented method. - * @param instrumentedMethod A description of the instrumented method. - * @param suppressionHandler The bound suppression handler that is used for suppressing exceptions of this advice method. + * @param methodVisitor A method visitor for writing byte code to the instrumented method. + * @param methodSizeHandler A handler for computing the method size requirements. + * @param stackMapFrameHandler A handler for translating and injecting stack map frames. + * @param instrumentedMethod A description of the instrumented method. + * @param suppressionHandler The bound suppression handler that is used for suppressing exceptions of this advice method. * @return A method visitor for visiting the advice method's byte code. */ protected abstract MethodVisitor apply(MethodVisitor methodVisitor, - StackSizeHandler stackSizeHandler, - StackFrameHandler.ForInstrumentedMethod stackFrameHandler, + MethodSizeHandler methodSizeHandler, + StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler, MethodDescription.InDefinedShape instrumentedMethod, SuppressionHandler.Bound suppressionHandler); @@ -4734,9 +4916,15 @@ protected class AdviceMethodInliner extends ClassVisitor implements Bound { */ private final MethodVisitor methodVisitor; - private final StackSizeHandler stackSizeHandler; + /** + * A handler for computing the method size requirements. + */ + private final MethodSizeHandler methodSizeHandler; - private final StackFrameHandler.ForInstrumentedMethod stackFrameHandler; + /** + * A handler for translating and injecting stack map frames. + */ + private final StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler; /** * A bound suppression handler that is used for suppressing exceptions of this advice method. @@ -4756,22 +4944,24 @@ protected class AdviceMethodInliner extends ClassVisitor implements Bound { /** * Creates a new code copier. * - * @param instrumentedMethod The instrumented method. - * @param methodVisitor The method visitor for writing the instrumented method. - * @param suppressionHandler A bound suppression handler that is used for suppressing exceptions of this advice method. - * @param classReader A class reader for parsing the class file containing the represented advice method. + * @param instrumentedMethod The instrumented method. + * @param methodVisitor The method visitor for writing the instrumented method. + * @param methodSizeHandler A handler for computing the method size requirements. + * @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 classReader A class reader for parsing the class file containing the represented advice method. */ protected AdviceMethodInliner(MethodDescription.InDefinedShape instrumentedMethod, MethodVisitor methodVisitor, - StackSizeHandler stackSizeHandler, - StackFrameHandler.ForInstrumentedMethod stackFrameHandler, + MethodSizeHandler methodSizeHandler, + StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler, SuppressionHandler.Bound suppressionHandler, ClassReader classReader) { super(Opcodes.ASM5); this.instrumentedMethod = instrumentedMethod; this.methodVisitor = methodVisitor; - this.stackSizeHandler = stackSizeHandler; - this.stackFrameHandler = stackFrameHandler; + this.methodSizeHandler = methodSizeHandler; + this.stackMapFrameHandler = stackMapFrameHandler; this.suppressionHandler = suppressionHandler; this.classReader = classReader; labels = new ArrayList