当前位置: 首页>>代码示例>>Java>>正文


Java Analyzer类代码示例

本文整理汇总了Java中org.objectweb.asm.tree.analysis.Analyzer的典型用法代码示例。如果您正苦于以下问题:Java Analyzer类的具体用法?Java Analyzer怎么用?Java Analyzer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Analyzer类属于org.objectweb.asm.tree.analysis包,在下文中一共展示了Analyzer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: printClass

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
@SuppressWarnings("unused")
private static void printClass(final byte[] classfileBuffer, final String classname) {
    /*
    final TraceClassVisitor v = new TraceClassVisitor(new PrintWriter(System.out));
    new ClassReader(classfileBuffer).accept(v, ClassReader.SKIP_DEBUG);
    */
    final ClassNode cn = new ClassNode();
    final ClassReader cr = new ClassReader(classfileBuffer);
    //cr.accept(new CheckClassAdapter(cn), ClassReader.SKIP_DEBUG);
    cr.accept(new CheckClassAdapter(cn), 0);

    for (final Object methodObj : cn.methods) {
        final MethodNode method = (MethodNode) methodObj;
        final Analyzer a = new Analyzer(new BasicVerifier());
        //final Analyzer a = new Analyzer(new SimpleVerifier());
        try {
            a.analyze(cn.name, method);
        } catch (final AnalyzerException e) {
            System.err.println("// error in method " + classname + "." + method.name
                    + method.desc + ":" + e);
        }
        printMethod(a, System.err, method);
    }
}
 
开发者ID:hammacher,项目名称:javaslicer,代码行数:25,代码来源:Transformer.java

示例2: verify

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
/**
 * Checks a given class.
 * 
 * @param cr
 *            a <code>ClassReader</code> that contains bytecode for the
 *            analysis.
 * @param loader
 *            a <code>ClassLoader</code> which will be used to load
 *            referenced classes. This is useful if you are verifiying
 *            multiple interdependent classes.
 * @param dump
 *            true if bytecode should be printed out not only when errors
 *            are found.
 * @param pw
 *            write where results going to be printed
 */
public static void verify(final ClassReader cr, final ClassLoader loader,
        final boolean dump, final PrintWriter pw) {
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);

    Type syperType = cn.superName == null ? null : Type
            .getObjectType(cn.superName);
    List<MethodNode> methods = cn.methods;

    List<Type> interfaces = new ArrayList<Type>();
    for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext();) {
        interfaces.add(Type.getObjectType(i.next()));
    }

    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = methods.get(i);
        SimpleVerifier verifier = new SimpleVerifier(
                Type.getObjectType(cn.name), syperType, interfaces,
                (cn.access & Opcodes.ACC_INTERFACE) != 0);
        Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
        if (loader != null) {
            verifier.setClassLoader(loader);
        }
        try {
            a.analyze(cn.name, method);
            if (!dump) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace(pw);
        }
        printAnalyzerResult(method, a, pw);
    }
    pw.flush();
}
 
开发者ID:ItzSomebody,项目名称:DirectLeaks-AntiReleak-Remover,代码行数:52,代码来源:CheckClassAdapter.java

示例3: printAnalyzerResult

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
static void printAnalyzerResult(MethodNode method, Analyzer<BasicValue> a,
        final PrintWriter pw) {
    Frame<BasicValue>[] frames = a.getFrames();
    Textifier t = new Textifier();
    TraceMethodVisitor mv = new TraceMethodVisitor(t);

    pw.println(method.name + method.desc);
    for (int j = 0; j < method.instructions.size(); ++j) {
        method.instructions.get(j).accept(mv);

        StringBuilder sb = new StringBuilder();
        Frame<BasicValue> f = frames[j];
        if (f == null) {
            sb.append('?');
        } else {
            for (int k = 0; k < f.getLocals(); ++k) {
                sb.append(getShortName(f.getLocal(k).toString()))
                        .append(' ');
            }
            sb.append(" : ");
            for (int k = 0; k < f.getStackSize(); ++k) {
                sb.append(getShortName(f.getStack(k).toString()))
                        .append(' ');
            }
        }
        while (sb.length() < method.maxStack + method.maxLocals + 1) {
            sb.append(' ');
        }
        pw.print(Integer.toString(j + 100000).substring(1));
        pw.print(" " + sb + " : " + t.text.get(t.text.size() - 1));
    }
    for (int j = 0; j < method.tryCatchBlocks.size(); ++j) {
        method.tryCatchBlocks.get(j).accept(mv);
        pw.print(" " + t.text.get(t.text.size() - 1));
    }
    pw.println();
}
 
开发者ID:ItzSomebody,项目名称:DirectLeaks-AntiReleak-Remover,代码行数:38,代码来源:CheckClassAdapter.java

示例4: CheckMethodAdapter

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:ItzSomebody,项目名称:DirectLeaks-AntiReleak-Remover,代码行数:47,代码来源:CheckMethodAdapter.java

示例5: InstrumentMethod

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
public InstrumentMethod(MethodDatabase db, String className, MethodNode mn) throws AnalyzerException {
    this.db = db;
    this.className = className;
    this.mn = mn;

    try {
        Analyzer a = new TypeAnalyzer(db);
        this.frames = a.analyze(className, mn);
        this.lvarStack = mn.maxLocals;
        this.firstLocal = ((mn.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) ? 0 : 1;
    } catch (UnsupportedOperationException ex) {
        throw new AnalyzerException(null, ex.getMessage(), ex);
    }
}
 
开发者ID:oltolm,项目名称:continuations,代码行数:15,代码来源:InstrumentMethod.java

示例6: getArrayFrames

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
private Frame[] getArrayFrames(MethodNode mn) {
	try {
		Analyzer a = new Analyzer(new BooleanArrayInterpreter());
		a.analyze(cn.name, mn);
		return a.getFrames();
	} catch (Exception e) {
		logger.info("[Array] Error during analysis: " + e);
		return null;
	}
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:11,代码来源:BooleanTestabilityTransformation.java

示例7: getFrames

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
private void getFrames(MethodNode mn, String className) {
	try {
		Analyzer a = new Analyzer(new BooleanValueInterpreter(mn.desc,
		        (mn.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC));
		a.analyze(className, mn);
		this.frames = a.getFrames();
	} catch (Exception e) {
		logger.info("1. Error during analysis: " + e);
		//e.printStackTrace();
		// TODO: Handle error
	}

}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:14,代码来源:MutationInstrumentation.java

示例8: visitEnd

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
public void visitEnd() {

        checkCallSites();

        if (instructions.size() == 0 || labels.size() == 0) {
            accept(mv);
            return;
        }

        this.stackRecorderVar = maxLocals;
        try {
            moveNew();

            analyzer = new Analyzer(new FastClassVerifier()) {
                @Override
                protected Frame newFrame(final int nLocals, final int nStack) {
                    return new MonitoringFrame(nLocals, nStack);
                }

                @Override
                protected Frame newFrame(final Frame src) {
                    return new MonitoringFrame(src);
                }
            };

            analyzer.analyze(className, this);
            accept(new ContinuableMethodVisitor(this));

        } catch (final AnalyzerException ex) {
            throw new RuntimeException(ex);
        }
    }
 
开发者ID:vsilaev,项目名称:tascalate-javaflow,代码行数:33,代码来源:ContinuableMethodNode.java

示例9: visitEnd

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
public void visitEnd() {
    if (instructions.size() == 0 || labels.size() == 0) {
        accept(mv);
        return;
    }

    this.stackRecorderVar = maxLocals;
    try {
        moveNew();

        analyzer = new Analyzer(new FastClassVerifier()) {
            @Override
            protected Frame newFrame(final int nLocals, final int nStack) {
                return new MonitoringFrame(nLocals, nStack);
            }

            @Override
            protected Frame newFrame(final Frame src) {
                return new MonitoringFrame(src);
            }
        };

        analyzer.analyze(className, this);
        accept(new ContinuableMethodVisitor(this));

    } catch (final AnalyzerException ex) {
        throw new RuntimeException(ex);
    }
}
 
开发者ID:vsilaev,项目名称:tascalate-javaflow,代码行数:30,代码来源:ContinuableMethodNode.java

示例10: CheckMethodAdapter

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
/**
 * 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, null, 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;
}
 
开发者ID:8BitPlus,项目名称:BitPlus,代码行数:47,代码来源:CheckMethodAdapter.java

示例11: verify

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
/**
 * Checks a given class.
 * 
 * @param cr
 *            a <code>ClassReader</code> that contains bytecode for the
 *            analysis.
 * @param loader
 *            a <code>ClassLoader</code> which will be used to load
 *            referenced classes. This is useful if you are verifiying
 *            multiple interdependent classes.
 * @param dump
 *            true if bytecode should be printed out not only when errors
 *            are found.
 * @param pw
 *            write where results going to be printed
 */
public static void verify(final ClassReader cr, final ClassLoader loader,
        final boolean dump, final PrintWriter pw) {
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);

    Type syperType = cn.superName == null ? null : Type
            .getObjectType(cn.superName);
    List<MethodNode> methods = cn.methods;

    List<Type> interfaces = new ArrayList<Type>();
    for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext();) {
        interfaces.add(Type.getObjectType(i.next().toString()));
    }

    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = methods.get(i);
        SimpleVerifier verifier = new SimpleVerifier(
                Type.getObjectType(cn.name), syperType, interfaces,
                (cn.access & Opcodes.ACC_INTERFACE) != 0);
        Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
        if (loader != null) {
            verifier.setClassLoader(loader);
        }
        try {
            a.analyze(cn.name, method);
            if (!dump) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace(pw);
        }
        printAnalyzerResult(method, a, pw);
    }
    pw.flush();
}
 
开发者ID:bcleenders,项目名称:Bramspr,代码行数:52,代码来源:CheckClassAdapter.java

示例12: printAnalyzerResult

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
static void printAnalyzerResult(MethodNode method, Analyzer<BasicValue> a,
        final PrintWriter pw) {
    Frame<BasicValue>[] frames = a.getFrames();
    Textifier t = new Textifier();
    TraceMethodVisitor mv = new TraceMethodVisitor(t);

    pw.println(method.name + method.desc);
    for (int j = 0; j < method.instructions.size(); ++j) {
        method.instructions.get(j).accept(mv);

        StringBuffer s = new StringBuffer();
        Frame<BasicValue> f = frames[j];
        if (f == null) {
            s.append('?');
        } else {
            for (int k = 0; k < f.getLocals(); ++k) {
                s.append(getShortName(f.getLocal(k).toString()))
                        .append(' ');
            }
            s.append(" : ");
            for (int k = 0; k < f.getStackSize(); ++k) {
                s.append(getShortName(f.getStack(k).toString()))
                        .append(' ');
            }
        }
        while (s.length() < method.maxStack + method.maxLocals + 1) {
            s.append(' ');
        }
        pw.print(Integer.toString(j + 100000).substring(1));
        pw.print(" " + s + " : " + t.text.get(t.text.size() - 1));
    }
    for (int j = 0; j < method.tryCatchBlocks.size(); ++j) {
        method.tryCatchBlocks.get(j).accept(mv);
        pw.print(" " + t.text.get(t.text.size() - 1));
    }
    pw.println();
}
 
开发者ID:bcleenders,项目名称:Bramspr,代码行数:38,代码来源:CheckClassAdapter.java

示例13: CheckMethodAdapter

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
/**
 * 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(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;
}
 
开发者ID:bcleenders,项目名称:Bramspr,代码行数:47,代码来源:CheckMethodAdapter.java

示例14: verifyMethodIntegrity

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
public static void verifyMethodIntegrity(String ownerInternalName, MethodNode method) {
    try {
        new Analyzer(new SimpleVerifier()).analyze(ownerInternalName, method);
    } catch (AnalyzerException e) {
        throw new RuntimeException(
                "Integrity error in method '" + method.name + "' of type '" + ownerInternalName + "': ", e);
    }
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:9,代码来源:AsmTestUtils.java

示例15: verifyMethodIntegrity

import org.objectweb.asm.tree.analysis.Analyzer; //导入依赖的package包/类
public static void verifyMethodIntegrity(final String ownerInternalName, final MethodNode method) {
    try {
        new Analyzer(new SimpleVerifier()).analyze(ownerInternalName, method);
    } catch (AnalyzerException e) {
        throw new RuntimeException(
                "Integrity error in method '" + method.name + "' of type '" + ownerInternalName + "': ", e);
    }
}
 
开发者ID:fge,项目名称:grappa,代码行数:9,代码来源:AsmTestUtils.java


注:本文中的org.objectweb.asm.tree.analysis.Analyzer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。