Example usage for org.objectweb.asm Opcodes ACC_ABSTRACT

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

Introduction

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

Prototype

int ACC_ABSTRACT

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

Click Source Link

Usage

From source file:com.sun.tdk.jcov.instrument.DataClass.java

License:Open Source License

void writeObject(DataOutput out) throws IOException {
    super.writeObject(out);
    out.writeUTF(name);/*from w w w  . ja  v a 2  s  .co m*/
    writeString(out, fullname);
    writeString(out, signature);
    writeString(out, source);
    writeString(out, superName);
    writeString(out, superInterfaces);
    out.writeLong(checksum);
    out.writeInt(access & ACCESS_MASK); // we don't save ALL the codes in XML, we shouldn't save all codes in net
    out.writeByte((differentiateClass ? 1 : 0) + (inner ? 2 : 0) + (anonym ? 4 : 0));

    out.writeShort(fields.size());
    for (DataField f : fields) {
        f.writeObject(out);
    }

    out.writeShort(methods.size());
    for (DataMethod m : methods) {
        if (m instanceof DataMethodEntryOnly) {
            if ((m.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) != 0) {
                out.write(2); // DMI
            } else {
                out.write(1); // DMEO
            }
        } else if (m instanceof DataMethodInvoked) {
            if ((m.access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) != 0) {
                out.write(2); // DMI
            } else {
                out.write(1); // DMEO
            }
        } else if (m instanceof DataMethodWithBlocks) {
            out.write(3);
        } else {
            System.out.println("ERROR " + m.getFullName());
            out.write(4);
            throw new IOException(
                    "DataClass.writeObject - Unknown dataMethod class " + m.getClass().getName() + ".");
        }
        m.writeObject(out);
    }
}

From source file:com.sun.tdk.jcov.instrument.DataMethod.java

License:Open Source License

/**
 * Check whether <b>access</b> field has ACC_ABSTRACT flag
 *
 * @see #getAccess()//from   w  ww .jav  a 2 s.co  m
 * @see org.objectweb.asm.Opcodes
 * @return true if <b>access</b> field has ACC_ABSTRACT flag
 */
public boolean isAbstract() {
    return (access & Opcodes.ACC_ABSTRACT) != 0;
}

From source file:com.sun.tdk.jcov.instrument.DataMethod.java

License:Open Source License

/**
 * XML Generation. Not supposed to use outside.
 *//*from www .j  a va2  s  .  c  om*/
@Override
void xmlGen(XmlContext ctx) {
    if (ctx.showAbstract || (access & Opcodes.ACC_ABSTRACT) == 0) {
        super.xmlGen(ctx);
    }
}

From source file:cz.vutbr.fit.xhriba01.bc.lib.Utils.java

License:Open Source License

/**
 * Creates text representation of asm method access flag.
 * //from   w  w  w. j a  v  a  2 s  . c om
 * @param flag asm method access flag
 * @return formatted string representing the access flag
 */
public static String formatMethodAccessFlags(int flag) {
    List<String> accesses = new ArrayList<>();
    if ((flag & Opcodes.ACC_PUBLIC) != 0) {
        accesses.add("public");
    }
    if ((flag & Opcodes.ACC_PROTECTED) != 0) {
        accesses.add("protected");
    }
    if ((flag & Opcodes.ACC_PRIVATE) != 0) {
        accesses.add("private");
    }
    if ((flag & Opcodes.ACC_STATIC) != 0) {
        accesses.add("static");
    }
    if ((flag & Opcodes.ACC_ABSTRACT) != 0) {
        accesses.add("abstract");
    }
    if ((flag & Opcodes.ACC_FINAL) != 0) {
        accesses.add("final");
    }
    return join(accesses.toArray(new String[accesses.size()]), " ");
}

From source file:cz.vutbr.fit.xhriba01.bc.lib.Utils.java

License:Open Source License

/**
 * Creates text representation of asm class access flag.
 * //from w w w.j av  a  2s .  com
 * @param flag asm class access flag
 * @return formatted string representing the access flag
 */
public static String formatClassAccessFlags(int flag) {
    List<String> accesses = new ArrayList<>();
    if ((flag & Opcodes.ACC_PUBLIC) != 0) {
        accesses.add("public");
    }
    if ((flag & Opcodes.ACC_PROTECTED) != 0) {
        accesses.add("protected");
    }
    if ((flag & Opcodes.ACC_PRIVATE) != 0) {
        accesses.add("private");
    }
    if ((flag & Opcodes.ACC_STATIC) != 0) {
        accesses.add("static");
    }
    if ((flag & Opcodes.ACC_ABSTRACT) != 0) {
        accesses.add("abstract");
    }
    if ((flag & Opcodes.ACC_FINAL) != 0) {
        accesses.add("final");
    }
    if ((flag & Opcodes.ACC_ENUM) != 0) {
        accesses.add("enum");
    } else if ((flag & Opcodes.ACC_INTERFACE) != 0) {
        accesses.add("interface");
    } else {
        accesses.add("class");
    }
    return join(accesses.toArray(new String[accesses.size()]), " ");
}

From source file:de.loskutov.bco.asm.DecompiledMethod.java

License:Open Source License

void setText(final List inputText) {
    formatText(inputText, new HashMap<Integer, String>(), new StringBuffer(), this.text);
    computeMaps(lineNumbers);//from w  w  w  .j a  v a 2s  .c o m

    if (options.modes.get(BCOConstants.F_SHOW_ANALYZER) && (access & Opcodes.ACC_ABSTRACT) == 0) {
        analyzeMethod(options.cl);
    }
}

From source file:de.tuberlin.uebb.jbop.optimizer.utils.rename.ClassRenamer.java

License:Open Source License

@Override
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature,
        final String[] exceptions) {
    MethodVisitor mv = super.visitMethod(access, name, fixer.fix(desc), fixer.fix(signature), exceptions);
    if ((mv != null) && ((access & Opcodes.ACC_ABSTRACT) == 0)) {
        mv = new MethodRenamer(mv, fixer);
    }//from   w w w  . j  a  v a 2 s  . com
    return mv;
}

From source file:edu.ubc.mirrors.holograms.HologramClassGenerator.java

License:Open Source License

@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {/*from www  .j av  a2  s  . c om*/
    this.name = name;
    this.isInterface = (Opcodes.ACC_INTERFACE & access) != 0;
    this.superName = getHologramSuperclassName(isInterface, name, superName);
    interfaces = getHologramInterfaces(name, isInterface, interfaces);

    // Force everything to be public, since HologramClassLoader has to reflectively
    // construct holograms. Again, not a problem because the VM will see the original flags on the ClassMirror instead.
    // Also remove enum flags.
    int hologramAccess = forcePublic(access);
    // Also remove abstract flag. Shouldn't be necessary, but the VM (OpenJDK at least)
    // creates objects that claim to be an instance of VirtualMachineError, which is abstract.
    if (name.equals("hologram/java/lang/VirtualMachineError")) {
        hologramAccess = ~Opcodes.ACC_ABSTRACT & access;
    }

    // We need at least 1.5 to use class literal constants
    // TODO-RS: Work out a better way to interpret 45.X numbers correctly
    if (version == Opcodes.V1_1 || version < Opcodes.V1_5) {
        version = 49;
    }

    super.visit(version, hologramAccess, name, signature, this.superName, interfaces);

    if (this.name.equals(hologramThrowableType.getInternalName())) {
        // Generate aliases for the original superclass' fillInStackTrace and getStackTrace methods,
        // so we can call them in stubs without hitting hologram code.
        MethodVisitor v = super.visitMethod(Opcodes.ACC_PUBLIC, "superFillInStackTrace",
                Type.getMethodDescriptor(Type.VOID_TYPE), null, null);
        v.visitCode();
        v.visitVarInsn(Opcodes.ALOAD, 0);
        v.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Throwable.class), "fillInStackTrace",
                Type.getMethodDescriptor(Type.getType(Throwable.class)));
        v.visitInsn(Opcodes.RETURN);
        v.visitMaxs(1, 1);
        v.visitEnd();

        v = super.visitMethod(Opcodes.ACC_PUBLIC, "superGetStackTrace",
                Type.getMethodDescriptor(Type.getType(StackTraceElement[].class)), null, null);
        v.visitCode();
        v.visitVarInsn(Opcodes.ALOAD, 0);
        v.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Throwable.class), "getStackTrace",
                Type.getMethodDescriptor(Type.getType(StackTraceElement[].class)));
        v.visitInsn(Opcodes.ARETURN);
        v.visitMaxs(1, 1);
        v.visitEnd();
    }
}

From source file:edu.ubc.mirrors.holograms.HologramClassGenerator.java

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {

    if (name.equals("<clinit>")) {
        hasClinit = true;// w  w w .ja  v a2 s .c  o m
    }

    // TODO-RS: Remove me - avoiding a race condition in ZipFileInflaterInputStream...
    if (name.equals("finalize")) {
        return null;
    }

    if (name.equals("<init>")) {
        // Add the implicit mirror argument
        desc = addMirrorParam(desc);
    }

    // toString() is a special case - it's defined in java.lang.Object, which this class must ultimately
    // extend, so we have to return a real String rather than a hologram.
    boolean isToString = name.equals("toString")
            && desc.equals(Type.getMethodDescriptor(getHologramType(Type.getType(String.class))));
    if (isToString) {
        desc = Type.getMethodDescriptor(Type.getType(String.class));
    }
    if (name.equals("equals")
            && desc.equals(Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Hologram.class)))) {
        desc = Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Object.class));
    }
    boolean isGetStackTrace = this.name.equals(hologramThrowableType.getInternalName())
            && name.equals("getStackTrace")
            && desc.equals(Type.getMethodDescriptor(getHologramType(Type.getType(StackTraceElement[].class))));
    if (isGetStackTrace) {
        desc = Type.getMethodDescriptor(Type.getType(StackTraceElement[].class));
    }
    if (name.equals("fillInStackTrace") && this.name.equals(hologramThrowableType.getInternalName())) {
        // Omit this - we'll use the Throwable superclass version
        return null;
    }

    // Take off the native keyword if it's there - we're going to fill in an actual
    // method (even if it's a stub that throws an exception).
    int hologramAccess = ~Opcodes.ACC_NATIVE & access;

    // Mild hack: generated method accessors are defined using ClassDefiner and Unsafe,
    // allowing them to make illegal access to this package-private constructor.
    if (this.name.equals("hologram/sun/reflect/MethodAccessorImpl") && name.equals("<init>")) {
        hologramAccess = forcePublic(hologramAccess);
    }

    MethodVisitor superVisitor = super.visitMethod(hologramAccess, name, desc, signature, exceptions);

    HologramMethodGenerator generator = new HologramMethodGenerator(this.name, hologramAccess, name, desc,
            superVisitor, isToString, isGetStackTrace);
    LocalVariablesSorter lvs = new LocalVariablesSorter(access, desc, generator);
    generator.setLocalVariablesSorter(lvs);

    boolean needsThunk = (Opcodes.ACC_NATIVE & access) != 0;
    if (!needsThunk && !name.startsWith("<")) {
        if ((Opcodes.ACC_ABSTRACT & access) == 0) {
            MethodMirror method;
            try {
                method = Reflection.getDeclaredMethod(classMirror, name,
                        getOriginalType(Type.getMethodType(desc)));
            } catch (NoSuchMethodException e) {
                throw new RuntimeException(e);
            }
            MirrorInvocationHandler handler = ClassHolograph.getMethodHandler(method);
            if (handler != null) {
                needsThunk = true;
            }
        }
    }

    if (needsThunk) {
        generator.generateNativeThunk();
        return null;
    }

    return lvs;
}

From source file:edu.ubc.mirrors.holograms.HologramClassGenerator.java

License:Open Source License

public static void generateArray(ClassVisitor visitor, HologramClassLoader loader,
        HologramClassMirror hologramClassMirror) {
    boolean isInterface = !hologramClassMirror.isImplementationClass();
    ClassMirror classMirror = hologramClassMirror.getOriginal();

    Type originalType = Reflection.typeForClassMirror(classMirror);
    Type originalElementType = originalType.getElementType();
    int dims = originalType.getDimensions();

    String internalName = getHologramType(originalType, !isInterface).getInternalName();

    ClassMirror superClassMirror = null;
    String superName = isInterface ? Type.getInternalName(Object.class)
            : Type.getInternalName(ObjectArrayHologram.class);
    Set<String> interfaces = new HashSet<String>();
    int access = Opcodes.ACC_PUBLIC | (isInterface ? Opcodes.ACC_INTERFACE : 0);

    if (originalElementType.getSort() == Type.OBJECT || originalElementType.getSort() == Type.ARRAY) {
        ClassMirror elementClass = loader.loadOriginalClassMirror(originalElementType.getClassName());
        superClassMirror = elementClass.getSuperClassMirror();

        if (isInterface) {
            if (superClassMirror != null) {
                Type superType = Reflection.makeArrayType(dims,
                        Type.getObjectType(superClassMirror.getClassName().replace('.', '/')));
                String superInterfaceName = getHologramType(superType).getInternalName();
                interfaces.add(superInterfaceName);
            }//from   w  w w .  java2s  .c  om

            for (ClassMirror interfaceMirror : elementClass.getInterfaceMirrors()) {
                Type superType = Reflection.makeArrayType(dims,
                        Type.getObjectType(interfaceMirror.getClassName().replace('.', '/')));
                String interfaceName = getHologramType(superType).getInternalName();
                interfaces.add(interfaceName);
            }

            interfaces.add(hologramType.getInternalName());

            Type nMinus1Type = Reflection.makeArrayType(dims - 1, Type.getType(Object.class));
            interfaces.add(getHologramType(nMinus1Type).getInternalName());
        }
    }
    if (!isInterface) {
        interfaces.add(getHologramType(originalType, false).getInternalName());
    }

    visitor.visit(Opcodes.V1_5, access, internalName, null, superName, interfaces.toArray(new String[0]));

    if (isInterface) {
        // Generate clone()
        String cloneDesc = Type.getMethodDescriptor(objectType);
        MethodVisitor mv = visitor.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "clone", cloneDesc,
                null, null);
        mv.visitEnd();
    } else {
        // Generate thunk constructors
        String initDesc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(ObjectArrayMirror.class));
        MethodVisitor mv = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", initDesc, null, null);
        mv.visitCode();
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitVarInsn(Opcodes.ALOAD, 1);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", initDesc);
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(2, 2);
        mv.visitEnd();

        initDesc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE);
        mv = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", initDesc, null, null);
        mv.visitCode();
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitVarInsn(Opcodes.ILOAD, 1);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", initDesc);
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(2, 2);
        mv.visitEnd();
    }

    // Generate the static field used to store the corresponding ClassMirror and the static initializer to set it
    int staticAccess = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_STATIC;
    visitor.visitField(staticAccess, "classMirror", classMirrorType.getDescriptor(), null, null);

    InstructionAdapter mv = new InstructionAdapter(
            visitor.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "<clinit>", "()V", null, null));
    mv.visitCode();
    HologramMethodGenerator.initializeStaticFields(Type.getObjectType(internalName), mv);
    mv.areturn(Type.VOID_TYPE);
    mv.visitMaxs(2, 2);
    mv.visitEnd();

    visitor.visitEnd();
}