Skip to content

Commit

Permalink
Remove frame padding visitor and replace with explicit noop instructi…
Browse files Browse the repository at this point in the history
…ons to introduce padding.
  • Loading branch information
raphw committed Oct 29, 2021
1 parent 91fa996 commit cf0aba1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 370 deletions.
15 changes: 9 additions & 6 deletions byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import net.bytebuddy.utility.JavaType;
import net.bytebuddy.utility.OpenedClassReader;
import net.bytebuddy.utility.visitor.ExceptionTableSensitiveMethodVisitor;
import net.bytebuddy.utility.visitor.FramePaddingMethodVisitor;
import net.bytebuddy.utility.visitor.LineNumberPrependingMethodVisitor;
import net.bytebuddy.utility.visitor.StackAwareMethodVisitor;
import org.objectweb.asm.*;
Expand Down Expand Up @@ -535,9 +534,9 @@ protected MethodVisitor doWrap(TypeDescription instrumentedType,
Implementation.Context implementationContext,
int writerFlags,
int readerFlags) {
methodVisitor = new FramePaddingMethodVisitor(methodEnter.isPrependLineNumber()
? new LineNumberPrependingMethodVisitor(methodVisitor)
: methodVisitor);
if (methodEnter.isPrependLineNumber()) {
methodVisitor = new LineNumberPrependingMethodVisitor(methodVisitor);
}
if (!methodExit.isAlive()) {
return new AdviceVisitor.WithoutExitAdvice(methodVisitor,
implementationContext,
Expand Down Expand Up @@ -4875,11 +4874,13 @@ protected abstract ForInstrumentedMethod resolve(MethodDescription instrumentedM
* the local variable array must still be intact and the stack must be empty. A frame is added
* subsequently to the post processor's execution, making it feasible to add a jump instruction to the
* end of the method after which no further byte code instructions must be issued. This also applies
* to compound post processors.
* to compound post processors. If a post processor emits a frame as its last instruction, it should
* yield a <i>NOP</i> instruction to avoid that subsequent code starts with a frame.
* </p>
* <p>
* <b>Important</b>: A post processor is triggered after the suppression handler. Exceptions triggered
* by post processing code will therefore cause those exceptions to be propagated.
* by post processing code will therefore cause those exceptions to be propagated unless the post
* processor configures explicit exception handling.
* </p>
*/
public interface PostProcessor {
Expand Down Expand Up @@ -10541,6 +10542,7 @@ protected void onAfterExceptionTable() {
mv.visitLabel(preparationStart);
methodSizeHandler.requireStackSize(argumentHandler.prepare(mv));
stackMapFrameHandler.injectStartFrame(mv);
mv.visitInsn(Opcodes.NOP);
onUserStart();
}

Expand Down Expand Up @@ -13161,6 +13163,7 @@ public Size apply(MethodVisitor methodVisitor, Context implementationContext) {
Size size = dispatcher.apply(methodVisitor, offset, label).aggregate(stackManipulation.apply(methodVisitor, implementationContext));
methodVisitor.visitLabel(label);
stackMapFrameHandler.injectIntermediateFrame(methodVisitor, Collections.<TypeDescription>emptyList());
methodVisitor.visitInsn(Opcodes.NOP);
return size;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import net.bytebuddy.utility.CompoundList;
import net.bytebuddy.utility.OpenedClassReader;
import net.bytebuddy.utility.privilege.GetSystemPropertyAction;
import net.bytebuddy.utility.visitor.FramePaddingMethodVisitor;
import net.bytebuddy.utility.visitor.MetadataAwareClassVisitor;
import org.objectweb.asm.*;
import org.objectweb.asm.commons.ClassRemapper;
Expand Down Expand Up @@ -4406,6 +4405,7 @@ public void onFrame(int type, int localVariableLength) {
*/
public void emitFrame(MethodVisitor methodVisitor) {
methodVisitor.visitFrame(Opcodes.F_NEW, EMPTY.length, EMPTY, EMPTY.length, EMPTY);
methodVisitor.visitInsn(Opcodes.NOP);
}
}

Expand Down Expand Up @@ -4453,6 +4453,7 @@ public void emitFrame(MethodVisitor methodVisitor) {
} else {
methodVisitor.visitFrame(Opcodes.F_CHOP, currentLocalVariableLength, EMPTY, EMPTY.length, EMPTY);
}
methodVisitor.visitInsn(Opcodes.NOP);
currentLocalVariableLength = 0;
}
}
Expand Down Expand Up @@ -4604,7 +4605,7 @@ protected WithDrain(MethodVisitor methodVisitor,
AnnotationValueFilter.Factory annotationValueFilterFactory,
boolean requireFrames,
boolean expandFrames) {
super(new FramePaddingMethodVisitor(methodVisitor), instrumentedType, record, annotationValueFilterFactory, requireFrames, expandFrames);
super(methodVisitor, instrumentedType, record, annotationValueFilterFactory, requireFrames, expandFrames);
appended = new Label();
original = new Label();
}
Expand Down Expand Up @@ -5358,7 +5359,6 @@ public void visitCode() {
if (!resolution.getAppendedParameters().isEmpty()
&& (writerFlags & ClassWriter.COMPUTE_FRAMES) == 0
&& implementationContext.getClassFileVersion().isAtLeast(ClassFileVersion.JAVA_V6)) {
mv = new FramePaddingMethodVisitor(mv);
if ((readerFlags & ClassReader.EXPAND_FRAMES) == 0 && resolution.getAppendedParameters().size() < 4) {
super.visitFrame(Opcodes.F_CHOP, resolution.getAppendedParameters().size(), EMPTY, EMPTY.length, EMPTY);
} else {
Expand Down Expand Up @@ -5391,6 +5391,7 @@ public void visitCode() {
? Opcodes.F_FULL
: Opcodes.F_NEW, frame.length, frame, EMPTY.length, EMPTY);
}
super.visitInsn(Opcodes.NOP);
}
} else {
mv = IGNORE_METHOD;
Expand Down

This file was deleted.

Loading

0 comments on commit cf0aba1

Please sign in to comment.