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:org.eclipse.pde.api.tools.internal.builder.ReferenceExtractor.java

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if (fIsVisitMembers) {
        IApiMember member = this.getMember();
        IApiType owner = null;//from  ww  w .j  a  v a  2s .c  o  m
        if (member instanceof IApiType) {
            owner = (IApiType) member;
        } else {
            try {
                owner = member.getEnclosingType();
            } catch (CoreException e) {
                // should not happen for field or method
                ApiPlugin.log(e.getStatus());
            }
        }
        if (owner == null) {
            return null;
        }
        IApiMethod method = owner.getMethod(name, desc);
        if (method == null) {
            ApiPlugin.log(new Status(IStatus.WARNING, ApiPlugin.PLUGIN_ID,
                    NLS.bind(BuilderMessages.ReferenceExtractor_failed_to_lookup_method,
                            new String[] { name, desc, Signatures.getQualifiedTypeSignature(owner) })));
            // if we can't find the method there is no point trying to
            // process it
            return null;
        }
        this.enterMember(method);
        // record potential method override reference
        if ((access & (Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC)) > 0) {
            try {
                IApiType def = null;
                if (fVersion >= Opcodes.V1_8) {
                    // See if we are overriding a default interface method
                    def = getDefaultDefined(owner, name, desc, true);
                }
                if (def != null) {
                    addReference(Reference.methodReference(method, def.getName(), method.getName(),
                            method.getSignature(), IReference.REF_OVERRIDE, IReference.F_DEFAULT_METHOD));
                } else if (!this.fSuperStack.isEmpty()) {
                    String superTypeName = this.fSuperStack.peek();
                    addReference(Reference.methodReference(method, superTypeName, method.getName(),
                            method.getSignature(), IReference.REF_OVERRIDE));
                }
            } catch (CoreException e) {
                // Do nothing, skip this reference
            }
        }
        int argumentcount = 0;
        if ((access & Opcodes.ACC_SYNTHETIC) == 0) {
            if (signature != null) {
                this.processSignature(name, signature, IReference.REF_PARAMETERIZED_METHODDECL, METHOD);
                argumentcount = this.signaturevisitor.argumentcount;
            } else {
                Type[] arguments = Type.getArgumentTypes(desc);
                for (int i = 0; i < arguments.length; i++) {
                    Type type = arguments[i];
                    this.addTypeReference(type, IReference.REF_PARAMETER);
                    argumentcount += type.getSize();
                }
                this.addTypeReference(Type.getReturnType(desc), IReference.REF_RETURNTYPE);
                if (exceptions != null) {
                    for (int i = 0; i < exceptions.length; i++) {
                        this.addTypeReference(Type.getObjectType(exceptions[i]), IReference.REF_THROWS);
                    }
                }
            }
        }
        MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
        if (mv != null && ((access & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0)) {
            return new ClassFileMethodVisitor(mv, name, argumentcount);
        }
    }
    return null;
}

From source file:org.evosuite.graphs.cfg.CFGMethodAdapter.java

License:Open Source License

/** {@inheritDoc} */
@Override//from  w ww.  ja v a 2s  .  c  om
public void visitEnd() {
    logger.debug("Creating CFG of " + className + "." + methodName);
    boolean isExcludedMethod = excludeMethod || EXCLUDE.contains(methodName);
    boolean isMainMethod = plain_name.equals("main") && Modifier.isStatic(access);

    List<MethodInstrumentation> instrumentations = new ArrayList<MethodInstrumentation>();
    if (DependencyAnalysis.shouldInstrument(className, methodName)) {
        if (ArrayUtil.contains(Properties.CRITERION, Criterion.DEFUSE)
                || ArrayUtil.contains(Properties.CRITERION, Criterion.ALLDEFS)) {
            instrumentations.add(new BranchInstrumentation());
            instrumentations.add(new DefUseInstrumentation());
        } else if (ArrayUtil.contains(Properties.CRITERION, Criterion.MUTATION)
                || ArrayUtil.contains(Properties.CRITERION, Criterion.WEAKMUTATION)
                || ArrayUtil.contains(Properties.CRITERION, Criterion.ONLYMUTATION)
                || ArrayUtil.contains(Properties.CRITERION, Criterion.STRONGMUTATION)) {
            instrumentations.add(new BranchInstrumentation());
            instrumentations.add(new MutationInstrumentation());
        } else {
            instrumentations.add(new BranchInstrumentation());
        }
    } else {
        //instrumentations.add(new BranchInstrumentation());
    }

    boolean executeOnMain = false;
    boolean executeOnExcluded = false;

    for (MethodInstrumentation instrumentation : instrumentations) {
        executeOnMain = executeOnMain || instrumentation.executeOnMainMethod();
        executeOnExcluded = executeOnExcluded || instrumentation.executeOnExcludedMethods();
    }

    // super.visitEnd();
    // Generate CFG of method
    MethodNode mn = (AnnotatedMethodNode) mv;

    boolean checkForMain = false;
    if (Properties.CONSIDER_MAIN_METHODS) {
        checkForMain = true;
    } else {
        checkForMain = !isMainMethod || executeOnMain;
    }

    // Only instrument if the method is (not main and not excluded) or (the
    // MethodInstrumentation wants it anyway)
    if (checkForMain && (!isExcludedMethod || executeOnExcluded) && (access & Opcodes.ACC_ABSTRACT) == 0
            && (access & Opcodes.ACC_NATIVE) == 0) {

        logger.info("Analyzing method " + methodName + " in class " + className);

        // MethodNode mn = new CFGMethodNode((MethodNode)mv);
        // System.out.println("Generating CFG for "+ className+"."+mn.name +
        // " ("+mn.desc +")");

        BytecodeAnalyzer bytecodeAnalyzer = new BytecodeAnalyzer();
        logger.info("Generating CFG for method " + methodName);

        try {

            bytecodeAnalyzer.analyze(classLoader, className, methodName, mn);
            logger.trace("Method graph for " + className + "." + methodName + " contains "
                    + bytecodeAnalyzer.retrieveCFGGenerator().getRawGraph().vertexSet().size() + " nodes for "
                    + bytecodeAnalyzer.getFrames().length + " instructions");
            // compute Raw and ActualCFG and put both into GraphPool
            bytecodeAnalyzer.retrieveCFGGenerator().registerCFGs();
            logger.info("Created CFG for method " + methodName);

            if (DependencyAnalysis.shouldInstrument(className, methodName)) {
                if (!methods.get(classLoader).containsKey(className))
                    methods.get(classLoader).put(className, new HashSet<String>());

                // add the actual instrumentation
                logger.info("Instrumenting method " + methodName + " in class " + className);
                for (MethodInstrumentation instrumentation : instrumentations)
                    instrumentation.analyze(classLoader, mn, className, methodName, access);

                handleBranchlessMethods();
                String id = className + "." + methodName;
                if (isUsable()) {
                    methods.get(classLoader).get(className).add(id);
                    logger.debug("Counting: " + id);
                }
            }
        } catch (AnalyzerException e) {
            logger.error("Analyzer exception while analyzing " + className + "." + methodName + ": " + e);
            e.printStackTrace();
        }

    } else {
        logger.debug("NOT Creating CFG of " + className + "." + methodName + ": " + checkForMain + ", "
                + ((!isExcludedMethod || executeOnExcluded)) + ", " + ((access & Opcodes.ACC_ABSTRACT) == 0)
                + ", " + ((access & Opcodes.ACC_NATIVE) == 0));
        super.visitEnd();
    }
    mn.accept(next);
}

From source file:org.evosuite.graphs.cfg.CFGMethodAdapter.java

License:Open Source License

/**
 * See description of CFGMethodAdapter.EXCLUDE
 * /*from   w  w w  . java  2 s  . com*/
 * @return
 */
private boolean isUsable() {
    if ((this.access & Opcodes.ACC_SYNTHETIC) != 0)
        return false;

    if ((this.access & Opcodes.ACC_BRIDGE) != 0)
        return false;

    if ((this.access & Opcodes.ACC_NATIVE) != 0)
        return false;

    if (methodName.contains("<clinit>"))
        return false;

    // If we are not using reflection, covering private constructors is difficult?
    if (Properties.P_REFLECTION_ON_PRIVATE <= 0.0) {
        if (methodName.contains("<init>") && (access & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE)
            return false;
    }

    return true;
}

From source file:org.evosuite.instrumentation.AccessibleClassAdapter.java

License:Open Source License

/**
 * {@inheritDoc}/*from ww  w .j  a  v a 2 s .  c  o  m*/
 *
 * Change methods to public
 */
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature,
        final String[] exceptions) {
    int skipMask = Opcodes.ACC_NATIVE | Opcodes.ACC_BRIDGE;

    if (!exclude && ((access & Opcodes.ACC_PRIVATE) != Opcodes.ACC_PRIVATE) && ((access & skipMask) == 0)) {
        access = access | Opcodes.ACC_PUBLIC;
        access = access & ~Opcodes.ACC_PROTECTED;
    }

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

From source file:org.evosuite.instrumentation.BooleanTestabilityTransformation.java

License:Open Source License

@SuppressWarnings("unchecked")
private void clearIntermediateResults() {
    List<MethodNode> methodNodes = cn.methods;
    for (MethodNode mn : methodNodes) {
        if ((mn.access & Opcodes.ACC_NATIVE) == Opcodes.ACC_NATIVE)
            continue;
        GraphPool.clearAll(className, mn.name + mn.desc);
        BytecodeInstructionPool.clearAll(className, mn.name + mn.desc);
        BranchPool.clear(className, mn.name + mn.desc);
    }/*from w  w w  .ja v a2 s  .  co  m*/
}

From source file:org.evosuite.instrumentation.BooleanTestabilityTransformation.java

License:Open Source License

/**
 * Handle transformation of methods defined in this class
 *//*from   w w w. ja  va  2 s .co  m*/
@SuppressWarnings("unchecked")
private void processMethods() {
    List<MethodNode> methodNodes = cn.methods;
    for (MethodNode mn : methodNodes) {
        if ((mn.access & Opcodes.ACC_NATIVE) == Opcodes.ACC_NATIVE)
            continue;
        if (DescriptorMapping.getInstance().isTransformedMethod(className, mn.name, mn.desc)) {
            logger.info("Transforming signature of method {}{}", mn.name, mn.desc);
            transformMethodSignature(mn);
            logger.info("Transformed signature to {}{}", mn.name, mn.desc);
        }
        transformMethod(mn);
    }
}

From source file:org.evosuite.instrumentation.testability.BooleanTestabilityTransformation.java

License:Open Source License

@SuppressWarnings("unchecked")
private void clearIntermediateResults() {
    List<MethodNode> methodNodes = cn.methods;
    for (MethodNode mn : methodNodes) {
        if ((mn.access & Opcodes.ACC_NATIVE) == Opcodes.ACC_NATIVE)
            continue;
        GraphPool.clearAll(className, mn.name + mn.desc);
        BytecodeInstructionPool.clearAll(className, mn.name + mn.desc);
        BranchPool.getInstance(classLoader).clear(className, mn.name + mn.desc);
    }/*from www.  j av  a  2 s .com*/
}

From source file:org.evosuite.instrumentation.testability.BooleanTestabilityTransformation.java

License:Open Source License

/**
 * Handle transformation of methods defined in this class
 *//*from   w w  w .  j  a v a  2  s  .  c om*/
@SuppressWarnings("unchecked")
private void processMethods() {
    List<MethodNode> methodNodes = cn.methods;
    for (MethodNode mn : methodNodes) {
        if ((mn.access & Opcodes.ACC_NATIVE) == Opcodes.ACC_NATIVE)
            continue;
        if (DescriptorMapping.getInstance().isTransformedMethod(className, mn.name, mn.desc)) {
            logger.info("Transforming signature of method " + mn.name + mn.desc);
            transformMethodSignature(mn);
            logger.info("Transformed signature to " + mn.name + mn.desc);
        }
        transformMethod(mn);
    }
}

From source file:org.evosuite.symbolic.instrument.AccessFlags.java

License:Open Source License

static boolean isNative(int access) {
    return is(access, Opcodes.ACC_NATIVE);
}

From source file:org.evosuite.testcarver.instrument.TransformerUtil.java

License:Open Source License

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