当前位置: 首页>>代码示例>>Java>>正文


Java Instruction类代码示例

本文整理汇总了Java中com.sun.tools.classfile.Instruction的典型用法代码示例。如果您正苦于以下问题:Java Instruction类的具体用法?Java Instruction怎么用?Java Instruction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Instruction类属于com.sun.tools.classfile包,在下文中一共展示了Instruction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeDetails

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
public void writeDetails(Instruction instr) {
    String indent = space(40); // could get from Options?
    Set<Integer> lines = lineMap.get(instr.getPC());
    if (lines != null) {
        for (int line: lines) {
            print(indent);
            print(String.format(" %4d ", line));
            if (line < sourceLines.length)
                print(sourceLines[line]);
            println();
            int nextLine = nextLine(line);
            for (int i = line + 1; i < nextLine; i++) {
                print(indent);
                print(String.format("(%4d)", i));
                if (i < sourceLines.length)
                    print(sourceLines[i]);
                println();
            }
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:SourceWriter.java

示例2: checkMethod

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
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);
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:LambdaAsm.java

示例3: checkClassFile

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
void checkClassFile(final Path path) throws Exception {
    ClassFile classFile = ClassFile.read(
            new BufferedInputStream(Files.newInputStream(path)));
    constantPool = classFile.constant_pool;
    utf8Index = constantPool.getUTF8Index("STR_TO_LOOK_FOR");
    for (Method method: classFile.methods) {
        if (method.getName(constantPool).equals("methodToLookFor")) {
            Code_attribute codeAtt = (Code_attribute)method.attributes.get(Attribute.Code);
            for (Instruction inst: codeAtt.getInstructions()) {
                inst.accept(codeVisitor, null);
            }
        }
    }
    Assert.check(numberOfRefToStr == 1,
            "There should only be one reference to a CONSTANT_String_info structure in the generated code");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:DeadCodeGeneratedForEmptyTryTest.java

示例4: verifyDefaultBody

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:TestDirectSuperInterfaceInvoke.java

示例5: writeDetails

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
@Override
void writeDetails(Instruction instr) {
    String indent = space(2); // get from Options?
    int pc = instr.getPC();
    List<Note> notes = pcMap.get(pc);
    if (notes != null) {
        for (Note n: notes) {
            print(indent);
            print("@");
            annotationWriter.write(n.anno, false, true);
            print(", ");
            println(StringUtils.toLowerCase(n.kind.toString()));
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:TypeAnnotationWriter.java

示例6: writeTrys

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
public void writeTrys(Instruction instr, NoteKind kind) {
    String indent = space(2); // get from Options?
    int pc = instr.getPC();
    List<Exception_data> entries = pcMap.get(pc);
    if (entries != null) {
        for (ListIterator<Exception_data> iter =
                entries.listIterator(kind == NoteKind.END ? entries.size() : 0);
                kind == NoteKind.END ? iter.hasPrevious() : iter.hasNext() ; ) {
            Exception_data entry =
                    kind == NoteKind.END ? iter.previous() : iter.next();
            if (kind.match(entry, pc)) {
                print(indent);
                print(kind.text);
                print("[");
                print(indexMap.get(entry));
                print("] ");
                if (entry.catch_type == 0)
                    print("finally");
                else {
                    print("#" + entry.catch_type);
                    print(" // ");
                    constantWriter.write(entry.catch_type);
                }
                println();
            }
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:TryBlockWriter.java

示例7: writeInstr

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
public void writeInstr(Instruction instr) {
    print(String.format("%4d: %-13s ", instr.getPC(), instr.getMnemonic()));
    // compute the number of indentations for the body of multi-line instructions
    // This is 6 (the width of "%4d: "), divided by the width of each indentation level,
    // and rounded up to the next integer.
    int indentWidth = options.indentWidth;
    int indent = (6 + indentWidth - 1) / indentWidth;
    instr.accept(instructionPrinter, indent);
    println();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:CodeWriter.java

示例8: visitConstantPoolRef

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
public Void visitConstantPoolRef(Instruction instr, int index, Integer indent) {
    print("#" + index);
    tab();
    print("// ");
    printConstant(index);
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:CodeWriter.java

示例9: visitConstantPoolRefAndValue

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
public Void visitConstantPoolRefAndValue(Instruction instr, int index, int value, Integer indent) {
    print("#" + index + ",  " + value);
    tab();
    print("// ");
    printConstant(index);
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:CodeWriter.java

示例10: visitLookupSwitch

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
public Void visitLookupSwitch(Instruction instr,
        int default_, int npairs, int[] matches, int[] offsets, Integer indent) {
    int pc = instr.getPC();
    print("{ // " + npairs);
    indent(indent);
    for (int i = 0; i < npairs; i++) {
        print(String.format("%n%12d: %d", matches[i], (pc + offsets[i])));
    }
    print("\n     default: " + (pc + default_) + "\n}");
    indent(-indent);
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:CodeWriter.java

示例11: visitTableSwitch

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
public Void visitTableSwitch(Instruction instr,
        int default_, int low, int high, int[] offsets, Integer indent) {
    int pc = instr.getPC();
    print("{ // " + low + " to " + high);
    indent(indent);
    for (int i = 0; i < offsets.length; i++) {
        print(String.format("%n%12d: %d", (low + i), (pc + offsets[i])));
    }
    print("\n     default: " + (pc + default_) + "\n}");
    indent(-indent);
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:CodeWriter.java

示例12: instructions

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
private Element instructions(Element code, Code_attribute c) {
    Element ielement = new Element("Instructions");
    for (Instruction ins : c.getInstructions()) {
        ielement.add(iv.visit(ins));
    }
    ielement.trimToSize();
    return ielement;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:ClassReader.java

示例13: visitNoOperands

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
@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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:ClassReader.java

示例14: visitArrayType

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
@Override
public Element visitArrayType(Instruction i, TypeKind tk, Void p) {
    Element ie = new Element(i.getMnemonic());
    ie.setAttr("num", "" + tk.value);
    ie.setAttr("val", tk.name);
    return ie;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:ClassReader.java

示例15: visitConstantPoolRefAndValue

import com.sun.tools.classfile.Instruction; //导入依赖的package包/类
@Override
public Element visitConstantPoolRefAndValue(Instruction i, int i1, int i2, Void p) {
    // workaround for a potential bug in classfile
    Element ie = new Element(i.getMnemonic());
    if (i.getOpcode().equals(Opcode.IINC_W)) {
        ie.setAttr("loc", "" + i1);
        ie.setAttr("num", "" + i2);
    } else {
        ie.setAttr("ref", x.getCpString(i1));
        ie.setAttr("val", "" + i2);
    }
    return ie;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:ClassReader.java


注:本文中的com.sun.tools.classfile.Instruction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。