Search in sources :

Example 1 with Attribute

use of com.oracle.truffle.espresso.runtime.Attribute in project graal by oracle.

the class Method method makeMirror.

public StaticObject makeMirror() {
    Meta meta = getMeta();
    Attribute rawRuntimeVisibleAnnotations = getAttribute(Name.RuntimeVisibleAnnotations);
    StaticObject runtimeVisibleAnnotations = rawRuntimeVisibleAnnotations != null ? StaticObject.wrap(rawRuntimeVisibleAnnotations.getData(), meta) : StaticObject.NULL;
    Attribute rawRuntimeVisibleParameterAnnotations = getAttribute(Name.RuntimeVisibleParameterAnnotations);
    StaticObject runtimeVisibleParameterAnnotations = rawRuntimeVisibleParameterAnnotations != null ? StaticObject.wrap(rawRuntimeVisibleParameterAnnotations.getData(), meta) : StaticObject.NULL;
    Attribute rawRuntimeVisibleTypeAnnotations = getAttribute(Name.RuntimeVisibleTypeAnnotations);
    StaticObject runtimeVisibleTypeAnnotations = rawRuntimeVisibleTypeAnnotations != null ? StaticObject.wrap(rawRuntimeVisibleTypeAnnotations.getData(), meta) : StaticObject.NULL;
    Attribute rawAnnotationDefault = getAttribute(Name.AnnotationDefault);
    StaticObject annotationDefault = rawAnnotationDefault != null ? StaticObject.wrap(rawAnnotationDefault.getData(), meta) : StaticObject.NULL;
    final Klass[] rawParameterKlasses = resolveParameterKlasses();
    StaticObject parameterTypes = meta.java_lang_Class.allocateReferenceArray(getParameterCount(), new IntFunction<StaticObject>() {

        @Override
        public StaticObject apply(int j) {
            return rawParameterKlasses[j].mirror();
        }
    });
    final Klass[] rawCheckedExceptions = getCheckedExceptions();
    StaticObject guestCheckedExceptions = meta.java_lang_Class.allocateReferenceArray(rawCheckedExceptions.length, new IntFunction<StaticObject>() {

        @Override
        public StaticObject apply(int j) {
            return rawCheckedExceptions[j].mirror();
        }
    });
    SignatureAttribute signatureAttribute = (SignatureAttribute) getAttribute(Name.Signature);
    StaticObject guestGenericSignature = StaticObject.NULL;
    if (signatureAttribute != null) {
        String sig = getConstantPool().symbolAt(signatureAttribute.getSignatureIndex(), "signature").toString();
        guestGenericSignature = meta.toGuestString(sig);
    }
    StaticObject instance = meta.java_lang_reflect_Method.allocateInstance();
    meta.java_lang_reflect_Method_init.invokeDirect(/* this */
    instance, /* declaringClass */
    getDeclaringKlass().mirror(), /* name */
    getContext().getStrings().intern(getName()), /* parameterTypes */
    parameterTypes, /* returnType */
    resolveReturnKlass().mirror(), /* checkedExceptions */
    guestCheckedExceptions, /* modifiers */
    getMethodModifiers(), /* slot */
    getVTableIndex(), /* signature */
    guestGenericSignature, /* annotations */
    runtimeVisibleAnnotations, /* parameterAnnotations */
    runtimeVisibleParameterAnnotations, /* annotationDefault */
    annotationDefault);
    meta.HIDDEN_METHOD_KEY.setHiddenObject(instance, this);
    meta.HIDDEN_METHOD_RUNTIME_VISIBLE_TYPE_ANNOTATIONS.setHiddenObject(instance, runtimeVisibleTypeAnnotations);
    return instance;
}
Also used : SignatureAttribute(com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute) Meta(com.oracle.truffle.espresso.meta.Meta) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) BootstrapMethodsAttribute(com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute) SourceFileAttribute(com.oracle.truffle.espresso.classfile.attributes.SourceFileAttribute) LineNumberTableAttribute(com.oracle.truffle.espresso.classfile.attributes.LineNumberTableAttribute) ExceptionsAttribute(com.oracle.truffle.espresso.classfile.attributes.ExceptionsAttribute) CodeAttribute(com.oracle.truffle.espresso.classfile.attributes.CodeAttribute) Attribute(com.oracle.truffle.espresso.runtime.Attribute) SignatureAttribute(com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute)

Example 2 with Attribute

use of com.oracle.truffle.espresso.runtime.Attribute in project graal by oracle.

the class ClassfileParser method parseRecordComponentAttributes.

private Attribute[] parseRecordComponentAttributes() {
    final int size = stream.readU2();
    Attribute[] componentAttributes = new Attribute[size];
    CommonAttributeParser commonAttributeParser = new CommonAttributeParser(InfoType.Record);
    for (int j = 0; j < size; j++) {
        final Symbol<Name> attributeName = pool.symbolAt(stream.readU2(), "attribute name");
        final int attributeSize = stream.readS4();
        Attribute attr = commonAttributeParser.parseCommonAttribute(attributeName, attributeSize);
        componentAttributes[j] = attr == null ? new Attribute(attributeName, stream.readByteArray(attributeSize)) : attr;
    }
    return componentAttributes;
}
Also used : BootstrapMethodsAttribute(com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute) EnclosingMethodAttribute(com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute) StackMapTableAttribute(com.oracle.truffle.espresso.classfile.attributes.StackMapTableAttribute) NestHostAttribute(com.oracle.truffle.espresso.classfile.attributes.NestHostAttribute) SourceFileAttribute(com.oracle.truffle.espresso.classfile.attributes.SourceFileAttribute) SourceDebugExtensionAttribute(com.oracle.truffle.espresso.classfile.attributes.SourceDebugExtensionAttribute) PermittedSubclassesAttribute(com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute) LineNumberTableAttribute(com.oracle.truffle.espresso.classfile.attributes.LineNumberTableAttribute) ExceptionsAttribute(com.oracle.truffle.espresso.classfile.attributes.ExceptionsAttribute) CodeAttribute(com.oracle.truffle.espresso.classfile.attributes.CodeAttribute) NestMembersAttribute(com.oracle.truffle.espresso.classfile.attributes.NestMembersAttribute) ConstantValueAttribute(com.oracle.truffle.espresso.classfile.attributes.ConstantValueAttribute) MethodParametersAttribute(com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute) Attribute(com.oracle.truffle.espresso.runtime.Attribute) InnerClassesAttribute(com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute) RecordAttribute(com.oracle.truffle.espresso.classfile.attributes.RecordAttribute) SignatureAttribute(com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 3 with Attribute

use of com.oracle.truffle.espresso.runtime.Attribute in project graal by oracle.

the class ClassfileParser method parseClassAttributes.

private Attribute[] parseClassAttributes() {
    int attributeCount = stream.readU2();
    if (attributeCount == 0) {
        if (maxBootstrapMethodAttrIndex >= 0) {
            throw ConstantPool.classFormatError("BootstrapMethods attribute is missing");
        }
        return Attribute.EMPTY_ARRAY;
    }
    SourceFileAttribute sourceFileName = null;
    SourceDebugExtensionAttribute sourceDebugExtensionAttribute = null;
    NestHostAttribute nestHost = null;
    NestMembersAttribute nestMembers = null;
    EnclosingMethodAttribute enclosingMethod = null;
    BootstrapMethodsAttribute bootstrapMethods = null;
    InnerClassesAttribute innerClasses = null;
    PermittedSubclassesAttribute permittedSubclasses = null;
    RecordAttribute record = null;
    CommonAttributeParser commonAttributeParser = new CommonAttributeParser(InfoType.Class);
    final Attribute[] classAttributes = spawnAttributesArray(attributeCount);
    for (int i = 0; i < attributeCount; i++) {
        final int attributeNameIndex = stream.readU2();
        final Symbol<Name> attributeName = pool.symbolAt(attributeNameIndex, "attribute name");
        final int attributeSize = stream.readS4();
        final int startPosition = stream.getPosition();
        if (attributeName.equals(Name.SourceFile)) {
            if (sourceFileName != null) {
                throw ConstantPool.classFormatError("Duplicate SourceFile attribute");
            }
            classAttributes[i] = sourceFileName = parseSourceFileAttribute(attributeName);
        } else if (attributeName.equals(Name.SourceDebugExtension)) {
            if (sourceDebugExtensionAttribute != null) {
                throw ConstantPool.classFormatError("Duplicate SourceDebugExtension attribute");
            }
            classAttributes[i] = sourceDebugExtensionAttribute = parseSourceDebugExtensionAttribute(attributeName, attributeSize);
        } else if (attributeName.equals(Name.Synthetic)) {
            classFlags |= ACC_SYNTHETIC;
            classAttributes[i] = new Attribute(attributeName, null);
        } else if (attributeName.equals(Name.InnerClasses)) {
            if (innerClasses != null) {
                throw ConstantPool.classFormatError("Duplicate InnerClasses attribute");
            }
            classAttributes[i] = innerClasses = parseInnerClasses(attributeName);
        } else if (majorVersion >= JAVA_1_5_VERSION) {
            if (majorVersion >= JAVA_7_VERSION && attributeName.equals(Name.BootstrapMethods)) {
                if (bootstrapMethods != null) {
                    throw ConstantPool.classFormatError("Duplicate BootstrapMethods attribute");
                }
                classAttributes[i] = bootstrapMethods = parseBootstrapMethods(attributeName);
            } else if (attributeName.equals(Name.EnclosingMethod)) {
                if (enclosingMethod != null) {
                    throw ConstantPool.classFormatError("Duplicate EnclosingMethod attribute");
                }
                classAttributes[i] = enclosingMethod = parseEnclosingMethodAttribute(attributeName);
            } else if (majorVersion >= JAVA_11_VERSION && attributeName.equals(Name.NestHost)) {
                if (nestHost != null) {
                    throw ConstantPool.classFormatError("Duplicate NestHost attribute");
                }
                if (nestMembers != null) {
                    throw ConstantPool.classFormatError("Classfile cannot have both a nest members and a nest host attribute.");
                }
                if (attributeSize != 2) {
                    throw ConstantPool.classFormatError("Attribute length of NestHost must be 2");
                }
                classAttributes[i] = nestHost = parseNestHostAttribute(attributeName);
            } else if (majorVersion >= JAVA_11_VERSION && attributeName.equals(Name.NestMembers)) {
                if (nestMembers != null) {
                    throw ConstantPool.classFormatError("Duplicate NestMembers attribute");
                }
                if (nestHost != null) {
                    throw ConstantPool.classFormatError("Classfile cannot have both a nest members and a nest host attribute.");
                }
                classAttributes[i] = nestMembers = parseNestMembers(attributeName);
            } else if (majorVersion >= JAVA_14_VERSION && attributeName.equals(Name.Record)) {
                if (record != null) {
                    throw ConstantPool.classFormatError("Duplicate Record attribute");
                }
                classAttributes[i] = record = parseRecord(attributeName);
            } else if (majorVersion >= JAVA_17_VERSION && attributeName.equals(Name.PermittedSubclasses)) {
                if (permittedSubclasses != null) {
                    throw ConstantPool.classFormatError("Duplicate PermittedSubclasses attribute");
                }
                classAttributes[i] = permittedSubclasses = parsePermittedSubclasses(attributeName);
            } else {
                Attribute attr = commonAttributeParser.parseCommonAttribute(attributeName, attributeSize);
                // stream.skip(attributeSize);
                classAttributes[i] = attr == null ? new Attribute(attributeName, stream.readByteArray(attributeSize)) : attr;
            }
        } else {
            // stream.skip(attributeSize);
            classAttributes[i] = new Attribute(attributeName, stream.readByteArray(attributeSize));
        }
        if (attributeSize != stream.getPosition() - startPosition) {
            throw ConstantPool.classFormatError("Invalid attribute length for " + attributeName + " attribute");
        }
    }
    if (maxBootstrapMethodAttrIndex >= 0 && bootstrapMethods == null) {
        throw ConstantPool.classFormatError("BootstrapMethods attribute is missing");
    }
    return classAttributes;
}
Also used : NestHostAttribute(com.oracle.truffle.espresso.classfile.attributes.NestHostAttribute) BootstrapMethodsAttribute(com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute) PermittedSubclassesAttribute(com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute) BootstrapMethodsAttribute(com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute) EnclosingMethodAttribute(com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute) StackMapTableAttribute(com.oracle.truffle.espresso.classfile.attributes.StackMapTableAttribute) NestHostAttribute(com.oracle.truffle.espresso.classfile.attributes.NestHostAttribute) SourceFileAttribute(com.oracle.truffle.espresso.classfile.attributes.SourceFileAttribute) SourceDebugExtensionAttribute(com.oracle.truffle.espresso.classfile.attributes.SourceDebugExtensionAttribute) PermittedSubclassesAttribute(com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute) LineNumberTableAttribute(com.oracle.truffle.espresso.classfile.attributes.LineNumberTableAttribute) ExceptionsAttribute(com.oracle.truffle.espresso.classfile.attributes.ExceptionsAttribute) CodeAttribute(com.oracle.truffle.espresso.classfile.attributes.CodeAttribute) NestMembersAttribute(com.oracle.truffle.espresso.classfile.attributes.NestMembersAttribute) ConstantValueAttribute(com.oracle.truffle.espresso.classfile.attributes.ConstantValueAttribute) MethodParametersAttribute(com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute) Attribute(com.oracle.truffle.espresso.runtime.Attribute) InnerClassesAttribute(com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute) RecordAttribute(com.oracle.truffle.espresso.classfile.attributes.RecordAttribute) SignatureAttribute(com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute) SourceDebugExtensionAttribute(com.oracle.truffle.espresso.classfile.attributes.SourceDebugExtensionAttribute) NestMembersAttribute(com.oracle.truffle.espresso.classfile.attributes.NestMembersAttribute) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name) SourceFileAttribute(com.oracle.truffle.espresso.classfile.attributes.SourceFileAttribute) RecordAttribute(com.oracle.truffle.espresso.classfile.attributes.RecordAttribute) EnclosingMethodAttribute(com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute) InnerClassesAttribute(com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)

Example 4 with Attribute

use of com.oracle.truffle.espresso.runtime.Attribute in project graal by oracle.

the class ClassfileParser method validateLocalTables.

private void validateLocalTables(Attribute[] codeAttributes) {
    if (getMajorVersion() < JAVA_1_5_VERSION) {
        return;
    }
    EconomicMap<Local, Boolean> table = EconomicMap.create(Local.localEquivalence);
    ArrayList<LocalVariableTable> typeTables = new ArrayList<>();
    for (Attribute attr : codeAttributes) {
        if (attr.getName() == Name.LocalVariableTable) {
            LocalVariableTable localTable = (LocalVariableTable) attr;
            for (Local local : localTable.getLocals()) {
                if (table.put(local, false) != null) {
                    throw ConstantPool.classFormatError("Duplicate local in local variable table: " + local);
                }
            }
        } else if (attr.getName() == Name.LocalVariableTypeTable) {
            typeTables.add((LocalVariableTable) attr);
        }
    }
    for (LocalVariableTable typeTable : typeTables) {
        for (Local local : typeTable.getLocals()) {
            Boolean present = table.put(local, true);
            if (present == null) {
                throw ConstantPool.classFormatError("Local in local variable type table does not match any local variable table entry: " + local);
            }
            if (present) {
                throw ConstantPool.classFormatError("Duplicate local in local variable type table: " + local);
            }
        }
    }
}
Also used : LocalVariableTable(com.oracle.truffle.espresso.classfile.attributes.LocalVariableTable) BootstrapMethodsAttribute(com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute) EnclosingMethodAttribute(com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute) StackMapTableAttribute(com.oracle.truffle.espresso.classfile.attributes.StackMapTableAttribute) NestHostAttribute(com.oracle.truffle.espresso.classfile.attributes.NestHostAttribute) SourceFileAttribute(com.oracle.truffle.espresso.classfile.attributes.SourceFileAttribute) SourceDebugExtensionAttribute(com.oracle.truffle.espresso.classfile.attributes.SourceDebugExtensionAttribute) PermittedSubclassesAttribute(com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute) LineNumberTableAttribute(com.oracle.truffle.espresso.classfile.attributes.LineNumberTableAttribute) ExceptionsAttribute(com.oracle.truffle.espresso.classfile.attributes.ExceptionsAttribute) CodeAttribute(com.oracle.truffle.espresso.classfile.attributes.CodeAttribute) NestMembersAttribute(com.oracle.truffle.espresso.classfile.attributes.NestMembersAttribute) ConstantValueAttribute(com.oracle.truffle.espresso.classfile.attributes.ConstantValueAttribute) MethodParametersAttribute(com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute) Attribute(com.oracle.truffle.espresso.runtime.Attribute) InnerClassesAttribute(com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute) RecordAttribute(com.oracle.truffle.espresso.classfile.attributes.RecordAttribute) SignatureAttribute(com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute) ArrayList(java.util.ArrayList) Local(com.oracle.truffle.espresso.classfile.attributes.Local)

Example 5 with Attribute

use of com.oracle.truffle.espresso.runtime.Attribute in project graal by oracle.

the class ClassRedefinition method attrChanged.

private static boolean attrChanged(ParserMethod oldMethod, ParserMethod newMethod, Symbol<Symbol.Name> name) {
    Attribute oldAttribute = oldMethod.getAttribute(name);
    Attribute newAttribute = newMethod.getAttribute(name);
    if ((oldAttribute == null || newAttribute == null)) {
        if (oldAttribute != null || newAttribute != null) {
            return true;
        }
    // else both null, so no change. Move on!
    } else if (!oldAttribute.sameAs(newAttribute)) {
        return true;
    }
    return false;
}
Also used : Attribute(com.oracle.truffle.espresso.runtime.Attribute) LineNumberTableAttribute(com.oracle.truffle.espresso.classfile.attributes.LineNumberTableAttribute) CodeAttribute(com.oracle.truffle.espresso.classfile.attributes.CodeAttribute)

Aggregations

Attribute (com.oracle.truffle.espresso.runtime.Attribute)12 CodeAttribute (com.oracle.truffle.espresso.classfile.attributes.CodeAttribute)10 LineNumberTableAttribute (com.oracle.truffle.espresso.classfile.attributes.LineNumberTableAttribute)10 SignatureAttribute (com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute)10 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)9 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)9 MethodParametersAttribute (com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute)9 PermittedSubclassesAttribute (com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute)9 RecordAttribute (com.oracle.truffle.espresso.classfile.attributes.RecordAttribute)9 BootstrapMethodsAttribute (com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute)8 ExceptionsAttribute (com.oracle.truffle.espresso.classfile.attributes.ExceptionsAttribute)8 SourceFileAttribute (com.oracle.truffle.espresso.classfile.attributes.SourceFileAttribute)8 ConstantValueAttribute (com.oracle.truffle.espresso.classfile.attributes.ConstantValueAttribute)7 NestHostAttribute (com.oracle.truffle.espresso.classfile.attributes.NestHostAttribute)7 NestMembersAttribute (com.oracle.truffle.espresso.classfile.attributes.NestMembersAttribute)7 SourceDebugExtensionAttribute (com.oracle.truffle.espresso.classfile.attributes.SourceDebugExtensionAttribute)7 StackMapTableAttribute (com.oracle.truffle.espresso.classfile.attributes.StackMapTableAttribute)7 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)6 Meta (com.oracle.truffle.espresso.meta.Meta)3 DebugCloseable (com.oracle.truffle.espresso.perf.DebugCloseable)3