Example usage for org.objectweb.asm Opcodes ACC_NATIVE

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

Introduction

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

Prototype

int ACC_NATIVE

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

Click Source Link

Usage

From source file:asmlib.InfoMethod.java

License:Open Source License

public boolean isNative() {
    return (access() & Opcodes.ACC_NATIVE) != 0;
}

From source file:blue.origami.asm.OAnno.java

License:Apache License

public void add(String spec) {
    String[] annos = spec.split(",");
    for (String s : annos) {
        s = s.toLowerCase();//from w  ww  .ja  v a 2  s .c  om
        switch (s) {
        case "public":
            acc |= Opcodes.ACC_PUBLIC;
            acc &= ~Opcodes.ACC_PROTECTED;
            acc &= ~Opcodes.ACC_PRIVATE;
            break;
        case "protected":
            acc |= Opcodes.ACC_PROTECTED;
            acc &= ~Opcodes.ACC_PUBLIC;
            acc &= ~Opcodes.ACC_PRIVATE;
            break;
        case "private":
            acc |= Opcodes.ACC_PRIVATE;
            acc &= ~Opcodes.ACC_PUBLIC;
            acc &= ~Opcodes.ACC_PROTECTED;
            break;
        case "static":
            acc |= Opcodes.ACC_STATIC;
            break;
        case "abstract":
            acc |= Opcodes.ACC_ABSTRACT;
            break;
        case "interface":
            acc |= Opcodes.ACC_INTERFACE;
            break;
        case "final":
            acc |= Opcodes.ACC_FINAL;
            break;
        case "native":
            acc |= Opcodes.ACC_NATIVE;
            break;
        case "synchronized":
            acc |= Opcodes.ACC_SYNCHRONIZED;
            break;
        case "strictfp":
            acc |= Opcodes.ACC_STRICT;
            break;
        }
    }
}

From source file:ch.eiafr.cojac.FloatReplaceClassVisitor.java

License:Apache License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    String oldDesc = desc;//from   w  ww  . j  a  va2 s.  c  o  m
    desc = replaceFloatMethodDescription(desc);
    boolean isNative = (access & Opcodes.ACC_NATIVE) > 0;
    //boolean isAbstrac = (access & Opcodes.ACC_ABSTRACT) > 0;
    //boolean isInterface = (access & Opcodes.ACC_INTERFACE) > 0;   
    if (isNative && desc.equals(oldDesc) == false) {
        /*  If the native method has not the same descriptor, create a 
             method to transform types and call the good native method. */
        cv.visitMethod(access, name, oldDesc, signature, exceptions);
        fpm.nativeCall(null, access, crtClassName, name, oldDesc);
        return null;
    }
    MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
    String currentMethodID = crtClassName + '/' + name;
    if (cav.isClassAnnotated() || cav.isMethodAnnotated(currentMethodID)) {
        return mv;
    }
    return instrumentMethod(mv, access, desc, oldDesc, name);
}

From source file:cl.inria.stiq.instrumenter.BCIUtils.java

License:Open Source License

public static boolean isNative(int access) {
    return (access & Opcodes.ACC_NATIVE) != 0;
}

From source file:co.paralleluniverse.fibers.instrument.InstrumentClass.java

License:Open Source License

private static boolean checkAccess(int access) {
    return (access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_NATIVE)) == 0;
}

From source file:co.paralleluniverse.fibers.instrument.LabelSuspendableCallSitesClassVisitor.java

License:Open Source License

@Override
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature,
        final String[] exceptions) {
    if ((access & Opcodes.ACC_NATIVE) == 0 && !isYieldMethod(className, name)) {
        // Bytecode-level AST of a method, being a MethodVisitor itself can be filled through delegation from another visitor
        // Analyze, fill and enqueue method ASTs
        final MethodVisitor outMV = super.visitMethod(access, name, desc, signature, exceptions);

        return new MethodVisitor(ASMAPI, outMV) {
            private int currLineNumber = -1;

            @Override//from www.  j  a  v a2  s. c o m
            public void visitLineNumber(int i, Label label) {
                currLineNumber = i;
                super.visitLineNumber(i, label);
            }

            @Override
            public void visitMethodInsn(int opcode, String owner, String name, String desc,
                    boolean isInterface) {
                final int type = AbstractInsnNode.METHOD_INSN;
                if (InstrumentMethod.isSuspendableCall(db, type, opcode, owner, name, desc)) {
                    final Label l = new Label();
                    super.visitLabel(l);
                    super.visitLineNumber(currLineNumber, l); // Force label
                }
                super.visitMethodInsn(opcode, owner, name, desc, isInterface);
            }

            @Override
            public void visitInvokeDynamicInsn(String name, String desc, Handle handle, Object... objects) {
                final int type = AbstractInsnNode.INVOKE_DYNAMIC_INSN;
                final int opcode = Opcodes.INVOKEDYNAMIC;
                if (InstrumentMethod.isSuspendableCall(db, type, opcode, handle.getOwner(), name, desc)) {
                    final Label l = new Label();
                    super.visitLabel(l);
                    super.visitLineNumber(currLineNumber, l); // Force label
                }
                super.visitInvokeDynamicInsn(name, desc, handle, objects);
            }
        };
    }
    return super.visitMethod(access, name, desc, signature, exceptions);
}

From source file:co.paralleluniverse.fibers.instrument.SuspOffsetsAfterInstrClassVisitor.java

License:Open Source License

@Override
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature,
        final String[] exceptions) {
    if ((access & Opcodes.ACC_NATIVE) == 0 && !isYieldMethod(className, name)) {
        // Bytecode-level AST of a method, being a MethodVisitor itself can be filled through delegation from another visitor
        final MethodNode mn = new MethodNode(access, name, desc, signature, exceptions);

        // Analyze, fill and enqueue method ASTs
        final MethodVisitor outMV = super.visitMethod(access, name, desc, signature, exceptions);

        return new MethodVisitor(ASMAPI, outMV) {
            private Label currLabel = null;
            private int prevOffset = -1;
            private boolean instrumented;
            private boolean optimized = false;
            private int methodStart = -1, methodEnd = -1;

            private List<Integer> suspOffsetsAfterInstrL = new ArrayList<>();
            private int[] suspCallSites = new int[0];

            @Override/*from  www.j  av  a  2 s.c  o m*/
            public AnnotationVisitor visitAnnotation(final String adesc, boolean visible) {
                if (Classes.INSTRUMENTED_DESC.equals(adesc)) {
                    instrumented = true;

                    return new AnnotationVisitor(ASMAPI) { // Only collect info
                        @Override
                        public void visit(String name, Object value) {
                            if (Instrumented.FIELD_NAME_METHOD_START.equals(name))
                                methodStart = (Integer) value;
                            else if (Instrumented.FIELD_NAME_METHOD_END.equals(name))
                                methodEnd = (Integer) value;
                            else if (Instrumented.FIELD_NAME_METHOD_OPTIMIZED.equals(name))
                                optimized = (Boolean) value;
                            else if (Instrumented.FIELD_NAME_SUSPENDABLE_CALL_SITES.equals(name))
                                suspCallSites = (int[]) value;
                            else //noinspection StatementWithEmptyBody
                            if (Instrumented.FIELD_NAME_SUSPENDABLE_CALL_SITES_OFFSETS_AFTER_INSTR.equals(name))
                                ; // Ignore, we're filling it
                            else
                                throw new RuntimeException("Unexpected `@Instrumented` field: " + name);
                        }
                    };
                }

                return super.visitAnnotation(adesc, visible);
            }

            @Override
            public void visitLocalVariable(String name, String desc, String sig, Label lStart, Label lEnd,
                    int slot) {
                super.visitLocalVariable(name, desc, sig, lStart, lEnd, slot);
            }

            @Override
            public void visitLabel(Label label) {
                if (instrumented) {
                    currLabel = label;
                }

                super.visitLabel(label);
            }

            @Override
            public void visitMethodInsn(int opcode, String owner, String name, String desc,
                    boolean isInterface) {
                if (instrumented) {
                    final int type = AbstractInsnNode.METHOD_INSN;
                    if (InstrumentMethod.isSuspendableCall(db, type, opcode, owner, name, desc)
                            && !Classes.STACK_NAME.equals(owner) && // postRestore
                    currLabel != null && currLabel.info instanceof Integer)
                        addLine();
                }

                super.visitMethodInsn(opcode, owner, name, desc, isInterface);
            }

            @Override
            public void visitInvokeDynamicInsn(String name, String desc, Handle handle, Object... objects) {
                if (instrumented) {
                    final int type = AbstractInsnNode.INVOKE_DYNAMIC_INSN;
                    final int opcode = Opcodes.INVOKEDYNAMIC;
                    if (InstrumentMethod.isSuspendableCall(db, type, opcode, handle.getOwner(), name, desc)
                            && !Classes.STACK_NAME.equals(handle.getOwner()) && // postRestore
                    currLabel != null && currLabel.info instanceof Integer)
                        addLine();
                }
                super.visitInvokeDynamicInsn(name, desc, handle, objects);
            }

            @Override
            public void visitEnd() {
                if (instrumented)
                    InstrumentMethod.emitInstrumentedAnn(db, outMV, mn, sourceName, className, optimized,
                            methodStart, methodEnd, suspCallSites, toIntArray(suspOffsetsAfterInstrL));

                super.visitEnd();
            }

            private void addLine() {
                final int currOffset = (Integer) currLabel.info;
                if (currOffset > prevOffset) {
                    suspOffsetsAfterInstrL.add(currOffset);
                    prevOffset = currOffset;
                }
            }
        };
    }

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

From source file:com.android.build.gradle.internal.incremental.IncrementalVisitor.java

License:Apache License

/**
 * Defines when a method access flags are compatible with InstantRun technology.
 *
 * - If the method is a bridge method, we do not enable it for instantReload.
 *   it is most likely only calling a twin method (same name, same parameters).
 * - if the method is abstract or native, we don't add a redirection.
 *
 * @param access the method access flags
 * @return true if the method should be InstantRun enabled, false otherwise.
 */// ww  w.j a  v  a2 s  .  c o  m
protected static boolean isAccessCompatibleWithInstantRun(int access) {
    return (access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_BRIDGE | Opcodes.ACC_NATIVE)) == 0;
}

From source file:com.android.builder.testing.MockableJarGenerator.java

License:Apache License

/**
 * Rewrites the method bytecode to remove the "Stub!" exception.
 *///w  w  w .  j  a v a2  s  .  c  o m
private void fixMethodBody(MethodNode methodNode, ClassNode classNode) {
    if ((methodNode.access & Opcodes.ACC_NATIVE) != 0 || (methodNode.access & Opcodes.ACC_ABSTRACT) != 0) {
        // Abstract and native method don't have bodies to rewrite.
        return;
    }

    if ((classNode.access & Opcodes.ACC_ENUM) != 0 && ENUM_METHODS.contains(methodNode.name)) {
        // Don't break enum classes.
        return;
    }

    Type returnType = Type.getReturnType(methodNode.desc);
    InsnList instructions = methodNode.instructions;

    if (methodNode.name.equals(CONSTRUCTOR)) {
        // Keep the call to parent constructor, delete the exception after that.

        boolean deadCode = false;
        for (AbstractInsnNode instruction : instructions.toArray()) {
            if (!deadCode) {
                if (instruction.getOpcode() == Opcodes.INVOKESPECIAL) {
                    instructions.insert(instruction, new InsnNode(Opcodes.RETURN));
                    // Start removing all following instructions.
                    deadCode = true;
                }
            } else {
                instructions.remove(instruction);
            }
        }
    } else {
        instructions.clear();

        if (returnDefaultValues || methodNode.name.equals(CLASS_CONSTRUCTOR)) {
            if (INTEGER_LIKE_TYPES.contains(returnType)) {
                instructions.add(new InsnNode(Opcodes.ICONST_0));
            } else if (returnType.equals(Type.LONG_TYPE)) {
                instructions.add(new InsnNode(Opcodes.LCONST_0));
            } else if (returnType.equals(Type.FLOAT_TYPE)) {
                instructions.add(new InsnNode(Opcodes.FCONST_0));
            } else if (returnType.equals(Type.DOUBLE_TYPE)) {
                instructions.add(new InsnNode(Opcodes.DCONST_0));
            } else {
                instructions.add(new InsnNode(Opcodes.ACONST_NULL));
            }

            instructions.add(new InsnNode(returnType.getOpcode(Opcodes.IRETURN)));
        } else {
            instructions.insert(throwExceptionsList(methodNode, classNode));
        }
    }
}

From source file:com.android.tools.layoutlib.create.ClassHasNativeVisitor.java

License:Apache License

public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if ((access & Opcodes.ACC_NATIVE) != 0) {
        setHasNativeMethods(true, name);
    }/*from w  w w.j av a2s .c o  m*/
    return null;
}