org.objectweb.asm.tree.analysis.BasicVerifier Java Examples

The following examples show how to use org.objectweb.asm.tree.analysis.BasicVerifier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CheckMethodAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a new {@link CheckMethodAdapter} object. This method adapter
 * will perform basic data flow checks. For instance in a method whose
 * signature is <tt>void m ()</tt>, the invalid instruction IRETURN, or the
 * invalid sequence IADD L2I will be detected.
 * 
 * @param access
 *          the method's access flags.
 * @param name
 *          the method's name.
 * @param desc
 *          the method's descriptor (see {@link Type Type}).
 * @param cmv
 *          the method visitor to which this adapter must delegate calls.
 * @param labels
 *          a map of already visited labels (in other methods).
 */
public CheckMethodAdapter(final int access, final String name, final String desc, final MethodVisitor cmv, final Map<Label, Integer> labels) {
  this(new MethodNode(Opcodes.ASM5, access, name, desc, null, null) {
    @Override
    public void visitEnd() {
      Analyzer<BasicValue> a = new Analyzer<BasicValue>(new BasicVerifier());
      try {
        a.analyze("dummy", this);
      } catch (Exception e) {
        if (e instanceof IndexOutOfBoundsException && maxLocals == 0 && maxStack == 0) {
          throw new RuntimeException("Data flow checking option requires valid, non zero maxLocals and maxStack values.");
        }
        e.printStackTrace();
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw, true);
        CheckClassAdapter.printAnalyzerResult(this, a, pw);
        pw.close();
        throw new RuntimeException(e.getMessage() + ' ' + sw.toString());
      }
      accept(cmv);
    }
  }, labels);
  this.access = access;
}