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

The following examples show how to use com.sun.tools.classfile.Instruction#getShort() . 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: TestDirectSuperInterfaceInvoke.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
void verifyDefaultBody(String classFile) {
    String workDir = System.getProperty("test.classes");
    File file = new File(workDir, classFile);
    try {
        final ClassFile cf = ClassFile.read(file);
        for (Method m : cf.methods) {
            Code_attribute codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            for (Instruction instr : codeAttr.getInstructions()) {
                if (instr.getOpcode() == Opcode.INVOKESPECIAL) {
                    int pc_index = instr.getShort(1);
                    CPRefInfo ref = (CPRefInfo)cf.constant_pool.get(pc_index);
                    String className = ref.getClassName();
                    if (className.equals("BaseInterface"))
                        throw new IllegalStateException("Must not directly refer to TestedInterface");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + file +": " + e);
    }
}
 
Example 2
Source File: TestDirectSuperInterfaceInvoke.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
void verifyDefaultBody(String classFile) {
    String workDir = System.getProperty("test.classes");
    File file = new File(workDir, classFile);
    try {
        final ClassFile cf = ClassFile.read(file);
        for (Method m : cf.methods) {
            Code_attribute codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            for (Instruction instr : codeAttr.getInstructions()) {
                if (instr.getOpcode() == Opcode.INVOKESPECIAL) {
                    int pc_index = instr.getShort(1);
                    CPRefInfo ref = (CPRefInfo)cf.constant_pool.get(pc_index);
                    String className = ref.getClassName();
                    if (className.equals("BaseInterface"))
                        throw new IllegalStateException("Must not directly refer to TestedInterface");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + file +": " + e);
    }
}
 
Example 3
Source File: TestDirectSuperInterfaceInvoke.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void verifyDefaultBody(String classFile) {
    String workDir = System.getProperty("test.classes");
    File file = new File(workDir, classFile);
    try {
        final ClassFile cf = ClassFile.read(file);
        for (Method m : cf.methods) {
            Code_attribute codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            for (Instruction instr : codeAttr.getInstructions()) {
                if (instr.getOpcode() == Opcode.INVOKESPECIAL) {
                    int pc_index = instr.getShort(1);
                    CPRefInfo ref = (CPRefInfo)cf.constant_pool.get(pc_index);
                    String className = ref.getClassName();
                    if (className.equals("BaseInterface"))
                        throw new IllegalStateException("Must not directly refer to TestedInterface");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + file +": " + e);
    }
}
 
Example 4
Source File: TestDirectSuperInterfaceInvoke.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
void verifyDefaultBody(String classFile) {
    String workDir = System.getProperty("test.classes");
    File file = new File(workDir, classFile);
    try {
        final ClassFile cf = ClassFile.read(file);
        for (Method m : cf.methods) {
            Code_attribute codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            for (Instruction instr : codeAttr.getInstructions()) {
                if (instr.getOpcode() == Opcode.INVOKESPECIAL) {
                    int pc_index = instr.getShort(1);
                    CPRefInfo ref = (CPRefInfo)cf.constant_pool.get(pc_index);
                    String className = ref.getClassName();
                    if (className.equals("BaseInterface"))
                        throw new IllegalStateException("Must not directly refer to TestedInterface");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + file +": " + e);
    }
}
 
Example 5
Source File: TestDirectSuperInterfaceInvoke.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void verifyDefaultBody(String classFile) {
    String workDir = System.getProperty("test.classes");
    File file = new File(workDir, classFile);
    try {
        final ClassFile cf = ClassFile.read(file);
        for (Method m : cf.methods) {
            Code_attribute codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            for (Instruction instr : codeAttr.getInstructions()) {
                if (instr.getOpcode() == Opcode.INVOKESPECIAL) {
                    int pc_index = instr.getShort(1);
                    CPRefInfo ref = (CPRefInfo)cf.constant_pool.get(pc_index);
                    String className = ref.getClassName();
                    if (className.equals("BaseInterface"))
                        throw new IllegalStateException("Must not directly refer to TestedInterface");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + file +": " + e);
    }
}
 
Example 6
Source File: TestDirectSuperInterfaceInvoke.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
void verifyDefaultBody(String classFile) {
    String workDir = System.getProperty("test.classes");
    File file = new File(workDir, classFile);
    try {
        final ClassFile cf = ClassFile.read(file);
        for (Method m : cf.methods) {
            Code_attribute codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            for (Instruction instr : codeAttr.getInstructions()) {
                if (instr.getOpcode() == Opcode.INVOKESPECIAL) {
                    int pc_index = instr.getShort(1);
                    CPRefInfo ref = (CPRefInfo)cf.constant_pool.get(pc_index);
                    String className = ref.getClassName();
                    if (className.equals("BaseInterface"))
                        throw new IllegalStateException("Must not directly refer to TestedInterface");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + file +": " + e);
    }
}
 
Example 7
Source File: TestDirectSuperInterfaceInvoke.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
void verifyDefaultBody(String classFile) {
    String workDir = System.getProperty("test.classes");
    File file = new File(workDir, classFile);
    try {
        final ClassFile cf = ClassFile.read(file);
        for (Method m : cf.methods) {
            Code_attribute codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            for (Instruction instr : codeAttr.getInstructions()) {
                if (instr.getOpcode() == Opcode.INVOKESPECIAL) {
                    int pc_index = instr.getShort(1);
                    CPRefInfo ref = (CPRefInfo)cf.constant_pool.get(pc_index);
                    String className = ref.getClassName();
                    if (className.equals("BaseInterface"))
                        throw new IllegalStateException("Must not directly refer to TestedInterface");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + file +": " + e);
    }
}
 
Example 8
Source File: TestDirectSuperInterfaceInvoke.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
void verifyDefaultBody(String classFile) {
    String workDir = System.getProperty("test.classes");
    File file = new File(workDir, classFile);
    try {
        final ClassFile cf = ClassFile.read(file);
        for (Method m : cf.methods) {
            Code_attribute codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            for (Instruction instr : codeAttr.getInstructions()) {
                if (instr.getOpcode() == Opcode.INVOKESPECIAL) {
                    int pc_index = instr.getShort(1);
                    CPRefInfo ref = (CPRefInfo)cf.constant_pool.get(pc_index);
                    String className = ref.getClassName();
                    if (className.equals("BaseInterface"))
                        throw new IllegalStateException("Must not directly refer to TestedInterface");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + file +": " + e);
    }
}
 
Example 9
Source File: TestDefaultBody.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
void verifyDefaultBody(File f) {
    System.err.println("verify: " + f);
    try {
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        Code_attribute codeAttr = null;
        for (Method m : cf.methods) {
            codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            String mname = m.getName(cf.constant_pool);
            if (mname.equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            } else {
                codeAttr = null;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        if (testMethod.access_flags.is(AccessFlags.ACC_ABSTRACT)) {
            throw new Error("Test method is abstract");
        }
        if (codeAttr == null) {
            throw new Error("Code attribute in test method not found");
        }

        boolean found = false;
        for (Instruction instr : codeAttr.getInstructions()) {
            if (instr.getOpcode() == Opcode.INVOKESTATIC) {
                found = true;
                int pc_index = instr.getShort(1);
                CONSTANT_Methodref_info mref = (CONSTANT_Methodref_info)cf.constant_pool.get(pc_index);
                String className = mref.getClassName();
                String targetName = mref.getNameAndTypeInfo().getName();
                String targetType = mref.getNameAndTypeInfo().getType();

                if (!className.equals(TARGET_CLASS_NAME)) {
                    throw new Error("unexpected class in default method body " + className);
                }
                if (!targetName.equals(TARGET_NAME)) {
                    throw new Error("unexpected method name in default method body " + targetName);
                }
                if (!targetType.equals(TARGET_TYPE)) {
                    throw new Error("unexpected method type in default method body " + targetType);
                }
                break;
            }
        }

        if (!found) {
            throw new Error("no invokestatic found in default method body");
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}
 
Example 10
Source File: TestDefaultBody.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
void verifyDefaultBody(File f) {
    System.err.println("verify: " + f);
    try {
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        Code_attribute codeAttr = null;
        for (Method m : cf.methods) {
            codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            String mname = m.getName(cf.constant_pool);
            if (mname.equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            } else {
                codeAttr = null;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        if (testMethod.access_flags.is(AccessFlags.ACC_ABSTRACT)) {
            throw new Error("Test method is abstract");
        }
        if (codeAttr == null) {
            throw new Error("Code attribute in test method not found");
        }

        boolean found = false;
        for (Instruction instr : codeAttr.getInstructions()) {
            if (instr.getOpcode() == Opcode.INVOKESTATIC) {
                found = true;
                int pc_index = instr.getShort(1);
                CONSTANT_Methodref_info mref = (CONSTANT_Methodref_info)cf.constant_pool.get(pc_index);
                String className = mref.getClassName();
                String targetName = mref.getNameAndTypeInfo().getName();
                String targetType = mref.getNameAndTypeInfo().getType();

                if (!className.equals(TARGET_CLASS_NAME)) {
                    throw new Error("unexpected class in default method body " + className);
                }
                if (!targetName.equals(TARGET_NAME)) {
                    throw new Error("unexpected method name in default method body " + targetName);
                }
                if (!targetType.equals(TARGET_TYPE)) {
                    throw new Error("unexpected method type in default method body " + targetType);
                }
                break;
            }
        }

        if (!found) {
            throw new Error("no invokestatic found in default method body");
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}
 
Example 11
Source File: TestDefaultBody.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
void verifyDefaultBody(File f) {
    System.err.println("verify: " + f);
    try {
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        Code_attribute codeAttr = null;
        for (Method m : cf.methods) {
            codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            String mname = m.getName(cf.constant_pool);
            if (mname.equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            } else {
                codeAttr = null;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        if (testMethod.access_flags.is(AccessFlags.ACC_ABSTRACT)) {
            throw new Error("Test method is abstract");
        }
        if (codeAttr == null) {
            throw new Error("Code attribute in test method not found");
        }

        boolean found = false;
        for (Instruction instr : codeAttr.getInstructions()) {
            if (instr.getOpcode() == Opcode.INVOKESTATIC) {
                found = true;
                int pc_index = instr.getShort(1);
                CONSTANT_Methodref_info mref = (CONSTANT_Methodref_info)cf.constant_pool.get(pc_index);
                String className = mref.getClassName();
                String targetName = mref.getNameAndTypeInfo().getName();
                String targetType = mref.getNameAndTypeInfo().getType();

                if (!className.equals(TARGET_CLASS_NAME)) {
                    throw new Error("unexpected class in default method body " + className);
                }
                if (!targetName.equals(TARGET_NAME)) {
                    throw new Error("unexpected method name in default method body " + targetName);
                }
                if (!targetType.equals(TARGET_TYPE)) {
                    throw new Error("unexpected method type in default method body " + targetType);
                }
                break;
            }
        }

        if (!found) {
            throw new Error("no invokestatic found in default method body");
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}
 
Example 12
Source File: TestDefaultBody.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void verifyDefaultBody(File f) {
    System.err.println("verify: " + f);
    try {
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        Code_attribute codeAttr = null;
        for (Method m : cf.methods) {
            codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            String mname = m.getName(cf.constant_pool);
            if (mname.equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            } else {
                codeAttr = null;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        if (testMethod.access_flags.is(AccessFlags.ACC_ABSTRACT)) {
            throw new Error("Test method is abstract");
        }
        if (codeAttr == null) {
            throw new Error("Code attribute in test method not found");
        }

        boolean found = false;
        for (Instruction instr : codeAttr.getInstructions()) {
            if (instr.getOpcode() == Opcode.INVOKESTATIC) {
                found = true;
                int pc_index = instr.getShort(1);
                CONSTANT_Methodref_info mref = (CONSTANT_Methodref_info)cf.constant_pool.get(pc_index);
                String className = mref.getClassName();
                String targetName = mref.getNameAndTypeInfo().getName();
                String targetType = mref.getNameAndTypeInfo().getType();

                if (!className.equals(TARGET_CLASS_NAME)) {
                    throw new Error("unexpected class in default method body " + className);
                }
                if (!targetName.equals(TARGET_NAME)) {
                    throw new Error("unexpected method name in default method body " + targetName);
                }
                if (!targetType.equals(TARGET_TYPE)) {
                    throw new Error("unexpected method type in default method body " + targetType);
                }
                break;
            }
        }

        if (!found) {
            throw new Error("no invokestatic found in default method body");
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}
 
Example 13
Source File: TestDefaultBody.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
void verifyDefaultBody(File f) {
    System.err.println("verify: " + f);
    try {
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        Code_attribute codeAttr = null;
        for (Method m : cf.methods) {
            codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            String mname = m.getName(cf.constant_pool);
            if (mname.equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            } else {
                codeAttr = null;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        if (testMethod.access_flags.is(AccessFlags.ACC_ABSTRACT)) {
            throw new Error("Test method is abstract");
        }
        if (codeAttr == null) {
            throw new Error("Code attribute in test method not found");
        }

        boolean found = false;
        for (Instruction instr : codeAttr.getInstructions()) {
            if (instr.getOpcode() == Opcode.INVOKESTATIC) {
                found = true;
                int pc_index = instr.getShort(1);
                CONSTANT_Methodref_info mref = (CONSTANT_Methodref_info)cf.constant_pool.get(pc_index);
                String className = mref.getClassName();
                String targetName = mref.getNameAndTypeInfo().getName();
                String targetType = mref.getNameAndTypeInfo().getType();

                if (!className.equals(TARGET_CLASS_NAME)) {
                    throw new Error("unexpected class in default method body " + className);
                }
                if (!targetName.equals(TARGET_NAME)) {
                    throw new Error("unexpected method name in default method body " + targetName);
                }
                if (!targetType.equals(TARGET_TYPE)) {
                    throw new Error("unexpected method type in default method body " + targetType);
                }
                break;
            }
        }

        if (!found) {
            throw new Error("no invokestatic found in default method body");
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}
 
Example 14
Source File: TestDefaultBody.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
void verifyDefaultBody(File f) {
    System.err.println("verify: " + f);
    try {
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        Code_attribute codeAttr = null;
        for (Method m : cf.methods) {
            codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            String mname = m.getName(cf.constant_pool);
            if (mname.equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            } else {
                codeAttr = null;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        if (testMethod.access_flags.is(AccessFlags.ACC_ABSTRACT)) {
            throw new Error("Test method is abstract");
        }
        if (codeAttr == null) {
            throw new Error("Code attribute in test method not found");
        }

        boolean found = false;
        for (Instruction instr : codeAttr.getInstructions()) {
            if (instr.getOpcode() == Opcode.INVOKESTATIC) {
                found = true;
                int pc_index = instr.getShort(1);
                CONSTANT_Methodref_info mref = (CONSTANT_Methodref_info)cf.constant_pool.get(pc_index);
                String className = mref.getClassName();
                String targetName = mref.getNameAndTypeInfo().getName();
                String targetType = mref.getNameAndTypeInfo().getType();

                if (!className.equals(TARGET_CLASS_NAME)) {
                    throw new Error("unexpected class in default method body " + className);
                }
                if (!targetName.equals(TARGET_NAME)) {
                    throw new Error("unexpected method name in default method body " + targetName);
                }
                if (!targetType.equals(TARGET_TYPE)) {
                    throw new Error("unexpected method type in default method body " + targetType);
                }
                break;
            }
        }

        if (!found) {
            throw new Error("no invokestatic found in default method body");
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}
 
Example 15
Source File: TestDefaultBody.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
void verifyDefaultBody(File f) {
    System.err.println("verify: " + f);
    try {
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        Code_attribute codeAttr = null;
        for (Method m : cf.methods) {
            codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            String mname = m.getName(cf.constant_pool);
            if (mname.equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            } else {
                codeAttr = null;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        if (testMethod.access_flags.is(AccessFlags.ACC_ABSTRACT)) {
            throw new Error("Test method is abstract");
        }
        if (codeAttr == null) {
            throw new Error("Code attribute in test method not found");
        }

        boolean found = false;
        for (Instruction instr : codeAttr.getInstructions()) {
            if (instr.getOpcode() == Opcode.INVOKESTATIC) {
                found = true;
                int pc_index = instr.getShort(1);
                CONSTANT_Methodref_info mref = (CONSTANT_Methodref_info)cf.constant_pool.get(pc_index);
                String className = mref.getClassName();
                String targetName = mref.getNameAndTypeInfo().getName();
                String targetType = mref.getNameAndTypeInfo().getType();

                if (!className.equals(TARGET_CLASS_NAME)) {
                    throw new Error("unexpected class in default method body " + className);
                }
                if (!targetName.equals(TARGET_NAME)) {
                    throw new Error("unexpected method name in default method body " + targetName);
                }
                if (!targetType.equals(TARGET_TYPE)) {
                    throw new Error("unexpected method type in default method body " + targetType);
                }
                break;
            }
        }

        if (!found) {
            throw new Error("no invokestatic found in default method body");
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}
 
Example 16
Source File: TestDefaultBody.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
void verifyDefaultBody(File f) {
    System.err.println("verify: " + f);
    try {
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        Code_attribute codeAttr = null;
        for (Method m : cf.methods) {
            codeAttr = (Code_attribute)m.attributes.get(Attribute.Code);
            String mname = m.getName(cf.constant_pool);
            if (mname.equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            } else {
                codeAttr = null;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        if (testMethod.access_flags.is(AccessFlags.ACC_ABSTRACT)) {
            throw new Error("Test method is abstract");
        }
        if (codeAttr == null) {
            throw new Error("Code attribute in test method not found");
        }

        boolean found = false;
        for (Instruction instr : codeAttr.getInstructions()) {
            if (instr.getOpcode() == Opcode.INVOKESTATIC) {
                found = true;
                int pc_index = instr.getShort(1);
                CONSTANT_Methodref_info mref = (CONSTANT_Methodref_info)cf.constant_pool.get(pc_index);
                String className = mref.getClassName();
                String targetName = mref.getNameAndTypeInfo().getName();
                String targetType = mref.getNameAndTypeInfo().getType();

                if (!className.equals(TARGET_CLASS_NAME)) {
                    throw new Error("unexpected class in default method body " + className);
                }
                if (!targetName.equals(TARGET_NAME)) {
                    throw new Error("unexpected method name in default method body " + targetName);
                }
                if (!targetType.equals(TARGET_TYPE)) {
                    throw new Error("unexpected method type in default method body " + targetType);
                }
                break;
            }
        }

        if (!found) {
            throw new Error("no invokestatic found in default method body");
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f +": " + e);
    }
}