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 4e1f9ab2407..cfe927357a7 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 @@ -6330,16 +6330,16 @@ public void apply() { adviceMethod.getInternalName(), adviceMethod.getDescriptor(), false); - onAfterCall(); + onMethodReturn(); suppressionHandler.onEndSkipped(methodVisitor, stackMapFrameHandler, this); + onMethodExit(); stackMapFrameHandler.injectCompletionFrame(methodVisitor, false); methodSizeHandler.recordMaxima(Math.max(maximumStackSize, adviceMethod.getReturnType().getStackSize().getSize()), EMPTY); } - /** - * Invoked after the advise method was invoked. - */ - protected abstract void onAfterCall(); + protected abstract void onMethodReturn(); + + protected abstract void onMethodExit(); @Override public String toString() { @@ -6379,7 +6379,12 @@ protected ForMethodEnter(MethodDescription.InDefinedShape adviceMethod, } @Override - protected void onAfterCall() { + protected void onMethodReturn() { + /* do nothing */ + } + + @Override + protected void onMethodExit() { if (adviceMethod.getReturnType().represents(boolean.class) || adviceMethod.getReturnType().represents(byte.class) || adviceMethod.getReturnType().represents(short.class) @@ -6405,19 +6410,14 @@ public void storeDefaultValue(MethodVisitor methodVisitor) { || adviceMethod.getReturnType().represents(char.class) || adviceMethod.getReturnType().represents(int.class)) { methodVisitor.visitInsn(Opcodes.ICONST_0); - methodVisitor.visitVarInsn(Opcodes.ISTORE, instrumentedMethod.getStackSize()); } else if (adviceMethod.getReturnType().represents(long.class)) { methodVisitor.visitInsn(Opcodes.LCONST_0); - methodVisitor.visitVarInsn(Opcodes.LSTORE, instrumentedMethod.getStackSize()); } else if (adviceMethod.getReturnType().represents(float.class)) { methodVisitor.visitInsn(Opcodes.FCONST_0); - methodVisitor.visitVarInsn(Opcodes.FSTORE, instrumentedMethod.getStackSize()); } else if (adviceMethod.getReturnType().represents(double.class)) { methodVisitor.visitInsn(Opcodes.DCONST_0); - methodVisitor.visitVarInsn(Opcodes.DSTORE, instrumentedMethod.getStackSize()); } else if (!adviceMethod.getReturnType().represents(void.class)) { methodVisitor.visitInsn(Opcodes.ACONST_NULL); - methodVisitor.visitVarInsn(Opcodes.ASTORE, instrumentedMethod.getStackSize()); } } @@ -6457,7 +6457,7 @@ protected ForMethodExit(MethodDescription.InDefinedShape adviceMethod, } @Override - protected void onAfterCall() { + protected void onMethodReturn() { switch (adviceMethod.getReturnType().getStackSize()) { case ZERO: return; @@ -6472,6 +6472,11 @@ protected void onAfterCall() { } } + @Override + protected void onMethodExit() { + /* do nothing */ + } + @Override public void storeDefaultValue(MethodVisitor methodVisitor) { /* do nothing */