Example usage for org.objectweb.asm Opcodes ACC_STATIC

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

Introduction

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

Prototype

int ACC_STATIC

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

Click Source Link

Usage

From source file:com.devexperts.usages.ClassUsagesAnalyzer.java

License:Open Source License

@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
    Member usedFrom = cache.resolveMember(className, name);
    markTypeUse(Type.getType(desc), usedFrom, UseKind.FIELD);
    markSignatureUse(signature, usedFrom);
    if ((access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0 && ((access & Opcodes.ACC_STATIC) == 0))
        usages.getUsagesForClass(className).addInheritableMember(name);
    return null;/*  ww  w  . j  a va 2  s. co  m*/
}

From source file:com.devexperts.usages.ClassUsagesAnalyzer.java

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    String methodMemberName = Member.methodMemberName(name, Type.getType(desc));
    Member usedFrom = cache.resolveMember(className, methodMemberName);
    markTypeUse(Type.getType(desc), usedFrom, UseKind.UNKNOWN); // will be replaced by RETURN/ARGUMENT
    markSignatureUse(signature, usedFrom);
    if (exceptions != null)
        for (String ex : exceptions)
            makeTypeUse(toClassName(ex), usedFrom, UseKind.THROW);
    if ((access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0 && ((access & Opcodes.ACC_STATIC) == 0)
            && !name.equals(INIT_METHOD))
        usages.getUsagesForClass(className).addInheritableMember(methodMemberName);
    return new MethodAnalyzer(usedFrom);
}

From source file:com.dragome.methodlogger.serverside.MethodLoggerAdapter.java

License:Apache License

private boolean isStatic() {
    return (methodAccess & Opcodes.ACC_STATIC) != 0 || name.equals("<init>");
}

From source file:com.e2info.helloasm.HelloAsmApp.java

License:Open Source License

public static void main(String[] args) throws IOException {
    String name = "HelloAsm";
    int flag = ClassWriter.COMPUTE_MAXS;
    ClassWriter cw = new ClassWriter(flag);
    cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, name, null, "java/lang/Object", null);

    cw.visitSource(name + ".java", null);

    {/*from  www  . j a v  a 2 s.c  om*/
        MethodVisitor mv;
        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
        mv.visitInsn(Opcodes.RETURN);
        // we need this call to take effect ClassWriter.COMPUTE_MAXS flag.
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }

    {
        MethodVisitor mv;
        mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", "([Ljava/lang/String;)V", null,
                null);
        mv.visitCode();
        mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
        mv.visitLdcInsn("hello ASM");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
        mv.visitInsn(Opcodes.RETURN);
        // we need this call to take effect ClassWriter.COMPUTE_MAXS flag.
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }

    cw.visitEnd();

    // build binary
    byte[] bin = cw.toByteArray();

    // save asm trace for human readable
    {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        new ClassReader(bin).accept(new TraceClassVisitor(pw), 0);
        File f = new File(name + ".txt");
        FileUtils.writeStringToFile(f, sw.toString());
    }

    // save as calss file
    {
        File f = new File(name + ".class");
        FileUtils.writeByteArrayToFile(f, bin);
    }

}

From source file:com.facebook.buck.jvm.java.abi.AbiFilteringClassVisitor.java

License:Apache License

@Override
@Nullable/*ww  w  . j  a va2s  . c o m*/
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    // Per JVMS8 2.9, "Class and interface initialization methods are invoked
    // implicitly by the Java Virtual Machine; they are never invoked directly from any
    // Java Virtual Machine instruction, but are invoked only indirectly as part of the class
    // initialization process." Thus we don't need to emit a stub of <clinit>.
    if (!shouldInclude(access) || (name.equals("<clinit>") && (access & Opcodes.ACC_STATIC) > 0)) {
        return null;
    }

    // We don't stub private constructors, but if stripping these constructors results in no
    // constructors at all, we want to include a default private constructor. This is because
    // removing all these private methods will make the class look like it has no constructors at
    // all, which is not possible. We track if this class has a public, non-synthetic constructor
    // and is not an interface or annotation to determine if a default private constructor is
    // generated when visitEnd() is called.
    if (name.equals("<init>") && (access & Opcodes.ACC_SYNTHETIC) == 0) {
        hasVisibleConstructor = true;
    }

    // Bridge methods are created by the compiler, and don't appear in source. It would be nice to
    // skip them, but they're used by the compiler to cover the fact that type erasure has occurred.
    // Normally the compiler adds these as public methods, but if you're compiling against a stub
    // produced using our ABI generator, we don't want people calling it accidentally. Oh well, I
    // guess it happens IRL too.
    //
    // Synthetic methods are also generated by the compiler, unless it's one of the methods named in
    // section 4.7.8 of the JVM spec, which are "<init>" and "Enum.valueOf()" and "Enum.values".
    // None of these are actually harmful to the ABI, so we allow synthetic methods through.
    // http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.8
    return super.visitMethod(access, name, desc, signature, exceptions);
}

From source file:com.facebook.buck.jvm.java.abi.AbiFilteringClassVisitorTest.java

License:Apache License

@Test
public void testExcludesPrivateStaticFields() {
    testExcludesFieldWithAccess(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC);
}

From source file:com.facebook.buck.jvm.java.abi.AbiFilteringClassVisitorTest.java

License:Apache License

@Test
public void testIncludesPackageStaticFields() {
    testIncludesFieldWithAccess(Opcodes.ACC_STATIC);
}

From source file:com.facebook.buck.jvm.java.abi.AbiFilteringClassVisitorTest.java

License:Apache License

@Test
public void testNotConfusedByOtherFieldAccessFlagsIncluding() {
    testIncludesFieldWithAccess(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_VOLATILE);
}

From source file:com.facebook.buck.jvm.java.abi.AbiFilteringClassVisitorTest.java

License:Apache License

@Test
public void testNotConfusedByOtherFieldAccessFlagsExcluding() {
    testExcludesFieldWithAccess(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_VOLATILE);
}

From source file:com.facebook.buck.jvm.java.abi.AbiFilteringClassVisitorTest.java

License:Apache License

@Test
public void testExcludesStaticInitializers() {
    testExcludesMethodWithAccess(Opcodes.ACC_STATIC, "<clinit>");
}