Class PeepholeOptimizingClassVisitor

java.lang.Object
org.objectweb.asm.ClassVisitor
org.codehaus.groovy.classgen.asm.PeepholeOptimizingClassVisitor

public final class PeepholeOptimizingClassVisitor extends org.objectweb.asm.ClassVisitor
Class-level installation point for Groovy's single-pass bytecode peephole layer.

Wraps each MethodVisitor returned by the delegate's visitMethod(int, String, String, String, String[]) with PeepholeOptimizingMethodVisitor, so every method body receives the same stack-local compaction — user methods, constructors, static initializers, and synthetic helpers alike (MOP bridges, call-site array initializers, class$/$get$ resolvers, large-list init chunks, and so on).

Centralizing the wrap here avoids ad-hoc new PeepholeOptimizingMethodVisitor(...) at individual emission sites and keeps compaction in lockstep with OperandStack, which emits integer and other primitive constants via visitLdcInsn and relies on the peephole visitor to narrow them to ICONST_*, BIPUSH, SIPUSH, etc.

Installed once by WriterController when the class visitor chain is built (optionally outside a LoggableClassVisitor / TraceClassVisitor pair used for classgen logging). Field and attribute visits are left unchanged; only method bodies are optimized.

Since:
6.0.0
See Also:
  • Field Summary

    Fields inherited from class org.objectweb.asm.ClassVisitor

    api, cv
  • Constructor Summary

    Constructors
    Constructor
    Description
    PeepholeOptimizingClassVisitor(org.objectweb.asm.ClassVisitor classVisitor)
    Creates a visitor that peephole-optimizes every method written to classVisitor.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.objectweb.asm.MethodVisitor
    visitMethod(int access, String name, String descriptor, String signature, String[] exceptions)

    Methods inherited from class org.objectweb.asm.ClassVisitor

    getDelegate, visit, visitAnnotation, visitAttribute, visitEnd, visitField, visitInnerClass, visitModule, visitNestHost, visitNestMember, visitOuterClass, visitPermittedSubclass, visitRecordComponent, visitSource, visitTypeAnnotation

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PeepholeOptimizingClassVisitor

      public PeepholeOptimizingClassVisitor(org.objectweb.asm.ClassVisitor classVisitor)
      Creates a visitor that peephole-optimizes every method written to classVisitor.
      Parameters:
      classVisitor - the next visitor in the class-generation chain (typically a ClassWriter, optionally preceded by logging / tracing adapters)
  • Method Details

    • visitMethod

      public org.objectweb.asm.MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions)

      When the delegate returns a non-null visitor, the result is a PeepholeOptimizingMethodVisitor (or the same instance if the delegate already wrapped the method). A null from the delegate is propagated unchanged so methods can still be skipped per the ASM contract.

      Overrides:
      visitMethod in class org.objectweb.asm.ClassVisitor