Example usage for org.objectweb.asm Opcodes ASM4

List of usage examples for org.objectweb.asm Opcodes ASM4

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ASM4.

Prototype

int ASM4

To view the source code for org.objectweb.asm Opcodes ASM4.

Click Source Link

Usage

From source file:jaspex.transactifier.MarkAsTransactifiedClassVisitor.java

License:Open Source License

public MarkAsTransactifiedClassVisitor(ClassVisitor cv) {
    super(Opcodes.ASM4, cv);
}

From source file:jaspex.transactifier.RemoveMonitorsClassVisitor.java

License:Open Source License

public RemoveMonitorsClassVisitor(int access, String name, String desc, String signature, String[] exceptions,
        ClassVisitor cv) {/* w w  w.j  a  v a2  s  .  co  m*/
    super(Opcodes.ASM4, cv.visitMethod(access, name, desc, signature, exceptions));
}

From source file:jaspex.transactifier.RemoveSyncClassVisitor.java

License:Open Source License

public RemoveSyncClassVisitor(ClassVisitor cv) {
    super(Opcodes.ASM4, cv);
}

From source file:jaspex.transactifier.Transactifier.java

License:Open Source License

private Transactifier(ClassReader classReader, boolean JDKClass) throws IOException {
    // Forar a gerao de FRAMES para todas as classes, logo no inicio de toda a cadeia,
    // para evitar possveis problemas em tudo o que se segue e que vai processar esta classe
    ClassWriter cw = new jaspex.util.ClassWriter(ClassWriter.COMPUTE_FRAMES);
    try {//  www.j a v a  2  s .c  o  m
        classReader.accept(cw, ClassReader.EXPAND_FRAMES);
    } catch (RuntimeException e) {
        if (!e.getMessage().equals("JSR/RET are not supported with computeFrames option"))
            throw e;

        Log.debug("Class " + classReader.getClassName() + " uses JSR/RET. Inlining...");
        // Repetir processo, fazendo inline de JSR/RET primeiro
        cw = new jaspex.util.ClassWriter(ClassWriter.COMPUTE_FRAMES);

        classReader.accept(new ClassVisitor(Opcodes.ASM4, cw) {
            @Override
            public MethodVisitor visitMethod(int access, String name, String desc, String signature,
                    String[] exceptions) {
                return new JSRInlinerAdapter(cv.visitMethod(access, name, desc, signature, exceptions), access,
                        name, desc, signature, exceptions);
            }
        }, ClassReader.EXPAND_FRAMES);
    }

    cr = new ClassReader(cw.toByteArray());
    currentClass = InfoClass.fromType(Type.fromAsm(cr.getClassName()));
    _JDKClass = JDKClass;
}

From source file:jaspex.transactifier.Transactifier.java

License:Open Source License

private byte[] transactify() throws IOException {
    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);

    // Copiar mtodos originais inalterados
    cr.accept(new ClassVisitor(Opcodes.ASM4) {
        @Override//ww w .  j a v  a 2s  .  c o m
        public void visit(int version, int access, String name, String signature, String superName,
                String[] interfaces) {
            cw.visit(version, access, name, signature, superName, interfaces);
        }

        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature,
                String[] exceptions) {
            if (name.equals("<clinit>"))
                return new EmptyMethodVisitor();
            return cw.visitMethod(access, name, desc, signature, exceptions);
        }

        @Override
        public void visitEnd() {
            cw.visitEnd();
        }
    }, 0);

    // Varivel que contm o ltimo ClassVisitor da "chain" de classvisitors que servem de filtros ao
    // ficheiro original
    ClassVisitor cv = cw;

    // Mtodos alterados so marcados com $transactional no nome
    // Este marcador  temporrio, e ir ser substituido por $speculative mais  frente
    // Nota: Apenas os mtodos so renomeados, os seus INVOKE* ainda no apontam para os
    // $transactional; essa alterao  feita no SpeculativeTransformer
    cv = new ClassVisitor(Opcodes.ASM4, cv) {
        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature,
                String[] exceptions) {
            if (name.equals("<init>")) {
                desc = desc.replace(")", "Ljaspex/MARKER/Transactional;)");
            } else if (!name.equals("<clinit>")) {
                name += "$transactional";
            }
            return cv.visitMethod(access, name, desc, signature, exceptions);
        }
    };

    // Remover ACC_SYNCHRONIZED dos mtodos
    if (Options.REMOVESYNC || _JDKClass)
        cv = new RemoveSyncClassVisitor(cv);

    // Remover MONITORENTER/MONITOREXIT dos mtodos
    if (Options.REMOVEMONITORS)
        cv = new GenericMethodVisitorAdapter(cv, RemoveMonitorsClassVisitor.class);

    // Verificar se existem mtodos com ACC_SYNCHRONIZED ou opcodes MONITORENTER/MONITOREXIT
    if (!_JDKClass)
        cv = new CheckMonitorUsage(cv);

    // Corrigir chamadas a alguns mtodos de java.lang.Object
    cv = new GenericMethodVisitorAdapter(cv, ChangeObjectMethodsMethodVisitor.class, currentClass);

    // Adicionar overrides a alguns mtodos de java.lang.Object
    cv = new AddObjectMethodsClassVisitor(cv, currentClass);

    // Suporte para Arrays
    cv = new GenericMethodVisitorAdapter(cv, ChangeArrayAccessMethodVisitor.class, currentClass, _JDKClass);

    // Adicionar inicializao de offsets usados pela unsafetrans ao clinit da classe
    // Nota: Visitor tem que estar *depois* do FieldTransactifierClassVisitor
    if (!_JDKClass)
        cv = new GenericMethodVisitorAdapter(cv, ChangeClinitMethodVisitor.class, currentClass);

    // Visitor que cria os fields offset e o staticfieldbase
    if (!_JDKClass)
        cv = new FieldTransactifierClassVisitor(cv);

    // Alterar acessos a fields para passarem pela STM
    cv = new GenericMethodVisitorAdapter(cv, ChangeFieldAccessMethodVisitor.class, currentClass, _JDKClass);

    // Modificar string com filename da classe que aparece em excepes
    if (!_JDKClass)
        cv = new MarkAsTransactifiedClassVisitor(cv);

    // Verificar e fazer upgrade da verso da classe, se necessrio
    if (!_JDKClass)
        cv = new ClassVisitor(Opcodes.ASM4, cv) {
            @Override
            public void visit(int version, int access, String name, String signature, String superName,
                    String[] interfaces) {
                // Transactificao precisa de version >= 49, porque usa o MethodVisitor.visitLdcInsn(Type)
                // MethodVisitor.visitLdcInsn(Type), que s funciona a partir dessa verso dos classfiles.
                // http://asm.ow2.org/asm40/javadoc/user/org/objectweb/asm/MethodVisitor.html#visitLdcInsn(java.lang.Object)
                // http://stackoverflow.com/questions/2784791/
                // Caso especial: V1_1  196653, por alguma razo...
                if (version < Opcodes.V1_5 || version == Opcodes.V1_1) {
                    //Log.debug("Class " + name + " has version " + version + ", upgrading it to Java 5");
                    version = Opcodes.V1_5;
                }

                if (version > Opcodes.V1_6 && !name.startsWith("java/")) {
                    Log.warn("Class " + name + " is compiled for Java 7 or newer");
                }

                super.visit(version, access, name, signature, superName, interfaces);
            }
        };

    cr.accept(cv, ClassReader.EXPAND_FRAMES);

    return cw.toByteArray();
}

From source file:jnr.ffi.provider.jffi.SkinnyMethodAdapter.java

License:Apache License

/** Creates a new instance of SkinnyMethodAdapter */
public SkinnyMethodAdapter(ClassVisitor cv, int flags, String name, String signature, String something,
        String[] exceptions) {/*from w ww  .  j  a va2s  . c o  m*/
    super(Opcodes.ASM4);
    setMethodVisitor(cv.visitMethod(flags, name, signature, something, exceptions));
}

From source file:keepcalm.mods.bukkit.Method.java

License:Open Source License

public InheritanceMapClassVisitor() {
    super(Opcodes.ASM4);
    strName = "";
    info = new ClassInfo();
}

From source file:kilim.tools.DumpClass.java

License:Open Source License

public DumpClass(InputStream is, int flags) throws IOException {
    super(Opcodes.ASM4);
    ClassReader cr = new ClassReader(is);
    cr.accept(this, flags);
}

From source file:kilim.tools.DumpClass.java

License:Open Source License

public DumpClass(String className, int flags) throws IOException {
    super(Opcodes.ASM4);
    ClassReader cr;//w w  w.j a v a 2 s.  co m
    if (className.endsWith(".class")) {
        FileInputStream fis = new FileInputStream(className);
        cr = new ClassReader(fis);
    } else {
        cr = new ClassReader(className);
    }
    cr.accept(this, flags);
}

From source file:kilim.tools.DumpClass.java

License:Open Source License

public DummyAnnotationVisitor() {
    super(Opcodes.ASM4);
}