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