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.speculation.SpeculativeTransformer.java

License:Open Source License

public byte[] createSpeculativeMethods(ClassReader cr) {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    ClassVisitor cv = cw;//from w w w. ja v  a  2s. c om

    // Tornar classe public: para o codegen funcionar, todas as classes tm que ser pblicas
    // (todos os mtodos $speculative tambm j so public)
    if (!_JDKClass)
        cv = new ClassVisitor(Opcodes.ASM4, cv) {
            @Override
            public void visit(int version, int access, String name, String signature, String superName,
                    String[] interfaces) {
                access = access & ~Opcodes.ACC_PRIVATE & ~Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC;
                cv.visit(version, access, name, signature, superName, interfaces);
            }
        };

    // Visitor que adiciona fields e mtodos para o -detectlocal
    cv = new InjectDetectLocalClassVisitor(cv);

    // Criar verses $speculative de mtodos
    cv = new GenericMethodVisitorAdapter(cv, CreateSpeculativeMethodVisitor.class, currentClass, _JDKClass);

    // Marcar constructores com SpeculativeCtorMarker
    cv = new GenericMethodVisitorAdapter(cv, SpeculativeCtorMethodVisitor.class);

    // Potencialmente substituir alguns dos mtodos com verses internas do JaSPEx
    cv = new GenericMethodVisitorAdapter(cv, MethodReplacerMethodVisitor.class, currentClass, _JDKClass);

    // Resolver problema com o acesso a mtodos privados
    cv = new GenericMethodVisitorAdapter(cv, FixPrivateMethodAccessMethodVisitor.class, currentClass,
            _JDKClass);

    // Injectar overloads para a todos os mtodos que so herdados de superclasses no-transactificveis
    // Nota: Deve estar na pipeline *antes* do CreateSpeculativeMethodVisitor
    if (!_JDKClass)
        cv = new InjectOverloadsClassVisitor(cv, currentClass);

    cr.accept(cv, 0);

    // Criar verses non-speculative dos mtodos, que funcionam transaccionalmente, mas no
    // fazem spawn de especulaes
    new ClassReader(cw.toByteArray()).accept(new CreateNonSpeculativeMethodsClassVisitor(cw), 0);

    return cw.toByteArray();
}

From source file:jaspex.transactifier.AddObjectMethodsClassVisitor.java

License:Open Source License

public AddObjectMethodsClassVisitor(ClassVisitor cv, InfoClass currentClass) {
    super(Opcodes.ASM4, cv);

    if (currentClass.isInterface())
        return;/*from   ww w .  j  a v  a  2s .  c  om*/

    if (currentClass.superclassType().equals(Type.OBJECT)) {
        _injectHashCode = true;
        _injectToString = true;
        return;
    }

    // Verificar se superclasse no-transactificvel tem toString/hashCode
    // Se no tiver, esta classe dever inserir copias dele, c.c. sero mais
    // tarde adicionados overrides pelo InjectOverloadsClassVisitor
    if (!ClassFilter.isTransactifiable(currentClass.superclassType())) {
        // Popular superclasses, se necessrio
        if (currentClass.superclass() == null) {
            try {
                asmlib.Util.populateSuperclasses(currentClass);
            } catch (IOException e) {
                throw new Error(e);
            }
        }

        InfoClass superclass = currentClass.superclass();
        boolean foundToString = false;
        boolean foundHashCode = false;
        while (!superclass.type().equals(Type.OBJECT)) {
            if (!foundToString) {
                foundToString = superclass.getMethod("toString", "()Ljava/lang/String;") != null;
            }
            if (!foundHashCode) {
                foundHashCode = superclass.getMethod("hashCode", "()I") != null;
            }
            superclass = superclass.superclass();
        }

        _injectToString = !foundToString;
        _injectHashCode = !foundHashCode;
    }
}

From source file:jaspex.transactifier.ChangeArrayAccessMethodVisitor.java

License:Open Source License

public ChangeArrayAccessMethodVisitor(int access, String name, String desc, String signature,
        String[] exceptions, ClassVisitor cv, InfoClass currentClass, Boolean JDKClass) {
    super(Opcodes.ASM4, new AnalyzerAdapter(currentClass.type().asmName(), access, name, desc,
            cv.visitMethod(access, name, desc, signature, exceptions)));
    _analyzerAdapter = (AnalyzerAdapter) mv;
    _active = !(name.equals("<clinit>") && JDKClass);
}

From source file:jaspex.transactifier.ChangeClinitMethodVisitor.java

License:Open Source License

public ChangeClinitMethodVisitor(int access, String name, String desc, String signature, String[] exceptions,
        ClassVisitor cv, InfoClass currentClass) {
    super(Opcodes.ASM4, cv.visitMethod(access, name, desc, signature, exceptions));
    _active = name.equals("<clinit>");
    _targetClassName = currentClass.type();
    _currentClassName = currentClass.type();
    _fieldList = currentClass.fields();/*from  ww  w  .ja  v  a 2s . com*/
    _injectedClinit = currentClass.getMethod("<clinit>", "()V") == null;
}

From source file:jaspex.transactifier.ChangeClinitMethodVisitor.java

License:Open Source License

public ChangeClinitMethodVisitor(int access, String name, String desc, String signature, String[] exceptions,
        ClassVisitor cv, Type targetClassName, Type currentClassName, ArrayList<InfoField> fieldList) {
    super(Opcodes.ASM4, cv.visitMethod(access, name, desc, signature, exceptions));
    _active = name.equals("<clinit>");
    _targetClassName = targetClassName;//  ww  w  . j av  a  2  s.  c  o m
    _currentClassName = currentClassName;
    _fieldList = fieldList;
    _injectedClinit = true;
}

From source file:jaspex.transactifier.ChangeFieldAccessMethodVisitor.java

License:Open Source License

public ChangeFieldAccessMethodVisitor(int access, String name, String desc, String signature,
        String[] exceptions, ClassVisitor cv, InfoClass currentClass, Boolean JDKClass) {
    super(Opcodes.ASM4, cv.visitMethod(access, name, desc, signature, exceptions));
    _currentClass = currentClass;//  w  w w. j  a  v  a2 s .c o m
    // FIXME: Crappy workaround. <clinit>, mesmo dentro de uma especulao, faz sempre escrita normal,
    // com a espectativa de que no depende de nada que seja estado especulativo.
    // A alternativa antiga era fazer as escritas especulativas, e rezar para que no fosse feito o
    // abort da transaco que acidentalmente tinha feito o trigger do <clinit>. Nenhuma das duas
    // opes  soluo, mas talvez esta seja mais "prtica".
    _active = !(name.equals("<clinit>") /*&& JDKClass*/);
}

From source file:jaspex.transactifier.ChangeObjectMethodsMethodVisitor.java

License:Open Source License

public ChangeObjectMethodsMethodVisitor(int access, String name, String desc, String signature,
        String[] exceptions, ClassVisitor cv, InfoClass currentClass) {
    super(Opcodes.ASM4, new AnalyzerAdapter(currentClass.type().asmName(), access, name, desc,
            cv.visitMethod(access, name, desc, signature, exceptions)));
    _analyzerAdapter = (AnalyzerAdapter) mv;
    _currentClass = currentClass;//from ww  w. ja va 2  s .c o  m
}

From source file:jaspex.transactifier.CheckMonitorUsage.java

License:Open Source License

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

From source file:jaspex.transactifier.CheckMonitorUsage.java

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if (!Options.REMOVESYNC && ((access & ACC_SYNCHRONIZED) != 0))
        _foundSynchronized = true;//from  ww w  .  j  a  v  a  2  s.  c om

    return new MethodVisitor(Opcodes.ASM4, cv.visitMethod(access, name, desc, signature, exceptions)) {
        @Override
        public void visitInsn(int opcode) {
            if (!Options.REMOVEMONITORS && (opcode == MONITORENTER || opcode == MONITOREXIT)) {
                _foundMonitors = true;
            }
            mv.visitInsn(opcode);
        }
    };
}

From source file:jaspex.transactifier.FieldTransactifierClassVisitor.java

License:Open Source License

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