Java Code Examples for com.sun.tools.classfile.Instruction#getUnsignedShort()

The following examples show how to use com.sun.tools.classfile.Instruction#getUnsignedShort() . 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: T6199075.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void verifyBytecode(VarargsMethod selected) {
    bytecodeCheckCount++;
    File compiledTest = new File("Test.class");
    try {
        ClassFile cf = ClassFile.read(compiledTest);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals("test")) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                int cp_entry = i.getUnsignedShort(1);
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.contains(selected.varargsElement.bytecodeString)) {
                    throw new Error("Unexpected type method call: " + type);
                }
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + compiledTest +": " + e);
    }
}
 
Example 2
Source File: T6199075.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void verifyBytecode(VarargsMethod selected) {
    bytecodeCheckCount++;
    File compiledTest = new File("Test.class");
    try {
        ClassFile cf = ClassFile.read(compiledTest);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals("test")) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                int cp_entry = i.getUnsignedShort(1);
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.contains(selected.varargsElement.bytecodeString)) {
                    throw new Error("Unexpected type method call: " + type);
                }
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + compiledTest +": " + e);
    }
}
 
Example 3
Source File: T6199075.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void verifyBytecode(VarargsMethod selected) {
    bytecodeCheckCount++;
    File compiledTest = new File("Test.class");
    try {
        ClassFile cf = ClassFile.read(compiledTest);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals("test")) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                int cp_entry = i.getUnsignedShort(1);
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.contains(selected.varargsElement.bytecodeString)) {
                    throw new Error("Unexpected type method call: " + type);
                }
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + compiledTest +": " + e);
    }
}
 
Example 4
Source File: T6199075.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void verifyBytecode(VarargsMethod selected) {
    bytecodeCheckCount++;
    File compiledTest = new File("Test.class");
    try {
        ClassFile cf = ClassFile.read(compiledTest);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals("test")) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                int cp_entry = i.getUnsignedShort(1);
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.contains(selected.varargsElement.bytecodeString)) {
                    throw new Error("Unexpected type method call: " + type);
                }
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + compiledTest +": " + e);
    }
}
 
Example 5
Source File: T6199075.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
void verifyBytecode(VarargsMethod selected) {
    bytecodeCheckCount++;
    File compiledTest = new File("Test.class");
    try {
        ClassFile cf = ClassFile.read(compiledTest);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals("test")) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                int cp_entry = i.getUnsignedShort(1);
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.contains(selected.varargsElement.bytecodeString)) {
                    throw new Error("Unexpected type method call: " + type);
                }
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + compiledTest +": " + e);
    }
}
 
Example 6
Source File: T6199075.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
void verifyBytecode(VarargsMethod selected) {
    bytecodeCheckCount++;
    File compiledTest = new File("Test.class");
    try {
        ClassFile cf = ClassFile.read(compiledTest);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals("test")) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                int cp_entry = i.getUnsignedShort(1);
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.contains(selected.varargsElement.bytecodeString)) {
                    throw new Error("Unexpected type method call: " + type);
                }
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + compiledTest +": " + e);
    }
}
 
Example 7
Source File: T6199075.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void verifyBytecode(VarargsMethod selected) {
    bytecodeCheckCount++;
    File compiledTest = new File("Test.class");
    try {
        ClassFile cf = ClassFile.read(compiledTest);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals("test")) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                int cp_entry = i.getUnsignedShort(1);
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.contains(selected.varargsElement.bytecodeString)) {
                    throw new Error("Unexpected type method call: " + type);
                }
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + compiledTest +": " + e);
    }
}
 
Example 8
Source File: T6199075.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void verifyBytecode(VarargsMethod selected) {
    bytecodeCheckCount++;
    File compiledTest = new File("Test.class");
    try {
        ClassFile cf = ClassFile.read(compiledTest);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals("test")) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                int cp_entry = i.getUnsignedShort(1);
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.contains(selected.varargsElement.bytecodeString)) {
                    throw new Error("Unexpected type method call: " + type);
                }
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + compiledTest +": " + e);
    }
}
 
Example 9
Source File: T7042566.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
void verifyBytecode(VarargsMethod selected, JavaSource source, int id) {
    bytecodeCheckCount.incrementAndGet();
    File compiledTest = new File(String.format("Test%d.class", id));
    try {
        ClassFile cf = ClassFile.read(compiledTest);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals("test")) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea =
            (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                int cp_entry = i.getUnsignedShort(1);
                CONSTANT_Methodref_info methRef =
                    (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                String sig = selected.parameterTypes.bytecodeSigStr;
                if (!type.contains(sig)) {
                    throw new Error("Unexpected type method call: " +
                                    type + "" +
                                    "\nfound: " + sig +
                                    "\n" + source.getCharContent(true));
                }
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + compiledTest +": " + e);
    }
}
 
Example 10
Source File: TestCP.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
void verifyMethodHandleInvocationDescriptors(File f) {
    System.err.println("verify: " + f);
    try {
        int count = 0;
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }
        int instr_count = 0;
        int cp_entry = -1;

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                instr_count++;
                if (cp_entry == -1) {
                    cp_entry = i.getUnsignedShort(1);
                } else if (cp_entry != i.getUnsignedShort(1)) {
                    throw new Error("Unexpected CP entry in polymorphic signature call");
                }
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.equals(PS_TYPE)) {
                    throw new Error("Unexpected type in polymorphic signature call: " + type);
                }
            }
        }
        if (instr_count != PS_CALLS_COUNT) {
            throw new Error("Wrong number of polymorphic signature call found: " + instr_count);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}
 
Example 11
Source File: TestCP.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
void verifyMethodHandleInvocationDescriptors(File f) {
    System.err.println("verify: " + f);
    try {
        int count = 0;
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }
        int instr_count = 0;
        int cp_entry = -1;

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                instr_count++;
                if (cp_entry == -1) {
                    cp_entry = i.getUnsignedShort(1);
                } else if (cp_entry != i.getUnsignedShort(1)) {
                    throw new Error("Unexpected CP entry in polymorphic signature call");
                }
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.equals(PS_TYPE)) {
                    throw new Error("Unexpected type in polymorphic signature call: " + type);
                }
            }
        }
        if (instr_count != PS_CALLS_COUNT) {
            throw new Error("Wrong number of polymorphic signature call found: " + instr_count);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}
 
Example 12
Source File: T7042566.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
void verifyBytecode(VarargsMethod selected, JavaSource source, int id) {
    bytecodeCheckCount.incrementAndGet();
    File compiledTest = new File(String.format("Test%d.class", id));
    try {
        ClassFile cf = ClassFile.read(compiledTest);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals("test")) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea =
            (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                int cp_entry = i.getUnsignedShort(1);
                CONSTANT_Methodref_info methRef =
                    (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                String sig = selected.parameterTypes.bytecodeSigStr;
                if (!type.contains(sig)) {
                    throw new Error("Unexpected type method call: " +
                                    type + "" +
                                    "\nfound: " + sig +
                                    "\n" + source.getCharContent(true));
                }
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + compiledTest +": " + e);
    }
}
 
Example 13
Source File: T7042566.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
void verifyBytecode(Result<Iterable<? extends JavaFileObject>> res, VarargsMethod selected) {
    try (InputStream is = res.get().iterator().next().openInputStream()) {
        ClassFile cf = ClassFile.read(is);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals("test")) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            fail("Test method not found");
            return;
        }
        Code_attribute ea =
            (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            fail("Code attribute for test() method not found");
            return;
        }

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                int cp_entry = i.getUnsignedShort(1);
                CONSTANT_Methodref_info methRef =
                    (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                String sig = selected.parameterTypes.bytecodeSigStr;
                if (!type.contains(sig)) {
                    fail("Unexpected type method call: " +
                                    type + "" +
                                    "\nfound: " + sig +
                                    "\n" + res.compilationInfo());
                    return;
                }
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("error reading classfile; " + res.compilationInfo() +": " + e);
    }
}
 
Example 14
Source File: TestCP.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
void verifySigPolyInvokeVirtual(File f, String psType) {
    System.err.println("verify: " + f);
    try {
        int count = 0;
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }
        int instr_count = 0;
        int cp_entry = -1;

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                instr_count++;
                if (cp_entry == -1) {
                    cp_entry = i.getUnsignedShort(1);
                } else if (cp_entry != i.getUnsignedShort(1)) {
                    throw new Error("Unexpected CP entry in polymorphic signature call");
                }
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.equals(psType)) {
                    throw new Error("Unexpected type in polymorphic signature call: " + type);
                }
            }
        }
        if (instr_count != PS_CALLS_COUNT) {
            throw new Error("Wrong number of polymorphic signature call found: " + instr_count);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}
 
Example 15
Source File: T7042566.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void verifyBytecode(VarargsMethod selected, JavaSource source, int id) {
    bytecodeCheckCount.incrementAndGet();
    File compiledTest = new File(String.format("Test%d.class", id));
    try {
        ClassFile cf = ClassFile.read(compiledTest);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals("test")) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea =
            (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                int cp_entry = i.getUnsignedShort(1);
                CONSTANT_Methodref_info methRef =
                    (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                String sig = selected.parameterTypes.bytecodeSigStr;
                if (!type.contains(sig)) {
                    throw new Error("Unexpected type method call: " +
                                    type + "" +
                                    "\nfound: " + sig +
                                    "\n" + source.getCharContent(true));
                }
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + compiledTest +": " + e);
    }
}
 
Example 16
Source File: TestCP.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void verifyMethodHandleInvocationDescriptors(File f) {
    System.err.println("verify: " + f);
    try {
        int count = 0;
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }
        int instr_count = 0;
        int cp_entry = -1;

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                instr_count++;
                if (cp_entry == -1) {
                    cp_entry = i.getUnsignedShort(1);
                } else if (cp_entry != i.getUnsignedShort(1)) {
                    throw new Error("Unexpected CP entry in polymorphic signature call");
                }
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.equals(PS_TYPE)) {
                    throw new Error("Unexpected type in polymorphic signature call: " + type);
                }
            }
        }
        if (instr_count != PS_CALLS_COUNT) {
            throw new Error("Wrong number of polymorphic signature call found: " + instr_count);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}
 
Example 17
Source File: T7042566.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
void verifyBytecode(VarargsMethod selected, JavaSource source, int id) {
    bytecodeCheckCount.incrementAndGet();
    File compiledTest = new File(String.format("Test%d.class", id));
    try {
        ClassFile cf = ClassFile.read(compiledTest);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals("test")) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea =
            (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                int cp_entry = i.getUnsignedShort(1);
                CONSTANT_Methodref_info methRef =
                    (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                String sig = selected.parameterTypes.bytecodeSigStr;
                if (!type.contains(sig)) {
                    throw new Error("Unexpected type method call: " +
                                    type + "" +
                                    "\nfound: " + sig +
                                    "\n" + source.getCharContent(true));
                }
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + compiledTest +": " + e);
    }
}
 
Example 18
Source File: TestCP.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
void verifyMethodHandleInvocationDescriptors(File f) {
    System.err.println("verify: " + f);
    try {
        int count = 0;
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }
        int instr_count = 0;
        int cp_entry = -1;

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                instr_count++;
                if (cp_entry == -1) {
                    cp_entry = i.getUnsignedShort(1);
                } else if (cp_entry != i.getUnsignedShort(1)) {
                    throw new Error("Unexpected CP entry in polymorphic signature call");
                }
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.equals(PS_TYPE)) {
                    throw new Error("Unexpected type in polymorphic signature call: " + type);
                }
            }
        }
        if (instr_count != PS_CALLS_COUNT) {
            throw new Error("Wrong number of polymorphic signature call found: " + instr_count);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}
 
Example 19
Source File: TestCP.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
void verifyMethodHandleInvocationDescriptors(File f) {
    System.err.println("verify: " + f);
    try {
        int count = 0;
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }
        int instr_count = 0;
        int cp_entry = -1;

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                instr_count++;
                if (cp_entry == -1) {
                    cp_entry = i.getUnsignedShort(1);
                } else if (cp_entry != i.getUnsignedShort(1)) {
                    throw new Error("Unexpected CP entry in polymorphic signature call");
                }
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.equals(PS_TYPE)) {
                    throw new Error("Unexpected type in polymorphic signature call: " + type);
                }
            }
        }
        if (instr_count != PS_CALLS_COUNT) {
            throw new Error("Wrong number of polymorphic signature call found: " + instr_count);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}
 
Example 20
Source File: TestCP.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
void verifyMethodHandleInvocationDescriptors(File f) {
    System.err.println("verify: " + f);
    try {
        int count = 0;
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }
        int instr_count = 0;
        int cp_entry = -1;

        for (Instruction i : ea.getInstructions()) {
            if (i.getMnemonic().equals("invokevirtual")) {
                instr_count++;
                if (cp_entry == -1) {
                    cp_entry = i.getUnsignedShort(1);
                } else if (cp_entry != i.getUnsignedShort(1)) {
                    throw new Error("Unexpected CP entry in polymorphic signature call");
                }
                CONSTANT_Methodref_info methRef =
                        (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
                String type = methRef.getNameAndTypeInfo().getType();
                if (!type.equals(PS_TYPE)) {
                    throw new Error("Unexpected type in polymorphic signature call: " + type);
                }
            }
        }
        if (instr_count != PS_CALLS_COUNT) {
            throw new Error("Wrong number of polymorphic signature call found: " + instr_count);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}