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

The following examples show how to use com.sun.tools.classfile.ConstantPool.CPInfo. 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 File: CPoolRefClassContainingInlinedCts.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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 #2
Source File: LambdaAsm.java    From jdk8u60 with 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 #3
Source File: LambdaAsm.java    From hottub with 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 #4
Source File: LambdaAsm.java    From openjdk-8 with 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 #5
Source File: CreateSymbols.java    From openjdk-jdk9 with 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 #6
Source File: CPoolRefClassContainingInlinedCts.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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 File: LambdaAsm.java    From openjdk-jdk9 with 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 File: CPoolRefClassContainingInlinedCts.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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 #9
Source File: LambdaAsm.java    From jdk8u-jdk with 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 #10
Source File: CPoolRefClassContainingInlinedCts.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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 #11
Source File: CPoolRefClassContainingInlinedCts.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: ClassTranslator.java    From openjdk-jdk8u with 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 #13
Source File: ClassTranslator.java    From openjdk-8-source with 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 #14
Source File: ClassTranslator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 #15
Source File: ClassTranslator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public CPInfo visitDouble(CONSTANT_Double_info info, Map<Object, Object> translations) {
    CONSTANT_Double_info info2 = (CONSTANT_Double_info) translations.get(info);
    if (info2 == null) {
        info2 = info;
        translations.put(info, info2);
    }
    return info;
}
 
Example #16
Source File: ClassTranslator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public CPInfo visitNameAndType(CONSTANT_NameAndType_info info, Map<Object, Object> translations) {
    CONSTANT_NameAndType_info info2 = (CONSTANT_NameAndType_info) translations.get(info);
    if (info2 == null) {
        ConstantPool cp2 = translate(info.cp, translations);
        if (cp2 == info.cp)
            info2 = info;
        else
            info2 = new CONSTANT_NameAndType_info(cp2, info.name_index, info.type_index);
        translations.put(info, info2);
    }
    return info;
}
 
Example #17
Source File: ClassTranslator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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 #18
Source File: ClassTranslator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
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 #19
Source File: ClassTranslator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
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 #20
Source File: ClassTranslator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public CPInfo visitDouble(CONSTANT_Double_info info, Map<Object, Object> translations) {
    CONSTANT_Double_info info2 = (CONSTANT_Double_info) translations.get(info);
    if (info2 == null) {
        info2 = info;
        translations.put(info, info2);
    }
    return info;
}
 
Example #21
Source File: CreateSymbols.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static int addString(List<CPInfo> constantPool, String string) {
    Assert.checkNonNull(string);

    int i = 0;
    for (CPInfo info : constantPool) {
        if (info instanceof CONSTANT_Utf8_info) {
            if (((CONSTANT_Utf8_info) info).value.equals(string)) {
                return i;
            }
        }
        i++;
    }

    return addToCP(constantPool, new CONSTANT_Utf8_info(string));
}
 
Example #22
Source File: ClassTranslator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 #23
Source File: DeadCodeGeneratedForEmptyTryTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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 #24
Source File: ClassTranslator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 #25
Source File: ClassTranslator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public CPInfo visitMethodref(CONSTANT_Methodref_info info, Map<Object, Object> translations) {
    CONSTANT_Methodref_info info2 = (CONSTANT_Methodref_info) translations.get(info);
    if (info2 == null) {
        ConstantPool cp2 = translate(info.cp, translations);
        if (cp2 == info.cp)
            info2 = info;
        else
            info2 = new CONSTANT_Methodref_info(cp2, info.class_index, info.name_and_type_index);
        translations.put(info, info2);
    }
    return info;
}
 
Example #26
Source File: ClassTranslator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public CPInfo visitDouble(CONSTANT_Double_info info, Map<Object, Object> translations) {
    CONSTANT_Double_info info2 = (CONSTANT_Double_info) translations.get(info);
    if (info2 == null) {
        info2 = info;
        translations.put(info, info2);
    }
    return info;
}
 
Example #27
Source File: ClassTranslator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public CPInfo visitNameAndType(CONSTANT_NameAndType_info info, Map<Object, Object> translations) {
    CONSTANT_NameAndType_info info2 = (CONSTANT_NameAndType_info) translations.get(info);
    if (info2 == null) {
        ConstantPool cp2 = translate(info.cp, translations);
        if (cp2 == info.cp)
            info2 = info;
        else
            info2 = new CONSTANT_NameAndType_info(cp2, info.name_index, info.type_index);
        translations.put(info, info2);
    }
    return info;
}
 
Example #28
Source File: ClassTranslator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 #29
Source File: ClassTranslator.java    From openjdk-8-source with 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 #30
Source File: ClassTranslator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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;
}