Search in sources :

Example 11 with ExceptionHandler

use of com.oracle.truffle.espresso.meta.ExceptionHandler 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)

Example 12 with ExceptionHandler

use of com.oracle.truffle.espresso.meta.ExceptionHandler in project graal by oracle.

the class GraphBuilder method identifyBlock.

/**
 * Analyses control flow of the byte code to identify every start of a basic block.
 */
private void identifyBlock() {
    int bci = 0;
    status[bci] = BLOCK_START;
    while (bci < bs.endBCI()) {
        int curOpcode = bs.currentBC(bci);
        if (Bytecodes.isBlockEnd(curOpcode)) {
            markBlock(bci, curOpcode);
        }
        bci = bs.nextBCI(bci);
    }
    for (ExceptionHandler handler : handlers) {
        markHandler(handler);
    }
}
Also used : ExceptionHandler(com.oracle.truffle.espresso.meta.ExceptionHandler)

Aggregations

ExceptionHandler (com.oracle.truffle.espresso.meta.ExceptionHandler)12 Klass (com.oracle.truffle.espresso.impl.Klass)3 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)2 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)2 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)2 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)1 AbstractTruffleException (com.oracle.truffle.api.exception.AbstractTruffleException)1 BytecodeLookupSwitch (com.oracle.truffle.espresso.bytecode.BytecodeLookupSwitch)1 BytecodeTableSwitch (com.oracle.truffle.espresso.bytecode.BytecodeTableSwitch)1 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