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.offbynull.coroutines.instrumenter.asm.VariableTable.java

License:Open Source License

/**
 * Constructs a {@link VariableTable} object.
 * @param classNode class that {@code methodeNode} resides in
 * @param methodNode method this variable table is for
 *//*www  . j  a v  a2 s  .  c o  m*/
public VariableTable(ClassNode classNode, MethodNode methodNode) {
    this((methodNode.access & Opcodes.ACC_STATIC) != 0, Type.getObjectType(classNode.name),
            Type.getType(methodNode.desc), methodNode.maxLocals);
    Validate.isTrue(classNode.methods.contains(methodNode)); // sanity check
}

From source file:com.offbynull.coroutines.instrumenter.Instrumenter.java

License:Open Source License

private int getLocalVariableIndexOfContinuationParameter(MethodNode methodNode) {
    // If it is NOT static, the first index in the local variables table is always the "this" pointer, followed by the arguments passed
    // in to the method.
    // If it is static, the local variables table doesn't contain the "this" pointer, just the arguments passed in to the method.
    boolean isStatic = (methodNode.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC;
    Type[] argumentTypes = Type.getMethodType(methodNode.desc).getArgumentTypes();

    int idx = -1;
    for (int i = 0; i < argumentTypes.length; i++) {
        Type type = argumentTypes[i];
        if (type.equals(CONTINUATION_CLASS_TYPE)) {
            if (idx == -1) {
                idx = i;/*  w w  w .  j  a  va 2  s .co  m*/
            } else {
                // should never really happen because we should be checking before calling this method
                throw new IllegalArgumentException(
                        "Multiple Continuation arguments found in method " + methodNode.name);
            }
        }
    }

    return isStatic ? idx : idx + 1;
}

From source file:com.peergreen.jartransformer.adapter.expiration.ExpirationDateClassAdapter.java

License:Apache License

/**
 * Visits the end of the class. This method, which is the last one to be
 * called, is used to inform the visitor that all the fields and methods of
 * the class have been visited./*from   w w w.j  a va  2 s  .c  om*/
 */
@Override
public void visitEnd() {
    if (isClass && !visitedStaticMethod) {
        // add static block if it doesn't exists
        MethodVisitor mv = cv.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
        mv = new ExpirationDateMethodAdapter(mv, expirationDate);
        mv.visitCode();
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }

    super.visitEnd();
}

From source file:com.poolik.classfinder.info.ClassInfo.java

License:BSD License

/**
 * Convert an ASM access mask to a reflection Modifier mask.
 *
 * @param asmAccessMask the ASM access mask
 * @return the Modifier mask//from  w ww. j a v a 2s  .c  om
 */
private int convertAccessMaskToModifierMask(int asmAccessMask) {
    int modifier = 0;

    // Convert the ASM access info into Reflection API modifiers.

    if ((asmAccessMask & Opcodes.ACC_FINAL) != 0)
        modifier |= Modifier.FINAL;

    if ((asmAccessMask & Opcodes.ACC_NATIVE) != 0)
        modifier |= Modifier.NATIVE;

    if ((asmAccessMask & Opcodes.ACC_INTERFACE) != 0)
        modifier |= Modifier.INTERFACE;

    if ((asmAccessMask & Opcodes.ACC_ABSTRACT) != 0)
        modifier |= Modifier.ABSTRACT;

    if ((asmAccessMask & Opcodes.ACC_PRIVATE) != 0)
        modifier |= Modifier.PRIVATE;

    if ((asmAccessMask & Opcodes.ACC_PROTECTED) != 0)
        modifier |= Modifier.PROTECTED;

    if ((asmAccessMask & Opcodes.ACC_PUBLIC) != 0)
        modifier |= Modifier.PUBLIC;

    if ((asmAccessMask & Opcodes.ACC_STATIC) != 0)
        modifier |= Modifier.STATIC;

    if ((asmAccessMask & Opcodes.ACC_STRICT) != 0)
        modifier |= Modifier.STRICT;

    if ((asmAccessMask & Opcodes.ACC_SYNCHRONIZED) != 0)
        modifier |= Modifier.SYNCHRONIZED;

    if ((asmAccessMask & Opcodes.ACC_TRANSIENT) != 0)
        modifier |= Modifier.TRANSIENT;

    if ((asmAccessMask & Opcodes.ACC_VOLATILE) != 0)
        modifier |= Modifier.VOLATILE;

    return modifier;
}

From source file:com.spotify.missinglink.ClassLoader.java

License:Apache License

private static void analyseMethod(String className, MethodNode method,
        Map<MethodDescriptor, DeclaredMethod> declaredMethods, Set<ClassTypeDescriptor> loadedClasses) {
    final Set<CalledMethod> thisCalls = new HashSet<>();
    final Set<AccessedField> thisFields = new HashSet<>();

    int lineNumber = 0;
    for (Iterator<AbstractInsnNode> instructions = ClassLoader
            .<AbstractInsnNode>uncheckedCast(method.instructions.iterator()); instructions.hasNext();) {
        try {//  w  w w.  j a v  a  2  s  .  c o m
            final AbstractInsnNode insn = instructions.next();
            if (insn instanceof LineNumberNode) {
                lineNumber = ((LineNumberNode) insn).line;
            }
            if (insn instanceof MethodInsnNode) {
                handleMethodCall(thisCalls, lineNumber, (MethodInsnNode) insn);
            }
            if (insn instanceof FieldInsnNode) {
                handleFieldAccess(thisFields, lineNumber, (FieldInsnNode) insn);
            }
            if (insn instanceof LdcInsnNode) {
                handleLdc(loadedClasses, (LdcInsnNode) insn);
            }
        } catch (Exception e) {
            throw new MissingLinkException(
                    "Error analysing " + className + "." + method.name + ", line: " + lineNumber, e);
        }
    }

    final DeclaredMethod declaredMethod = new DeclaredMethodBuilder()
            .descriptor(MethodDescriptors.fromDesc(method.desc, method.name)).lineNumber(lineNumber)
            .methodCalls(ImmutableSet.copyOf(thisCalls)).fieldAccesses(ImmutableSet.copyOf(thisFields))
            .isStatic((method.access & Opcodes.ACC_STATIC) != 0).build();

    if (declaredMethods.put(declaredMethod.descriptor(), declaredMethod) != null) {
        throw new RuntimeException(
                "Multiple definitions of " + declaredMethod.descriptor() + " in class " + className);
    }
}

From source file:com.sun.fortress.compiler.asmbytecodeoptimizer.ByteCodeMethodVisitor.java

License:Open Source License

public boolean isStaticMethod() {
    return ((access & Opcodes.ACC_STATIC) > 0);
}

From source file:com.sun.fortress.compiler.codegen.CodeGenMethodVisitor.java

License:Open Source License

public CodeGenMethodVisitor(int access, String name, String desc, String signature, String[] exceptions,
        MethodVisitor mvisitor) {/*  w  ww. j ava 2 s .  c  o  m*/
    super(mvisitor);
    this.access = access;
    this.name = name;
    this.desc = desc;
    this.signature = signature;
    this.exceptions = exceptions;
    this.argumentTypes = NamingCzar.parseArgs(desc);
    this.resultType = NamingCzar.parseResult(desc);
    this.localVariableCount = 0;

    int sz = 5 + this.localVariableCount + this.argumentTypes.size();
    this.varNames = new ArrayList(sz);
    this.varTypes = new ArrayList(sz);
    this.varFirstUse = new ArrayList(sz);

    this.hasThis = (access & Opcodes.ACC_STATIC) != Opcodes.ACC_STATIC;

    Debug.debug(Debug.Type.CODEGEN, 2, "MethodVisitor: name = ", name, " desc = ", desc, " argumentTypes = ",
            argumentTypes, " resultType ", resultType);

}

From source file:com.sun.fortress.compiler.OverloadSet.java

License:Open Source License

protected void generateAnOverloadDefinitionInner(String _name, CodeGenClassWriter cv) {

    if (principalMember == null)
        return;/*w ww  .ja  v a 2s  .  co  m*/

    // "(" anOverloadedArg^N ")" returnType
    // Not sure what to do with return type.
    String signature = getSignature();
    String[] exceptions = getExceptions();

    // Right now we extract any necessary static arguments from
    // the principalMember.  This may turn out to be wrong, but it
    // ought to be the case that principalMember is always set to
    // the statically most applicable method for the given set of
    // overloadings under consideration.  [At present this does
    // not always appear to be the case in practice.]
    List<StaticParam> sargs = null;
    /* Some overloads have static args, but even if they are supplied,
     * runtime inference is still necessary (so I think) -- drc 2010-02-24
     * 
     * Not quite so -- if each static parameter is mentioned in any
     * invariant occurrence, then the supplied type is exact.
     * Runtime inference is only necessary when the occurrences are
     * ALL in variant context.  Static analysis can also supply 
     * no-more-precise-than information that it learns from context.
     * If no-less and no-more precise information are equal, then
     * again, dynamic inference is not needed.
     */
    if (principalMember != null) {
        sargs = staticParametersOf(principalMember.tagF);
    }

    if (CodeGenerationPhase.debugOverloading >= 2)
        System.err.println("Emitting overload " + _name + signature);

    String PCNOuter = null;
    Naming.XlationData xldata = null;
    String overloaded_name = oMangle(_name);

    ArrayList<InitializedStaticField> isf_list = new ArrayList<InitializedStaticField>();

    if (sargs != null) {
        // Map<String, String> xlation = new HashMap<String, String>();
        xldata = CodeGen.xlationData(Naming.FUNCTION_GENERIC_TAG);

        String sparamsType = NamingCzar.genericDecoration(sargs, xldata, ifNone);
        // TODO: which signature is which?  One needs to not have generics info in it.
        genericSchema = NamingCzar.makeArrowDescriptor(ifNone, overloadedDomain(), getRange());

        /* Save this for later, to forestall collisions with
         * single functions that hit the generic type.
         * 
         * Question: is this a problem with references to single
         * types within the overload itself?  I think it might be, if we
         * do not use exactly the same handshake.
         */
        // temporary fix to problems with type analysis.  Check to make sure
        // that we don't generate a generic function class that was already
        // generated by our parent
        // A more complete fix would delve into the type checker
        // see bug PROJECTFORTRESS-19 (not_working_library_tests/MaybeTest2.fss)
        if (parent != null && parent.genericSchema.equals(genericSchema))
            return; //prevent duplication

        String packageAndClassName = NamingCzar.javaPackageClassForApi(ifNone);
        // If we have static arguments, then our caller must be
        // invoking us by instantiating a closure class and then
        // calling its apply method.  Thus we need to make sure
        // that we generate the expected closure class rather than
        // a top-level method.
        String PCN = Naming.genericFunctionPkgClass(packageAndClassName, _name, sparamsType, genericSchema);
        PCNOuter = Naming.genericFunctionPkgClass(packageAndClassName, _name,
                Naming.LEFT_OXFORD + Naming.RIGHT_OXFORD, genericSchema);
        // System.err.println("Looks generic.\n    signature " + signature +
        //                    "\n    gArrType " + genericArrowType +
        //                    "\n    sparamsType " + sparamsType +
        //                    "\n    PCN " + PCN +
        //                    "\n    PCNOuter " + PCNOuter);
        cv = new CodeGenClassWriter(ClassWriter.COMPUTE_FRAMES, cv);

        overloaded_name = InstantiatingClassloader.closureClassPrefix(PCN, cv, PCN, signature, null, isf_list);
    }
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, // access,
            overloaded_name, // name,
            signature, // sp.getFortressifiedSignature(),
            null, // signature, // depends on generics, I think
            exceptions); // exceptions);

    generateBody(mv, 0);

    if (PCNOuter != null) {
        InstantiatingClassloader.optionalStaticsAndClassInitForTO(isf_list, cv);
        cv.dumpClass(PCNOuter, xldata);
    }
}

From source file:com.sun.fortress.repository.ForeignJava.java

License:Open Source License

private boolean isStatic(int modifiers) {
    return 0 != (modifiers & Opcodes.ACC_STATIC);
}

From source file:com.sun.fortress.runtimeSystem.Instantiater.java

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    // necessary?
    name = oprs.getMethodName(name);//from   w ww.  ja  v  a  2 s . co m
    //System.out.println("old desc=" + desc);
    //desc = types.getMethodDesc(desc);
    //System.out.println("new desc=" + desc);
    String newDesc = types.getMethodDesc(desc);
    MethodVisitor mv = cv.visitMethod(access, name, newDesc, signature, exceptions);

    if (!desc.equals(newDesc)) { // catch flattened tuples
        String params = desc.substring(desc.indexOf("(") + 1, //TODO: wrong if nested parens
                desc.indexOf(")"));
        String newParams = newDesc.substring(newDesc.indexOf("(") + 1, newDesc.indexOf(")"));
        if (params.split(";").length == 1 && //single generic parameter 
                newParams.startsWith("LTuple")) { //tuple substituted in
            //System.out.println(access + " " + name + " " + signature + " " +this.instanceName);
            if ((this.access_flags & Opcodes.ACC_INTERFACE) == 0 && //not in an interface
                    (access & Opcodes.ACC_STATIC) == 0) { //and not a static method, so generate a body  

                //extract the parameters and create strings for the types 
                List<String> paramList = InstantiationMap.extractStringParameters(newParams,
                        newParams.indexOf(Naming.LEFT_OXFORD),
                        InstantiationMap.templateClosingRightOxford(newParams), new ArrayList<String>());
                String rawParams = "";
                for (String p : paramList)
                    rawParams = rawParams + Naming.internalToDesc(p);
                final String altDesc = newDesc.substring(0, newDesc.indexOf("(") + 1) + rawParams
                        + newDesc.substring(newDesc.indexOf(")"), newDesc.length());
                String tuple_params = InstantiatingClassloader.stringListToTuple(paramList);
                String make_sig = InstantiatingClassloader.toJvmSig(paramList,
                        Naming.javaDescForTaggedFortressType(tuple_params));

                MethodVisitor altMv = cv.visitMethod(access, name, altDesc, signature, exceptions);

                altMv.visitVarInsn(Opcodes.ALOAD, 0); //load this

                final int n = paramList.size(); //load the parameters
                for (int i = 1; i <= n; i++) {
                    altMv.visitVarInsn(Opcodes.ALOAD, i);
                }
                altMv.visitMethodInsn(Opcodes.INVOKESTATIC, InstantiatingClassloader.CONCRETE_ + tuple_params,
                        "make", make_sig); //create a tuple from the parameters

                if (name.equals("<init>")) {
                    altMv.visitMethodInsn(Opcodes.INVOKESPECIAL, this.instanceName, name, newDesc); //call original method
                    altMv.visitInsn(Opcodes.RETURN); //return
                } else {
                    altMv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, this.instanceName, name, newDesc); //call original method
                    altMv.visitInsn(Opcodes.ARETURN); //return
                }
                altMv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter);
                altMv.visitEnd();
            }
        }
    }
    return new MethodInstantiater(mv, types, icl);
}