@Override public void accept(ClassVisitor cv) { super.accept(cv); } }
public static void replaceMethodWriter(MethodVisitor mv, MethodNode mn) { MethodWriter mw = (MethodWriter) mv; ClassWriter cw = mw.cw; mn.accept(cw); removeMethodWriter(mw); } }
m2.access = m.access; m2.desc = m.desc; m.accept(m2); cleanDebug(m2);
@Override public void convertCode(DexMethodNode methodNode, MethodVisitor mv) { MethodVisitor mw = AsmBridge.searchMethodWriter(mv); MethodNode mn = new MethodNode(Opcodes.ASM5, methodNode.access, methodNode.method.getName(), methodNode.method.getDesc(), null, null); try { super.convertCode(methodNode, mn); } catch (Exception ex) { if (exceptionHandler == null) { throw new DexException(ex, "fail convert code for %s", methodNode.method); } else { mn.instructions.clear(); mn.tryCatchBlocks.clear(); exceptionHandler.handleMethodTranslateException(methodNode.method, methodNode, mn, ex); } } // code convert ok, copy to MethodWriter and check for Size mn.accept(mv); if (mw != null) { try { AsmBridge.sizeOfMethodWriter(mw); } catch (Exception ex) { mn.instructions.clear(); mn.tryCatchBlocks.clear(); exceptionHandler.handleMethodTranslateException(methodNode.method, methodNode, mn, ex); AsmBridge.replaceMethodWriter(mw, mn); } } } }
JSRInlinerAdapter adapter = new JSRInlinerAdapter(nodeWithoutJsr, node.access, node.name, node.desc, node.signature, node.exceptions.toArray(new String[0])); node.accept(adapter); node = nodeWithoutJsr; ValueType[] signature = MethodDescriptor.parseSignature(node.desc);
private void checkMehod(MethodTree each, Set<Integer> lines) { each.rawNode().accept(new TryWithResourcesMethodVisitor(lines)); }
private void findLoggingLines(MethodTree each, Set<Integer> lines) { each.rawNode().accept(new LoggingLineScanner(lines, this.loggingClasses)); }
@RequiresNonNull("type") private void addMixin(ClassNode mixinClassNode) { List<FieldNode> fieldNodes = mixinClassNode.fields; for (FieldNode fieldNode : fieldNodes) { if (!Modifier.isTransient(fieldNode.access)) { // this is needed to avoid serialization issues (even if the new field is // serializable, this can still cause issues in a cluster if glowroot is not // deployed on all nodes) throw new IllegalStateException( "@Mixin fields must be marked transient: " + mixinClassNode.name); } fieldNode.accept(this); } List<MethodNode> methodNodes = mixinClassNode.methods; for (MethodNode mn : methodNodes) { if (mn.name.equals("<init>")) { continue; } String[] exceptions = Iterables.toArray(mn.exceptions, String.class); MethodVisitor mv = cw.visitMethod(mn.access, mn.name, mn.desc, mn.signature, exceptions); mn.accept(new MethodRemapper(mv, new SimpleRemapper(mixinClassNode.name, type.getInternalName()))); } }
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()); }
/** {@inheritDoc} */ @Override public void visitEnd() { MethodNode mn = (MethodNode) mv; mn.accept(next); }
/** * This method can be overwritten to hook into the process of emitting the * instructions of this method as <code>visitX()</code> events. * * @param methodNode * the content to emit * @param methodVisitor * A visitor to emit the content to. Note that this is not * necessarily this visitor instance but some wrapper which * calculates the probes. */ public void accept(final MethodNode methodNode, final MethodVisitor methodVisitor) { methodNode.accept(methodVisitor); }
/** * Makes the given class visitor visit this method. * * @param classVisitor a class visitor. */ public void accept(final ClassVisitor classVisitor) { String[] exceptionsArray = new String[this.exceptions.size()]; this.exceptions.toArray(exceptionsArray); MethodVisitor methodVisitor = classVisitor.visitMethod(access, name, desc, signature, exceptionsArray); if (methodVisitor != null) { accept(methodVisitor); } }
/** * Makes the given class visitor visit this method. * * @param cv * a class visitor. */ public void accept(final ClassVisitor cv) { String[] exceptions = new String[this.exceptions.size()]; this.exceptions.toArray(exceptions); MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions); if (mv != null) { accept(mv); } }
/** * Verifies a method implementation against the blacklisted list of APIs. * @param method the method to verify * @return a {@link InstantRunVerifierStatus} instance or null if the method is not making any * blacklisted calls. */ @NonNull public static InstantRunVerifierStatus verifyMethod(MethodNode method) { VerifierMethodVisitor mv = new VerifierMethodVisitor(method); method.accept(mv); return mv.incompatibleChange.or(InstantRunVerifierStatus.COMPATIBLE); }
/** * Verifies a method implementation against the blacklisted list of APIs. * @param method the method to verify * @return a {@link WormholeVerifierStatus} instance or null if the method is not making any * blacklisted calls. */ @NonNull public static WormholeVerifierStatus verifyMethod(MethodNode method) { VerifierMethodVisitor mv = new VerifierMethodVisitor(method); method.accept(mv); return mv.incompatibleChange.or(WormholeVerifierStatus.COMPATIBLE); }
public void visitEnd() { super.visitEnd(); methodNode.accept(lineLabels.isEmpty() ? writerMethodVisitor : new SecondPassMethodInstrumenter(this)); //when there is no line number info -> no instrumentation }
/** * Returns the remaining leeway of a method's allowed size. * * @param methodNode the {@link MethodNode} to check. * @return the remaining leeway of a method's allowed size. */ protected int getSizeLeeway(MethodNode methodNode) { CodeSizeEvaluator cse = new CodeSizeEvaluator(null); methodNode.accept(cse); // Max allowed method size is 65534 (https://docs.oracle.com/javase/specs/jvms/se10/html/jvms-4.html#jvms-4.7.3) return (65534 - cse.getMaxSize()); }
/** * 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); }