Search in sources :

Example 1 with StackMapTableAttribute

use of com.oracle.truffle.espresso.classfile.attributes.StackMapTableAttribute in project graal by oracle.

the class ClassfileParser method parseCodeAttribute.

private CodeAttribute parseCodeAttribute(Symbol<Name> name) {
    int maxStack = stream.readU2();
    int maxLocals = stream.readU2();
    final int codeLength = stream.readS4();
    if (codeLength <= 0) {
        throw ConstantPool.classFormatError("code_length must be > than 0");
    } else if (codeLength > 0xFFFF) {
        throw ConstantPool.classFormatError("code_length > than 64 KB");
    }
    byte[] code;
    try (DebugCloseable codeRead = CODE_READ.scope(context.getTimers())) {
        code = stream.readByteArray(codeLength);
    }
    ExceptionHandler[] entries;
    try (DebugCloseable handlers = EXCEPTION_HANDLERS.scope(context.getTimers())) {
        entries = parseExceptionHandlerEntries();
    }
    int attributeCount = stream.readU2();
    final Attribute[] codeAttributes = spawnAttributesArray(attributeCount);
    int totalLocalTableCount = 0;
    CommonAttributeParser commonAttributeParser = new CommonAttributeParser(InfoType.Code);
    StackMapTableAttribute stackMapTable = null;
    for (int i = 0; i < attributeCount; i++) {
        final int attributeNameIndex = stream.readU2();
        final Symbol<Name> attributeName;
        attributeName = pool.symbolAt(attributeNameIndex, "attribute name");
        final int attributeSize = stream.readS4();
        final int startPosition = stream.getPosition();
        if (attributeName.equals(Name.LineNumberTable)) {
            codeAttributes[i] = parseLineNumberTable(attributeName);
        } else if (attributeName.equals(Name.LocalVariableTable)) {
            codeAttributes[i] = parseLocalVariableAttribute(attributeName, codeLength, maxLocals);
            totalLocalTableCount++;
        } else if (attributeName.equals(Name.LocalVariableTypeTable)) {
            codeAttributes[i] = parseLocalVariableTypeAttribute(attributeName, codeLength, maxLocals);
        } else if (attributeName.equals(Name.StackMapTable)) {
            if (stackMapTable != null) {
                throw ConstantPool.classFormatError("Duplicate StackMapTable attribute");
            }
            codeAttributes[i] = stackMapTable = parseStackMapTableAttribute(attributeName, attributeSize);
        } else {
            Attribute attr = commonAttributeParser.parseCommonAttribute(attributeName, attributeSize);
            // stream.skip(attributeSize);
            codeAttributes[i] = attr == null ? new Attribute(attributeName, stream.readByteArray(attributeSize)) : attr;
        }
        if (attributeSize != stream.getPosition() - startPosition) {
            throw ConstantPool.classFormatError("Invalid attribute length for " + attributeName + " attribute");
        }
    }
    if (totalLocalTableCount > 0) {
        validateLocalTables(codeAttributes);
    }
    return new CodeAttribute(name, maxStack, maxLocals, code, entries, codeAttributes, majorVersion);
}
Also used : ExceptionHandler(com.oracle.truffle.espresso.meta.ExceptionHandler) StackMapTableAttribute(com.oracle.truffle.espresso.classfile.attributes.StackMapTableAttribute) 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) CodeAttribute(com.oracle.truffle.espresso.classfile.attributes.CodeAttribute) DebugCloseable(com.oracle.truffle.espresso.perf.DebugCloseable) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Aggregations

BootstrapMethodsAttribute (com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute)1 CodeAttribute (com.oracle.truffle.espresso.classfile.attributes.CodeAttribute)1 ConstantValueAttribute (com.oracle.truffle.espresso.classfile.attributes.ConstantValueAttribute)1 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)1 ExceptionsAttribute (com.oracle.truffle.espresso.classfile.attributes.ExceptionsAttribute)1 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)1 LineNumberTableAttribute (com.oracle.truffle.espresso.classfile.attributes.LineNumberTableAttribute)1 MethodParametersAttribute (com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute)1 NestHostAttribute (com.oracle.truffle.espresso.classfile.attributes.NestHostAttribute)1 NestMembersAttribute (com.oracle.truffle.espresso.classfile.attributes.NestMembersAttribute)1 PermittedSubclassesAttribute (com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute)1 RecordAttribute (com.oracle.truffle.espresso.classfile.attributes.RecordAttribute)1 SignatureAttribute (com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute)1 SourceDebugExtensionAttribute (com.oracle.truffle.espresso.classfile.attributes.SourceDebugExtensionAttribute)1 SourceFileAttribute (com.oracle.truffle.espresso.classfile.attributes.SourceFileAttribute)1 StackMapTableAttribute (com.oracle.truffle.espresso.classfile.attributes.StackMapTableAttribute)1 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)1 ExceptionHandler (com.oracle.truffle.espresso.meta.ExceptionHandler)1 DebugCloseable (com.oracle.truffle.espresso.perf.DebugCloseable)1 Attribute (com.oracle.truffle.espresso.runtime.Attribute)1