Search in sources :

Example 16 with Textifier

use of org.objectweb.asm.util.Textifier in project groovy by apache.

the class LoggableTextifier method visitAnnotationDefault.

@Override
public Textifier visitAnnotationDefault() {
    Textifier t = super.visitAnnotationDefault();
    log();
    return t;
}
Also used : Textifier(org.objectweb.asm.util.Textifier)

Example 17 with Textifier

use of org.objectweb.asm.util.Textifier in project bazel by bazelbuild.

the class JavacTurbineTest method textify.

static String textify(byte[] bytes) {
    StringWriter sw = new StringWriter();
    ClassReader cr = new ClassReader(bytes);
    cr.accept(new TraceClassVisitor(null, new Textifier(), new PrintWriter(sw, true)), 0);
    return sw.toString();
}
Also used : TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) StringWriter(java.io.StringWriter) ClassReader(org.objectweb.asm.ClassReader) Textifier(org.objectweb.asm.util.Textifier) PrintWriter(java.io.PrintWriter)

Example 18 with Textifier

use of org.objectweb.asm.util.Textifier in project elasticsearch by elastic.

the class Debugger method toString.

/** compiles to bytecode, and returns debugging output */
static String toString(Class<?> iface, String source, CompilerSettings settings) {
    StringWriter output = new StringWriter();
    PrintWriter outputWriter = new PrintWriter(output);
    Textifier textifier = new Textifier();
    try {
        Compiler.compile(iface, "<debugging>", source, settings, textifier);
    } catch (Exception e) {
        textifier.print(outputWriter);
        e.addSuppressed(new Exception("current bytecode: \n" + output));
        IOUtils.reThrowUnchecked(e);
        throw new AssertionError();
    }
    textifier.print(outputWriter);
    return output.toString();
}
Also used : StringWriter(java.io.StringWriter) Textifier(org.objectweb.asm.util.Textifier) PrintWriter(java.io.PrintWriter)

Example 19 with Textifier

use of org.objectweb.asm.util.Textifier in project Galacticraft by micdoodle8.

the class InsnListSection method toString.

public String toString() {
    Textifier t = new Textifier();
    accept(new TraceMethodVisitor(t));
    StringWriter sw = new StringWriter();
    t.print(new PrintWriter(sw));
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) Textifier(org.objectweb.asm.util.Textifier) TraceMethodVisitor(org.objectweb.asm.util.TraceMethodVisitor) PrintWriter(java.io.PrintWriter)

Example 20 with Textifier

use of org.objectweb.asm.util.Textifier in project drill by axbaretto.

the class ReplaceMethodInvoke method main.

// private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ReplaceMethodInvoke.class);
public static void main(String[] args) throws Exception {
    final String k2 = "org/apache/drill/Pickle.class";
    final URL url = Resources.getResource(k2);
    final byte[] clazz = Resources.toByteArray(url);
    final ClassReader cr = new ClassReader(clazz);
    final ClassWriter cw = writer();
    final TraceClassVisitor visitor = new TraceClassVisitor(cw, new Textifier(), new PrintWriter(System.out));
    final ValueHolderReplacementVisitor v2 = new ValueHolderReplacementVisitor(visitor, true);
    // | ClassReader.SKIP_DEBUG);
    cr.accept(v2, ClassReader.EXPAND_FRAMES);
    final byte[] output = cw.toByteArray();
    Files.write(output, new File("/src/scratch/bytes/S.class"));
    check(output);
    final DrillConfig c = DrillConfig.forClient();
    final SystemOptionManager m = new SystemOptionManager(PhysicalPlanReaderTestFactory.defaultLogicalPlanPersistence(c), new LocalPersistentStoreProvider(c), c);
    m.init();
    try (QueryClassLoader ql = new QueryClassLoader(DrillConfig.create(), m)) {
        ql.injectByteCode("org.apache.drill.Pickle$OutgoingBatch", output);
        Class<?> clz = ql.loadClass("org.apache.drill.Pickle$OutgoingBatch");
        clz.getMethod("x").invoke(null);
    }
}
Also used : LocalPersistentStoreProvider(org.apache.drill.exec.store.sys.store.provider.LocalPersistentStoreProvider) SystemOptionManager(org.apache.drill.exec.server.options.SystemOptionManager) Textifier(org.objectweb.asm.util.Textifier) URL(java.net.URL) ClassWriter(org.objectweb.asm.ClassWriter) QueryClassLoader(org.apache.drill.exec.compile.QueryClassLoader) TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) DrillConfig(org.apache.drill.common.config.DrillConfig) ClassReader(org.objectweb.asm.ClassReader) File(java.io.File) PrintWriter(java.io.PrintWriter)

Aggregations

Textifier (org.objectweb.asm.util.Textifier)32 PrintWriter (java.io.PrintWriter)15 StringWriter (java.io.StringWriter)10 TraceClassVisitor (org.objectweb.asm.util.TraceClassVisitor)10 ClassReader (org.objectweb.asm.ClassReader)8 TraceMethodVisitor (org.objectweb.asm.util.TraceMethodVisitor)8 IOException (java.io.IOException)5 ClassWriter (org.objectweb.asm.ClassWriter)4 File (java.io.File)3 ClassVisitor (org.objectweb.asm.ClassVisitor)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 DrillConfig (org.apache.drill.common.config.DrillConfig)2 QueryClassLoader (org.apache.drill.exec.compile.QueryClassLoader)2 SystemOptionManager (org.apache.drill.exec.server.options.SystemOptionManager)2 LocalPersistentStoreProvider (org.apache.drill.exec.store.sys.store.provider.LocalPersistentStoreProvider)2 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)2