Example usage for org.objectweb.asm Opcodes ACC_PUBLIC

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

Introduction

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

Prototype

int ACC_PUBLIC

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

Click Source Link

Usage

From source file:io.syncframework.optimizer.OControllerClassVisitor.java

License:Apache License

/**
 * Generates the _asUrl() method with using a constant string
 * public String _asUrl() { return "/*"; }
 *///from   w w w  .  ja v a 2 s.c  o  m
public void createUrlMethod() {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asUrl", "()Ljava/lang/String;", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitLdcInsn(reflector.getUrl());
    mv.visitInsn(Opcodes.ARETURN);
    Label l1 = new Label();
    mv.visitLocalVariable("this", Type.getDescriptor(reflector.getClazz()), null, l0, l1, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}

From source file:io.syncframework.optimizer.OInitializerClassVisitor.java

License:Apache License

/**
 * Generates the code://from  ww w  .  j av  a2  s  . co  m
 * 
 * public void _asDestroy() {
 *    return destroy();
 * }
 */
public void createDestroyMethod() {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asDestroy", "()V", null, null);
    Label l0 = new Label();
    if (reflector.getInit() != null) {
        mv.visitLabel(l0);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, reflector.getClazzInternalName(), "destroy", "()V", false);
        mv.visitInsn(Opcodes.RETURN);
    } else {
        mv.visitLabel(l0);
        mv.visitInsn(Opcodes.RETURN);
    }

    Label l1 = new Label();
    mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, l0, l1, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}

From source file:io.syncframework.optimizer.OInitializerClassVisitor.java

License:Apache License

/**
 * Generates the code:/*from  w ww  .  ja v  a  2s . c o m*/
 * 
 * public void _asInit() {
 *    return init();
 * }
 */
public void createInitMethod() {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asInit", "()V", null, null);
    Label l0 = new Label();
    if (reflector.getInit() != null) {
        mv.visitLabel(l0);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, reflector.getClazzInternalName(), "init", "()V", false);
        mv.visitInsn(Opcodes.RETURN);
    } else {
        mv.visitLabel(l0);
        mv.visitInsn(Opcodes.RETURN);
    }
    Label l1 = new Label();
    mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, l0, l1, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}

From source file:io.syncframework.optimizer.OInterceptorClassVisitor.java

License:Apache License

/**
 * Generates the code:/* w  ww. j av  a 2s.  c om*/
 * 
 * public Result _asAfter() {
 *    return after();
 * }
 */
public void createAfterMethod() {
    String signature = "()" + Type.getDescriptor(Result.class);
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asAfter", signature, null, null);
    Label l0 = new Label();

    if (reflector.getAfter() != null) {
        mv.visitLabel(l0);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, reflector.getClazzInternalName(), "after", signature, false);
        mv.visitInsn(Opcodes.ARETURN);
    } else {
        mv.visitLabel(l0);
        mv.visitInsn(Opcodes.ACONST_NULL);
        mv.visitInsn(Opcodes.ARETURN);
    }

    Label l1 = new Label();
    mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, l0, l1, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}

From source file:io.syncframework.optimizer.OInterceptorClassVisitor.java

License:Apache License

/**
 * Generates the code://from www  .  j  a va2s .  c  o  m
 * 
 * public Result _asBefore() {
 *    return before();
 * }
 */
public void createBeforeMethod() {
    String signature = "()" + Type.getDescriptor(Result.class);
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asBefore", signature, null, null);
    Label l0 = new Label();

    if (reflector.getAfter() != null) {
        mv.visitLabel(l0);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, reflector.getClazzInternalName(), "before", signature, false);
        mv.visitInsn(Opcodes.ARETURN);
    } else {
        mv.visitLabel(l0);
        mv.visitInsn(Opcodes.ACONST_NULL);
        mv.visitInsn(Opcodes.ARETURN);
    }

    Label l1 = new Label();
    mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, l0, l1, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}

From source file:jaspex.speculation.Cache.java

License:Open Source License

public static void saveClass(final Type className, byte[] classBytes) {
    new File(CACHE_DIR).mkdir();
    try {/*w w  w. j a v a  2 s  .c  om*/
        ClassReader cr = new ClassReader(classBytes);
        ClassWriter cw = new ClassWriter(cr, 0);

        cr.accept(new ClassVisitor(Opcodes.ASM4, cw) {
            @Override
            public void visitEnd() {
                visitField(Opcodes.ACC_FINAL | Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, CLASS_HASH_FIELD,
                        asmlib.Type.STRING.bytecodeName(), null, hashClass(className));
                cv.visitEnd();
            }
        }, 0);

        FileOutputStream fos = new FileOutputStream(CACHE_DIR + className.commonName() + ".class");
        fos.write(cw.toByteArray());
        fos.close();
    } catch (IOException e) {
        throw new Error(e);
    }
}

From source file:jaspex.speculation.CreateSpeculativeMethodVisitor.java

License:Open Source License

private static MethodVisitor createNextMethodVisitor(int access, String name, String desc, String signature,
        String[] exceptions, ClassVisitor cv) {

    if (name.endsWith("$transactional")) {
        name = name.replace("$transactional", "$speculative");

        // Mtodo original podia ser nativo, mas o $speculative no 
        access &= ~Opcodes.ACC_NATIVE;

        // Todos os mtodos $speculative devem ser public (seno o codegen falha com java.lang.IllegalAccessError)
        access = access & ~Opcodes.ACC_PRIVATE & ~Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC;
    }/*from w w w. j  av  a2  s  .  c  o m*/

    return cv.visitMethod(access, name, desc, signature, exceptions);
}

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  ww  .j av  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:jasy.lang.ASMCompiler.java

private static int getAccessModifier(JasyParser.AccessModifierContext ctx,
        JasyParser.ModStaticContext statCtx) {
    int mod = Opcodes.ACC_PRIVATE;

    if (ctx != null) {
        switch (((TerminalNode) ctx.getChild(0)).getSymbol().getType()) {
        case JasyLexer.ACC_MOD_PRIVATE:
            mod = Opcodes.ACC_PRIVATE;/*from ww w.  j a  v  a 2s  . c  o  m*/
            break;
        case JasyLexer.ACC_MOD_PROTECTED:
            mod = Opcodes.ACC_PROTECTED;
            break;
        case JasyLexer.ACC_MOD_PUBLIC:
            mod = Opcodes.ACC_PUBLIC;
            break;
        }
    }

    if (statCtx != null)
        return mod | Opcodes.ACC_STATIC;

    return mod;
}

From source file:jasy.SourceToAstTest.java

private static Predicate<FieldAST> fIsPublic() {
    return f -> f.selector.accessModifier == Opcodes.ACC_PUBLIC;
}