Fix JDK5 class constant handling in ldc

Maintain major/minor class file version from original file
master
patrickroemer 17 years ago
parent ffa5912729
commit bc3c3dad55
  1. 9
      changes.txt
  2. 4
      src/EDU/purdue/cs/bloat/context/BloatingClassLoader.java
  3. 17
      src/EDU/purdue/cs/bloat/editor/CodeArray.java
  4. 12
      src/EDU/purdue/cs/bloat/file/ClassFile.java
  5. 2
      src/EDU/purdue/cs/bloat/file/ClassFileLoader.java

@ -1,3 +1,12 @@
2007-10-25
- ClassFileLoader#loadClassFromRessource(): String#replaceAll() -> String#replace()
- Added BloatingClassLoader#getEditorContext()
- CodeArray#visit_ldc: fix for JDK5 class literal constant references
- ClassFile: maintain original major/minor class format version information
---
- FlowGraph#addHandlerEdges: added visited parameter to keep track of
blocks already visited to break 'infinite loop' in compiler-generated
'self-handling' exception handlers since JDK 1.4

@ -99,6 +99,10 @@ public abstract class BloatingClassLoader extends URLClassLoader {
return this.loader;
}
protected EditorContext getEditorContext() {
return context;
}
/**
* This method is invoked as a class is being loaded.
*/

@ -853,9 +853,19 @@ public class CodeArray implements InstructionVisitor, Opcode {
}
stackHeight += 2;
} else if (operand instanceof String) {
final int index = constants.addConstant(Constant.STRING, operand);
int index = constants.addConstant(Constant.STRING, operand);
createLDC(index);
} else if (operand instanceof Type) {
// JDK5+ class literal
int index = constants.addConstant(Constant.CLASS, operand);
createLDC(index);
} else {
throw new RuntimeException();
}
}
private void createLDC(int index) {
if (index < 256) {
addOpcode(Opcode.opc_ldc);
@ -866,9 +876,6 @@ public class CodeArray implements InstructionVisitor, Opcode {
}
stackHeight++;
} else {
throw new RuntimeException();
}
}
/*

@ -60,6 +60,10 @@ public class ClassFile implements ClassInfo {
private File file; // (.class) File in which this class resides
private int major = 45;
private int minor = 3;
/**
* Constructor. This constructor parses the class file from the input
* stream.
@ -407,8 +411,8 @@ public class ClassFile implements ClassInfo {
*/
private void writeHeader(final DataOutputStream out) throws IOException {
out.writeInt(0xCAFEBABE);
out.writeShort(3);
out.writeShort(45);
out.writeShort(major);
out.writeShort(minor);
}
/**
@ -650,8 +654,8 @@ public class ClassFile implements ClassInfo {
throw new ClassFormatError("Bad magic number.");
}
in.readUnsignedShort(); // major
in.readUnsignedShort(); // minor
this.major = in.readUnsignedShort(); // major
this.minor = in.readUnsignedShort(); // minor
}
/**

@ -210,7 +210,7 @@ public class ClassFileLoader implements ClassInfoLoader {
* @return the ClassInfo
*/
private ClassInfo loadClassFromRessource(String name){
name = name.replaceAll("/",".");
name = name.replace('/','.');
try {
Class clazz = _classSource.loadClass(name);
int i = name.lastIndexOf('.');

Loading…
Cancel
Save