use of com.sun.tools.classfile.ClassFile in project ceylon-compiler by ceylon.
the class ConstantWriter method write.
protected void write(int cpx) {
ClassFile classFile = classWriter.getClassFile();
if (cpx == 0) {
print("#0");
return;
}
CPInfo cpInfo;
try {
cpInfo = classFile.constant_pool.get(cpx);
} catch (ConstantPoolException e) {
print("#" + cpx);
return;
}
int tag = cpInfo.getTag();
switch(tag) {
case CONSTANT_Methodref:
case CONSTANT_InterfaceMethodref:
case CONSTANT_Fieldref:
// simplify references within this class
CPRefInfo ref = (CPRefInfo) cpInfo;
try {
if (ref.class_index == classFile.this_class)
cpInfo = classFile.constant_pool.get(ref.name_and_type_index);
} catch (ConstantPool.InvalidIndex e) {
// ignore, for now
}
}
print(tagName(tag) + " " + stringValue(cpInfo));
}
use of com.sun.tools.classfile.ClassFile in project ceylon-compiler by ceylon.
the class T4241573 method verifySourceFileAttribute.
/** Check the SourceFileAttribute is the simple name of the original source file. */
void verifySourceFileAttribute(File f) {
System.err.println("verify: " + f);
try {
ClassFile cf = ClassFile.read(f);
SourceFile_attribute sfa = (SourceFile_attribute) cf.getAttribute(Attribute.SourceFile);
String found = sfa.getSourceFile(cf.constant_pool);
String expect = f.getName().replaceAll("([$.].*)?\\.class", ".java");
if (!expect.equals(found)) {
error("bad value found: " + found + ", expected: " + expect);
}
} catch (Exception e) {
error("error reading " + f + ": " + e);
}
}
use of com.sun.tools.classfile.ClassFile in project ceylon-compiler by ceylon.
the class Pos05 method verifyMulticatchExceptionRanges.
void verifyMulticatchExceptionRanges(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");
}
Exception_data firstExceptionTable = null;
for (int i = 0; i < ea.exception_table_langth; i++) {
if (firstExceptionTable == null) {
firstExceptionTable = ea.exception_table[i];
}
if (ea.exception_table[i].handler_pc != firstExceptionTable.handler_pc || ea.exception_table[i].start_pc != firstExceptionTable.start_pc || ea.exception_table[i].end_pc != firstExceptionTable.end_pc) {
throw new Error("Multiple overlapping catch clause found in generated code");
}
count++;
}
if (count != TYPES_IN_MULTICATCH) {
throw new Error("Wrong number of exception data found: " + count);
}
} catch (Exception e) {
e.printStackTrace();
throw new Error("error reading " + f + ": " + e);
}
}
use of com.sun.tools.classfile.ClassFile in project ceylon-compiler by ceylon.
the class FindNativeFiles method isNativeClass.
boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException {
String name = entry.getName();
if (name.startsWith("META-INF") || !name.endsWith(".class"))
return false;
//String className = name.substring(0, name.length() - 6).replace("/", ".");
//System.err.println("check " + className);
InputStream in = jar.getInputStream(entry);
ClassFile cf = ClassFile.read(in);
in.close();
for (int i = 0; i < cf.methods.length; i++) {
Method m = cf.methods[i];
if (m.access_flags.is(AccessFlags.ACC_NATIVE)) {
// System.err.println(className);
return true;
}
}
return false;
}
use of com.sun.tools.classfile.ClassFile 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);
}
}
Aggregations