/** * {@inheritDoc} * * In addition, the returned {@link org.objectweb.asm.MethodVisitor} * will throw an exception if the method is greater than 64K in length. */ @Override public MethodVisitor visitMethod( final int access, final String name, final String desc, final String signature, final String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); return new CodeSizeEvaluator(mv) { @Override public void visitEnd() { super.visitEnd(); if (getMaxSize() > 64 * 1024) { state = State.FAIL_TOO_LONG; message = "the method " + name + " was too long."; } } }; }
public CodeSizeHelper getCodeSizeHelper() { ClassNode node = new ClassNode(); node.name = getClassCtx().getClazz().name; ClassCompilationContext ccc = new ClassCompilationContext(node, true, classCtx.getCompiler()); CodeSizeEvaluator cse = new CodeSizeEvaluator(null); MethodCompilationContext mcc = new MethodCompilationContext(ccc, new GeneratorAdapter(cse, access, "method", desc), access, desc); CodeSizeHelper helper = new CodeSizeHelper(); helper.ctx = mcc; helper.cse = cse; return helper; }
/** * Clears this block. */ void clear() { readers.clear(); writers.clear(); parameters.clear(); insns.clear(); varMap.clear(); pushParameters.clear(); sizeEvaluator = new CodeSizeEvaluator(null); }
private int getLength(final MethodNode methodNode) { final CodeSizeEvaluator codeSizeEvaluator = new CodeSizeEvaluator(null); methodNode.accept(codeSizeEvaluator); return codeSizeEvaluator.getMaxSize(); }