Package org.objectweb.asm.tree.analysis

Examples of org.objectweb.asm.tree.analysis.Analyzer$IntMap


     * @param owner
     * @param meth
     * @param cl
     */
    private void analyzeMethod(final ClassLoader cl) {
        Analyzer a = new Analyzer(new SimpleVerifier() {

            protected Class getClass(final Type t) {
                try {
                    if (t.getSort() == Type.ARRAY) {
                        return Class.forName(t.getDescriptor().replace(
                            '/', '.'), true, cl);
                    }
                    return cl.loadClass(t.getClassName());
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException(e.toString()+" " +cl, e);
                }
            }
        });
        try {
            a.analyze(owner, meth);
        } catch (AnalyzerException e) {
            error = e.getMessage();
            if (error.startsWith("Error at instruction ")) {
                error = error.substring("Error at instruction ".length());
                errorInsn = Integer.parseInt(error.substring(0, error
                    .indexOf(':')));
                error = error.substring(error.indexOf(':') + 2);
            } else {
                BytecodeOutlinePlugin.log(e, IStatus.ERROR);
                error = null;
            }
        }
        frames = a.getFrames();
    }
View Full Code Here


*/
public class CyclomaticComplexity {
 
  public int getCyclomaticComplexity(String owner, MethodNode mn)
      throws AnalyzerException {
    Analyzer a = new Analyzer(new BasicInterpreter()) {
      protected Frame newFrame(int nLocals, int nStack) {
        return new Node(nLocals, nStack);
      }

      protected Frame newFrame(Frame src) {
        return new Node(src);
      }

      protected void newControlFlowEdge(int src, int dst) {
        Node s = (Node) getFrames()[src];
        s.successors.add((Node) getFrames()[dst]);
      }
    };
    a.analyze(owner, mn);
    Frame[] frames = a.getFrames();
    int edges = 0;
    int nodes = 0;
    for (int i = 0; i < frames.length; ++i) {
      if (frames[i] != null) {
        edges += ((Node) frames[i]).successors.size();
View Full Code Here

    next = mv;
  }

  public void visitEnd() {
    MethodNode mn = (MethodNode) mv;
    Analyzer a = new Analyzer(new BasicInterpreter());
    try {
      a.analyze(owner, mn);
      Frame[] frames = a.getFrames();
      AbstractInsnNode[] insns = mn.instructions.toArray();
      for (int i = 0; i < frames.length; ++i) {
        if (frames[i] == null && !(insns[i] instanceof LabelNode)) {
          mn.instructions.remove(insns[i]);
        }
View Full Code Here

public class NullDereferenceAnalyzer {

  public List<AbstractInsnNode> findNullDereferences(String owner,
      MethodNode mn) throws AnalyzerException {
    List<AbstractInsnNode> result = new ArrayList<AbstractInsnNode>();
    Analyzer a = new Analyzer(new IsNullInterpreter());
    a.analyze(owner, mn);
    Frame[] frames = a.getFrames();
    AbstractInsnNode[] insns = mn.instructions.toArray();
    for (int i = 0; i < insns.length; ++i) {
      AbstractInsnNode insn = insns[i];
      if (frames[i] != null) {
        Value v = getTarget(insn, frames[i]);
View Full Code Here

    super(mt);
    this.owner = owner;
  }

  public void transform(MethodNode mn) {
    Analyzer a = new Analyzer(new SimpleVerifier());
    try {
      a.analyze(owner, mn);
      Frame[] frames = a.getFrames();
      AbstractInsnNode[] insns = mn.instructions.toArray();
      for (int i = 0; i < insns.length; ++i) {
        AbstractInsnNode insn = insns[i];
        if (insn.getOpcode() == CHECKCAST) {
          Frame f = frames[i];
View Full Code Here

    next = mv;
  }

  public void visitEnd() {
    MethodNode mn = (MethodNode) mv;
    Analyzer a = new Analyzer(new BasicVerifier());
    try {
      a.analyze(owner, mn);
    } catch (AnalyzerException e) {
      throw new RuntimeException(e.getMessage());
    }
    mn.accept(next);
  }
View Full Code Here

        cr.accept(cn, 0);
        List methods = cn.methods;
        for (int k = 0; k < methods.size(); ++k) {
          MethodNode method = (MethodNode) methods.get(k);
          if (method.instructions.size() > 0) {
            Analyzer a = new Analyzer(new BasicInterpreter());
            try {
              a.analyze(cn.name, method);
            } catch (Throwable th) {
              ++errors;
            }
          }
        }
      }
      t = System.currentTimeMillis() - t;
      times[13] = Math.min(t, times[13]);
      System.out.println("Time to analyze " + classes.size() / 10
          + " classes with BasicInterpreter = " + t + " ms (" + errors
          + " errors)");
    }

    for (int i = 0; i < 10; ++i) {
      int errors = 0;
      long t = System.currentTimeMillis();
      for (int j = 0; j < classes.size() / 10; ++j) {
        byte[] b = (byte[]) classes.get(j);
        ClassReader cr = new ClassReader(b);
        ClassNode cn = new ClassNode();
        cr.accept(cn, 0);
        List methods = cn.methods;
        for (int k = 0; k < methods.size(); ++k) {
          MethodNode method = (MethodNode) methods.get(k);
          if (method.instructions.size() > 0) {
            Analyzer a = new Analyzer(new SimpleVerifier());
            try {
              a.analyze(cn.name, method);
            } catch (Throwable th) {
              ++errors;
            }
          }
        }
View Full Code Here

    List methods = ca.classNode.methods;
    for (int i = 0; i < methods.size(); ++i) {
      MethodNode method = (MethodNode)methods.get(i);
      if (method.instructions.size() > 0) {
        if (!analyze(ca.classNode, method)) {
          Analyzer a = new Analyzer(new BasicVerifier());
          try {
            a.analyze(ca.classNode, method);
          } catch (Exception ignored) {
          }
          final Frame[] frames = a.getFrames();
         
          TraceCodeVisitor cv = new TraceCodeVisitor(null) {
            public void visitMaxs (int maxStack, int maxLocals) {
              for (int i = 0; i < text.size(); ++i) {
                String s = frames[i] == null ? "null" : frames[i].toString();
View Full Code Here

   * least one xLOAD corresponding instruction in their successor instructions
   * (in the control flow graph).
   */
 
  public static boolean analyze (ClassNode c, MethodNode m) throws Exception {
    Analyzer a = new Analyzer(new DataflowInterpreter());
    Frame[] frames = a.analyze(c, m);

    // for each xLOAD instruction, we find the xSTORE instructions that can
    // produce the value loaded by this instruction, and we put them in 'stores'
    Set stores = new HashSet();
    for (int i = 0; i < m.instructions.size(); ++i) {
View Full Code Here

   
    List methods = ca.classNode.methods;
    for (int i = 0; i < methods.size(); ++i) {
      MethodNode method = (MethodNode)methods.get(i);
      if (method.instructions.size() > 0) {
        Analyzer a = new Analyzer(new SimpleVerifier());
        try {
          a.analyze(ca.classNode, method);
          continue;
        } catch (Exception e) {
          e.printStackTrace();
        }
        final Frame[] frames = a.getFrames();
       
        System.out.println(method.name + method.desc);
        TraceCodeVisitor cv = new TraceCodeVisitor(null) {
          public void visitMaxs (int maxStack, int maxLocals) {
            for (int i = 0; i < text.size(); ++i) {
View Full Code Here

TOP

Related Classes of org.objectweb.asm.tree.analysis.Analyzer$IntMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.