Package org.codehaus.groovy.classgen.asm
Class ConditionalJumpFoldingMethodVisitor
java.lang.Object
org.objectweb.asm.MethodVisitor
org.codehaus.groovy.classgen.asm.ConditionalJumpFoldingMethodVisitor
public class ConditionalJumpFoldingMethodVisitor
extends org.objectweb.asm.MethodVisitor
Folds a boolean that is materialized only to be branched on straight away.
Comparisons such as i < n are written as a 0/1 value
(see BinaryExpressionWriter), and conditions of if, while
and for statements then branch on that value. This visitor rewrites
Jcc L1; ICONST_1; GOTO L2; L1: ICONST_0; L2: IFEQ L3 ==> Jcc L3
Jcc L1; ICONST_1; GOTO L2; L1: ICONST_0; L2: IFNE L3 ==> !Jcc L3
which is the shape javac produces. Besides being smaller and faster, some
bytecode consumers (e.g. GPU kernel compilers detecting counted loops) only
recognize loop conditions in this form.
The rewrite is exact: the folded jump tests the same operands (or the same
LCMP/FCMPx/DCMPx result) as the original jump. It is
only applied when L1 and L2 are referenced solely by the
pattern itself, so labels shared with other jumps (e.g. from &&/||)
are left untouched.
- Since:
- 7.0.0
- See Also:
-
Field Summary
Fields inherited from class org.objectweb.asm.MethodVisitor
api, mv -
Constructor Summary
ConstructorsConstructorDescriptionConditionalJumpFoldingMethodVisitor(org.objectweb.asm.MethodVisitor delegate) Creates a folding visitor that forwards todelegate. -
Method Summary
Modifier and TypeMethodDescriptionvoidvisitAnnotableParameterCount(int parameterCount, boolean visible) org.objectweb.asm.AnnotationVisitorvisitAnnotation(String descriptor, boolean visible) org.objectweb.asm.AnnotationVisitorvoidvisitAttribute(org.objectweb.asm.Attribute attribute) voidvoidvisitEnd()voidvisitFieldInsn(int opcode, String owner, String name, String descriptor) voidvisitFrame(int type, int numLocal, Object[] local, int numStack, Object[] stack) voidvisitIincInsn(int varIndex, int increment) voidvisitInsn(int opcode) org.objectweb.asm.AnnotationVisitorvisitInsnAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) voidvisitIntInsn(int opcode, int operand) voidvisitInvokeDynamicInsn(String name, String descriptor, org.objectweb.asm.Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) voidvisitJumpInsn(int opcode, org.objectweb.asm.Label label) voidvisitLabel(org.objectweb.asm.Label label) voidvisitLdcInsn(Object value) voidvisitLineNumber(int line, org.objectweb.asm.Label start) voidvisitLocalVariable(String name, String descriptor, String signature, org.objectweb.asm.Label start, org.objectweb.asm.Label end, int index) org.objectweb.asm.AnnotationVisitorvisitLocalVariableAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, org.objectweb.asm.Label[] start, org.objectweb.asm.Label[] end, int[] index, String descriptor, boolean visible) voidvisitLookupSwitchInsn(org.objectweb.asm.Label dflt, int[] keys, org.objectweb.asm.Label[] labels) voidvisitMaxs(int maxStack, int maxLocals) voidvisitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) voidvisitMultiANewArrayInsn(String descriptor, int numDimensions) voidvisitParameter(String name, int access) org.objectweb.asm.AnnotationVisitorvisitParameterAnnotation(int parameter, String descriptor, boolean visible) voidvisitTableSwitchInsn(int min, int max, org.objectweb.asm.Label dflt, org.objectweb.asm.Label... labels) org.objectweb.asm.AnnotationVisitorvisitTryCatchAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) voidvisitTryCatchBlock(org.objectweb.asm.Label start, org.objectweb.asm.Label end, org.objectweb.asm.Label handler, String type) org.objectweb.asm.AnnotationVisitorvisitTypeAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) voidvisitTypeInsn(int opcode, String type) voidvisitVarInsn(int opcode, int varIndex) static org.objectweb.asm.MethodVisitorwrap(org.objectweb.asm.MethodVisitor delegate) Idempotent factory: returnsdelegateunchanged when it isnullor already aConditionalJumpFoldingMethodVisitor, otherwise wraps it.Methods inherited from class org.objectweb.asm.MethodVisitor
getDelegate, visitMethodInsn
-
Constructor Details
-
ConditionalJumpFoldingMethodVisitor
public ConditionalJumpFoldingMethodVisitor(org.objectweb.asm.MethodVisitor delegate) Creates a folding visitor that forwards todelegate.- Parameters:
delegate- the next method visitor in the chain
-
-
Method Details
-
wrap
public static org.objectweb.asm.MethodVisitor wrap(org.objectweb.asm.MethodVisitor delegate) Idempotent factory: returnsdelegateunchanged when it isnullor already aConditionalJumpFoldingMethodVisitor, otherwise wraps it.- Parameters:
delegate- the visitor to wrap, ornullto skip- Returns:
- a folding method visitor, or
nullwhendelegateisnull
-
visitJumpInsn
public void visitJumpInsn(int opcode, org.objectweb.asm.Label label) - Overrides:
visitJumpInsnin classorg.objectweb.asm.MethodVisitor
-
visitInsn
public void visitInsn(int opcode) - Overrides:
visitInsnin classorg.objectweb.asm.MethodVisitor
-
visitLabel
public void visitLabel(org.objectweb.asm.Label label) - Overrides:
visitLabelin classorg.objectweb.asm.MethodVisitor
-
visitParameter
- Overrides:
visitParameterin classorg.objectweb.asm.MethodVisitor
-
visitAnnotationDefault
public org.objectweb.asm.AnnotationVisitor visitAnnotationDefault()- Overrides:
visitAnnotationDefaultin classorg.objectweb.asm.MethodVisitor
-
visitAnnotation
- Overrides:
visitAnnotationin classorg.objectweb.asm.MethodVisitor
-
visitTypeAnnotation
public org.objectweb.asm.AnnotationVisitor visitTypeAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) - Overrides:
visitTypeAnnotationin classorg.objectweb.asm.MethodVisitor
-
visitAnnotableParameterCount
public void visitAnnotableParameterCount(int parameterCount, boolean visible) - Overrides:
visitAnnotableParameterCountin classorg.objectweb.asm.MethodVisitor
-
visitParameterAnnotation
public org.objectweb.asm.AnnotationVisitor visitParameterAnnotation(int parameter, String descriptor, boolean visible) - Overrides:
visitParameterAnnotationin classorg.objectweb.asm.MethodVisitor
-
visitAttribute
public void visitAttribute(org.objectweb.asm.Attribute attribute) - Overrides:
visitAttributein classorg.objectweb.asm.MethodVisitor
-
visitCode
public void visitCode()- Overrides:
visitCodein classorg.objectweb.asm.MethodVisitor
-
visitFrame
- Overrides:
visitFramein classorg.objectweb.asm.MethodVisitor
-
visitIntInsn
public void visitIntInsn(int opcode, int operand) - Overrides:
visitIntInsnin classorg.objectweb.asm.MethodVisitor
-
visitVarInsn
public void visitVarInsn(int opcode, int varIndex) - Overrides:
visitVarInsnin classorg.objectweb.asm.MethodVisitor
-
visitTypeInsn
- Overrides:
visitTypeInsnin classorg.objectweb.asm.MethodVisitor
-
visitFieldInsn
- Overrides:
visitFieldInsnin classorg.objectweb.asm.MethodVisitor
-
visitMethodInsn
public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) - Overrides:
visitMethodInsnin classorg.objectweb.asm.MethodVisitor
-
visitInvokeDynamicInsn
public void visitInvokeDynamicInsn(String name, String descriptor, org.objectweb.asm.Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) - Overrides:
visitInvokeDynamicInsnin classorg.objectweb.asm.MethodVisitor
-
visitLdcInsn
- Overrides:
visitLdcInsnin classorg.objectweb.asm.MethodVisitor
-
visitIincInsn
public void visitIincInsn(int varIndex, int increment) - Overrides:
visitIincInsnin classorg.objectweb.asm.MethodVisitor
-
visitTableSwitchInsn
public void visitTableSwitchInsn(int min, int max, org.objectweb.asm.Label dflt, org.objectweb.asm.Label... labels) - Overrides:
visitTableSwitchInsnin classorg.objectweb.asm.MethodVisitor
-
visitLookupSwitchInsn
public void visitLookupSwitchInsn(org.objectweb.asm.Label dflt, int[] keys, org.objectweb.asm.Label[] labels) - Overrides:
visitLookupSwitchInsnin classorg.objectweb.asm.MethodVisitor
-
visitMultiANewArrayInsn
- Overrides:
visitMultiANewArrayInsnin classorg.objectweb.asm.MethodVisitor
-
visitInsnAnnotation
public org.objectweb.asm.AnnotationVisitor visitInsnAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) - Overrides:
visitInsnAnnotationin classorg.objectweb.asm.MethodVisitor
-
visitTryCatchBlock
public void visitTryCatchBlock(org.objectweb.asm.Label start, org.objectweb.asm.Label end, org.objectweb.asm.Label handler, String type) - Overrides:
visitTryCatchBlockin classorg.objectweb.asm.MethodVisitor
-
visitTryCatchAnnotation
public org.objectweb.asm.AnnotationVisitor visitTryCatchAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) - Overrides:
visitTryCatchAnnotationin classorg.objectweb.asm.MethodVisitor
-
visitLocalVariable
public void visitLocalVariable(String name, String descriptor, String signature, org.objectweb.asm.Label start, org.objectweb.asm.Label end, int index) - Overrides:
visitLocalVariablein classorg.objectweb.asm.MethodVisitor
-
visitLocalVariableAnnotation
public org.objectweb.asm.AnnotationVisitor visitLocalVariableAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, org.objectweb.asm.Label[] start, org.objectweb.asm.Label[] end, int[] index, String descriptor, boolean visible) - Overrides:
visitLocalVariableAnnotationin classorg.objectweb.asm.MethodVisitor
-
visitLineNumber
public void visitLineNumber(int line, org.objectweb.asm.Label start) - Overrides:
visitLineNumberin classorg.objectweb.asm.MethodVisitor
-
visitMaxs
public void visitMaxs(int maxStack, int maxLocals) - Overrides:
visitMaxsin classorg.objectweb.asm.MethodVisitor
-
visitEnd
public void visitEnd()- Overrides:
visitEndin classorg.objectweb.asm.MethodVisitor
-