use UnifiyHash

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1122 379699f6-c40d-0410-875b-85095c16579e
branch_1_1
jochen 25 years ago
parent fccee54533
commit 1cfa18f43c
  1. 111
      jode/jode/type/Type.java.in

@ -21,14 +21,9 @@ package jode.type;
import jode.AssertError; import jode.AssertError;
import jode.GlobalOptions; import jode.GlobalOptions;
import jode.bytecode.ClassInfo; import jode.bytecode.ClassInfo;
///#ifdef JDK12 import jode.util.UnifyHash;
///import java.lang.ref.WeakReference;
///import java.lang.ref.ReferenceQueue; import @COLLECTIONS@.Iterator;
///import java.util.Map;
///import java.util.HashMap;
///#else
import java.util.Hashtable;
///#endif
/** /**
* This is my type class. It differs from java.lang.class, in that it * This is my type class. It differs from java.lang.class, in that it
@ -58,18 +53,9 @@ public class Type {
public static final int TC_RANGE = 103; public static final int TC_RANGE = 103;
public static final int TC_INTEGER = 107; public static final int TC_INTEGER = 107;
///#ifdef JDK12 private static final UnifyHash classHash = new UnifyHash();
/// private static final Map classHash = new HashMap(); private static final UnifyHash arrayHash = new UnifyHash();
/// private static final ReferenceQueue classQueue = new ReferenceQueue(); private static final UnifyHash methodHash = new UnifyHash();
/// private static final Map arrayHash = new HashMap();
/// private static final ReferenceQueue arrayQueue = new ReferenceQueue();
/// private static final Map methodHash = new HashMap();
/// private static final ReferenceQueue methodQueue = new ReferenceQueue();
///#else
private static final Hashtable classHash = new Hashtable();
private static final Hashtable arrayHash = new Hashtable();
private static final Hashtable methodHash = new Hashtable();
///#endif
/** /**
* This type represents the singleton set containing the boolean type. * This type represents the singleton set containing the boolean type.
@ -234,24 +220,16 @@ public class Type {
* @return a singleton set containing the given type. * @return a singleton set containing the given type.
*/ */
public static final ClassInterfacesType tClass(ClassInfo clazzinfo) { public static final ClassInterfacesType tClass(ClassInfo clazzinfo) {
///#ifdef JDK12 int hash = clazzinfo.hashCode();
/// java.lang.ref.Reference died; Iterator iter = classHash.iterateHashCode(hash);
/// while ((died = classQueue.poll()) != null) while (iter.hasNext()) {
/// classHash.values().remove(died); ClassInterfacesType type = (ClassInterfacesType) iter.next();
/// WeakReference ref = (WeakReference) classHash.get(clazzinfo); if (type.getClassInfo() == clazzinfo)
/// Object result = (ref == null) ? null : ref.get(); return type;
///#else }
Object result = classHash.get(clazzinfo); ClassInterfacesType type = new ClassInterfacesType(clazzinfo);
///#endif classHash.put(hash, type);
if (result == null) { return type;
result = new ClassInterfacesType(clazzinfo);
///#ifdef JDK12
/// classHash.put(clazzinfo, new WeakReference(result, classQueue));
///#else
classHash.put(clazzinfo, result);
///#endif
}
return (ClassInterfacesType) result;
} }
/** /**
@ -263,24 +241,17 @@ public class Type {
public static final Type tArray(Type type) { public static final Type tArray(Type type) {
if (type == tError) if (type == tError)
return type; return type;
///#ifdef JDK12
/// java.lang.ref.Reference died; int hash = type.hashCode();
/// while ((died = arrayQueue.poll()) != null) Iterator iter = arrayHash.iterateHashCode(hash);
/// arrayHash.values().remove(died); while (iter.hasNext()) {
/// WeakReference ref = (WeakReference) arrayHash.get(type); ArrayType arrType = (ArrayType) iter.next();
/// Type result = (ref == null) ? null : (Type) ref.get(); if (arrType.getElementType().equals(type))
///#else return arrType;
Type result = (Type) arrayHash.get(type); }
///#endif ArrayType arrType = new ArrayType(type);
if (result == null) { arrayHash.put(hash, arrType);
result = new ArrayType(type); return arrType;
///#ifdef JDK12
/// arrayHash.put(type, new WeakReference(result, arrayQueue));
///#else
arrayHash.put(type, result);
///#endif
}
return result;
} }
/** /**
@ -289,24 +260,16 @@ public class Type {
* @return a method type (a singleton set). * @return a method type (a singleton set).
*/ */
public static MethodType tMethod(String signature) { public static MethodType tMethod(String signature) {
///#ifdef JDK12 int hash = signature.hashCode();
/// java.lang.ref.Reference died; Iterator iter = methodHash.iterateHashCode(hash);
/// while ((died = methodQueue.poll()) != null) while (iter.hasNext()) {
/// methodHash.values().remove(died); MethodType methodType = (MethodType) iter.next();
/// WeakReference ref = (WeakReference) methodHash.get(signature); if (methodType.getTypeSignature().equals(signature))
/// MethodType result = (ref == null) ? null : (MethodType) ref.get(); return methodType;
///#else }
MethodType result = (MethodType) methodHash.get(signature); MethodType methodType = new MethodType(signature);
///#endif methodHash.put(hash, methodType);
if (result == null) { return methodType;
result = new MethodType(signature);
///#ifdef JDK12
/// methodHash.put(signature, new WeakReference(result, methodQueue));
///#else
methodHash.put(signature, result);
///#endif
}
return result;
} }
/** /**
Loading…
Cancel
Save