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);
}
Aggregations