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

The following examples show how to use com.sun.tools.classfile.ConstantPool. 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: TencentKona-8   Source File: LVTHarness.java    License: GNU General Public License v2.0 6 votes vote down vote up
void checkClassFile(File file)
        throws IOException, ConstantPoolException, InvalidDescriptor {
    ClassFile classFile = ClassFile.read(file);
    ConstantPool constantPool = classFile.constant_pool;

    //lets get all the methods in the class file.
    for (Method method : classFile.methods) {
        for (ElementKey elementKey: aliveRangeMap.keySet()) {
            String methodDesc = method.getName(constantPool) +
                    method.descriptor.getParameterTypes(constantPool).replace(" ", "");
            if (methodDesc.equals(elementKey.elem.toString())) {
                checkMethod(constantPool, method, aliveRangeMap.get(elementKey));
                seenAliveRanges.add(elementKey);
            }
        }
    }
}
 
Example 2
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 3
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 4
Source Project: TencentKona-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 5
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 6
Source Project: jdk8u60   Source File: LVTHarness.java    License: GNU General Public License v2.0 6 votes vote down vote up
void checkMethod(ConstantPool constantPool, Method method, AliveRanges ranges)
        throws InvalidIndex, UnexpectedEntry, ConstantPoolException {
    Code_attribute code = (Code_attribute) method.attributes.get(Attribute.Code);
    LocalVariableTable_attribute lvt =
        (LocalVariableTable_attribute) (code.attributes.get(Attribute.LocalVariableTable));
    List<String> infoFromRanges = convertToStringList(ranges);
    List<String> infoFromLVT = convertToStringList(constantPool, lvt);

    // infoFromRanges most be contained in infoFromLVT
    int i = 0;
    int j = 0;
    while (i < infoFromRanges.size() && j < infoFromLVT.size()) {
        int comparison = infoFromRanges.get(i).compareTo(infoFromLVT.get(j));
        if (comparison == 0) {
            i++; j++;
        } else if (comparison > 0) {
            j++;
        } else {
            break;
        }
    }

    if (i < infoFromRanges.size()) {
        error(infoFromLVT, infoFromRanges, method.getName(constantPool).toString());
    }
}
 
Example 7
Source Project: jdk8u-dev-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 8
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 9
Source Project: openjdk-jdk8u   Source File: LVTHarness.java    License: GNU General Public License v2.0 6 votes vote down vote up
void checkMethod(ConstantPool constantPool, Method method, AliveRanges ranges)
        throws InvalidIndex, UnexpectedEntry, ConstantPoolException {
    Code_attribute code = (Code_attribute) method.attributes.get(Attribute.Code);
    LocalVariableTable_attribute lvt =
        (LocalVariableTable_attribute) (code.attributes.get(Attribute.LocalVariableTable));
    List<String> infoFromRanges = convertToStringList(ranges);
    List<String> infoFromLVT = convertToStringList(constantPool, lvt);

    // infoFromRanges most be contained in infoFromLVT
    int i = 0;
    int j = 0;
    while (i < infoFromRanges.size() && j < infoFromLVT.size()) {
        int comparison = infoFromRanges.get(i).compareTo(infoFromLVT.get(j));
        if (comparison == 0) {
            i++; j++;
        } else if (comparison > 0) {
            j++;
        } else {
            break;
        }
    }

    if (i < infoFromRanges.size()) {
        error(infoFromLVT, infoFromRanges, method.getName(constantPool).toString());
    }
}
 
Example 10
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 11
Source Project: openjdk-8   Source File: LVTHarness.java    License: GNU General Public License v2.0 6 votes vote down vote up
void checkMethod(ConstantPool constantPool, Method method, AliveRanges ranges)
        throws InvalidIndex, UnexpectedEntry {
    Code_attribute code = (Code_attribute) method.attributes.get(Attribute.Code);
    LocalVariableTable_attribute lvt =
        (LocalVariableTable_attribute) (code.attributes.get(Attribute.LocalVariableTable));
    List<String> infoFromRanges = convertToStringList(ranges);
    List<String> infoFromLVT = convertToStringList(constantPool, lvt);

    // infoFromRanges most be contained in infoFromLVT
    int i = 0;
    int j = 0;
    while (i < infoFromRanges.size() && j < infoFromLVT.size()) {
        int comparison = infoFromRanges.get(i).compareTo(infoFromLVT.get(j));
        if (comparison == 0) {
            i++; j++;
        } else if (comparison > 0) {
            j++;
        } else {
            break;
        }
    }

    if (i < infoFromRanges.size()) {
        error(infoFromLVT, infoFromRanges);
    }
}
 
Example 12
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 13
void checkClassFile(File file)
        throws IOException, ConstantPoolException, InvalidDescriptor {
    ClassFile classFile = ClassFile.read(file);
    ConstantPool constantPool = classFile.constant_pool;

    //lets get all the methods in the class file.
    for (Method method : classFile.methods) {
        for (ElementKey elementKey: aliveRangeMap.keySet()) {
            String methodDesc = method.getName(constantPool) +
                    method.descriptor.getParameterTypes(constantPool).replace(" ", "");
            if (methodDesc.equals(elementKey.elem.toString())) {
                checkMethod(constantPool, method, aliveRangeMap.get(elementKey));
                seenAliveRanges.add(elementKey);
            }
        }
    }
}
 
Example 14
void checkMethod(ConstantPool constantPool, Method method, AliveRanges ranges)
        throws InvalidIndex, UnexpectedEntry, ConstantPoolException {
    Code_attribute code = (Code_attribute) method.attributes.get(Attribute.Code);
    LocalVariableTable_attribute lvt =
        (LocalVariableTable_attribute) (code.attributes.get(Attribute.LocalVariableTable));
    List<String> infoFromRanges = convertToStringList(ranges);
    List<String> infoFromLVT = convertToStringList(constantPool, lvt);

    // infoFromRanges most be contained in infoFromLVT
    int i = 0;
    int j = 0;
    while (i < infoFromRanges.size() && j < infoFromLVT.size()) {
        int comparison = infoFromRanges.get(i).compareTo(infoFromLVT.get(j));
        if (comparison == 0) {
            i++; j++;
        } else if (comparison > 0) {
            j++;
        } else {
            break;
        }
    }

    if (i < infoFromRanges.size()) {
        error(infoFromLVT, infoFromRanges, method.getName(constantPool).toString());
    }
}
 
Example 15
Source Project: hottub   Source File: LVTHarness.java    License: GNU General Public License v2.0 6 votes vote down vote up
void checkMethod(ConstantPool constantPool, Method method, AliveRanges ranges)
        throws InvalidIndex, UnexpectedEntry, ConstantPoolException {
    Code_attribute code = (Code_attribute) method.attributes.get(Attribute.Code);
    LocalVariableTable_attribute lvt =
        (LocalVariableTable_attribute) (code.attributes.get(Attribute.LocalVariableTable));
    List<String> infoFromRanges = convertToStringList(ranges);
    List<String> infoFromLVT = convertToStringList(constantPool, lvt);

    // infoFromRanges most be contained in infoFromLVT
    int i = 0;
    int j = 0;
    while (i < infoFromRanges.size() && j < infoFromLVT.size()) {
        int comparison = infoFromRanges.get(i).compareTo(infoFromLVT.get(j));
        if (comparison == 0) {
            i++; j++;
        } else if (comparison > 0) {
            j++;
        } else {
            break;
        }
    }

    if (i < infoFromRanges.size()) {
        error(infoFromLVT, infoFromRanges, method.getName(constantPool).toString());
    }
}
 
Example 16
public void write(Object owner, Attribute attr, ConstantPool constant_pool) {
    if (attr != null) {
        // null checks
        owner.getClass();
        constant_pool.getClass();
        this.constant_pool = constant_pool;
        this.owner = owner;
        attr.accept(this, null);
    }
}
 
Example 17
public void write(Object owner, Attributes attrs, ConstantPool constant_pool) {
    if (attrs != null) {
        // null checks
        owner.getClass();
        constant_pool.getClass();
        this.constant_pool = constant_pool;
        this.owner = owner;
        for (Attribute attr: attrs)
            attr.accept(this, null);
    }
}
 
Example 18
Source Project: openjdk-8   Source File: AttributeWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void write(Object owner, Attribute attr, ConstantPool constant_pool) {
    if (attr != null) {
        // null checks
        owner.getClass();
        constant_pool.getClass();
        this.constant_pool = constant_pool;
        this.owner = owner;
        attr.accept(this, null);
    }
}
 
Example 19
Source Project: TencentKona-8   Source File: ConstantWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
String stringValue(int constant_pool_index) {
    ClassFile classFile = classWriter.getClassFile();
    try {
        return stringValue(classFile.constant_pool.get(constant_pool_index));
    } catch (ConstantPool.InvalidIndex e) {
        return report(e);
    }
}
 
Example 20
void checkClassFile(File file)
        throws IOException, ConstantPoolException, InvalidDescriptor, InvalidIndex {
    ClassFile classFile = ClassFile.read(file);
    ConstantPool constantPool = classFile.constant_pool;

    //lets get all the methods in the class file.
    for (Method method : classFile.methods) {
        if (method.getName(constantPool).equals("arrMethod")) {
            Code_attribute code = (Code_attribute) method.attributes
                    .get(Attribute.Code);
            if (code.max_locals > 4)
                throw new AssertionError("Too many locals for method arrMethod");
        }
    }
}
 
Example 21
Source Project: jdk8u60   Source File: AttributeWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void write(Object owner, Attribute attr, ConstantPool constant_pool) {
    if (attr != null) {
        // null checks
        owner.getClass();
        constant_pool.getClass();
        this.constant_pool = constant_pool;
        this.owner = owner;
        attr.accept(this, null);
    }
}
 
Example 22
Source Project: jdk8u60   Source File: AttributeWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void write(Object owner, Attributes attrs, ConstantPool constant_pool) {
    if (attrs != null) {
        // null checks
        owner.getClass();
        constant_pool.getClass();
        this.constant_pool = constant_pool;
        this.owner = owner;
        for (Attribute attr: attrs)
            attr.accept(this, null);
    }
}
 
Example 23
Source Project: jdk8u60   Source File: AttributeWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
String getInnerName(ConstantPool constant_pool, InnerClasses_attribute.Info info) {
    try {
        return info.getInnerName(constant_pool);
    } catch (ConstantPoolException e) {
        return report(e);
    }
}
 
Example 24
Source Project: jdk8u60   Source File: ConstantWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
String stringValue(int constant_pool_index) {
    ClassFile classFile = classWriter.getClassFile();
    try {
        return stringValue(classFile.constant_pool.get(constant_pool_index));
    } catch (ConstantPool.InvalidIndex e) {
        return report(e);
    }
}
 
Example 25
Source Project: jdk8u60   Source File: CodeWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
void write(Code_attribute attr, ConstantPool constant_pool) {
    println("Code:");
    indent(+1);
    writeVerboseHeader(attr, constant_pool);
    writeInstrs(attr);
    writeExceptionTable(attr);
    attrWriter.write(attr, attr.attributes, constant_pool);
    indent(-1);
}
 
Example 26
void checkClassFile(File file)
        throws IOException, ConstantPoolException, InvalidDescriptor, InvalidIndex {
    ClassFile classFile = ClassFile.read(file);
    ConstantPool constantPool = classFile.constant_pool;

    //lets get all the methods in the class file.
    for (Method method : classFile.methods) {
        if (method.getName(constantPool).equals("arrMethod")) {
            Code_attribute code = (Code_attribute) method.attributes
                    .get(Attribute.Code);
            if (code.max_locals > 4)
                throw new AssertionError("Too many locals for method arrMethod");
        }
    }
}
 
Example 27
Source Project: openjdk-jdk9   Source File: ModuleTestBase.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void testModuleAttribute(Path modulePath, ModuleDescriptor moduleDescriptor) throws Exception {
    ClassFile classFile = ClassFile.read(modulePath.resolve("module-info.class"));
    Module_attribute moduleAttribute = (Module_attribute) classFile.getAttribute("Module");
    ConstantPool constantPool = classFile.constant_pool;
    testModuleName(moduleDescriptor, moduleAttribute, constantPool);
    testModuleFlags(moduleDescriptor, moduleAttribute);
    testRequires(moduleDescriptor, moduleAttribute, constantPool);
    testExports(moduleDescriptor, moduleAttribute, constantPool);
    testOpens(moduleDescriptor, moduleAttribute, constantPool);
    testProvides(moduleDescriptor, moduleAttribute, constantPool);
    testUses(moduleDescriptor, moduleAttribute, constantPool);
}
 
Example 28
Source Project: openjdk-8   Source File: ConstantWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
String stringValue(int constant_pool_index) {
    ClassFile classFile = classWriter.getClassFile();
    try {
        return stringValue(classFile.constant_pool.get(constant_pool_index));
    } catch (ConstantPool.InvalidIndex e) {
        return report(e);
    }
}
 
Example 29
Source Project: openjdk-jdk9   Source File: IncubatingTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void addModuleResolutionAttribute(Path classfile, int resolution_flags) throws Exception {
    ClassFile cf = ClassFile.read(classfile);
    Attributes attrs = cf.attributes;
    List<CPInfo> cpData = new ArrayList<>();
    cpData.add(null);
    for (CPInfo info : cf.constant_pool.entries()) {
        cpData.add(info);
        if (info.size() == 2)
            cpData.add(null);
    }
    cpData.add(new CONSTANT_Utf8_info(Attribute.ModuleResolution));
    ConstantPool newCP = new ConstantPool(cpData.toArray(new CPInfo[0]));
    ModuleResolution_attribute res = new ModuleResolution_attribute(newCP, resolution_flags);
    Map<String, Attribute> newAttributeMap = new HashMap<>(attrs.map);
    newAttributeMap.put(Attribute.ModuleResolution, res);
    Attributes newAttrs = new Attributes(newAttributeMap);
    ClassFile newCF = new ClassFile(cf.magic,
                                    cf.minor_version,
                                    cf.major_version,
                                    newCP,
                                    cf.access_flags,
                                    cf.this_class,
                                    cf.super_class,
                                    cf.interfaces,
                                    cf.fields,
                                    cf.methods,
                                    newAttrs);
    try (OutputStream out = Files.newOutputStream(classfile)) {
        new ClassWriter().write(newCF, out);
    }
}
 
Example 30
String stringValue(int constant_pool_index) {
    ClassFile classFile = classWriter.getClassFile();
    try {
        return stringValue(classFile.constant_pool.get(constant_pool_index));
    } catch (ConstantPool.InvalidIndex e) {
        return report(e);
    }
}