Search in sources :

Example 11 with ConstantPoolException

use of com.sun.tools.classfile.ConstantPoolException in project jdk8u_jdk by JetBrains.

the class AnnotationsElementVisitor method readFrom.

public Element readFrom(InputStream in) throws IOException {
    try {
        this.in = in;
        ClassFile c = ClassFile.read(in);
        // read the file header
        if (c.magic != 0xCAFEBABE) {
            throw new RuntimeException("bad magic number " + Integer.toHexString(c.magic));
        }
        cfile.setAttr("magic", "" + c.magic);
        int minver = c.minor_version;
        int majver = c.major_version;
        cfile.setAttr("minver", "" + minver);
        cfile.setAttr("majver", "" + majver);
        readCP(c);
        readClass(c);
        return result();
    } catch (InvalidDescriptor | ConstantPoolException ex) {
        throw new IOException("Fatal error", ex);
    }
}
Also used : ClassFile(com.sun.tools.classfile.ClassFile) ConstantPoolException(com.sun.tools.classfile.ConstantPoolException) InvalidDescriptor(com.sun.tools.classfile.Descriptor.InvalidDescriptor)

Example 12 with ConstantPoolException

use of com.sun.tools.classfile.ConstantPoolException in project jdk8u_jdk by JetBrains.

the class AnnotationsElementVisitor method visitString.

@Override
public String visitString(CONSTANT_String_info c, Integer p) {
    try {
        String value = slist.get(p);
        if (value == null) {
            value = c.getString();
            slist.set(p, value);
            xpool.add(new Element("CONSTANT_String", new String[] { "id", p.toString() }, value));
        }
        return value;
    } catch (ConstantPoolException ex) {
        throw new RuntimeException("Fatal error", ex);
    }
}
Also used : Element(xmlkit.XMLKit.Element) ConstantPoolException(com.sun.tools.classfile.ConstantPoolException)

Example 13 with ConstantPoolException

use of com.sun.tools.classfile.ConstantPoolException in project ceylon-compiler by ceylon.

the class AnnotationWriter method writeDescriptor.

private void writeDescriptor(int index, boolean resolveIndices) {
    if (resolveIndices) {
        try {
            ConstantPool constant_pool = classWriter.getClassFile().constant_pool;
            Descriptor d = new Descriptor(index);
            print(d.getFieldType(constant_pool));
            return;
        } catch (ConstantPoolException ignore) {
        } catch (InvalidDescriptor ignore) {
        }
    }
    print("#" + index);
}
Also used : ConstantPool(com.sun.tools.classfile.ConstantPool) ConstantPoolException(com.sun.tools.classfile.ConstantPoolException) Descriptor(com.sun.tools.classfile.Descriptor) InvalidDescriptor(com.sun.tools.classfile.Descriptor.InvalidDescriptor) InvalidDescriptor(com.sun.tools.classfile.Descriptor.InvalidDescriptor)

Example 14 with ConstantPoolException

use of com.sun.tools.classfile.ConstantPoolException in project ceylon-compiler by ceylon.

the class CodeWriter method writeVerboseHeader.

public void writeVerboseHeader(Code_attribute attr, ConstantPool constant_pool) {
    Method method = classWriter.getMethod();
    String argCount;
    try {
        int n = method.descriptor.getParameterCount(constant_pool);
        if (!method.access_flags.is(AccessFlags.ACC_STATIC))
            // for 'this'
            ++n;
        argCount = Integer.toString(n);
    } catch (ConstantPoolException e) {
        argCount = report(e);
    } catch (DescriptorException e) {
        argCount = report(e);
    }
    println("stack=" + attr.max_stack + ", locals=" + attr.max_locals + ", args_size=" + argCount);
}
Also used : DescriptorException(com.sun.tools.classfile.DescriptorException) ConstantPoolException(com.sun.tools.classfile.ConstantPoolException) Method(com.sun.tools.classfile.Method)

Example 15 with ConstantPoolException

use of com.sun.tools.classfile.ConstantPoolException in project ceylon-compiler by ceylon.

the class StackMapWriter method setStackMap.

void setStackMap(StackMapTable_attribute attr) {
    if (attr == null) {
        map = null;
        return;
    }
    Method m = classWriter.getMethod();
    Descriptor d = m.descriptor;
    String[] args;
    try {
        ConstantPool cp = classWriter.getClassFile().constant_pool;
        String argString = d.getParameterTypes(cp);
        args = argString.substring(1, argString.length() - 1).split("[, ]+");
    } catch (ConstantPoolException e) {
        return;
    } catch (InvalidDescriptor e) {
        return;
    }
    boolean isStatic = m.access_flags.is(AccessFlags.ACC_STATIC);
    verification_type_info[] initialLocals = new verification_type_info[(isStatic ? 0 : 1) + args.length];
    if (!isStatic)
        initialLocals[0] = new CustomVerificationTypeInfo("this");
    for (int i = 0; i < args.length; i++) {
        initialLocals[(isStatic ? 0 : 1) + i] = new CustomVerificationTypeInfo(args[i].replace(".", "/"));
    }
    map = new HashMap<Integer, StackMap>();
    StackMapBuilder builder = new StackMapBuilder();
    // using -1 as the pc for the initial frame effectively compensates for
    // the difference in behavior for the first stack map frame (where the
    // pc offset is just offset_delta) compared to subsequent frames (where
    // the pc offset is always offset_delta+1).
    int pc = -1;
    map.put(pc, new StackMap(initialLocals, empty));
    for (int i = 0; i < attr.entries.length; i++) pc = attr.entries[i].accept(builder, pc);
}
Also used : Method(com.sun.tools.classfile.Method) StackMapTable_attribute.verification_type_info(com.sun.tools.classfile.StackMapTable_attribute.verification_type_info) ConstantPool(com.sun.tools.classfile.ConstantPool) ConstantPoolException(com.sun.tools.classfile.ConstantPoolException) InvalidDescriptor(com.sun.tools.classfile.Descriptor.InvalidDescriptor) Descriptor(com.sun.tools.classfile.Descriptor) InvalidDescriptor(com.sun.tools.classfile.Descriptor.InvalidDescriptor)

Aggregations

ConstantPoolException (com.sun.tools.classfile.ConstantPoolException)20 Element (xmlkit.XMLKit.Element)8 ConstantPool (com.sun.tools.classfile.ConstantPool)6 Descriptor (com.sun.tools.classfile.Descriptor)5 InvalidDescriptor (com.sun.tools.classfile.Descriptor.InvalidDescriptor)5 AccessFlags (com.sun.tools.classfile.AccessFlags)3 Attribute (com.sun.tools.classfile.Attribute)3 Signature_attribute (com.sun.tools.classfile.Signature_attribute)3 Type (com.sun.tools.classfile.Type)3 ArrayType (com.sun.tools.classfile.Type.ArrayType)3 ClassSigType (com.sun.tools.classfile.Type.ClassSigType)3 ClassType (com.sun.tools.classfile.Type.ClassType)3 MethodType (com.sun.tools.classfile.Type.MethodType)3 SimpleType (com.sun.tools.classfile.Type.SimpleType)3 TypeParamType (com.sun.tools.classfile.Type.TypeParamType)3 WildcardType (com.sun.tools.classfile.Type.WildcardType)3 ClassFile (com.sun.tools.classfile.ClassFile)2 Method (com.sun.tools.classfile.Method)2 Signature (com.sun.tools.classfile.Signature)2 SourceFile_attribute (com.sun.tools.classfile.SourceFile_attribute)2