Search in sources :

Example 36 with TraceClassVisitor

use of org.objectweb.asm.util.TraceClassVisitor in project pinpoint by naver.

the class ASMBytecodeDisassembler method accept.

private void accept(byte[] bytecode, Printer printer, PrintWriter writer) {
    final ClassReader cr = new ClassReader(bytecode);
    final ClassWriter cw = new ClassWriter(this.cwFlag);
    final TraceClassVisitor tcv = new TraceClassVisitor(cw, printer, writer);
    cr.accept(tcv, this.crFlag);
}
Also used : TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) ClassReader(org.objectweb.asm.ClassReader) ClassWriter(org.objectweb.asm.ClassWriter)

Example 37 with TraceClassVisitor

use of org.objectweb.asm.util.TraceClassVisitor in project btrace by btraceio.

the class InstrumentorTestBase method asmify.

protected String asmify(byte[] bytecode) {
    StringWriter sw = new StringWriter();
    TraceClassVisitor acv = new TraceClassVisitor(new PrintWriter(sw));
    new org.objectweb.asm.ClassReader(bytecode).accept(acv, 0);
    return sw.toString();
}
Also used : TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) ClassReader(com.sun.btrace.org.objectweb.asm.ClassReader)

Example 38 with TraceClassVisitor

use of org.objectweb.asm.util.TraceClassVisitor in project qi4j-sdk by Qi4j.

the class ASMTest method fragmentClassLoaderGenerateClassTest.

@Test
@Ignore("This was dead commented code, ~70% of this source file ... What should we do about this!?!")
public void fragmentClassLoaderGenerateClassTest() throws Exception {
    byte[] asm = generateClass();
    byte[] cl = FragmentClassLoader.generateClass(QI256Test.TestTransient.TestTransientMixin.class.getName() + "_Stub", QI256Test.TestTransient.TestTransientMixin.class);
    new ClassReader(cl).accept(new TraceClassVisitor(new PrintWriter(System.out, true)), 0);
    Assert.assertArrayEquals(asm, cl);
}
Also used : TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) ClassReader(org.objectweb.asm.ClassReader) PrintWriter(java.io.PrintWriter) Ignore(org.junit.Ignore) Test(org.junit.Test) QI256Test(org.qi4j.runtime.composite.QI256Test)

Example 39 with TraceClassVisitor

use of org.objectweb.asm.util.TraceClassVisitor in project LogisticsPipes by RS485.

the class ASMHelper method getContentForMethod.

public static String getContentForMethod(ClassReader classReader, String methodName, String desc, boolean newLine) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    TraceClassVisitor traceClassVisitor = new TraceClassVisitor(null, new MethodTextifier(), printWriter);
    FilterClassVisitor myClassVisitor = new FilterClassVisitor(traceClassVisitor, methodName, desc);
    classReader.accept(myClassVisitor, ClassReader.SKIP_DEBUG);
    BufferedReader reader = new BufferedReader(new StringReader(stringWriter.toString()));
    StringBuilder builder = new StringBuilder();
    String line;
    try {
        while ((line = reader.readLine()) != null) {
            line = line.trim();
            String oldLine = line;
            line += " ";
            while (!oldLine.equals(line)) {
                oldLine = line;
                line = line.trim();
                line = line.replace("\t", " ");
                line = line.replace("  ", " ");
            }
            builder.append(" ");
            builder.append(line);
            if (newLine) {
                builder.append(System.lineSeparator());
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return builder.toString();
}
Also used : TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) StringWriter(java.io.StringWriter) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

TraceClassVisitor (org.objectweb.asm.util.TraceClassVisitor)39 PrintWriter (java.io.PrintWriter)31 ClassReader (org.objectweb.asm.ClassReader)24 ClassWriter (org.objectweb.asm.ClassWriter)16 StringWriter (java.io.StringWriter)14 ClassVisitor (org.objectweb.asm.ClassVisitor)10 Textifier (org.objectweb.asm.util.Textifier)10 IOException (java.io.IOException)6 File (java.io.File)5 ClassNode (org.objectweb.asm.tree.ClassNode)5 ArrayList (java.util.ArrayList)3 ASMifier (org.objectweb.asm.util.ASMifier)3 CheckClassAdapter (org.objectweb.asm.util.CheckClassAdapter)3 NeverNullArgAnalyzerAdapter (edu.columbia.cs.psl.phosphor.instrumenter.analyzer.NeverNullArgAnalyzerAdapter)2 FileInputStream (java.io.FileInputStream)2 URL (java.net.URL)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 DrillConfig (org.apache.drill.common.config.DrillConfig)2 QueryClassLoader (org.apache.drill.exec.compile.QueryClassLoader)2