Fixed compile problems, but still not working

git-svn-id: https://svn.code.sf.net/p/jode/code/branches/generics@1400 379699f6-c40d-0410-875b-85095c16579e
generics
hoenicke 18 years ago
parent a5a48b3727
commit a9e2d0fdaa
  1. BIN
      jode/doc/jode-2.png
  2. 32
      jode/src/net/sf/jode/bytecode/BasicBlockReader.java
  3. 15
      jode/src/net/sf/jode/bytecode/BasicBlockWriter.java
  4. 6
      jode/src/net/sf/jode/bytecode/BasicBlocks.java
  5. 6
      jode/src/net/sf/jode/bytecode/Block.java
  6. 2
      jode/src/net/sf/jode/bytecode/ClassFormatException.java
  7. 2
      jode/src/net/sf/jode/bytecode/ClassInfo.java
  8. 3
      jode/src/net/sf/jode/bytecode/ClassPath.java
  9. 1
      jode/src/net/sf/jode/bytecode/SwitchInstruction.java
  10. 44
      jode/src/net/sf/jode/bytecode/TypeSignature.java
  11. 1
      jode/src/net/sf/jode/decompiler/Applet.java
  12. 25
      jode/src/net/sf/jode/decompiler/ClassAnalyzer.java
  13. 1
      jode/src/net/sf/jode/decompiler/Decompiler.java
  14. 4
      jode/src/net/sf/jode/decompiler/FieldAnalyzer.java
  15. 30
      jode/src/net/sf/jode/swingui/Main.java
  16. 4
      jode/src/net/sf/jode/type/ArrayType.java
  17. 17
      jode/src/net/sf/jode/type/ClassInfoType.java
  18. 23
      jode/src/net/sf/jode/type/ClassType.java
  19. 4
      jode/src/net/sf/jode/type/MultiClassType.java
  20. 4
      jode/src/net/sf/jode/type/NullType.java
  21. 84
      jode/src/net/sf/jode/type/RangeType.java
  22. 2
      jode/src/net/sf/jode/type/Type.java
  23. 99
      jode/test/CountOpcodes.java
  24. 4
      jode/test/InlineTest.java
  25. 2
      jode/test/ResolveConflicts.java
  26. 3
      jode/test/innerclasses/CheckSuperRemove.java

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

@ -25,9 +25,6 @@ import java.io.IOException;
import java.util.Stack; import java.util.Stack;
import java.util.Vector; import java.util.Vector;
import java.util.Enumeration; import java.util.Enumeration;
///#def COLLECTIONS java.util
import java.util.Arrays;
///#enddef
/** /**
* This is a helper class, that contains the method to read in basic * This is a helper class, that contains the method to read in basic
@ -66,11 +63,6 @@ class BasicBlockReader implements Opcodes {
String name, type; String name, type;
} }
private class LNTEntry {
int lineNr;
int start;
}
InstrInfo[] infos; InstrInfo[] infos;
HandlerEntry[] handlers; HandlerEntry[] handlers;
BasicBlocks bb; BasicBlocks bb;
@ -546,8 +538,10 @@ class BasicBlockReader implements Opcodes {
case opc_ldc: { case opc_ldc: {
int index = input.readUnsignedByte(); int index = input.readUnsignedByte();
int tag = cp.getTag(index); int tag = cp.getTag(index);
if (tag != cp.STRING && tag != cp.CLASS if (tag != ConstantPool.STRING
&& tag != cp.INTEGER && tag != cp.FLOAT) && tag != ConstantPool.CLASS
&& tag != ConstantPool.INTEGER
&& tag != ConstantPool.FLOAT)
throw new ClassFormatException throw new ClassFormatException
("wrong constant tag: "+tag); ("wrong constant tag: "+tag);
instr = new ConstantInstruction instr = new ConstantInstruction
@ -558,8 +552,10 @@ class BasicBlockReader implements Opcodes {
case opc_ldc_w: { case opc_ldc_w: {
int index = input.readUnsignedShort(); int index = input.readUnsignedShort();
int tag = cp.getTag(index); int tag = cp.getTag(index);
if (tag != cp.STRING && tag != cp.CLASS if (tag != ConstantPool.STRING
&& tag != cp.INTEGER && tag != cp.FLOAT) && tag != ConstantPool.CLASS
&& tag != ConstantPool.INTEGER
&& tag != ConstantPool.FLOAT)
throw new ClassFormatException throw new ClassFormatException
("wrong constant tag: "+tag); ("wrong constant tag: "+tag);
instr = new ConstantInstruction instr = new ConstantInstruction
@ -570,7 +566,7 @@ class BasicBlockReader implements Opcodes {
case opc_ldc2_w: { case opc_ldc2_w: {
int index = input.readUnsignedShort(); int index = input.readUnsignedShort();
int tag = cp.getTag(index); int tag = cp.getTag(index);
if (tag != cp.LONG && tag != cp.DOUBLE) if (tag != ConstantPool.LONG && tag != ConstantPool.DOUBLE)
throw new ClassFormatException throw new ClassFormatException
("wrong constant tag: "+tag); ("wrong constant tag: "+tag);
instr = new ConstantInstruction instr = new ConstantInstruction
@ -680,11 +676,11 @@ class BasicBlockReader implements Opcodes {
int index = input.readUnsignedShort(); int index = input.readUnsignedShort();
int tag = cp.getTag(index); int tag = cp.getTag(index);
if (opcode < opc_invokevirtual) { if (opcode < opc_invokevirtual) {
if (tag != cp.FIELDREF) if (tag != ConstantPool.FIELDREF)
throw new ClassFormatException throw new ClassFormatException
("field tag mismatch: "+tag); ("field tag mismatch: "+tag);
} else { } else {
if (tag != cp.METHODREF) if (tag != ConstantPool.METHODREF)
throw new ClassFormatException throw new ClassFormatException
("method tag mismatch: "+tag); ("method tag mismatch: "+tag);
} }
@ -704,7 +700,7 @@ class BasicBlockReader implements Opcodes {
case opc_invokeinterface: { case opc_invokeinterface: {
int index = input.readUnsignedShort(); int index = input.readUnsignedShort();
int tag = cp.getTag(index); int tag = cp.getTag(index);
if (tag != cp.INTERFACEMETHODREF) if (tag != ConstantPool.INTERFACEMETHODREF)
throw new ClassFormatException throw new ClassFormatException
("interface tag mismatch: "+tag); ("interface tag mismatch: "+tag);
Reference ref = cp.getRef(index); Reference ref = cp.getRef(index);
@ -966,8 +962,8 @@ class BasicBlockReader implements Opcodes {
int nameIndex = input.readUnsignedShort(); int nameIndex = input.readUnsignedShort();
int typeIndex = input.readUnsignedShort(); int typeIndex = input.readUnsignedShort();
int slot = input.readUnsignedShort(); int slot = input.readUnsignedShort();
if (nameIndex == 0 || cp.getTag(nameIndex) != cp.UTF8 if (nameIndex == 0 || cp.getTag(nameIndex) != ConstantPool.UTF8
|| typeIndex == 0 || cp.getTag(typeIndex) != cp.UTF8 || typeIndex == 0 || cp.getTag(typeIndex) != ConstantPool.UTF8
|| slot >= maxLocals) { || slot >= maxLocals) {
// This is probably an evil lvt as created by HashJava // This is probably an evil lvt as created by HashJava

@ -25,8 +25,6 @@ import java.util.BitSet;
import java.util.Stack; import java.util.Stack;
///#def COLLECTIONS java.util ///#def COLLECTIONS java.util
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
///#enddef ///#enddef
/** /**
@ -382,17 +380,18 @@ class BasicBlockWriter implements Opcodes {
case opc_getfield: case opc_getfield:
case opc_putstatic: case opc_putstatic:
case opc_putfield: case opc_putfield:
gcp.putRef(gcp.FIELDREF, instr.getReference()); gcp.putRef(ConstantPool.FIELDREF, instr.getReference());
length = 3; length = 3;
break; break;
case opc_invokespecial: case opc_invokespecial:
case opc_invokestatic: case opc_invokestatic:
case opc_invokevirtual: case opc_invokevirtual:
gcp.putRef(gcp.METHODREF, instr.getReference()); gcp.putRef(ConstantPool.METHODREF, instr.getReference());
length = 3; length = 3;
break; break;
case opc_invokeinterface: case opc_invokeinterface:
gcp.putRef(gcp.INTERFACEMETHODREF, instr.getReference()); gcp.putRef(ConstantPool.INTERFACEMETHODREF,
instr.getReference());
length = 5; length = 5;
break; break;
case opc_new: case opc_new:
@ -880,7 +879,7 @@ class BasicBlockWriter implements Opcodes {
case opc_putstatic: case opc_putstatic:
case opc_putfield: case opc_putfield:
output.writeByte(opcode); output.writeByte(opcode);
output.writeShort(gcp.putRef(gcp.FIELDREF, output.writeShort(gcp.putRef(ConstantPool.FIELDREF,
instr.getReference())); instr.getReference()));
break; break;
@ -892,13 +891,13 @@ class BasicBlockWriter implements Opcodes {
output.writeByte(opcode); output.writeByte(opcode);
if (opcode == opc_invokeinterface) { if (opcode == opc_invokeinterface) {
output.writeShort output.writeShort
(gcp.putRef(gcp.INTERFACEMETHODREF, ref)); (gcp.putRef(ConstantPool.INTERFACEMETHODREF, ref));
output.writeByte output.writeByte
(TypeSignature (TypeSignature
.getParameterSize(ref.getType()) + 1); .getParameterSize(ref.getType()) + 1);
output.writeByte(0); output.writeByte(0);
} else } else
output.writeShort(gcp.putRef(gcp.METHODREF, ref)); output.writeShort(gcp.putRef(ConstantPool.METHODREF, ref));
break; break;
} }
case opc_new: case opc_new:

@ -32,10 +32,6 @@ import java.util.Stack;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException;
///#enddef
///#def COLLECTIONEXTRA java.lang
import java.lang.UnsupportedOperationException;
///#enddef ///#enddef
/** /**
@ -187,8 +183,6 @@ public class BasicBlocks extends BinaryInfo implements Opcodes {
BitSet visited = new BitSet(); BitSet visited = new BitSet();
Stack todo = new Stack(); Stack todo = new Stack();
int[] poppush = new int[2];
startBlock.stackHeight = 0; startBlock.stackHeight = 0;
todo.push(startBlock); todo.push(startBlock);
while (!todo.isEmpty()) { while (!todo.isEmpty()) {

@ -20,12 +20,6 @@
package net.sf.jode.bytecode; package net.sf.jode.bytecode;
import java.io.PrintWriter; import java.io.PrintWriter;
///#def COLLECTIONS java.util
import java.util.Collection;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
///#enddef
/** /**
* <p>Represents a single basic block. It contains a list of * <p>Represents a single basic block. It contains a list of

@ -24,7 +24,7 @@ package net.sf.jode.bytecode;
* *
* @author Jochen Hoenicke * @author Jochen Hoenicke
*/ */
public class ClassFormatException extends java.io.IOException{ public class ClassFormatException extends java.io.IOException {
/** /**
* Constructs a new class format exception with the given detail * Constructs a new class format exception with the given detail
* message. * message.

@ -19,10 +19,8 @@
package net.sf.jode.bytecode; package net.sf.jode.bytecode;
import net.sf.jode.GlobalOptions; import net.sf.jode.GlobalOptions;
import net.sf.jode.util.UnifyHash;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.BufferedInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.IOException; import java.io.IOException;

@ -25,7 +25,6 @@ import java.io.DataInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FilterInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -36,7 +35,6 @@ import java.net.URLConnection;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector; import java.util.Vector;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
@ -288,7 +286,6 @@ public class ClassPath {
if (!directory.endsWith(File.separator)) if (!directory.endsWith(File.separator))
directory += File.separator; directory += File.separator;
final String prefix = directory;
return new Enumeration() { return new Enumeration() {
int i = 0; int i = 0;
public boolean hasMoreElements() { public boolean hasMoreElements() {

@ -18,7 +18,6 @@
*/ */
package net.sf.jode.bytecode; package net.sf.jode.bytecode;
import net.sf.jode.util.StringQuoter;
/** /**
* This class represents an instruction in the byte code. * This class represents an instruction in the byte code.

@ -18,7 +18,6 @@
*/ */
package net.sf.jode.bytecode; package net.sf.jode.bytecode;
import net.sf.jode.util.UnifyHash;
///#def COLLECTIONS java.util ///#def COLLECTIONS java.util
import java.util.Map; import java.util.Map;
///#enddef ///#enddef
@ -344,6 +343,49 @@ public class TypeSignature {
return methodTypeSig.substring(methodTypeSig.lastIndexOf(')')+1); return methodTypeSig.substring(methodTypeSig.lastIndexOf(')')+1);
} }
/**
* Gets the names and types of the generic parameters of the given type signature.
* @param typeSig the type signature.
* @return an array containing all generic parameters together with their
* type in correct order, or null if there aren't any generic parameters.
*/
public static String[] getGenericSignatures(String typeSig) {
System.err.println(typeSig);
if (typeSig.charAt(0) != '<')
return null;
int pos = 1;
int count = 0;
while (typeSig.charAt(pos) != '>') {
while (typeSig.charAt(pos) != ':')
pos++;
/* check for empty entry */
if (typeSig.charAt(pos+1) == ':')
pos++;
while (typeSig.charAt(pos) == ':') {
/* skip colon and type */
pos = skipType(typeSig, pos + 1);
}
count++;
}
String[] params = new String[count];
pos = 1;
count = 0;
while (typeSig.charAt(pos) != '>') {
int spos = pos;
while (typeSig.charAt(pos) != ':')
pos++;
/* check for empty entry */
if (typeSig.charAt(pos+1) == ':')
pos++;
while (typeSig.charAt(pos) == ':') {
/* skip colon and type */
pos = skipType(typeSig, pos + 1);
}
params[count++] = typeSig.substring(spos, pos);
}
return params;
}
/** /**
* Gets the names of the generic parameters of the given type signature. * Gets the names of the generic parameters of the given type signature.
* @param typeSig the type signature. * @param typeSig the type signature.

@ -24,6 +24,7 @@ import java.awt.Graphics;
import java.awt.Insets; import java.awt.Insets;
public class Applet extends java.applet.Applet { public class Applet extends java.applet.Applet {
private static final long serialVersionUID = -132941289170424862L;
private final int BORDER = 10; private final int BORDER = 10;
private final int BEVEL = 2; private final int BEVEL = 2;
private Window jodeWin = new Window(this); private Window jodeWin = new Window(this);

@ -21,11 +21,14 @@ package net.sf.jode.decompiler;
import net.sf.jode.GlobalOptions; import net.sf.jode.GlobalOptions;
import net.sf.jode.type.MethodType; import net.sf.jode.type.MethodType;
import net.sf.jode.type.Type; import net.sf.jode.type.Type;
import net.sf.jode.type.GenericParameterType;
import net.sf.jode.type.ClassType;
import net.sf.jode.bytecode.ClassFormatException; import net.sf.jode.bytecode.ClassFormatException;
import net.sf.jode.bytecode.ClassInfo; import net.sf.jode.bytecode.ClassInfo;
import net.sf.jode.bytecode.ClassPath; import net.sf.jode.bytecode.ClassPath;
import net.sf.jode.bytecode.FieldInfo; import net.sf.jode.bytecode.FieldInfo;
import net.sf.jode.bytecode.MethodInfo; import net.sf.jode.bytecode.MethodInfo;
import net.sf.jode.bytecode.TypeSignature;
import net.sf.jode.expr.Expression; import net.sf.jode.expr.Expression;
import net.sf.jode.expr.ThisOperator; import net.sf.jode.expr.ThisOperator;
import net.sf.jode.flow.TransformConstructors; import net.sf.jode.flow.TransformConstructors;
@ -33,6 +36,8 @@ import net.sf.jode.flow.StructuredBlock;
import net.sf.jode.util.SimpleSet; import net.sf.jode.util.SimpleSet;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Vector; import java.util.Vector;
import java.util.Enumeration; import java.util.Enumeration;
@ -96,27 +101,29 @@ public class ClassAnalyzer
throws ClassFormatException, IOException throws ClassFormatException, IOException
{ {
clazz.load(ClassInfo.ALL); clazz.load(ClassInfo.ALL);
String signatures = clazz.getSignature(); String signature = clazz.getSignature();
if (signatures.charAt(0) == '<') { if (signature.charAt(0) == '<') {
String[] genericSignatures = signature.getGenericNames(); String[] genericSignatures = TypeSignature.getGenericSignatures(signature);
generics = new String[genericSignatures.length]; generics = new String[genericSignatures.length];
genericTypes = new Type[genericSignatures.length];
for (int i = 0; i < generics.length; i++) { for (int i = 0; i < generics.length; i++) {
int colon = genericSignatures[i].charAt(':'); int colon = genericSignatures[i].indexOf(':');
String genName; String genName;
if (colon == -1) { if (colon == -1) {
generics[i] = genericSignatures[i]; generics[i] = genericSignatures[i];
genericType[i] = genericTypes[i] =
new GenericParameterType(genericSignatures[i], new GenericParameterType(genericSignatures[i],
Type.tObject, Type.tObject,
new ClassType[0]); new ClassType[0]);
} else { } else {
generics[i] = genericSignatures[i].substring(0, colon); generics[i] = genericSignatures[i].substring(0, colon);
String remainder = genericSignatures[i].substring(colon+1); String remainder = genericSignatures[i].substring(colon+1);
int nextIndex = remainder.skipType(remainder, 0); int nextIndex = TypeSignature.skipType(remainder, 0);
List superClazzes; List superClazzes = new ArrayList();
for (;;) { for (;;) {
String clazzSig = remainder.substring(0, nextIndex); String clazzSig = remainder.substring(0, nextIndex);
superClazzes.add(Type.tType(clazzSig)); superClazzes.add(Type.tType(clazz.getClassPath(),
clazzSig));
if (nextIndex >= remainder.length()) if (nextIndex >= remainder.length())
break; break;
remainder = remainder.substring(nextIndex+1); remainder = remainder.substring(nextIndex+1);
@ -128,7 +135,7 @@ public class ClassAnalyzer
genSupClass = Type.tObject; genSupClass = Type.tObject;
ClassType[] genSupIfaces = (ClassType[]) ClassType[] genSupIfaces = (ClassType[])
superClazzes.toArray(new ClassType[0]); superClazzes.toArray(new ClassType[0]);
genericType[i] = new GenericParameterType(generics[i], genericTypes[i] = new GenericParameterType(generics[i],
genSupClass, genSupClass,
genSupIfaces); genSupIfaces);
} }

@ -24,7 +24,6 @@ import net.sf.jode.bytecode.ClassInfo;
import java.io.File; import java.io.File;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Writer; import java.io.Writer;
import java.io.BufferedWriter;
/** /**
* This is the interface that other java classes may use to decompile * This is the interface that other java classes may use to decompile

@ -183,7 +183,7 @@ public class FieldAnalyzer implements Analyzer {
| Modifier.STATIC | Modifier.STATIC
| Modifier.FINAL); | Modifier.FINAL);
*/ */
writer.startOp(writer.NO_PAREN, 0); writer.startOp(TabbedPrintWriter.NO_PAREN, 0);
String modif = Modifier.toString(modifiedModifiers); String modif = Modifier.toString(modifiedModifiers);
if (modif.length() > 0) if (modif.length() > 0)
writer.print(modif+" "); writer.print(modif+" ");
@ -193,7 +193,7 @@ public class FieldAnalyzer implements Analyzer {
if (constant != null) { if (constant != null) {
writer.breakOp(); writer.breakOp();
writer.print(" = "); writer.print(" = ");
constant.dumpExpression(writer.IMPL_PAREN, writer); constant.dumpExpression(TabbedPrintWriter.IMPL_PAREN, writer);
} }
writer.endOp(); writer.endOp();
writer.println(";"); writer.println(";");

@ -32,8 +32,6 @@ import javax.swing.tree.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.io.*; import java.io.*;
import java.util.StringTokenizer;
import java.util.ResourceBundle;
import java.util.*; import java.util.*;
public class Main public class Main
@ -147,8 +145,9 @@ public class Main
rightPane.setDividerSize(4); rightPane.setDividerSize(4);
allPane.setDividerLocation(200); allPane.setDividerLocation(200);
allPane.setDividerSize(4); allPane.setDividerSize(4);
decompiler.setErr(new PrintWriter decompiler.setErr(new PrintWriter(System.err));
(new BufferedWriter(new AreaWriter(errorArea)), true)); //new PrintWriter
// (new BufferedWriter(new AreaWriter(errorArea)), true));
} }
public synchronized void valueChanged(TreeSelectionEvent e) { public synchronized void valueChanged(TreeSelectionEvent e) {
@ -250,16 +249,19 @@ public class Main
}; };
try { try {
decompiler.decompile(lastClassName, writer, progListener); decompiler.decompile(lastClassName, writer, progListener);
} catch (Throwable t) { // } catch (Throwable t) {
try { // try {
writer.write(bundle.getString("main.exception")); // writer.write(bundle.getString("main.exception"));
PrintWriter pw = new PrintWriter(writer); // PrintWriter pw = new PrintWriter(writer);
t.printStackTrace(pw); // t.printStackTrace(pw);
pw.flush(); // pw.flush();
} catch (IOException ex) { // } catch (IOException ex) {
/* Shouldn't happen, complain to stderr */ // /* Shouldn't happen, complain to stderr */
ex.printStackTrace(); // ex.printStackTrace();
} // }
} catch (IOException e) {
// TODO Auto-generated catch block
throw (RuntimeException) new RuntimeException().initCause(e);
} finally { } finally {
try { try {
writer.close(); writer.close();

@ -124,7 +124,7 @@ public class ArrayType extends ClassType {
* tArray(x), other -> tError * tArray(x), other -> tError
*/ */
if (type.getTypeCode() == TC_RANGE) { if (type.getTypeCode() == TC_RANGE) {
type = ((RangeType) type).getBottom(); type = ((RangeType) type).getTop();
} }
if (type == tNull) if (type == tNull)
return this; return this;
@ -150,7 +150,7 @@ public class ArrayType extends ClassType {
* tArray(x), other -> tError * tArray(x), other -> tError
*/ */
if (type.getTypeCode() == TC_RANGE) { if (type.getTypeCode() == TC_RANGE) {
type = ((RangeType) type).getTop(); type = ((RangeType) type).getBottom();
} }
if (type == tNull) if (type == tNull)
return this; return this;

@ -20,6 +20,8 @@
package net.sf.jode.type; package net.sf.jode.type;
import net.sf.jode.bytecode.ClassInfo; import net.sf.jode.bytecode.ClassInfo;
import net.sf.jode.bytecode.TypeSignature; import net.sf.jode.bytecode.TypeSignature;
import net.sf.jode.util.SimpleMap;
import net.sf.jode.util.SimpleSet;
import net.sf.jode.GlobalOptions; import net.sf.jode.GlobalOptions;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
@ -30,6 +32,7 @@ import java.util.Hashtable;
///#def COLLECTIONS java.util ///#def COLLECTIONS java.util
import java.util.Map; import java.util.Map;
import java.util.Set;
///#enddef ///#enddef
/** /**
@ -68,22 +71,24 @@ public class ClassInfoType extends ClassType {
return; return;
} }
genInstances = generics; genericInstances = generics;
Map genericMap = new SimpleMap();
if (generics != null) { if (generics != null) {
/* parse generic names */ /* parse generic names */
String[] genNames; String[] genNames;
if (signature.charAt(0) == '<') if (signature.charAt(0) != '<')
genNames = TypeSignature.getGenericNames(signature);
if (genNames == null)
throw new IllegalArgumentException throw new IllegalArgumentException
("Generic parameters for non-generic class"); ("Generic parameters for non-generic class");
genNames = TypeSignature.getGenericNames(signature);
if (generics.length != genNames.length) if (generics.length != genNames.length)
throw new IllegalArgumentException throw new IllegalArgumentException
("Wrong number of generic parameters"); ("Wrong number of generic parameters");
for (int i = 0; i < generics.length; i++)
genericMap.put(genNames[i], generics[i].getTypeSignature());
} }
signature = TypeSignature.mapGenerics(signature, getGenerics()); signature = TypeSignature.mapGenerics(signature, genericMap);
} }
public boolean isUnknown() { public boolean isUnknown() {

@ -18,15 +18,8 @@
*/ */
package net.sf.jode.type; package net.sf.jode.type;
import java.util.Stack;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Enumeration; import java.util.Stack;
import java.io.IOException;
///#def COLLECTIONS java.util
import java.util.Collections;
import java.util.Map;
///#enddef
/** /**
* This class is the base class of all types representing a class type.<p> * This class is the base class of all types representing a class type.<p>
@ -70,7 +63,7 @@ public abstract class ClassType extends ReferenceType {
super(typecode); super(typecode);
className = clazzName; className = clazzName;
genericNames = genNames; genericNames = genNames;
genericTypes = genTypes; genericInstances = genTypes;
} }
/** /**
@ -208,7 +201,7 @@ public abstract class ClassType extends ReferenceType {
*/ */
public Type getSpecializedType(Type type) { public Type getSpecializedType(Type type) {
if (type instanceof RangeType) { if (type instanceof RangeType) {
type = ((RangeType) type).getBottom(); type = ((RangeType) type).getTop();
} }
/* Most times (almost always) one of the two classes is /* Most times (almost always) one of the two classes is
@ -238,7 +231,7 @@ public abstract class ClassType extends ReferenceType {
public Type getGeneralizedType(Type type) { public Type getGeneralizedType(Type type) {
int code = type.typecode; int code = type.typecode;
if (code == TC_RANGE) { if (code == TC_RANGE) {
type = ((RangeType) type).getTop(); type = ((RangeType) type).getBottom();
code = type.typecode; code = type.typecode;
} }
if (code == TC_NULL) if (code == TC_NULL)
@ -270,12 +263,12 @@ public abstract class ClassType extends ReferenceType {
public String toString() public String toString()
{ {
if (genInstances == null) if (genericInstances == null)
return className; return className;
StringBuffer sb = new StringBuffer(className).append('<'); StringBuffer sb = new StringBuffer(className).append('<');
String comma = ""; String comma = "";
for (int i = 0; i < genInstances.length; i++) { for (int i = 0; i < genericInstances.length; i++) {
sb.append(comma).append(genInstances[i].toString()); sb.append(comma).append(genericInstances[i].toString());
} }
sb.append('>'); sb.append('>');
return sb.toString(); return sb.toString();
@ -289,7 +282,7 @@ public abstract class ClassType extends ReferenceType {
public Type getCastHelper(Type fromType) { public Type getCastHelper(Type fromType) {
if (isInterface() || fromType == tNull if (isInterface() || fromType == tNull
|| (fromType instanceof RangeType || (fromType instanceof RangeType
&& ((RangeType)fromType).getBottom() == tNull)) && ((RangeType)fromType).getTop() == tNull))
return null; return null;
Type hint = fromType.getHint(); Type hint = fromType.getHint();
if (hint.isSuperTypeOf(this) if (hint.isSuperTypeOf(this)

@ -154,7 +154,7 @@ public class MultiClassType extends ReferenceType {
*/ */
public Type getSpecializedType(Type type) { public Type getSpecializedType(Type type) {
if (type instanceof RangeType) if (type instanceof RangeType)
type = ((RangeType) type).getBottom(); type = ((RangeType) type).getTop();
/* Most times (almost always) one of the two types is /* Most times (almost always) one of the two types is
* already more specialized. Optimize for this case. * already more specialized. Optimize for this case.
@ -212,7 +212,7 @@ public class MultiClassType extends ReferenceType {
*/ */
public Type getGeneralizedType(Type type) { public Type getGeneralizedType(Type type) {
if (type instanceof RangeType) if (type instanceof RangeType)
type = ((RangeType) type).getTop(); type = ((RangeType) type).getBottom();
/* Often one of the two classes is already more generalized. /* Often one of the two classes is already more generalized.
* Optimize for this case. * Optimize for this case.

@ -55,7 +55,7 @@ public class NullType extends ReferenceType {
*/ */
public Type getGeneralizedType(Type type) { public Type getGeneralizedType(Type type) {
if (type.typecode == TC_RANGE) if (type.typecode == TC_RANGE)
type = ((RangeType) type).getTop(); type = ((RangeType) type).getBottom();
if (type instanceof ReferenceType) if (type instanceof ReferenceType)
return type; return type;
return tError; return tError;
@ -69,7 +69,7 @@ public class NullType extends ReferenceType {
*/ */
public Type getSpecializedType(Type type) { public Type getSpecializedType(Type type) {
if (type.typecode == TC_RANGE) if (type.typecode == TC_RANGE)
type = ((RangeType) type).getBottom(); type = ((RangeType) type).getTop();
if (type != tNull) if (type != tNull)
return tError; return tError;
return tNull; return tNull;

@ -53,25 +53,25 @@ import java.util.Hashtable;
* @date 98/08/06 */ * @date 98/08/06 */
public class RangeType extends Type { public class RangeType extends Type {
/** /**
* The bottom type set. Each type in the set represented by * The top type set. Each type in the set represented by
* this range type can be casted to all types in bottom type. * this range type can be casted to all types in bottom type.
*/ */
final ReferenceType bottomType; final ReferenceType topType;
/** /**
* The top type set. For each type in this range type, there is a * The bottom type set. For each type in this range type, there is a
* top type, that can be casted to this type. * top type, that can be casted to this type.
*/ */
final ReferenceType topType; final ReferenceType bottomType;
/** /**
* Create a new range type with the given bottom and top set. * Create a new range type with the given bottom and top set.
*/ */
RangeType(ReferenceType bottomType, ReferenceType topType) { RangeType(ReferenceType topType, ReferenceType bottomType) {
super(TC_RANGE); super(TC_RANGE);
if (bottomType == tNull) if (topType == tNull)
throw new InternalError("bottom is NULL"); throw new InternalError("top is NULL");
this.bottomType = bottomType;
this.topType = topType; this.topType = topType;
this.bottomType = bottomType;
} }
/** /**
@ -79,17 +79,17 @@ public class RangeType extends Type {
* be casted to all bottom types by a widening cast. * be casted to all bottom types by a widening cast.
* @return the bottom type set * @return the bottom type set
*/ */
ReferenceType getBottom() { ReferenceType getTop() {
return bottomType; return topType;
} }
/** /**
* Returns the top type set. For each type in this range type, * Returns the bottom type set. For each type in this range type,
* there is a top type, that can be casted to this type. * there is a bottom type, that can be casted to this type.
* @return the top type set * @return the bottom type set
*/ */
ReferenceType getTop() { ReferenceType getBottom() {
return topType; return bottomType;
} }
@ -101,13 +101,13 @@ public class RangeType extends Type {
* @return the hint type. * @return the hint type.
*/ */
public Type getHint() { public Type getHint() {
Type bottomHint = bottomType.getHint();
Type topHint = topType.getHint(); Type topHint = topType.getHint();
Type bottomHint = bottomType.getHint();
if (topType == tNull && bottomType.equals(bottomHint)) if (bottomType == tNull && topType.equals(topHint))
return bottomHint;
return topHint; return topHint;
return bottomHint;
} }
/** /**
@ -116,7 +116,7 @@ public class RangeType extends Type {
* @return the canonic type. * @return the canonic type.
*/ */
public Type getCanonic() { public Type getCanonic() {
return topType.getCanonic(); return bottomType.getCanonic();
} }
/** /**
@ -125,7 +125,7 @@ public class RangeType extends Type {
* @return the set of super types. * @return the set of super types.
*/ */
public Type getSuperType() { public Type getSuperType() {
return topType.getSuperType(); return bottomType.getSuperType();
} }
/** /**
@ -134,7 +134,7 @@ public class RangeType extends Type {
* @return the set of super types. * @return the set of super types.
*/ */
public Type getSubType() { public Type getSubType() {
return tRange(bottomType, tNull); return tRange(topType, tNull);
} }
/** /**
@ -143,26 +143,26 @@ public class RangeType extends Type {
* @return the middle type, or null if it is not necessary. * @return the middle type, or null if it is not necessary.
*/ */
public Type getCastHelper(Type fromType) { public Type getCastHelper(Type fromType) {
return topType.getCastHelper(fromType); return bottomType.getCastHelper(fromType);
} }
public String getTypeSignature() { public String getTypeSignature() {
if (topType.isClassType() || !bottomType.isValidType()) if (bottomType.isClassType() || !topType.isValidType())
return topType.getTypeSignature();
else
return bottomType.getTypeSignature(); return bottomType.getTypeSignature();
else
return topType.getTypeSignature();
} }
public Class getTypeClass() throws ClassNotFoundException { public Class getTypeClass() throws ClassNotFoundException {
if (topType.isClassType() || !bottomType.isValidType()) if (bottomType.isClassType() || !topType.isValidType())
return topType.getTypeClass();
else
return bottomType.getTypeClass(); return bottomType.getTypeClass();
else
return topType.getTypeClass();
} }
public String toString() public String toString()
{ {
return "<" + bottomType + "-" + topType + ">"; return "<" + topType + "-" + bottomType + ">";
} }
public String getDefaultName() { public String getDefaultName() {
@ -170,29 +170,29 @@ public class RangeType extends Type {
} }
public int hashCode() { public int hashCode() {
int hashcode = topType.hashCode(); int hashcode = bottomType.hashCode();
return (hashcode << 16 | hashcode >>> 16) ^ bottomType.hashCode(); return (hashcode << 16 | hashcode >>> 16) ^ topType.hashCode();
} }
public boolean equals(Object o) { public boolean equals(Object o) {
if (o instanceof RangeType) { if (o instanceof RangeType) {
RangeType type = (RangeType) o; RangeType type = (RangeType) o;
return topType.equals(type.topType) return bottomType.equals(type.bottomType)
&& bottomType.equals(type.bottomType); && topType.equals(type.topType);
} }
return false; return false;
} }
public boolean containsClass(ClassInfo clazz) { public boolean containsClass(ClassInfo clazz) {
ClassType clazzType = Type.tClass(clazz, null); ClassType clazzType = Type.tClass(clazz, null);
if (!bottomType.maybeSuperTypeOf(clazzType)) if (!topType.maybeSuperTypeOf(clazzType))
return false; return false;
if (topType == tNull) if (bottomType == tNull)
return true; return true;
if (topType instanceof ClassType) if (bottomType instanceof ClassType)
return clazzType.maybeSuperTypeOf((ClassType) topType); return clazzType.maybeSuperTypeOf((ClassType) bottomType);
if (topType instanceof MultiClassType) { if (bottomType instanceof MultiClassType) {
ClassType[] classes = ((MultiClassType) topType).classes; ClassType[] classes = ((MultiClassType) bottomType).classes;
for (int i = 0; i < classes.length; i++) { for (int i = 0; i < classes.length; i++) {
if (clazzType.maybeSuperTypeOf(classes[i])) if (clazzType.maybeSuperTypeOf(classes[i]))
return true; return true;
@ -213,8 +213,8 @@ public class RangeType extends Type {
return this; return this;
Type top, bottom, result; Type top, bottom, result;
bottom = bottomType.getSpecializedType(type); bottom = topType.getSpecializedType(type);
top = topType.getGeneralizedType(type); top = bottomType.getGeneralizedType(type);
if (top.equals(bottom)) if (top.equals(bottom))
result = top; result = top;
else if (top instanceof ReferenceType else if (top instanceof ReferenceType

@ -327,7 +327,7 @@ public class Type {
while (iter.hasNext()) { while (iter.hasNext()) {
ClassInfoType type = (ClassInfoType) iter.next(); ClassInfoType type = (ClassInfoType) iter.next();
if (type.getClassInfo() == clazzinfo if (type.getClassInfo() == clazzinfo
&& Arrays.equals(generics, type.genInstances)) && Arrays.equals(generics, type.genericInstances))
return type; return type;
} }
ClassInfoType type = new ClassInfoType(clazzinfo, generics); ClassInfoType type = new ClassInfoType(clazzinfo, generics);

@ -1,99 +0,0 @@
import jode.bytecode.*;
import java.util.*;
import com.sun.java.util.collections.Iterator;
public class CountOpcodes {
static int[] opcodeCount = new int[256];
static int[] predsCount = new int[1024];
static int[] succsCount = new int[1024];
static Vector instructions = new Vector(73400);
public static void handleBytecode(BytecodeInfo bc) {
for (Iterator i = bc.getInstructions().iterator(); i.hasNext();) {
Instruction instr = (Instruction) i.next();
instructions.addElement(instr);
opcodeCount[instr.getOpcode()]++;
Instruction[] p = instr.getPreds();
if (p == null)
predsCount[0]++;
else
predsCount[p.length]++;
Instruction[] s = instr.getSuccs();
if (s == null)
succsCount[0]++;
else
succsCount[s.length]++;
}
}
public static void handlePackage(String pack) {
Enumeration subs = ClassInfo.getClassesAndPackages(pack);
while (subs.hasMoreElements()) {
String comp = (String) subs.nextElement();
String full = pack + "." + comp;
if (ClassInfo.isPackage(full))
handlePackage(full);
else {
ClassInfo clazz = ClassInfo.forName(full);
clazz.loadInfo(ClassInfo.FULLINFO);
MethodInfo[] ms = clazz.getMethods();
for (int i=0; i < ms.length; i++) {
BytecodeInfo bc = ms[i].getBytecode();
if (bc != null)
handleBytecode(bc);
}
}
}
}
public static void main(String[] params) {
ClassInfo.setClassPath(params[0]);
Runtime runtime = Runtime.getRuntime();
long free = runtime.freeMemory();
long last;
do {
last = free;
runtime.gc();
runtime.runFinalization();
free = runtime.freeMemory();
} while (free < last);
System.err.println("used before: "+(runtime.totalMemory()- free));
long time = System.currentTimeMillis();
handlePackage("com");
System.err.println("Time used: "+(System.currentTimeMillis() - time));
free = runtime.freeMemory();
do {
last = free;
runtime.gc();
runtime.runFinalization();
free = runtime.freeMemory();
} while (free < last);
System.err.println("used after: "+(runtime.totalMemory()- free));
System.err.println("instruction count: "+instructions.size());
for (int i=0; i< 256; i++) {
if (opcodeCount[i] > 0)
System.err.println("Opcode "+i+": \t ("+Opcodes.opcodeString[i]+")\t"+opcodeCount[i]);
}
int moreThanTwo = 0;
for (int i=0; i< predsCount.length; i++) {
if (predsCount[i] > 0) {
System.err.println("preds "+i+": \t"+predsCount[i]);
if (i>1)
moreThanTwo +=predsCount[i];
}
}
System.err.println("preds >2: \t"+moreThanTwo);
moreThanTwo = 0;
for (int i=0; i< succsCount.length; i++) {
if (succsCount[i] > 0) {
System.err.println("succs "+i+": \t"+succsCount[i]);
if (i>1)
moreThanTwo +=succsCount[i];
}
}
System.err.println("succs >2: \t"+moreThanTwo);
}
}

@ -23,12 +23,12 @@
* in a different package to check if inlining works over package borders. * in a different package to check if inlining works over package borders.
* *
* @author Jochen Hoenicke * @author Jochen Hoenicke
* @see jode.test.OptimizeTest * @see OptimizeTest
*/ */
public class InlineTest { public class InlineTest {
public static final int public static final int
difficultSideInline(jode.test.OptimizeTest ot, int a) { difficultSideInline(OptimizeTest ot, int a) {
return ot.g++ + a; return ot.g++ + a;
} }
} }

@ -119,7 +119,7 @@ public class ResolveConflicts
///#endif ///#endif
///#endif ///#endif
///#ifdef JAVAC11 ///#ifdef JAVAC11
return null; /// return null;
///#else ///#else
return ResolveConflicts.this.new Conflicts().new Inner(); return ResolveConflicts.this.new Conflicts().new Inner();
///#endif ///#endif

@ -7,9 +7,10 @@ public class CheckSuperRemove {
Inner anonInner = new Inner() { Inner anonInner = new Inner() {
public void test() {} public void test() {}
}; };
/*FIXME: Understand why this does not work:
MyInner anonInner2 = new MyInner() { MyInner anonInner2 = new MyInner() {
public void test() {} public void test() {}
}; };*/
} }
} }

Loading…
Cancel
Save