public static ClassNode loadClass(InputStream is, int mode) { try { final ClassReader reader = new ClassReader(is); final ClassNode node = new ClassNode(); reader.accept(node, mode); for(int i = 0; i < node.methods.size(); ++i) { final MethodNode methodNode2 = (MethodNode) node.methods.get(i); final JSRInlinerAdapter adapter = new JSRInlinerAdapter(methodNode2, methodNode2.access, methodNode2.name, methodNode2.desc, methodNode2.signature, (String[]) methodNode2.exceptions.toArray(new String[0])); methodNode2.accept(adapter); node.methods.set(i, adapter); } Main.getInstance().nameToNode.put(node.name, node); Main.getInstance().nodeToName.put(node, node.name); return node; } catch(Throwable t) { t.printStackTrace(); return null; } }
/** * For each method in the class being instrumented, <code>visitMethod</code> * is called and the returned MethodVisitor is used to visit the method. * Note that a new MethodVisitor is constructed for each method. */ @Override public MethodVisitor visitMethod(int access, String base, String desc, String signature, String[] exceptions) { MethodVisitor mv = cv.visitMethod(access, base, desc, signature, exceptions); if (mv != null) { // We need to compute stackmaps (see // AllocationInstrumenter#instrument). This can't really be // done for old bytecode that contains JSR and RET instructions. // So, we remove JSRs and RETs. JSRInlinerAdapter jsria = new JSRInlinerAdapter( mv, access, base, desc, signature, exceptions); AllocationMethodAdapter aimv = new AllocationMethodAdapter(jsria, recorderClass, recorderMethod); LocalVariablesSorter lvs = new LocalVariablesSorter(access, desc, aimv); aimv.lvs = lvs; mv = lvs; } return mv; }
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodNode node = new JSRInlinerAdapter(null, access, name, desc, signature, exceptions); JarCode code = context.lookupMap.get(application.getMethod(context.owner.type, name, desc)); if (code != null) { code.context = null; code.node = node; return node; } return null; }
private static ClassVisitor useJSRInlinerAdapter(ClassVisitor visitor) { return new ClassVisitor(Opcodes.ASM5, visitor) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { return new JSRInlinerAdapter(super.visitMethod(access, name, desc, signature, exceptions), access, name, desc, signature, exceptions); } }; }
static byte[] fixJSRInlining(byte[] byteCode) { ClassReader reader = new ClassReader(byteCode); ClassWriter writer = new FixedClassWriter(reader, 0); ClassVisitor visitor = new ClassVisitor(Opcodes.ASM5, writer) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { return new JSRInlinerAdapter(super.visitMethod(access, name, desc, signature, exceptions), access, name, desc, signature, exceptions); } }; reader.accept(visitor, 0); return writer.toByteArray(); }
@Override public MethodVisitor visitAllowedMethod(MethodVisitor mv, int access, String name, String desc, String signature, String[] exceptions) { List<Metric> metadata = config.findMetrics(className, name, desc); mv = new MetricAdapter(mv, className, access, name, desc, metadata); return new JSRInlinerAdapter(mv, access, name, desc, signature, exceptions); }
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { BytecodeMethod mtd = new BytecodeMethod(clsName, access, name, desc, signature, exceptions); cls.addMethod(mtd); JSRInlinerAdapter a = new JSRInlinerAdapter(new MethodVisitorWrapper(super.visitMethod(access, name, desc, signature, exceptions), mtd), access, name, desc, signature, exceptions); return a; }
/** * helper method for method visitor generation * @param access * @param method * @param cv * @return */ private static MethodVisitor toMethodVisitor(int access, Method method, ClassVisitor cv) { MethodVisitor visitor = cv.visitMethod(access, method.getName(), method.getDescriptor(), null, null); JSRInlinerAdapter inlinerAdapter = new JSRInlinerAdapter(visitor, access, method.getName(), method.getDescriptor(), null, null); return inlinerAdapter; }
@Override public MethodVisitor visitMethod(int access, String name, String desc, @Nullable String signature, String /*@Nullable*/ [] exceptions) { MethodVisitor mv = checkNotNull(cv).visitMethod(access, name, desc, signature, exceptions); return new JSRInlinerAdapter(mv, access, name, desc, signature, exceptions); }
static byte[] fixJSRInlining(byte[] byteCode) { ClassReader reader = new ClassReader(byteCode); ClassWriter writer = new FixedClassWriter(reader, 0); ClassVisitor visitor = new ClassVisitor(Opcodes.ASM4, writer) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { return new JSRInlinerAdapter(super.visitMethod(access, name, desc, signature, exceptions), access, name, desc, signature, exceptions); } }; reader.accept(visitor, 0); return writer.toByteArray(); }
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor origVisitor = super.visitMethod(access, name, desc, signature, exceptions); return new JSRInlinerAdapter(origVisitor, access, name, desc, signature, exceptions); }
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { return new JSRInlinerAdapter(super.visitMethod(access, name, desc, signature, exceptions), access, name, desc, signature, exceptions); }
@Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { final MethodVisitor visitor = super.visitMethod(access, name, desc, signature, exceptions); return visitor == null ? null : new JSRInlinerAdapter(visitor, access, name, desc, signature, exceptions); }
/** * helper method for method visitor generation * * @param access * @param method * @param cv * @return */ private static MethodVisitor toMethodVisitor(int access, Method method, ClassVisitor cv) { MethodVisitor visitor = cv.visitMethod(access, method.getName(), method.getDescriptor(), null, null); JSRInlinerAdapter inlinerAdapter = new JSRInlinerAdapter(visitor, access, method.getName(), method.getDescriptor(), null, null); return inlinerAdapter; // return visitor; }