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 - FlowGraph#addHandlerEdges: added visited parameter to keep track of
blocks already visited to break 'infinite loop' in compiler-generated blocks already visited to break 'infinite loop' in compiler-generated
'self-handling' exception handlers since JDK 1.4 'self-handling' exception handlers since JDK 1.4

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

@ -853,9 +853,19 @@ public class CodeArray implements InstructionVisitor, Opcode {
} }
stackHeight += 2; stackHeight += 2;
} else if (operand instanceof String) { } 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) { if (index < 256) {
addOpcode(Opcode.opc_ldc); addOpcode(Opcode.opc_ldc);
@ -866,9 +876,6 @@ public class CodeArray implements InstructionVisitor, Opcode {
} }
stackHeight++; 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 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 * Constructor. This constructor parses the class file from the input
* stream. * stream.
@ -407,8 +411,8 @@ public class ClassFile implements ClassInfo {
*/ */
private void writeHeader(final DataOutputStream out) throws IOException { private void writeHeader(final DataOutputStream out) throws IOException {
out.writeInt(0xCAFEBABE); out.writeInt(0xCAFEBABE);
out.writeShort(3); out.writeShort(major);
out.writeShort(45); out.writeShort(minor);
} }
/** /**
@ -650,8 +654,8 @@ public class ClassFile implements ClassInfo {
throw new ClassFormatError("Bad magic number."); throw new ClassFormatError("Bad magic number.");
} }
in.readUnsignedShort(); // major this.major = in.readUnsignedShort(); // major
in.readUnsignedShort(); // minor this.minor = in.readUnsignedShort(); // minor
} }
/** /**

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

Loading…
Cancel
Save