Class PeepholeOptimizingClassVisitor
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
ConstructorsConstructorDescriptionPeepholeOptimizingClassVisitor(org.objectweb.asm.ClassVisitor classVisitor) Creates a visitor that peephole-optimizes every method written toclassVisitor. -
Method Summary
Modifier and TypeMethodDescriptionorg.objectweb.asm.MethodVisitorvisitMethod(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
-
Constructor Details
-
PeepholeOptimizingClassVisitor
public PeepholeOptimizingClassVisitor(org.objectweb.asm.ClassVisitor classVisitor) Creates a visitor that peephole-optimizes every method written toclassVisitor.- Parameters:
classVisitor- the next visitor in the class-generation chain (typically aClassWriter, 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-
nullvisitor, the result is aPeepholeOptimizingMethodVisitor(or the same instance if the delegate already wrapped the method). Anullfrom the delegate is propagated unchanged so methods can still be skipped per the ASM contract.- Overrides:
visitMethodin classorg.objectweb.asm.ClassVisitor
-