Java Code Examples for com.sun.tools.classfile.ConstantPool.CPInfo

The following examples show how to use com.sun.tools.classfile.ConstantPool.CPInfo. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jdk8u-jdk   Source File: LambdaAsm.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void checkMethod(String cname, String mname, ConstantPool cp,
        Code_attribute code) throws ConstantPool.InvalidIndex {
    for (Instruction i : code.getInstructions()) {
        String iname = i.getMnemonic();
        if ("invokespecial".equals(iname)
                || "invokestatic".equals(iname)) {
            int idx = i.getByte(2);
            System.out.println("Verifying " + cname + ":" + mname +
                    " instruction:" + iname + " index @" + idx);
            CPInfo cpinfo = cp.get(idx);
            if (cpinfo instanceof ConstantPool.CONSTANT_Methodref_info) {
                throw new RuntimeException("unexpected CP type expected "
                        + "InterfaceMethodRef, got MethodRef, " + cname
                        + ", " + mname);
            }
        }
    }
}
 
Example 2
void checkReferences() throws IOException, ConstantPoolException {
    File testClasses = new File(System.getProperty("test.classes"));
    File file = new File(testClasses,
            CPoolRefClassContainingInlinedCts.class.getName() + ".class");
    ClassFile classFile = ClassFile.read(file);
    int i = 1;
    CPInfo cpInfo;
    while (i < classFile.constant_pool.size()) {
        cpInfo = classFile.constant_pool.get(i);
        if (cpInfo instanceof CONSTANT_Class_info) {
            checkClassName(((CONSTANT_Class_info)cpInfo).getName());
        }
        i += cpInfo.size();
    }
    if (numberOfReferencedClassesToBeChecked != 8) {
        throw new AssertionError("Class reference missing in the constant pool");
    }
}
 
Example 3
void checkReferences() throws IOException, ConstantPoolException {
    File testClasses = new File(System.getProperty("test.classes"));
    File file = new File(testClasses,
            CPoolRefClassContainingInlinedCts.class.getName() + ".class");
    ClassFile classFile = ClassFile.read(file);
    int i = 1;
    CPInfo cpInfo;
    while (i < classFile.constant_pool.size()) {
        cpInfo = classFile.constant_pool.get(i);
        if (cpInfo instanceof CONSTANT_Class_info) {
            checkClassName(((CONSTANT_Class_info)cpInfo).getName());
        }
        i += cpInfo.size();
    }
    if (numberOfReferencedClassesToBeChecked != 16) {
        throw new AssertionError("Class reference missing in the constant pool");
    }
}
 
Example 4
void checkReferences() throws IOException, ConstantPoolException {
    File testClasses = new File(System.getProperty("test.classes"));
    File file = new File(testClasses,
            CPoolRefClassContainingInlinedCts.class.getName() + ".class");
    ClassFile classFile = ClassFile.read(file);
    int i = 1;
    CPInfo cpInfo;
    while (i < classFile.constant_pool.size()) {
        cpInfo = classFile.constant_pool.get(i);
        if (cpInfo instanceof CONSTANT_Class_info) {
            checkClassName(((CONSTANT_Class_info)cpInfo).getName());
        }
        i += cpInfo.size();
    }
    if (numberOfReferencedClassesToBeChecked != 16) {
        throw new AssertionError("Class reference missing in the constant pool");
    }
}
 
Example 5
Source Project: openjdk-8   Source File: LambdaAsm.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void checkMethod(String cname, String mname, ConstantPool cp,
        Code_attribute code) throws ConstantPool.InvalidIndex {
    for (Instruction i : code.getInstructions()) {
        String iname = i.getMnemonic();
        if ("invokespecial".equals(iname)
                || "invokestatic".equals(iname)) {
            int idx = i.getByte(2);
            System.out.println("Verifying " + cname + ":" + mname +
                    " instruction:" + iname + " index @" + idx);
            CPInfo cpinfo = cp.get(idx);
            if (cpinfo instanceof ConstantPool.CONSTANT_Methodref_info) {
                throw new RuntimeException("unexpected CP type expected "
                        + "InterfaceMethodRef, got MethodRef, " + cname
                        + ", " + mname);
            }
        }
    }
}
 
Example 6
void checkReferences() throws IOException, ConstantPoolException {
    File testClasses = new File(System.getProperty("test.classes"));
    File file = new File(testClasses,
            CPoolRefClassContainingInlinedCts.class.getName() + ".class");
    ClassFile classFile = ClassFile.read(file);
    int i = 1;
    CPInfo cpInfo;
    while (i < classFile.constant_pool.size()) {
        cpInfo = classFile.constant_pool.get(i);
        if (cpInfo instanceof CONSTANT_Class_info) {
            checkClassName(((CONSTANT_Class_info)cpInfo).getName());
        }
        i += cpInfo.size();
    }
    if (numberOfReferencedClassesToBeChecked != 16) {
        throw new AssertionError("Class reference missing in the constant pool");
    }
}
 
Example 7
Source Project: jdk8u60   Source File: LambdaAsm.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void checkMethod(String cname, String mname, ConstantPool cp,
        Code_attribute code) throws ConstantPool.InvalidIndex {
    for (Instruction i : code.getInstructions()) {
        String iname = i.getMnemonic();
        if ("invokespecial".equals(iname)
                || "invokestatic".equals(iname)) {
            int idx = i.getByte(2);
            System.out.println("Verifying " + cname + ":" + mname +
                    " instruction:" + iname + " index @" + idx);
            CPInfo cpinfo = cp.get(idx);
            if (cpinfo instanceof ConstantPool.CONSTANT_Methodref_info) {
                throw new RuntimeException("unexpected CP type expected "
                        + "InterfaceMethodRef, got MethodRef, " + cname
                        + ", " + mname);
            }
        }
    }
}
 
Example 8
Source Project: hottub   Source File: LambdaAsm.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void checkMethod(String cname, String mname, ConstantPool cp,
        Code_attribute code) throws ConstantPool.InvalidIndex {
    for (Instruction i : code.getInstructions()) {
        String iname = i.getMnemonic();
        if ("invokespecial".equals(iname)
                || "invokestatic".equals(iname)) {
            int idx = i.getByte(2);
            System.out.println("Verifying " + cname + ":" + mname +
                    " instruction:" + iname + " index @" + idx);
            CPInfo cpinfo = cp.get(idx);
            if (cpinfo instanceof ConstantPool.CONSTANT_Methodref_info) {
                throw new RuntimeException("unexpected CP type expected "
                        + "InterfaceMethodRef, got MethodRef, " + cname
                        + ", " + mname);
            }
        }
    }
}
 
Example 9
Source Project: openjdk-jdk9   Source File: CreateSymbols.java    License: GNU General Public License v2.0 6 votes vote down vote up
Object convertConstantValue(CPInfo info, String descriptor) throws ConstantPoolException {
    if (info instanceof CONSTANT_Integer_info) {
        if ("Z".equals(descriptor))
            return ((CONSTANT_Integer_info) info).value == 1;
        else
            return ((CONSTANT_Integer_info) info).value;
    } else if (info instanceof CONSTANT_Long_info) {
        return ((CONSTANT_Long_info) info).value;
    } else if (info instanceof CONSTANT_Float_info) {
        return ((CONSTANT_Float_info) info).value;
    } else if (info instanceof CONSTANT_Double_info) {
        return ((CONSTANT_Double_info) info).value;
    } else if (info instanceof CONSTANT_String_info) {
        return ((CONSTANT_String_info) info).getString();
    }
    throw new IllegalStateException(info.getClass().getName());
}
 
Example 10
Source Project: openjdk-jdk9   Source File: LambdaAsm.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void checkMethod(String cname, String mname, ConstantPool cp,
        Code_attribute code) throws ConstantPool.InvalidIndex {
    for (Instruction i : code.getInstructions()) {
        String iname = i.getMnemonic();
        if ("invokespecial".equals(iname)
                || "invokestatic".equals(iname)) {
            int idx = i.getByte(2);
            System.out.println("Verifying " + cname + ":" + mname +
                    " instruction:" + iname + " index @" + idx);
            CPInfo cpinfo = cp.get(idx);
            if (cpinfo instanceof ConstantPool.CONSTANT_Methodref_info) {
                throw new RuntimeException("unexpected CP type expected "
                        + "InterfaceMethodRef, got MethodRef, " + cname
                        + ", " + mname);
            }
        }
    }
}
 
Example 11
void checkReferences() throws IOException, ConstantPoolException {
    File testClasses = new File(System.getProperty("test.classes"));
    File file = new File(testClasses,
            CPoolRefClassContainingInlinedCts.class.getName() + ".class");
    ClassFile classFile = ClassFile.read(file);
    int i = 1;
    CPInfo cpInfo;
    while (i < classFile.constant_pool.size()) {
        cpInfo = classFile.constant_pool.get(i);
        if (cpInfo instanceof CONSTANT_Class_info) {
            checkClassName(((CONSTANT_Class_info)cpInfo).getName());
        }
        i += cpInfo.size();
    }
    if (numberOfReferencedClassesToBeChecked != 8) {
        throw new AssertionError("Class reference missing in the constant pool");
    }
}
 
Example 12
ConstantPool translate(ConstantPool cp, Map<Object,Object> translations) {
    ConstantPool cp2 = (ConstantPool) translations.get(cp);
    if (cp2 == null) {
        ConstantPool.CPInfo[] pool2 = new ConstantPool.CPInfo[cp.size()];
        boolean eq = true;
        for (int i = 0; i < cp.size(); ) {
            ConstantPool.CPInfo cpInfo;
            try {
                cpInfo = cp.get(i);
            } catch (ConstantPool.InvalidIndex e) {
                throw new IllegalStateException(e);
            }
            ConstantPool.CPInfo cpInfo2 = translate(cpInfo, translations);
            eq &= (cpInfo == cpInfo2);
            pool2[i] = cpInfo2;
            if (cpInfo.getTag() != cpInfo2.getTag())
                throw new IllegalStateException();
            i += cpInfo.size();
        }

        if (eq)
            cp2 = cp;
        else
            cp2 = new ConstantPool(pool2);

        translations.put(cp, cp2);
    }
    return cp2;
}
 
Example 13
public CPInfo visitClass(CONSTANT_Class_info info, Map<Object, Object> translations) {
    CONSTANT_Class_info info2 = (CONSTANT_Class_info) translations.get(info);
    if (info2 == null) {
        ConstantPool cp2 = translate(info.cp, translations);
        if (cp2 == info.cp)
            info2 = info;
        else
            info2 = new CONSTANT_Class_info(cp2, info.name_index);
        translations.put(info, info2);
    }
    return info;
}
 
Example 14
Source Project: openjdk-8   Source File: ClassTranslator.java    License: GNU General Public License v2.0 5 votes vote down vote up
public CPInfo visitString(CONSTANT_String_info info, Map<Object, Object> translations) {
    CONSTANT_String_info info2 = (CONSTANT_String_info) translations.get(info);
    if (info2 == null) {
        ConstantPool cp2 = translate(info.cp, translations);
        if (cp2 == info.cp)
            info2 = info;
        else
            info2 = new CONSTANT_String_info(cp2, info.string_index);
        translations.put(info, info2);
    }
    return info;
}
 
Example 15
public CPInfo visitFieldref(CONSTANT_Fieldref_info info, Map<Object, Object> translations) {
    CONSTANT_Fieldref_info info2 = (CONSTANT_Fieldref_info) translations.get(info);
    if (info2 == null) {
        ConstantPool cp2 = translate(info.cp, translations);
        if (cp2 == info.cp)
            info2 = info;
        else
            info2 = new CONSTANT_Fieldref_info(cp2, info.class_index, info.name_and_type_index);
        translations.put(info, info2);
    }
    return info;
}
 
Example 16
public CPInfo visitFloat(CONSTANT_Float_info info, Map<Object, Object> translations) {
    CONSTANT_Float_info info2 = (CONSTANT_Float_info) translations.get(info);
    if (info2 == null) {
        info2 = info;
        translations.put(info, info2);
    }
    return info;
}
 
Example 17
public CPInfo visitInteger(CONSTANT_Integer_info info, Map<Object, Object> translations) {
    CONSTANT_Integer_info info2 = (CONSTANT_Integer_info) translations.get(info);
    if (info2 == null) {
        info2 = info;
        translations.put(info, info2);
    }
    return info;
}
 
Example 18
public CPInfo visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Map<Object, Object> translations) {
    CONSTANT_InterfaceMethodref_info info2 = (CONSTANT_InterfaceMethodref_info) translations.get(info);
    if (info2 == null) {
        ConstantPool cp2 = translate(info.cp, translations);
        if (cp2 == info.cp)
            info2 = info;
        else
            info2 = new CONSTANT_InterfaceMethodref_info(cp2, info.class_index, info.name_and_type_index);
        translations.put(info, info2);
    }
    return info;
}
 
Example 19
public CPInfo visitMethodType(CONSTANT_MethodType_info info, Map<Object, Object> translations) {
    CONSTANT_MethodType_info info2 = (CONSTANT_MethodType_info) translations.get(info);
    if (info2 == null) {
        ConstantPool cp2 = translate(info.cp, translations);
        if (cp2 == info.cp) {
            info2 = info;
        } else {
            info2 = new CONSTANT_MethodType_info(cp2, info.descriptor_index);
        }
        translations.put(info, info2);
    }
    return info;
}
 
Example 20
Source Project: hottub   Source File: ClassTranslator.java    License: GNU General Public License v2.0 5 votes vote down vote up
public CPInfo visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Map<Object, Object> translations) {
    CONSTANT_InterfaceMethodref_info info2 = (CONSTANT_InterfaceMethodref_info) translations.get(info);
    if (info2 == null) {
        ConstantPool cp2 = translate(info.cp, translations);
        if (cp2 == info.cp)
            info2 = info;
        else
            info2 = new CONSTANT_InterfaceMethodref_info(cp2, info.class_index, info.name_and_type_index);
        translations.put(info, info2);
    }
    return info;
}
 
Example 21
Source Project: openjdk-jdk9   Source File: ClassTranslator.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public CPInfo visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Map<Object, Object> translations) {
    CONSTANT_InvokeDynamic_info info2 = (CONSTANT_InvokeDynamic_info) translations.get(info);
    if (info2 == null) {
        ConstantPool cp2 = translate(info.cp, translations);
        if (cp2 == info.cp) {
            info2 = info;
        } else {
            info2 = new CONSTANT_InvokeDynamic_info(cp2, info.bootstrap_method_attr_index, info.name_and_type_index);
        }
        translations.put(info, info2);
    }
    return info;
}
 
Example 22
public CPInfo visitMethodHandle(CONSTANT_MethodHandle_info info, Map<Object, Object> translations) {
    CONSTANT_MethodHandle_info info2 = (CONSTANT_MethodHandle_info) translations.get(info);
    if (info2 == null) {
        ConstantPool cp2 = translate(info.cp, translations);
        if (cp2 == info.cp) {
            info2 = info;
        } else {
            info2 = new CONSTANT_MethodHandle_info(cp2, info.reference_kind, info.reference_index);
        }
        translations.put(info, info2);
    }
    return info;
}
 
Example 23
public CPInfo visitUtf8(CONSTANT_Utf8_info info, Map<Object, Object> translations) {
    CONSTANT_Utf8_info info2 = (CONSTANT_Utf8_info) translations.get(info);
    if (info2 == null) {
        info2 = info;
        translations.put(info, info2);
    }
    return info;
}
 
Example 24
public CPInfo visitString(CONSTANT_String_info info, Map<Object, Object> translations) {
    CONSTANT_String_info info2 = (CONSTANT_String_info) translations.get(info);
    if (info2 == null) {
        ConstantPool cp2 = translate(info.cp, translations);
        if (cp2 == info.cp)
            info2 = info;
        else
            info2 = new CONSTANT_String_info(cp2, info.string_index);
        translations.put(info, info2);
    }
    return info;
}
 
Example 25
Source Project: hottub   Source File: ClassTranslator.java    License: GNU General Public License v2.0 5 votes vote down vote up
public CPInfo visitMethodType(CONSTANT_MethodType_info info, Map<Object, Object> translations) {
    CONSTANT_MethodType_info info2 = (CONSTANT_MethodType_info) translations.get(info);
    if (info2 == null) {
        ConstantPool cp2 = translate(info.cp, translations);
        if (cp2 == info.cp) {
            info2 = info;
        } else {
            info2 = new CONSTANT_MethodType_info(cp2, info.descriptor_index);
        }
        translations.put(info, info2);
    }
    return info;
}
 
Example 26
void checkIndirectRefToString(int cp_index) {
    try {
        CPInfo cInfo = constantPool.get(cp_index);
        if (cInfo instanceof CONSTANT_String_info) {
            CONSTANT_String_info strInfo = (CONSTANT_String_info)cInfo;
            if (strInfo.string_index == utf8Index) {
                numberOfRefToStr++;
            }
        }
    } catch (InvalidIndex ex) {
        throw new AssertionError("invalid constant pool index at " + cp_index);
    }
}
 
Example 27
void checkIndirectRefToString(int cp_index) {
    try {
        CPInfo cInfo = constantPool.get(cp_index);
        if (cInfo instanceof CONSTANT_String_info) {
            CONSTANT_String_info strInfo = (CONSTANT_String_info)cInfo;
            if (strInfo.string_index == utf8Index) {
                numberOfRefToStr++;
            }
        }
    } catch (InvalidIndex ex) {
        throw new AssertionError("invalid constant pool index at " + cp_index);
    }
}
 
Example 28
Source Project: openjdk-jdk9   Source File: CreateSymbols.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Pair<Integer, Character> addConstant(List<CPInfo> constantPool, Object value, boolean annotation) {
    if (value instanceof Boolean) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info(((Boolean) value) ? 1 : 0)), 'Z');
    } else if (value instanceof Byte) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info((byte) value)), 'B');
    } else if (value instanceof Character) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info((char) value)), 'C');
    } else if (value instanceof Short) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info((short) value)), 'S');
    } else if (value instanceof Integer) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info((int) value)), 'I');
    } else if (value instanceof Long) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Long_info((long) value)), 'J');
    } else if (value instanceof Float) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Float_info((float) value)), 'F');
    } else if (value instanceof Double) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Double_info((double) value)), 'D');
    } else if (value instanceof String) {
        int stringIndex = addString(constantPool, (String) value);
        if (annotation) {
            return Pair.of(stringIndex, 's');
        } else {
            return Pair.of(addToCP(constantPool, new CONSTANT_String_info(null, stringIndex)), 's');
        }
    }

    return null;
}
 
Example 29
Source Project: jdk8u60   Source File: ClassTranslator.java    License: GNU General Public License v2.0 5 votes vote down vote up
ConstantPool.CPInfo translate(ConstantPool.CPInfo cpInfo, Map<Object,Object> translations) {
    ConstantPool.CPInfo cpInfo2 = (ConstantPool.CPInfo) translations.get(cpInfo);
    if (cpInfo2 == null) {
        cpInfo2 = cpInfo.accept(this, translations);
        translations.put(cpInfo, cpInfo2);
    }
    return cpInfo2;
}
 
Example 30
Source Project: jdk8u60   Source File: ClassTranslator.java    License: GNU General Public License v2.0 5 votes vote down vote up
public CPInfo visitClass(CONSTANT_Class_info info, Map<Object, Object> translations) {
    CONSTANT_Class_info info2 = (CONSTANT_Class_info) translations.get(info);
    if (info2 == null) {
        ConstantPool cp2 = translate(info.cp, translations);
        if (cp2 == info.cp)
            info2 = info;
        else
            info2 = new CONSTANT_Class_info(cp2, info.name_index);
        translations.put(info, info2);
    }
    return info;
}