Example usage for org.objectweb.asm Opcodes ACC_VOLATILE

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

Introduction

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

Prototype

int ACC_VOLATILE

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

Click Source Link

Usage

From source file:org.apache.tika.parser.asm.XHTMLClassVisitor.java

License:Apache License

private void writeAccess(int access) throws SAXException {
    writeAccess(access, Opcodes.ACC_PRIVATE, "private");
    writeAccess(access, Opcodes.ACC_PROTECTED, "protected");
    writeAccess(access, Opcodes.ACC_PUBLIC, "public");
    writeAccess(access, Opcodes.ACC_STATIC, "static");
    writeAccess(access, Opcodes.ACC_FINAL, "final");
    writeAccess(access, Opcodes.ACC_ABSTRACT, "abstract");
    writeAccess(access, Opcodes.ACC_SYNCHRONIZED, "synchronized");
    writeAccess(access, Opcodes.ACC_TRANSIENT, "transient");
    writeAccess(access, Opcodes.ACC_VOLATILE, "volatile");
    writeAccess(access, Opcodes.ACC_NATIVE, "native");
}

From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java

License:Apache License

protected void methodDef(AST methodDef) {
    MethodNode oldNode = methodNode;/*from w  ww .  j  a v  a 2 s.  c  o m*/
    List<AnnotationNode> annotations = new ArrayList<>();
    AST node = methodDef.getFirstChild();

    GenericsType[] generics = null;
    if (isType(TYPE_PARAMETERS, node)) {
        generics = makeGenericsType(node);
        node = node.getNextSibling();
    }

    int modifiers = Opcodes.ACC_PUBLIC;
    if (isType(MODIFIERS, node)) {
        modifiers = modifiers(node, annotations, modifiers);
        checkNoInvalidModifier(methodDef, "Method", modifiers, Opcodes.ACC_VOLATILE, "volatile");
        node = node.getNextSibling();
    }

    if (isAnInterface()) {
        modifiers |= Opcodes.ACC_ABSTRACT;
    }

    ClassNode returnType = null;
    if (isType(TYPE, node)) {
        returnType = makeTypeWithArguments(node);
        node = node.getNextSibling();
    }

    String name = identifier(node);
    if (classNode != null && !classNode.isAnnotationDefinition()) {
        if (classNode.getNameWithoutPackage().equals(name)) {
            if (isAnInterface()) {
                throw new ASTRuntimeException(methodDef, "Constructor not permitted within an interface.");
            }
            throw new ASTRuntimeException(methodDef, "Invalid constructor format. Remove '"
                    + returnType.getName()
                    + "' as the return type if you want a constructor, or use a different name if you want a method.");
        }
    }
    node = node.getNextSibling();

    Parameter[] parameters = Parameter.EMPTY_ARRAY;
    ClassNode[] exceptions = ClassNode.EMPTY_ARRAY;

    if (classNode == null || !classNode.isAnnotationDefinition()) {
        assertNodeType(PARAMETERS, node);
        parameters = parameters(node);
        if (parameters == null)
            parameters = Parameter.EMPTY_ARRAY;
        node = node.getNextSibling();

        if (isType(LITERAL_throws, node)) {
            AST throwsNode = node.getFirstChild();
            List<ClassNode> exceptionList = new ArrayList<>();
            throwsList(throwsNode, exceptionList);
            exceptions = exceptionList.toArray(exceptions);
            node = node.getNextSibling();
        }
    }

    boolean hasAnnotationDefault = false;
    Statement code = null;
    boolean syntheticPublic = ((modifiers & Opcodes.ACC_SYNTHETIC) != 0);
    modifiers &= ~Opcodes.ACC_SYNTHETIC;
    methodNode = new MethodNode(name, modifiers, returnType, parameters, exceptions, code);
    if ((modifiers & Opcodes.ACC_ABSTRACT) == 0) {
        if (node == null) {
            throw new ASTRuntimeException(methodDef,
                    "You defined a method without a body. Try adding a body, or declare it abstract.");
        } else {
            assertNodeType(SLIST, node);
            code = statementList(node);
        }
    } else if (node != null) {
        if (classNode != null && classNode.isAnnotationDefinition()) {
            code = statement(node);
            hasAnnotationDefault = true;
        } else {
            throw new ASTRuntimeException(methodDef, "Abstract methods do not define a body.");
        }
    }
    methodNode.setCode(code);
    methodNode.addAnnotations(annotations);
    methodNode.setGenericsTypes(generics);
    methodNode.setAnnotationDefault(hasAnnotationDefault);
    methodNode.setSyntheticPublic(syntheticPublic);
    configureAST(methodNode, methodDef);

    if (classNode != null) {
        classNode.addMethod(methodNode);
    } else {
        output.addMethod(methodNode);
    }
    methodNode = oldNode;
}

From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java

License:Apache License

protected void fieldDef(AST fieldDef) {
    List<AnnotationNode> annotations = new ArrayList<>();
    AST node = fieldDef.getFirstChild();

    int modifiers = 0;
    if (isType(MODIFIERS, node)) {
        modifiers = modifiers(node, annotations, modifiers);
        node = node.getNextSibling();/*from   ww w  .  j  a  va2 s  .  c  o  m*/
    }

    if (classNode.isInterface()) {
        modifiers |= Opcodes.ACC_STATIC | Opcodes.ACC_FINAL;
        if ((modifiers & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) == 0) {
            modifiers |= Opcodes.ACC_PUBLIC;
        }
    }

    ClassNode type = null;
    if (isType(TYPE, node)) {
        type = makeTypeWithArguments(node);
        node = node.getNextSibling();
    }

    String name = identifier(node);
    node = node.getNextSibling();

    Expression initialValue = null;
    if (node != null) {
        assertNodeType(ASSIGN, node);
        initialValue = expression(node.getFirstChild());
    }

    if (classNode.isInterface() && initialValue == null && type != null) {
        initialValue = getDefaultValueForPrimitive(type);
    }

    FieldNode fieldNode = new FieldNode(name, modifiers, type, classNode, initialValue);
    fieldNode.addAnnotations(annotations);
    configureAST(fieldNode, fieldDef);

    if (!hasVisibility(modifiers)) {
        // let's set the modifiers on the field
        int fieldModifiers = 0;
        int flags = Opcodes.ACC_STATIC | Opcodes.ACC_TRANSIENT | Opcodes.ACC_VOLATILE | Opcodes.ACC_FINAL;

        if (!hasVisibility(modifiers)) {
            modifiers |= Opcodes.ACC_PUBLIC;
            fieldModifiers |= Opcodes.ACC_PRIVATE;
        }

        // let's pass along any other modifiers we need
        fieldModifiers |= (modifiers & flags);
        fieldNode.setModifiers(fieldModifiers);
        fieldNode.setSynthetic(true);

        // in the case that there is already a field, we would
        // like to use that field, instead of the default field
        // for the property
        FieldNode storedNode = classNode.getDeclaredField(fieldNode.getName());
        if (storedNode != null && !classNode.hasProperty(name)) {
            fieldNode = storedNode;
            // we remove it here, because addProperty will add it
            // again and we want to avoid it showing up multiple
            // times in the fields list.
            classNode.getFields().remove(storedNode);
        }

        PropertyNode propertyNode = new PropertyNode(fieldNode, modifiers, null, null);
        configureAST(propertyNode, fieldDef);
        classNode.addProperty(propertyNode);
    } else {
        fieldNode.setModifiers(modifiers);
        // if there is a property of that name, then a field of that
        // name already exists, which means this new field here should
        // be used instead of the field the property originally has.
        PropertyNode pn = classNode.getProperty(name);
        if (pn != null && pn.getField().isSynthetic()) {
            classNode.getFields().remove(pn.getField());
            pn.setField(fieldNode);
        }
        classNode.addField(fieldNode);
    }
}

From source file:org.codehaus.groovy.antlr.AntlrParserPlugin.java

License:Apache License

protected int modifiers(AST modifierNode, List<AnnotationNode> annotations, int defaultModifiers) {
    assertNodeType(MODIFIERS, modifierNode);

    boolean access = false;
    int answer = 0;

    for (AST node = modifierNode.getFirstChild(); node != null; node = node.getNextSibling()) {
        int type = node.getType();
        switch (type) {
        case STATIC_IMPORT:
            // ignore
            break;

        // annotations
        case ANNOTATION:
            annotations.add(annotation(node));
            break;

        // core access scope modifiers
        case LITERAL_private:
            answer = setModifierBit(node, answer, Opcodes.ACC_PRIVATE);
            access = setAccessTrue(node, access);
            break;

        case LITERAL_protected:
            answer = setModifierBit(node, answer, Opcodes.ACC_PROTECTED);
            access = setAccessTrue(node, access);
            break;

        case LITERAL_public:
            answer = setModifierBit(node, answer, Opcodes.ACC_PUBLIC);
            access = setAccessTrue(node, access);
            break;

        // other modifiers
        case ABSTRACT:
            answer = setModifierBit(node, answer, Opcodes.ACC_ABSTRACT);
            break;

        case FINAL:
            answer = setModifierBit(node, answer, Opcodes.ACC_FINAL);
            break;

        case LITERAL_native:
            answer = setModifierBit(node, answer, Opcodes.ACC_NATIVE);
            break;

        case LITERAL_static:
            answer = setModifierBit(node, answer, Opcodes.ACC_STATIC);
            break;

        case STRICTFP:
            answer = setModifierBit(node, answer, Opcodes.ACC_STRICT);
            break;

        case LITERAL_synchronized:
            answer = setModifierBit(node, answer, Opcodes.ACC_SYNCHRONIZED);
            break;

        case LITERAL_transient:
            answer = setModifierBit(node, answer, Opcodes.ACC_TRANSIENT);
            break;

        case LITERAL_volatile:
            answer = setModifierBit(node, answer, Opcodes.ACC_VOLATILE);
            break;

        default://from   w  ww  . j av  a2s.c  o m
            unknownAST(node);
        }
    }
    if (!access) {
        answer |= defaultModifiers;
        // ACC_SYNTHETIC isn't used here, use it as a special flag
        if (defaultModifiers == Opcodes.ACC_PUBLIC)
            answer |= Opcodes.ACC_SYNTHETIC;
    }
    return answer;
}

From source file:org.codehaus.groovy.parser.antlr4.ASTBuilder.java

License:Apache License

/**
 * Traverse through modifiers, and combine them in one int value. Raise an error if there is multiple occurrences of same modifier.
 *
 * @param ctxList                   modifiers list.
 * @param defaultVisibilityModifier Default visibility modifier. Can be null. Applied if providen, and no visibility modifier exists in the ctxList.
 * @return tuple of int modifier and boolean flag, signalising visibility modifiers presence(true if there is visibility modifier in list, false otherwise).
 * @see #checkModifierDuplication(int, int, TerminalNode)
 *///from  w ww  . ja v  a 2  s.c om
public List<Object> parseModifiers(List<? extends GroovyLangParser.MemberModifierContext> ctxList,
        Integer defaultVisibilityModifier) {
    int modifiers = 0;
    boolean hasVisibilityModifier = false;
    for (GroovyLangParser.MemberModifierContext it : ctxList) {
        TerminalNode child = (TerminalNode) it.getChild(0);
        switch (child.getSymbol().getType()) {
        case GroovyLangLexer.KW_STATIC:
            modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_STATIC, child);
            break;
        case GroovyLangLexer.KW_ABSTRACT:
            modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_ABSTRACT, child);
            break;
        case GroovyLangLexer.KW_FINAL:
            modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_FINAL, child);
            break;
        case GroovyLangLexer.KW_NATIVE:
            modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_NATIVE, child);
            break;
        case GroovyLangLexer.KW_SYNCHRONIZED:
            modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_SYNCHRONIZED, child);
            break;
        case GroovyLangLexer.KW_TRANSIENT:
            modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_TRANSIENT, child);
            break;
        case GroovyLangLexer.KW_VOLATILE:
            modifiers |= checkModifierDuplication(modifiers, Opcodes.ACC_VOLATILE, child);
            break;
        case GroovyLangLexer.VISIBILITY_MODIFIER:
            modifiers |= parseVisibilityModifiers(child);
            hasVisibilityModifier = true;
            break;
        }
    }
    if (!hasVisibilityModifier && defaultVisibilityModifier != null)
        modifiers |= defaultVisibilityModifier;

    return new LinkedList<Object>(Arrays.asList(modifiers, hasVisibilityModifier));
}

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

License:Open Source License

static boolean isVolatile(int access) {
    return is(access, Opcodes.ACC_VOLATILE);
}

From source file:org.freud.analysed.classbytecode.parser.asm.AsmField.java

License:Apache License

@Override
public boolean isVolatile() {
    return isAccessModifier(Opcodes.ACC_VOLATILE);
}

From source file:org.jtsan.Agent.java

License:Apache License

private ClassAdapter newMethodTransformAdapter(final Agent myself, ClassWriter cw, final String className,
        final CodePos codePos, final Set<String> volatiles) {
    return new ClassAdapter(cw) {
        private String source;

        private final Set<String> volatileFields = volatiles;

        /*//from  w  w  w . j a  v  a2s.  c om
         * Compose a chain of visitors:
         *   MethodTransformer -> LocalVariablesSorter -> CodeSizeLimiter -> MethodVisitor
         */
        public MethodVisitor visitMethod(int access, String name, String desc, String signature,
                String[] exceptions) {
            MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
            String signatureStr = (null == signature ? "" : signature);

            int pos = className.lastIndexOf("/");
            String fullSourcePath = className.substring(0, pos + 1) + (source == null ? "" : source);
            String fullMethodName = className.substring(pos + 1) + "." + name + signatureStr;
            String fullClassName = "L" + className + ";";
            CodeSizeLimiter csl = new CodeSizeLimiter(mv, name);
            LocalVariablesSorter sorter = new LocalVariablesSorter(access, desc, csl);
            MethodTransformer transformer = new MethodTransformer(myself, sorter, access, name, fullMethodName,
                    desc, fullSourcePath, fullClassName, syncMethods, codePos, volatileFields);
            transformer.setLocalVarsSorter(sorter);
            return transformer;
        }

        @Override
        public void visitSource(String source, String debug) {
            this.source = source;
        }

        @Override
        public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
            if ((access & Opcodes.ACC_VOLATILE) != 0) {
                volatileFields.add(className + "." + name);
            }
            return super.visitField(access, name, desc, signature, value);
        }
    };
}

From source file:org.mbte.groovypp.compiler.transformers.MethodCallExpressionTransformer.java

License:Apache License

private Expression createNormalMethodCall(MethodCallExpression exp, CompilerTransformer compiler,
        String methodName, Expression args, ClassNode[] argTypes) {
    MethodNode foundMethod;// w  ww. j  a  va  2  s .co m
    BytecodeExpr object;
    ClassNode type;
    object = (BytecodeExpr) compiler.transformToGround(exp.getObjectExpression());
    type = object.getType();

    if (type instanceof ClosureClassNode && methodName.equals("call"))
        // Since ClosureClassNode can't (at least currently) escape its scope we have a typed closure,
        // so let's forget about 'call' and deal with 'doCall' instead.
        methodName = "doCall";

    foundMethod = findMethodWithClosureCoercion(type, methodName, argTypes, compiler, false);

    if (foundMethod == null) {
        // Try some property with 'call' method.
        Object prop = resolveCallableProperty(compiler, methodName, type, false);
        if (prop != null && !(prop instanceof PropertyUtil.GetUnresolved)) {
            final MethodNode callMethod = resolveCallMethod(compiler, argTypes, prop);
            if (callMethod != null) {
                return createCallMethodCall(exp, compiler, methodName, args, object, prop, callMethod, type);
            }
        }
    }

    if (foundMethod == null) {
        if (TypeUtil.isAssignableFrom(TypeUtil.TCLOSURE, object.getType())) {
            foundMethod = findMethodWithClosureCoercion(ClassHelper.CLOSURE_TYPE, methodName, argTypes,
                    compiler, false);
            if (foundMethod != null) {
                ClosureUtil.improveClosureType(object.getType(), ClassHelper.CLOSURE_TYPE);
                return createCall(exp, compiler, args, object, foundMethod);
            }
        } else {
            MethodNode unboxing = TypeUtil.getReferenceUnboxingMethod(type);
            if (unboxing != null) {
                ClassNode t = TypeUtil.getSubstitutedType(unboxing.getReturnType(),
                        unboxing.getDeclaringClass(), type);
                foundMethod = findMethodWithClosureCoercion(t, methodName, argTypes, compiler, false);
                if (foundMethod != null) {
                    object = ResolvedMethodBytecodeExpr.create(exp, unboxing, object,
                            new ArgumentListExpression(), compiler);
                    return createCall(exp, compiler, args, object, foundMethod);
                }
            }
        }

        if (object instanceof ResolvedFieldBytecodeExpr) {
            ResolvedFieldBytecodeExpr obj = (ResolvedFieldBytecodeExpr) object;
            FieldNode fieldNode = obj.getFieldNode();
            if ((fieldNode.getModifiers() & Opcodes.ACC_VOLATILE) != 0) {
                FieldNode updater = fieldNode.getDeclaringClass()
                        .getDeclaredField(fieldNode.getName() + "$updater");
                if (updater != null) {
                    ClassNode[] newArgs = new ClassNode[argTypes.length + 1];
                    System.arraycopy(argTypes, 0, newArgs, 1, argTypes.length);
                    newArgs[0] = obj.getObject().getType();
                    MethodNode updaterMethod = findMethodWithClosureCoercion(updater.getType(), methodName,
                            newArgs, compiler, false);
                    if (updaterMethod != null) {
                        ResolvedFieldBytecodeExpr updaterInstance = new ResolvedFieldBytecodeExpr(exp, updater,
                                null, null, compiler);
                        ((TupleExpression) args).getExpressions().add(0, obj.getObject());
                        return createCall(exp, compiler, args, updaterInstance, updaterMethod);
                    }
                }
            }
        } else if (object instanceof ResolvedGetterBytecodeExpr) {
            ResolvedGetterBytecodeExpr obj = (ResolvedGetterBytecodeExpr) object;
            FieldNode fieldNode = obj.getFieldNode();
            if (fieldNode != null && (fieldNode.getModifiers() & Opcodes.ACC_VOLATILE) != 0) {
                FieldNode updater = fieldNode.getDeclaringClass()
                        .getDeclaredField(fieldNode.getName() + "$updater");
                if (updater != null) {
                    ClassNode[] newArgs = new ClassNode[argTypes.length + 1];
                    System.arraycopy(argTypes, 0, newArgs, 1, argTypes.length);
                    newArgs[0] = obj.getObject().getType();
                    MethodNode updaterMethod = compiler.findMethod(updater.getType(), methodName, newArgs,
                            false);
                    if (updaterMethod != null) {
                        ResolvedFieldBytecodeExpr updaterInstance = new ResolvedFieldBytecodeExpr(exp, updater,
                                null, null, compiler);
                        ((TupleExpression) args).getExpressions().add(0, obj.getObject());
                        return createCall(exp, compiler, args, updaterInstance, updaterMethod);
                    }
                }
            }
        }

        ClassNode[] na = new ClassNode[argTypes.length + 1];
        na[0] = ClassHelper.STRING_TYPE;
        System.arraycopy(argTypes, 0, na, 1, argTypes.length);
        foundMethod = findMethodWithClosureCoercion(object.getType(), "invokeUnresolvedMethod", na, compiler,
                false);
        if (foundMethod != null) {
            ((TupleExpression) args).getExpressions().add(0,
                    compiler.transform(new ConstantExpression(methodName)));
            return createCall(exp, compiler, args, object, foundMethod);
        }

        return dynamicOrError(exp, compiler, methodName, type, argTypes, "Cannot find method ");
    }

    // 'super' access is always permitted.
    final ClassNode accessType = object instanceof VariableExpressionTransformer.Super ? null : type;
    if (!AccessibilityCheck.isAccessible(foundMethod.getModifiers(), foundMethod.getDeclaringClass(),
            compiler.classNode, accessType)) {
        return dynamicOrError(exp, compiler, methodName, type, argTypes, "Cannot access method ");
    }

    return createCall(exp, compiler, args, object, foundMethod);
}

From source file:org.openspotlight.bundle.language.java.resolver.JavaGraphNodeSupport.java

License:Open Source License

/**
 * Insert field data./*from  w  w w  .ja  va  2s.c om*/
 * 
 * @param field the field
 * @param fieldType the field type
 * @param access the access
 * @param isArray the is array
 * @param dimension the dimension
 * @throws Exception the exception
 */
private void insertFieldData(final JavaDataField field, final JavaType fieldType, final int access,
        final boolean isArray, final int dimension) throws Exception {
    final DataType fieldTypeLink = session.addLink(DataType.class, field, fieldType, false);
    fieldTypeLink.setArray(isArray);
    fieldTypeLink.setArrayDimension(dimension);
    final boolean isFieldPublic = (access & Opcodes.ACC_PUBLIC) != 0;
    final boolean isFieldPrivate = (access & Opcodes.ACC_PRIVATE) != 0;
    final boolean isFieldStatic = (access & Opcodes.ACC_STATIC) != 0;
    final boolean isFieldFinal = (access & Opcodes.ACC_FINAL) != 0;
    final boolean isFieldProtected = (access & Opcodes.ACC_PROTECTED) != 0;
    final boolean isFieldTransient = (access & Opcodes.ACC_TRANSIENT) != 0;
    final boolean isFieldVolatile = (access & Opcodes.ACC_VOLATILE) != 0;
    field.setPublic(isFieldPublic);
    field.setPrivate(isFieldPrivate);
    field.setStatic(isFieldStatic);
    field.setFinal(isFieldFinal);
    field.setProtected(isFieldProtected);
    field.setTransient(isFieldTransient);
    field.setVolatile(isFieldVolatile);
}