本文整理汇总了Java中com.sun.tools.classfile.Opcode类的典型用法代码示例。如果您正苦于以下问题:Java Opcode类的具体用法?Java Opcode怎么用?Java Opcode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Opcode类属于com.sun.tools.classfile包,在下文中一共展示了Opcode类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyDefaultBody
import com.sun.tools.classfile.Opcode; //导入依赖的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);
}
}
示例2: visitNoOperands
import com.sun.tools.classfile.Opcode; //导入依赖的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;
}
示例3: visitConstantPoolRefAndValue
import com.sun.tools.classfile.Opcode; //导入依赖的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;
}
示例4: verifyDefaultBody
import com.sun.tools.classfile.Opcode; //导入依赖的package包/类
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);
}
}