use of com.sun.tools.classfile.Instruction in project jdk8u_jdk by JetBrains.
the class LambdaAsm method checkMethod.
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);
}
}
}
}
use of com.sun.tools.classfile.Instruction in project jdk8u_jdk by JetBrains.
the class AnnotationsElementVisitor method instructions.
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;
}
use of com.sun.tools.classfile.Instruction in project ceylon-compiler by ceylon.
the class TestCP method verifyMethodHandleInvocationDescriptors.
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);
}
}
use of com.sun.tools.classfile.Instruction in project ceylon-compiler by ceylon.
the class T6199075 method verifyBytecode.
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);
}
}
use of com.sun.tools.classfile.Instruction in project ceylon-compiler by ceylon.
the class T7042566 method verifyBytecode.
void verifyBytecode(VarargsMethod selected, JavaSource source) {
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();
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);
}
}
Aggregations