@Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { Printer p = this.p.visitMethod(access, name, desc, signature, exceptions); MethodVisitor mv = cv == null ? null : cv.visitMethod(access, name, desc, signature, exceptions); return new TraceMethodVisitor(mv, p); }
@Override public String toString() { Printer printer = new ASMifier(); TraceMethodVisitor visitor = new TraceMethodVisitor(printer); node.accept(visitor); return printer.getText().toString(); }
Frame[] frames = a.getFrames(); Textifier t = new Textifier(); TraceMethodVisitor mv = new TraceMethodVisitor(t); String format = "%05d %-" + (method.maxStack + method.maxLocals + 6) + "s|%s"; for (int j = 0; j < method.instructions.size(); ++j) {
TraceMethodVisitor mv = new TraceMethodVisitor(null);
static void printAnalyzerResult(MethodNode method, Analyzer a, final PrintWriter pw) throws IllegalArgumentException, IllegalAccessException { Frame[] frames = a.getFrames(); Textifier t = new Textifier(); TraceMethodVisitor mv = new TraceMethodVisitor(t); String format = "%05d %-" + (method.maxStack + method.maxLocals + 6) + "s|%s"; for (int j = 0; j < method.instructions.size(); ++j) { method.instructions.get(j).accept(mv); StringBuffer s = new StringBuffer(); Frame f = frames[j]; if (f == null) { s.append('?'); } else { for (int k = 0; k < f.getLocals(); ++k) { s.append(getShortName(f.getLocal(k).toString())); } s.append(" : "); for (int k = 0; k < f.getStackSize(); ++k) { s.append(getShortName(f.getStack(k).toString())); } } pw.printf(format, j, s, buf.get(t)); // mv.text.get(j)); } for (int j = 0; j < method.tryCatchBlocks.size(); ++j) { ((TryCatchBlockNode) method.tryCatchBlocks.get(j)).accept(mv); pw.print(" " + buf.get(t)); } pw.println(); pw.flush(); }
private String toString(MethodTree mt) { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final TraceMethodVisitor mv = new TraceMethodVisitor(new Textifier()); mt.rawNode().accept(mv); try (PrintWriter pw = new PrintWriter(bos)) { mv.p.print(pw); } return "Byte code is \n" + new String(bos.toByteArray()); }
@Override public MethodVisitor visitMethod( final int access, final String name, final String descriptor, final String signature, final String[] exceptions) { Printer methodPrinter = p.visitMethod(access, name, descriptor, signature, exceptions); return new TraceMethodVisitor( super.visitMethod(access, name, descriptor, signature, exceptions), methodPrinter); }
@Override public MethodVisitor visitMethod( final int access, final String name, final String descriptor, final String signature, final String[] exceptions) { Printer methodPrinter = p.visitMethod(access, name, descriptor, signature, exceptions); return new TraceMethodVisitor( super.visitMethod(access, name, descriptor, signature, exceptions), methodPrinter); }
@Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { Printer p = this.p.visitMethod(access, name, desc, signature, exceptions); MethodVisitor mv = cv == null ? null : cv.visitMethod(access, name, desc, signature, exceptions); return new TraceMethodVisitor(mv, p); }
public static String toString(AbstractInsnNode insnNode) { TraceMethodVisitor asmifier = new TraceMethodVisitor(); insnNode.accept(asmifier); StringBuffer sb = new StringBuffer(); for (String line : (List<String>) asmifier.getText()) { sb.append(line); } return sb.toString(); }
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (methodName.equals(name) && methodType.toMethodDescriptorString().equals(desc)) { Printer p = printer.visitMethod(access, name, desc, signature, exceptions); return new TraceMethodVisitor(null, p); } return null; } }
private static String getNodeString(AbstractInsnNode node) { Printer printer = new Textifier(); TraceMethodVisitor visitor = new TraceMethodVisitor(printer); node.accept(visitor); StringWriter sw = new StringWriter(); printer.print(new PrintWriter(sw)); printer.getText().clear(); return sw.toString().replaceAll("\n", "").trim(); }
$TraceMethodVisitor(MethodCode method, MethodVisitor mv) { super(Opcodes.ASM5, new TraceMethodVisitor(mv, new SimpleTypeTextifier())); this.method = method; }
public static void viewByteCode(byte[] bytecode) { ClassReader cr = new ClassReader(bytecode); ClassNode cn = new ClassNode(); cr.accept(cn, 0); final List<MethodNode> mns = cn.methods; Printer printer = new Textifier(); TraceMethodVisitor mp = new TraceMethodVisitor(printer); for (MethodNode mn : mns) { InsnList inList = mn.instructions; System.out.println(mn.name); for (int i = 0; i < inList.size(); i++) { inList.get(i).accept(mp); StringWriter sw = new StringWriter(); printer.print(new PrintWriter(sw)); printer.getText().clear(); System.out.print(sw.toString()); } } } }
@Override public void visitEnd() { try { accept(inner); super.visitEnd(); } catch(Exception e){ Textifier t = new Textifier(); accept(new TraceMethodVisitor(t)); StringBuilderWriter sw = new StringBuilderWriter(); PrintWriter pw = new PrintWriter(sw); t.print(pw); pw.flush(); String bytecode = sw.getBuilder().toString(); logger.error(String.format("Failure while rendering method %s, %s, %s. ByteCode:\n %s", name, desc, signature, bytecode), e); throw new RuntimeException(String.format("Failure while rendering method %s, %s, %s. ByteCode:\n %s", name, desc, signature, bytecode), e); } } }
public static void viewByteCode(byte[] bytecode) { ClassReader cr = new ClassReader(bytecode); ClassNode cn = new ClassNode(); cr.accept(cn, 0); final List<MethodNode> mns = cn.methods; Printer printer = new Textifier(); TraceMethodVisitor mp = new TraceMethodVisitor(printer); for (MethodNode mn : mns) { InsnList inList = mn.instructions; System.out.println(mn.name); for (int i = 0; i < inList.size(); i++) { inList.get(i).accept(mp); StringWriter sw = new StringWriter(); printer.print(new PrintWriter(sw)); printer.getText().clear(); System.out.print(sw.toString()); } } } }
/** * Converts the given method to a String. */ public static String textify(@NonNull MethodNode method) { Textifier textifier = new Textifier(); TraceMethodVisitor trace = new TraceMethodVisitor(textifier); method.accept(trace); String ret = ""; for (Object line : textifier.getText()) { ret += line; } return ret; }
/** * Converts the given method to a String. */ public static String textify(@NonNull MethodNode method) { Textifier textifier = new Textifier(); TraceMethodVisitor trace = new TraceMethodVisitor(textifier); method.accept(trace); String ret = ""; for (Object line : textifier.getText()) { ret += line; } return ret; }
public static void assertTraceDumpEquality( final MethodNode method, final String traceDump) throws Exception { Preconditions.checkNotNull(method, "method"); final Printer printer = new NonMaxTextifier(); final TraceMethodVisitor traceMethodVisitor = new TraceMethodVisitor(printer); // MethodAdapter checkMethodAdapter = new MethodAdapter(traceMethodVisitor); final MethodVisitor checkMethodAdapter = new CheckMethodAdapter(traceMethodVisitor); method.accept(checkMethodAdapter); final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); printer.print(printWriter); printWriter.flush(); assertEquals(stringWriter.toString(), traceDump); }
public void optimize(MethodNode methodNode) { methodNode.accept(new TraceMethodVisitor(new Textifier())); NodeIt it = new NodeIt(methodNode.instructions, findJumpTargets(methodNode)); do { boolean changing; do { changing = false; for (PeepholeOptimization optimization : optimizations) { if (optimization.apply(it)) { changing = true; } } } while (changing); } while (it.next()); }