Java Code Examples for jdk.internal.org.objectweb.asm.Opcodes#ACC_STATIC

The following examples show how to use jdk.internal.org.objectweb.asm.Opcodes#ACC_STATIC . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JIMethodCallInliner.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitMethodInsn(int opcode, String owner, String name,
        String desc, boolean itf) {
    // Now we are looking at method call in the source method
    if (!shouldBeInlined(owner, name, desc)) {
        // If this method call should not be inlined, just keep it
        mv.visitMethodInsn(opcode, owner, name, desc, itf);
        return;
    }
    // If the call should be inlined, we create a MethodInliningAdapter
    // The MIA will walk the instructions in the inlineTarget and add them
    // to the current method, doing the necessary name remappings.
    Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.DEBUG, "Inlining call to " + name + desc);
    Remapper remapper = new SimpleRemapper(oldClass, newClass);
    Label end = new Label();
    inlining = true;
    inlineTarget.instructions.resetLabels();
    JIMethodInliningAdapter mia = new JIMethodInliningAdapter(this, end,
            opcode == Opcodes.INVOKESTATIC ? Opcodes.ACC_STATIC : 0, desc,
            remapper);
    inlineTarget.accept(mia);
    inlining = false;
    super.visitLabel(end);
}
 
Example 2
Source File: GeneratorAdapter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates the instruction to load 'this' on the stack.
 */
public void loadThis() {
    if ((access & Opcodes.ACC_STATIC) != 0) {
        throw new IllegalStateException(
                "no 'this' pointer within static method");
    }
    mv.visitVarInsn(Opcodes.ALOAD, 0);
}
 
Example 3
Source File: SerialVersionUIDAdder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MethodVisitor visitMethod(final int access, final String name,
        final String desc, final String signature, final String[] exceptions) {
    if (computeSVUID) {
        if ("<clinit>".equals(name)) {
            hasStaticInitializer = true;
        }
        /*
         * Remembers non private constructors and methods for SVUID
         * computation For constructor and method modifiers, only the
         * ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
         * ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT and ACC_STRICT flags
         * are used.
         */
        int mods = access
                & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE
                        | Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC
                        | Opcodes.ACC_FINAL | Opcodes.ACC_SYNCHRONIZED
                        | Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT | Opcodes.ACC_STRICT);

        // all non private methods
        if ((access & Opcodes.ACC_PRIVATE) == 0) {
            if ("<init>".equals(name)) {
                svuidConstructors.add(new Item(name, mods, desc));
            } else if (!"<clinit>".equals(name)) {
                svuidMethods.add(new Item(name, mods, desc));
            }
        }
    }

    return super.visitMethod(access, name, desc, signature, exceptions);
}
 
Example 4
Source File: SerialVersionUIDAdder.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public FieldVisitor visitField(
        final int access,
        final String name,
        final String desc,
        final String signature,
        final Object value) {
    // Get the class field information for step 4 of the algorithm. Also determine if the class
    // already has a SVUID.
    if (computeSvuid) {
        if ("serialVersionUID".equals(name)) {
            // Since the class already has SVUID, we won't be computing it.
            computeSvuid = false;
            hasSvuid = true;
        }
        // Collect the non private fields. Only the ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED,
        // ACC_STATIC, ACC_FINAL, ACC_VOLATILE, and ACC_TRANSIENT flags are used when computing
        // serialVersionUID values.
        if ((access & Opcodes.ACC_PRIVATE) == 0
                || (access & (Opcodes.ACC_STATIC | Opcodes.ACC_TRANSIENT)) == 0) {
            int mods =
                    access
                            & (Opcodes.ACC_PUBLIC
                                    | Opcodes.ACC_PRIVATE
                                    | Opcodes.ACC_PROTECTED
                                    | Opcodes.ACC_STATIC
                                    | Opcodes.ACC_FINAL
                                    | Opcodes.ACC_VOLATILE
                                    | Opcodes.ACC_TRANSIENT);
            svuidFields.add(new Item(name, mods, desc));
        }
    }

    return super.visitField(access, name, desc, signature, value);
}
 
Example 5
Source File: SerialVersionUIDAdder.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MethodVisitor visitMethod(final int access, final String name,
        final String desc, final String signature, final String[] exceptions) {
    if (computeSVUID) {
        if ("<clinit>".equals(name)) {
            hasStaticInitializer = true;
        }
        /*
         * Remembers non private constructors and methods for SVUID
         * computation For constructor and method modifiers, only the
         * ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
         * ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT and ACC_STRICT flags
         * are used.
         */
        int mods = access
                & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE
                        | Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC
                        | Opcodes.ACC_FINAL | Opcodes.ACC_SYNCHRONIZED
                        | Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT | Opcodes.ACC_STRICT);

        // all non private methods
        if ((access & Opcodes.ACC_PRIVATE) == 0) {
            if ("<init>".equals(name)) {
                svuidConstructors.add(new Item(name, mods, desc));
            } else if (!"<clinit>".equals(name)) {
                svuidMethods.add(new Item(name, mods, desc));
            }
        }
    }

    return super.visitMethod(access, name, desc, signature, exceptions);
}
 
Example 6
Source File: SerialVersionUIDAdder.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected void addSVUID(long svuid) {
    FieldVisitor fv = super.visitField(Opcodes.ACC_FINAL
            + Opcodes.ACC_STATIC, "serialVersionUID", "J", null, svuid);
    if (fv != null) {
        fv.visitEnd();
    }
}
 
Example 7
Source File: GeneratorAdapter.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
  * Returns the index of the given method argument in the frame's local variables array.
  *
  * @param arg the index of a method argument.
  * @return the index of the given method argument in the frame's local variables array.
  */
private int getArgIndex(final int arg) {
    int index = (access & Opcodes.ACC_STATIC) == 0 ? 1 : 0;
    for (int i = 0; i < arg; i++) {
        index += argumentTypes[i].getSize();
    }
    return index;
}
 
Example 8
Source File: SerialVersionUIDAdder.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public FieldVisitor visitField(
    final int access,
    final String name,
    final String desc,
    final String signature,
    final Object value)
{
    if (computeSVUID) {
        if ("serialVersionUID".equals(name)) {
            // since the class already has SVUID, we won't be computing it.
            computeSVUID = false;
            hasSVUID = true;
        }
        /*
         * Remember field for SVUID computation For field modifiers, only
         * the ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC,
         * ACC_FINAL, ACC_VOLATILE, and ACC_TRANSIENT flags are used when
         * computing serialVersionUID values.
         */
        if ((access & Opcodes.ACC_PRIVATE) == 0
                || (access & (Opcodes.ACC_STATIC | Opcodes.ACC_TRANSIENT)) == 0)
        {
            int mods = access
            & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE
                    | Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC
                    | Opcodes.ACC_FINAL | Opcodes.ACC_VOLATILE | Opcodes.ACC_TRANSIENT);
            svuidFields.add(new Item(name, mods, desc));
        }
    }

    return super.visitField(access, name, desc, signature, value);
}
 
Example 9
Source File: SerialVersionUIDAdder.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public FieldVisitor visitField(final int access, final String name,
        final String desc, final String signature, final Object value) {
    if (computeSVUID) {
        if ("serialVersionUID".equals(name)) {
            // since the class already has SVUID, we won't be computing it.
            computeSVUID = false;
            hasSVUID = true;
        }
        /*
         * Remember field for SVUID computation For field modifiers, only
         * the ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC,
         * ACC_FINAL, ACC_VOLATILE, and ACC_TRANSIENT flags are used when
         * computing serialVersionUID values.
         */
        if ((access & Opcodes.ACC_PRIVATE) == 0
                || (access & (Opcodes.ACC_STATIC | Opcodes.ACC_TRANSIENT)) == 0) {
            int mods = access
                    & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE
                            | Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC
                            | Opcodes.ACC_FINAL | Opcodes.ACC_VOLATILE | Opcodes.ACC_TRANSIENT);
            svuidFields.add(new Item(name, mods, desc));
        }
    }

    return super.visitField(access, name, desc, signature, value);
}
 
Example 10
Source File: SerialVersionUIDAdder.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void addSVUID(long svuid) {
    FieldVisitor fv = super.visitField(Opcodes.ACC_FINAL
            + Opcodes.ACC_STATIC, "serialVersionUID", "J", null, svuid);
    if (fv != null) {
        fv.visitEnd();
    }
}
 
Example 11
Source File: SerialVersionUIDAdder.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public FieldVisitor visitField(final int access, final String name,
        final String desc, final String signature, final Object value) {
    if (computeSVUID) {
        if ("serialVersionUID".equals(name)) {
            // since the class already has SVUID, we won't be computing it.
            computeSVUID = false;
            hasSVUID = true;
        }
        /*
         * Remember field for SVUID computation For field modifiers, only
         * the ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC,
         * ACC_FINAL, ACC_VOLATILE, and ACC_TRANSIENT flags are used when
         * computing serialVersionUID values.
         */
        if ((access & Opcodes.ACC_PRIVATE) == 0
                || (access & (Opcodes.ACC_STATIC | Opcodes.ACC_TRANSIENT)) == 0) {
            int mods = access
                    & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE
                            | Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC
                            | Opcodes.ACC_FINAL | Opcodes.ACC_VOLATILE | Opcodes.ACC_TRANSIENT);
            svuidFields.add(new Item(name, mods, desc));
        }
    }

    return super.visitField(access, name, desc, signature, value);
}
 
Example 12
Source File: NashornTextifier.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static void appendAccess(final StringBuilder sb, final int access) {
    if ((access & Opcodes.ACC_PUBLIC) != 0) {
        sb.append("public ");
    }
    if ((access & Opcodes.ACC_PRIVATE) != 0) {
        sb.append("private ");
    }
    if ((access & Opcodes.ACC_PROTECTED) != 0) {
        sb.append("protected ");
    }
    if ((access & Opcodes.ACC_FINAL) != 0) {
        sb.append("final ");
    }
    if ((access & Opcodes.ACC_STATIC) != 0) {
        sb.append("static ");
    }
    if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) {
        sb.append("synchronized ");
    }
    if ((access & Opcodes.ACC_VOLATILE) != 0) {
        sb.append("volatile ");
    }
    if ((access & Opcodes.ACC_TRANSIENT) != 0) {
        sb.append("transient ");
    }
    if ((access & Opcodes.ACC_ABSTRACT) != 0) {
        sb.append("abstract ");
    }
    if ((access & Opcodes.ACC_STRICT) != 0) {
        sb.append("strictfp ");
    }
    if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
        sb.append("synthetic ");
    }
    if ((access & Opcodes.ACC_MANDATED) != 0) {
        sb.append("mandated ");
    }
    if ((access & Opcodes.ACC_ENUM) != 0) {
        sb.append("enum ");
    }
}
 
Example 13
Source File: Textifier.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Appends a string representation of the given access modifiers to
 * {@link #buf buf}.
 *
 * @param access
 *            some access modifiers.
 */
private void appendAccess(final int access) {
    if ((access & Opcodes.ACC_PUBLIC) != 0) {
        buf.append("public ");
    }
    if ((access & Opcodes.ACC_PRIVATE) != 0) {
        buf.append("private ");
    }
    if ((access & Opcodes.ACC_PROTECTED) != 0) {
        buf.append("protected ");
    }
    if ((access & Opcodes.ACC_FINAL) != 0) {
        buf.append("final ");
    }
    if ((access & Opcodes.ACC_STATIC) != 0) {
        buf.append("static ");
    }
    if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) {
        buf.append("synchronized ");
    }
    if ((access & Opcodes.ACC_VOLATILE) != 0) {
        buf.append("volatile ");
    }
    if ((access & Opcodes.ACC_TRANSIENT) != 0) {
        buf.append("transient ");
    }
    if ((access & Opcodes.ACC_ABSTRACT) != 0) {
        buf.append("abstract ");
    }
    if ((access & Opcodes.ACC_STRICT) != 0) {
        buf.append("strictfp ");
    }
    if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
        buf.append("synthetic ");
    }
    if ((access & Opcodes.ACC_MANDATED) != 0) {
        buf.append("mandated ");
    }
    if ((access & Opcodes.ACC_ENUM) != 0) {
        buf.append("enum ");
    }
}
 
Example 14
Source File: Textifier.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Appends a string representation of the given access modifiers to
 * {@link #buf buf}.
 *
 * @param access
 *            some access modifiers.
 */
private void appendAccess(final int access) {
    if ((access & Opcodes.ACC_PUBLIC) != 0) {
        buf.append("public ");
    }
    if ((access & Opcodes.ACC_PRIVATE) != 0) {
        buf.append("private ");
    }
    if ((access & Opcodes.ACC_PROTECTED) != 0) {
        buf.append("protected ");
    }
    if ((access & Opcodes.ACC_FINAL) != 0) {
        buf.append("final ");
    }
    if ((access & Opcodes.ACC_STATIC) != 0) {
        buf.append("static ");
    }
    if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) {
        buf.append("synchronized ");
    }
    if ((access & Opcodes.ACC_VOLATILE) != 0) {
        buf.append("volatile ");
    }
    if ((access & Opcodes.ACC_TRANSIENT) != 0) {
        buf.append("transient ");
    }
    if ((access & Opcodes.ACC_ABSTRACT) != 0) {
        buf.append("abstract ");
    }
    if ((access & Opcodes.ACC_STRICT) != 0) {
        buf.append("strictfp ");
    }
    if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
        buf.append("synthetic ");
    }
    if ((access & Opcodes.ACC_MANDATED) != 0) {
        buf.append("mandated ");
    }
    if ((access & Opcodes.ACC_ENUM) != 0) {
        buf.append("enum ");
    }
}
 
Example 15
Source File: Textifier.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Appends a string representation of the given access modifiers to
 * {@link #buf buf}.
 *
 * @param access
 *            some access modifiers.
 */
private void appendAccess(final int access) {
    if ((access & Opcodes.ACC_PUBLIC) != 0) {
        buf.append("public ");
    }
    if ((access & Opcodes.ACC_PRIVATE) != 0) {
        buf.append("private ");
    }
    if ((access & Opcodes.ACC_PROTECTED) != 0) {
        buf.append("protected ");
    }
    if ((access & Opcodes.ACC_FINAL) != 0) {
        buf.append("final ");
    }
    if ((access & Opcodes.ACC_STATIC) != 0) {
        buf.append("static ");
    }
    if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) {
        buf.append("synchronized ");
    }
    if ((access & Opcodes.ACC_VOLATILE) != 0) {
        buf.append("volatile ");
    }
    if ((access & Opcodes.ACC_TRANSIENT) != 0) {
        buf.append("transient ");
    }
    if ((access & Opcodes.ACC_ABSTRACT) != 0) {
        buf.append("abstract ");
    }
    if ((access & Opcodes.ACC_STRICT) != 0) {
        buf.append("strictfp ");
    }
    if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
        buf.append("synthetic ");
    }
    if ((access & Opcodes.ACC_MANDATED) != 0) {
        buf.append("mandated ");
    }
    if ((access & Opcodes.ACC_ENUM) != 0) {
        buf.append("enum ");
    }
}
 
Example 16
Source File: ScriptClassInfoCollector.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public FieldVisitor visitField(final int fieldAccess, final String fieldName, final String fieldDesc, final String signature, final Object value) {
    final FieldVisitor delegateFV = super.visitField(fieldAccess, fieldName, fieldDesc, signature, value);

    return new FieldVisitor(Opcodes.ASM4, delegateFV) {
        @Override
        public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) {
            final AnnotationVisitor delegateAV = super.visitAnnotation(descriptor, visible);

            if (ScriptClassInfo.PROPERTY_ANNO_DESC.equals(descriptor)) {
                final MemberInfo memInfo = new MemberInfo();

                memInfo.setKind(Kind.PROPERTY);
                memInfo.setJavaName(fieldName);
                memInfo.setJavaDesc(fieldDesc);
                memInfo.setJavaAccess(fieldAccess);

                if ((fieldAccess & Opcodes.ACC_STATIC) != 0) {
                    memInfo.setValue(value);
                }

                addScriptMember(memInfo);

                return new AnnotationVisitor(Opcodes.ASM4, delegateAV) {
                    // These could be "null" if values are not suppiled,
                    // in which case we have to use the default values.
                    private String  name;
                    private Integer attributes;
                    private String  clazz = "";
                    private Where   where;

                    @Override
                    public void visit(final String annotationName, final Object annotationValue) {
                        switch (annotationName) {
                        case "name":
                            this.name = (String) annotationValue;
                            break;
                        case "attributes":
                            this.attributes = (Integer) annotationValue;
                            break;
                        case "clazz":
                            this.clazz = (annotationValue == null) ? "" : annotationValue.toString();
                            break;
                        default:
                            break;
                        }
                        super.visit(annotationName, annotationValue);
                    }

                    @Override
                    public void visitEnum(final String enumName, final String desc, final String enumValue) {
                        if ("where".equals(enumName) && WHERE_ENUM_DESC.equals(desc)) {
                            this.where = Where.valueOf(enumValue);
                        }
                        super.visitEnum(enumName, desc, enumValue);
                    }

                    @Override
                    public void visitEnd() {
                        super.visitEnd();
                        memInfo.setName(name == null ? fieldName : name);
                        memInfo.setAttributes(attributes == null
                                ? MemberInfo.DEFAULT_ATTRIBUTES : attributes);
                        clazz = clazz.replace('.', '/');
                        memInfo.setInitClass(clazz);
                        memInfo.setWhere(where == null? Where.INSTANCE : where);
                    }
                };
            }

            return delegateAV;
        }
    };
}
 
Example 17
Source File: MemberInfo.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
boolean isStatic() {
    return (javaAccess & Opcodes.ACC_STATIC) != 0;
}
 
Example 18
Source File: GeneratorAdapter.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the index of the given method argument in the frame's local
 * variables array.
 *
 * @param arg
 *            the index of a method argument.
 * @return the index of the given method argument in the frame's local
 *         variables array.
 */
private int getArgIndex(final int arg) {
    int index = (access & Opcodes.ACC_STATIC) == 0 ? 1 : 0;
    for (int i = 0; i < arg; i++) {
        index += argumentTypes[i].getSize();
    }
    return index;
}
 
Example 19
Source File: GeneratorAdapter.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the index of the given method argument in the frame's local
 * variables array.
 *
 * @param arg
 *            the index of a method argument.
 * @return the index of the given method argument in the frame's local
 *         variables array.
 */
private int getArgIndex(final int arg) {
    int index = (access & Opcodes.ACC_STATIC) == 0 ? 1 : 0;
    for (int i = 0; i < arg; i++) {
        index += argumentTypes[i].getSize();
    }
    return index;
}
 
Example 20
Source File: LocalVariablesSorter.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a new {@link LocalVariablesSorter}.
 *
 * @param api
 *            the ASM API version implemented by this visitor. Must be one
 *            of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
 * @param access
 *            access flags of the adapted method.
 * @param desc
 *            the method's descriptor (see {@link Type Type}).
 * @param mv
 *            the method visitor to which this adapter delegates calls.
 */
protected LocalVariablesSorter(final int api, final int access,
        final String desc, final MethodVisitor mv) {
    super(api, mv);
    Type[] args = Type.getArgumentTypes(desc);
    nextLocal = (Opcodes.ACC_STATIC & access) == 0 ? 1 : 0;
    for (int i = 0; i < args.length; i++) {
        nextLocal += args[i].getSize();
    }
    firstLocal = nextLocal;
}