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

The following examples show how to use com.sun.tools.classfile.Instruction#getOpcode() . 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 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 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-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 4
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 5
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 6
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 7
Source File: ClassReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitNoOperands(Instruction i, Void p) {
    Opcode o = i.getOpcode();
    Element e = new Element(i.getMnemonic());
    if (o.opcode > 0xab && o.opcode <= 0xb1) {
        e.setAttr("pc", "" + i.getPC());
    }
    return e;
}
 
Example 8
Source File: ClassReader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitNoOperands(Instruction i, Void p) {
    Opcode o = i.getOpcode();
    Element e = new Element(i.getMnemonic());
    if (o.opcode > 0xab && o.opcode <= 0xb1) {
        e.setAttr("pc", "" + i.getPC());
    }
    return e;
}
 
Example 9
Source File: ClassReader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitNoOperands(Instruction i, Void p) {
    Opcode o = i.getOpcode();
    Element e = new Element(i.getMnemonic());
    if (o.opcode > 0xab && o.opcode <= 0xb1) {
        e.setAttr("pc", "" + i.getPC());
    }
    return e;
}
 
Example 10
Source File: ClassReader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitNoOperands(Instruction i, Void p) {
    Opcode o = i.getOpcode();
    Element e = new Element(i.getMnemonic());
    if (o.opcode > 0xab && o.opcode <= 0xb1) {
        e.setAttr("pc", "" + i.getPC());
    }
    return e;
}
 
Example 11
Source File: ClassReader.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitNoOperands(Instruction i, Void p) {
    Opcode o = i.getOpcode();
    Element e = new Element(i.getMnemonic());
    if (o.opcode > 0xab && o.opcode <= 0xb1) {
        e.setAttr("pc", "" + i.getPC());
    }
    return e;
}
 
Example 12
Source File: ClassReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitNoOperands(Instruction i, Void p) {
    Opcode o = i.getOpcode();
    Element e = new Element(i.getMnemonic());
    if (o.opcode > 0xab && o.opcode <= 0xb1) {
        e.setAttr("pc", "" + i.getPC());
    }
    return e;
}
 
Example 13
Source File: ClassReader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitNoOperands(Instruction i, Void p) {
    Opcode o = i.getOpcode();
    Element e = new Element(i.getMnemonic());
    if (o.opcode > 0xab && o.opcode <= 0xb1) {
        e.setAttr("pc", "" + i.getPC());
    }
    return e;
}
 
Example 14
Source File: ClassReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitNoOperands(Instruction i, Void p) {
    Opcode o = i.getOpcode();
    Element e = new Element(i.getMnemonic());
    if (o.opcode > 0xab && o.opcode <= 0xb1) {
        e.setAttr("pc", "" + i.getPC());
    }
    return e;
}
 
Example 15
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 16
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 17
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 18
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 19
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 20
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);
    }
}