Search in sources :

Example 81 with ClassVisitor

use of org.objectweb.asm.ClassVisitor in project Hystrix by Netflix.

the class MethodProvider method unbride.

/**
 * Finds generic method for the given bridge method.
 *
 * @param bridgeMethod the bridge method
 * @param aClass       the type where the bridge method is declared
 * @return generic method
 * @throws IOException
 * @throws NoSuchMethodException
 * @throws ClassNotFoundException
 */
public Method unbride(final Method bridgeMethod, Class<?> aClass) throws IOException, NoSuchMethodException, ClassNotFoundException {
    if (bridgeMethod.isBridge() && bridgeMethod.isSynthetic()) {
        if (cache.containsKey(bridgeMethod)) {
            return cache.get(bridgeMethod);
        }
        ClassReader classReader = new ClassReader(aClass.getName());
        final MethodSignature methodSignature = new MethodSignature();
        classReader.accept(new ClassVisitor(ASM5) {

            @Override
            public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
                boolean bridge = (access & ACC_BRIDGE) != 0 && (access & ACC_SYNTHETIC) != 0;
                if (bridge && bridgeMethod.getName().equals(name) && getParameterCount(desc) == bridgeMethod.getParameterTypes().length) {
                    return new MethodFinder(methodSignature);
                }
                return super.visitMethod(access, name, desc, signature, exceptions);
            }
        }, 0);
        Method method = aClass.getDeclaredMethod(methodSignature.name, methodSignature.getParameterTypes());
        cache.put(bridgeMethod, method);
        return method;
    } else {
        return bridgeMethod;
    }
}
Also used : ClassReader(org.objectweb.asm.ClassReader) ClassVisitor(org.objectweb.asm.ClassVisitor) Method(java.lang.reflect.Method) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 82 with ClassVisitor

use of org.objectweb.asm.ClassVisitor in project jacoco by jacoco.

the class ProbeInserterTest method setup.

@Before
public void setup() {
    actual = new MethodRecorder();
    actualVisitor = actual.getVisitor();
    expected = new MethodRecorder();
    expectedVisitor = expected.getVisitor();
    arrayStrategy = new IProbeArrayStrategy() {

        public int storeInstance(MethodVisitor mv, boolean clinit, int variable) {
            mv.visitLdcInsn(clinit ? "clinit" : "init");
            return 5;
        }

        public void addMembers(ClassVisitor delegate, int probeCount) {
        }
    };
}
Also used : MethodRecorder(org.jacoco.core.instr.MethodRecorder) ClassVisitor(org.objectweb.asm.ClassVisitor) MethodVisitor(org.objectweb.asm.MethodVisitor) Before(org.junit.Before)

Example 83 with ClassVisitor

use of org.objectweb.asm.ClassVisitor in project jacoco by jacoco.

the class FramesTest method calculateFrames.

private byte[] calculateFrames(byte[] source) {
    source = BytecodeVersion.downgradeIfNeeded(BytecodeVersion.get(source), source);
    ClassReader rc = new ClassReader(source);
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    // Adjust Version to 1.6 to enable frames:
    rc.accept(new ClassVisitor(InstrSupport.ASM_API_VERSION, cw) {

        @Override
        public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
            super.visit(Opcodes.V1_6, access, name, signature, superName, interfaces);
        }
    }, 0);
    return cw.toByteArray();
}
Also used : ClassReader(org.objectweb.asm.ClassReader) ClassVisitor(org.objectweb.asm.ClassVisitor) TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) ClassWriter(org.objectweb.asm.ClassWriter)

Example 84 with ClassVisitor

use of org.objectweb.asm.ClassVisitor in project J2ME-Loader by nikita36078.

the class AndroidProducer method instrument.

private static byte[] instrument(String name, final InputStream classInputStream, boolean isMidlet) throws IOException {
    ClassReader cr = new ClassReader(classInputStream);
    ClassWriter cw = new ClassWriter(0);
    ClassVisitor cv = new AndroidClassVisitor(cw, isMidlet, classesHierarchy, fieldTranslations, methodTranslations);
    cr.accept(cv, 0);
    return cw.toByteArray();
}
Also used : ClassReader(org.objectweb.asm.ClassReader) ClassVisitor(org.objectweb.asm.ClassVisitor) ClassWriter(org.objectweb.asm.ClassWriter)

Example 85 with ClassVisitor

use of org.objectweb.asm.ClassVisitor in project openj9 by eclipse.

the class ASMTransformer method inject_call_to_timerMethod.

public static synchronized byte[] inject_call_to_timerMethod(Class classToTransform) {
    try {
        ClassReader reader = new ClassReader(classToTransform.getCanonicalName());
        ClassWriter cw = new ClassWriter(reader, ClassWriter.COMPUTE_FRAMES);
        ClassVisitor visitor = new MyClassVisitor(cw, classToTransform.getCanonicalName());
        reader.accept(visitor, ClassReader.EXPAND_FRAMES);
        return cw.toByteArray();
    } catch (IOException e) {
        return null;
    }
}
Also used : ClassReader(org.objectweb.asm.ClassReader) ClassVisitor(org.objectweb.asm.ClassVisitor) IOException(java.io.IOException) ClassWriter(org.objectweb.asm.ClassWriter)

Aggregations

ClassVisitor (org.objectweb.asm.ClassVisitor)133 ClassReader (org.objectweb.asm.ClassReader)97 ClassWriter (org.objectweb.asm.ClassWriter)80 MethodVisitor (org.objectweb.asm.MethodVisitor)45 IOException (java.io.IOException)19 InputStream (java.io.InputStream)19 Type (org.objectweb.asm.Type)14 TraceClassVisitor (org.objectweb.asm.util.TraceClassVisitor)14 File (java.io.File)11 PrintWriter (java.io.PrintWriter)11 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)10 Label (org.objectweb.asm.Label)10 FileInputStream (java.io.FileInputStream)9 Test (org.junit.Test)9 FileOutputStream (java.io.FileOutputStream)6 FieldVisitor (org.objectweb.asm.FieldVisitor)6 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)6 ArrayList (java.util.ArrayList)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 FieldList (net.bytebuddy.description.field.FieldList)5