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.
| Constructor and description |
|---|
ConditionalJumpFoldingMethodVisitor(org.objectweb.asm.MethodVisitor delegate)Creates a folding visitor that forwards to delegate. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
visitAnnotableParameterCount(int parameterCount, boolean visible) |
|
public org.objectweb.asm.AnnotationVisitor |
visitAnnotation(String descriptor, boolean visible) |
|
public org.objectweb.asm.AnnotationVisitor |
visitAnnotationDefault() |
|
public void |
visitAttribute(org.objectweb.asm.Attribute attribute) |
|
public void |
visitCode() |
|
public void |
visitEnd() |
|
public void |
visitFieldInsn(int opcode, String owner, String name, String descriptor) |
|
public void |
visitFrame(int type, int numLocal, Object[] local, int numStack, Object[] stack) |
|
public void |
visitIincInsn(int varIndex, int increment) |
|
public void |
visitInsn(int opcode) |
|
public org.objectweb.asm.AnnotationVisitor |
visitInsnAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) |
|
public void |
visitIntInsn(int opcode, int operand) |
|
public void |
visitInvokeDynamicInsn(String name, String descriptor, org.objectweb.asm.Handle bootstrapMethodHandle, Object bootstrapMethodArguments) |
|
public void |
visitJumpInsn(int opcode, org.objectweb.asm.Label label) |
|
public void |
visitLabel(org.objectweb.asm.Label label) |
|
public void |
visitLdcInsn(Object value) |
|
public void |
visitLineNumber(int line, org.objectweb.asm.Label start) |
|
public void |
visitLocalVariable(String name, String descriptor, String signature, org.objectweb.asm.Label start, org.objectweb.asm.Label end, int index) |
|
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) |
|
public void |
visitLookupSwitchInsn(org.objectweb.asm.Label dflt, int[] keys, org.objectweb.asm.Label[] labels) |
|
public void |
visitMaxs(int maxStack, int maxLocals) |
|
public void |
visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) |
|
public void |
visitMultiANewArrayInsn(String descriptor, int numDimensions) |
|
public void |
visitParameter(String name, int access) |
|
public org.objectweb.asm.AnnotationVisitor |
visitParameterAnnotation(int parameter, String descriptor, boolean visible) |
|
public void |
visitTableSwitchInsn(int min, int max, org.objectweb.asm.Label dflt, org.objectweb.asm.Label labels) |
|
public org.objectweb.asm.AnnotationVisitor |
visitTryCatchAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) |
|
public void |
visitTryCatchBlock(org.objectweb.asm.Label start, org.objectweb.asm.Label end, org.objectweb.asm.Label handler, String type) |
|
public org.objectweb.asm.AnnotationVisitor |
visitTypeAnnotation(int typeRef, org.objectweb.asm.TypePath typePath, String descriptor, boolean visible) |
|
public void |
visitTypeInsn(int opcode, String type) |
|
public void |
visitVarInsn(int opcode, int varIndex) |
|
public static org.objectweb.asm.MethodVisitor |
wrap(org.objectweb.asm.MethodVisitor delegate)Idempotent factory: returns delegate unchanged when it is
null or already a ConditionalJumpFoldingMethodVisitor,
otherwise wraps it. |
| Methods inherited from class | Name |
|---|---|
class org.objectweb.asm.MethodVisitor |
org.objectweb.asm.MethodVisitor#equals(java.lang.Object), org.objectweb.asm.MethodVisitor#getClass(), org.objectweb.asm.MethodVisitor#getDelegate(), org.objectweb.asm.MethodVisitor#hashCode(), org.objectweb.asm.MethodVisitor#notify(), org.objectweb.asm.MethodVisitor#notifyAll(), org.objectweb.asm.MethodVisitor#toString(), org.objectweb.asm.MethodVisitor#visitAnnotableParameterCount(int, boolean), org.objectweb.asm.MethodVisitor#visitAnnotation(java.lang.String, boolean), org.objectweb.asm.MethodVisitor#visitAnnotationDefault(), org.objectweb.asm.MethodVisitor#visitAttribute(org.objectweb.asm.Attribute), org.objectweb.asm.MethodVisitor#visitCode(), org.objectweb.asm.MethodVisitor#visitEnd(), org.objectweb.asm.MethodVisitor#visitFieldInsn(int, java.lang.String, java.lang.String, java.lang.String), org.objectweb.asm.MethodVisitor#visitFrame(int, int, [Ljava.lang.Object;, int, [Ljava.lang.Object;), org.objectweb.asm.MethodVisitor#visitIincInsn(int, int), org.objectweb.asm.MethodVisitor#visitInsn(int), org.objectweb.asm.MethodVisitor#visitInsnAnnotation(int, org.objectweb.asm.TypePath, java.lang.String, boolean), org.objectweb.asm.MethodVisitor#visitIntInsn(int, int), org.objectweb.asm.MethodVisitor#visitInvokeDynamicInsn(java.lang.String, java.lang.String, org.objectweb.asm.Handle, [Ljava.lang.Object;), org.objectweb.asm.MethodVisitor#visitJumpInsn(int, org.objectweb.asm.Label), org.objectweb.asm.MethodVisitor#visitLabel(org.objectweb.asm.Label), org.objectweb.asm.MethodVisitor#visitLdcInsn(java.lang.Object), org.objectweb.asm.MethodVisitor#visitLineNumber(int, org.objectweb.asm.Label), org.objectweb.asm.MethodVisitor#visitLocalVariable(java.lang.String, java.lang.String, java.lang.String, org.objectweb.asm.Label, org.objectweb.asm.Label, int), org.objectweb.asm.MethodVisitor#visitLocalVariableAnnotation(int, org.objectweb.asm.TypePath, [Lorg.objectweb.asm.Label;, [Lorg.objectweb.asm.Label;, [I, java.lang.String, boolean), org.objectweb.asm.MethodVisitor#visitLookupSwitchInsn(org.objectweb.asm.Label, [I, [Lorg.objectweb.asm.Label;), org.objectweb.asm.MethodVisitor#visitMaxs(int, int), org.objectweb.asm.MethodVisitor#visitMethodInsn(int, java.lang.String, java.lang.String, java.lang.String), org.objectweb.asm.MethodVisitor#visitMethodInsn(int, java.lang.String, java.lang.String, java.lang.String, boolean), org.objectweb.asm.MethodVisitor#visitMultiANewArrayInsn(java.lang.String, int), org.objectweb.asm.MethodVisitor#visitParameter(java.lang.String, int), org.objectweb.asm.MethodVisitor#visitParameterAnnotation(int, java.lang.String, boolean), org.objectweb.asm.MethodVisitor#visitTableSwitchInsn(int, int, org.objectweb.asm.Label, [Lorg.objectweb.asm.Label;), org.objectweb.asm.MethodVisitor#visitTryCatchAnnotation(int, org.objectweb.asm.TypePath, java.lang.String, boolean), org.objectweb.asm.MethodVisitor#visitTryCatchBlock(org.objectweb.asm.Label, org.objectweb.asm.Label, org.objectweb.asm.Label, java.lang.String), org.objectweb.asm.MethodVisitor#visitTypeAnnotation(int, org.objectweb.asm.TypePath, java.lang.String, boolean), org.objectweb.asm.MethodVisitor#visitTypeInsn(int, java.lang.String), org.objectweb.asm.MethodVisitor#visitVarInsn(int, int), org.objectweb.asm.MethodVisitor#wait(), org.objectweb.asm.MethodVisitor#wait(long), org.objectweb.asm.MethodVisitor#wait(long, int) |
Creates a folding visitor that forwards to delegate.
delegate - the next method visitor in the chain Idempotent factory: returns delegate unchanged when it is
null or already a ConditionalJumpFoldingMethodVisitor,
otherwise wraps it.
delegate - the visitor to wrap, or null to skipnull when delegate is nullCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.